-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from smartdevicelink/feature/streaming_media_…
…manager Streaming Media Manager Updates
- Loading branch information
Showing
48 changed files
with
2,874 additions
and
1,170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// CVPixelBufferRef+SDLUtil.h | ||
// SmartDeviceLink-iOS | ||
// | ||
// Created by Muller, Alexander (A.) on 3/16/17. | ||
// Copyright © 2017 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <CoreVideo/CVPixelBuffer.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
Take a CVPixelBuffer frame and append some text onto it, attempting to fit it to the rect. This is used for a "blank" screen when streaming navigation is pushed to the background or otherwise disabled in progress. | ||
@param pixelBuffer The pixel buffer to draw text over | ||
@param text The text to draw | ||
@return Whether or not it succeeded. | ||
*/ | ||
Boolean CVPixelBufferAddText(CVPixelBufferRef CV_NONNULL pixelBuffer, NSString *text); | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// CVPixelBufferRef+SDLUtil.m | ||
// SmartDeviceLink-iOS | ||
// | ||
// Created by Muller, Alexander (A.) on 3/16/17. | ||
// Copyright © 2017 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import "CVPixelBufferRef+SDLUtil.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
UIFont * _Nullable sdl_findFontSizeToFitText(CGSize size, NSString *text) { | ||
CGFloat fontSize = 100; | ||
|
||
do { | ||
CGSize textSize = [text boundingRectWithSize:CGSizeMake(size.width, CGFLOAT_MAX) | ||
options:NSStringDrawingUsesLineFragmentOrigin | ||
attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:fontSize]} | ||
context:nil].size; | ||
|
||
if (textSize.height <= size.height) { | ||
break; | ||
} | ||
|
||
fontSize -= 10.0; | ||
} while (fontSize > 0.0); | ||
|
||
return (fontSize > 0) ? [UIFont boldSystemFontOfSize:fontSize] : nil; | ||
} | ||
|
||
UIImage * _Nullable sdl_createTextImage(NSString *text, CGSize size) { | ||
UIFont *font = sdl_findFontSizeToFitText(size, text); | ||
|
||
if (!font) { | ||
NSLog(@"Text cannot fit inside frame"); | ||
return nil; | ||
} | ||
|
||
CGRect frame = CGRectMake(0, 0, size.width, size.height); | ||
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 1.0); | ||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
|
||
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); | ||
CGContextFillRect(context, frame); | ||
CGContextSaveGState(context); | ||
|
||
NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy; | ||
textStyle.alignment = NSTextAlignmentCenter; | ||
|
||
NSDictionary* textAttributes = @{ | ||
NSFontAttributeName: font, | ||
NSForegroundColorAttributeName: [UIColor whiteColor], | ||
NSParagraphStyleAttributeName: textStyle | ||
}; | ||
CGRect textFrame = [text boundingRectWithSize:size | ||
options:NSStringDrawingUsesLineFragmentOrigin | ||
attributes:textAttributes | ||
context:nil]; | ||
|
||
CGRect textInset = CGRectMake(0, | ||
(frame.size.height - CGRectGetHeight(textFrame)) / 2.0, | ||
frame.size.width, | ||
frame.size.height); | ||
|
||
[text drawInRect:textInset | ||
withAttributes:textAttributes]; | ||
|
||
CGContextRestoreGState(context); | ||
UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); | ||
|
||
return image; | ||
} | ||
|
||
Boolean CVPixelBufferAddText(CVPixelBufferRef CV_NONNULL pixelBuffer, NSString *text) { | ||
size_t width = CVPixelBufferGetWidth(pixelBuffer); | ||
size_t height = CVPixelBufferGetHeight(pixelBuffer); | ||
|
||
UIImage *image = sdl_createTextImage(text, CGSizeMake(width, height)); | ||
if (!image) { | ||
NSLog(@"Could not create text image."); | ||
return false; | ||
} | ||
|
||
CVPixelBufferLockBaseAddress(pixelBuffer, 0); | ||
void *data = CVPixelBufferGetBaseAddress(pixelBuffer); | ||
|
||
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); | ||
CGContextRef context = CGBitmapContextCreate(data, width, height, | ||
8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace, | ||
kCGBitmapByteOrder32Little | | ||
kCGImageAlphaPremultipliedFirst); | ||
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage); | ||
CGColorSpaceRelease(rgbColorSpace); | ||
|
||
CGContextRelease(context); | ||
|
||
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); | ||
|
||
return true; | ||
} | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.