ObjC style fix for injectable video codecs

This CL fixes some ObjC style issues from CL
https://codereview.webrtc.org/2977213002/.

BUG=webrtc:7924

Review-Url: https://codereview.webrtc.org/2989803002
Cr-Commit-Position: refs/heads/master@{#19186}
This commit is contained in:
magjed
2017-07-31 02:56:35 -07:00
committed by Commit Bot
parent 654c73ef90
commit 8eab09c77b
10 changed files with 37 additions and 35 deletions

View File

@ -51,7 +51,7 @@
return self;
}
- (webrtc::EncodedImage)toCpp {
- (webrtc::EncodedImage)nativeEncodedImage {
// Return the pointer without copying.
webrtc::EncodedImage encodedImage(
(uint8_t *)_buffer.bytes, (size_t)_buffer.length, (size_t)_buffer.length);

View File

@ -19,7 +19,7 @@
@synthesize fragmentationTimeDiff = _fragmentationTimeDiff;
@synthesize fragmentationPlType = _fragmentationPlType;
- (instancetype)initWithFragmentationHeader:
- (instancetype)initWithNativeFragmentationHeader:
(const webrtc::RTPFragmentationHeader *)fragmentationHeader {
if (self = [super init]) {
if (fragmentationHeader) {
@ -44,7 +44,7 @@
return self;
}
- (std::unique_ptr<webrtc::RTPFragmentationHeader>)toCpp {
- (std::unique_ptr<webrtc::RTPFragmentationHeader>)createNativeFragmentationHeader {
auto fragmentationHeader =
std::unique_ptr<webrtc::RTPFragmentationHeader>(new webrtc::RTPFragmentationHeader);
fragmentationHeader->VerifyAndAllocateFragmentationHeader(_fragmentationOffset.count);

View File

@ -22,35 +22,35 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTCEncodedImage ()
- (instancetype)initWithNativeEncodedImage:(webrtc::EncodedImage)encodedImage;
- (webrtc::EncodedImage)toCpp;
- (webrtc::EncodedImage)nativeEncodedImage;
@end
@interface RTCVideoEncoderSettings ()
- (instancetype)initWithVideoCodec:(const webrtc::VideoCodec *__nullable)videoCodec;
- (std::unique_ptr<webrtc::VideoCodec>)toCpp;
- (instancetype)initWithNativeVideoCodec:(const webrtc::VideoCodec *__nullable)videoCodec;
- (std::unique_ptr<webrtc::VideoCodec>)createNativeVideoEncoderSettings;
@end
@interface RTCCodecSpecificInfoH264 ()
- (webrtc::CodecSpecificInfo)toCpp;
- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo;
@end
@interface RTCRtpFragmentationHeader ()
- (instancetype)initWithFragmentationHeader:
- (instancetype)initWithNativeFragmentationHeader:
(const webrtc::RTPFragmentationHeader *__nullable)fragmentationHeader;
- (std::unique_ptr<webrtc::RTPFragmentationHeader>)toCpp;
- (std::unique_ptr<webrtc::RTPFragmentationHeader>)createNativeFragmentationHeader;
@end
@interface RTCVideoCodecInfo ()
- (instancetype)initWithVideoCodec:(cricket::VideoCodec)videoCodec;
- (cricket::VideoCodec)toCpp;
- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec;
- (cricket::VideoCodec)nativeVideoCodec;
@end

View File

@ -32,7 +32,7 @@
return self;
}
- (instancetype)initWithVideoCodec:(cricket::VideoCodec)videoCodec {
- (instancetype)initWithNativeVideoCodec:(cricket::VideoCodec)videoCodec {
NSMutableDictionary *params = [NSMutableDictionary dictionary];
for (auto it = videoCodec.params.begin(); it != videoCodec.params.end(); ++it) {
[params setObject:[NSString stringForStdString:it->second]
@ -43,7 +43,7 @@
parameters:params];
}
- (cricket::VideoCodec)toCpp {
- (cricket::VideoCodec)nativeVideoCodec {
cricket::VideoCodec codec([NSString stdStringForString:_name]);
for (NSString *paramKey in _parameters.allKeys) {
codec.SetParam([NSString stdStringForString:paramKey],

View File

@ -36,7 +36,7 @@ bool IsHighProfileEnabled() {
@synthesize packetizationMode = _packetizationMode;
- (webrtc::CodecSpecificInfo)toCpp {
- (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo {
webrtc::CodecSpecificInfo codecSpecificInfo;
codecSpecificInfo.codecType = webrtc::kVideoCodecH264;
codecSpecificInfo.codec_name = "H264";
@ -62,7 +62,7 @@ class H264VideoToolboxEncodeCompleteCallback : public webrtc::EncodedImageCallba
(RTCH264PacketizationMode)codec_specific_info->codecSpecific.H264.packetization_mode;
RTCRtpFragmentationHeader *header =
[[RTCRtpFragmentationHeader alloc] initWithFragmentationHeader:fragmentation];
[[RTCRtpFragmentationHeader alloc] initWithNativeFragmentationHeader:fragmentation];
callback(image, info, header);
return Result(Result::OK, 0);
@ -105,7 +105,7 @@ class H264VideoToolboxDecodeCompleteCallback : public webrtc::DecodedImageCallba
- (instancetype)initWithCodecInfo:(RTCVideoCodecInfo *)codecInfo {
if (self = [super init]) {
cricket::VideoCodec codec = [codecInfo toCpp];
cricket::VideoCodec codec = [codecInfo nativeVideoCodec];
_videoToolboxEncoder = new webrtc::H264VideoToolboxEncoder(codec);
}
return self;
@ -133,7 +133,7 @@ class H264VideoToolboxDecodeCompleteCallback : public webrtc::DecodedImageCallba
- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
numberOfCores:(int)numberOfCores {
std::unique_ptr<webrtc::VideoCodec> codecSettings = [settings toCpp];
std::unique_ptr<webrtc::VideoCodec> codecSettings = [settings createNativeVideoEncoderSettings];
return _videoToolboxEncoder->InitEncode(
codecSettings.release(), numberOfCores, kDefaultPayloadSize);
}
@ -155,7 +155,7 @@ class H264VideoToolboxDecodeCompleteCallback : public webrtc::DecodedImageCallba
// Handle types than can be converted into one of webrtc::CodecSpecificInfo's hard coded cases.
webrtc::CodecSpecificInfo codecSpecificInfo;
if ([info isKindOfClass:[RTCCodecSpecificInfoH264 class]]) {
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info toCpp];
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info nativeCodecSpecificInfo];
}
std::vector<webrtc::FrameType> nativeFrameTypes;
@ -189,7 +189,7 @@ class H264VideoToolboxDecodeCompleteCallback : public webrtc::DecodedImageCallba
- (NSInteger)startDecodeWithSettings:(RTCVideoEncoderSettings *)settings
numberOfCores:(int)numberOfCores {
std::unique_ptr<webrtc::VideoCodec> codecSettings = [settings toCpp];
std::unique_ptr<webrtc::VideoCodec> codecSettings = [settings createNativeVideoEncoderSettings];
return _videoToolboxDecoder->InitDecode(codecSettings.release(), numberOfCores);
}
@ -222,15 +222,16 @@ class H264VideoToolboxDecodeCompleteCallback : public webrtc::DecodedImageCallba
fragmentationHeader:(RTCRtpFragmentationHeader *)fragmentationHeader
codecSpecificInfo:(__nullable id<RTCCodecSpecificInfo>)info
renderTimeMs:(int64_t)renderTimeMs {
webrtc::EncodedImage image = [encodedImage toCpp];
webrtc::EncodedImage image = [encodedImage nativeEncodedImage];
// Handle types than can be converted into one of webrtc::CodecSpecificInfo's hard coded cases.
webrtc::CodecSpecificInfo codecSpecificInfo;
if ([info isKindOfClass:[RTCCodecSpecificInfoH264 class]]) {
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info toCpp];
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info nativeCodecSpecificInfo];
}
std::unique_ptr<webrtc::RTPFragmentationHeader> header = [fragmentationHeader toCpp];
std::unique_ptr<webrtc::RTPFragmentationHeader> header =
[fragmentationHeader createNativeFragmentationHeader];
return _videoToolboxDecoder->Decode(
image, missingFrames, header.release(), &codecSpecificInfo, renderTimeMs);

View File

@ -26,7 +26,7 @@
@synthesize maxFramerate = _maxFramerate;
@synthesize qpMax = _qpMax;
- (instancetype)initWithVideoCodec:(const webrtc::VideoCodec *__nullable)videoCodec {
- (instancetype)initWithNativeVideoCodec:(const webrtc::VideoCodec *)videoCodec {
if (self = [super init]) {
if (videoCodec) {
rtc::Optional<const char *> codecName = CodecTypeToPayloadName(videoCodec->codecType);
@ -48,7 +48,7 @@
return self;
}
- (std::unique_ptr<webrtc::VideoCodec>)toCpp {
- (std::unique_ptr<webrtc::VideoCodec>)createNativeVideoEncoderSettings {
auto codecSettings = std::unique_ptr<webrtc::VideoCodec>(new webrtc::VideoCodec);
rtc::Optional<webrtc::VideoCodecType> codecType =

View File

@ -35,7 +35,7 @@ class ObjCVideoDecoder : public VideoDecoder {
int32_t InitDecode(const VideoCodec *codec_settings, int32_t number_of_cores) {
RTCVideoEncoderSettings *settings =
[[RTCVideoEncoderSettings alloc] initWithVideoCodec:codec_settings];
[[RTCVideoEncoderSettings alloc] initWithNativeVideoCodec:codec_settings];
return [decoder_ startDecodeWithSettings:settings numberOfCores:number_of_cores];
}
@ -47,7 +47,7 @@ class ObjCVideoDecoder : public VideoDecoder {
RTCEncodedImage *encodedImage =
[[RTCEncodedImage alloc] initWithNativeEncodedImage:input_image];
RTCRtpFragmentationHeader *header =
[[RTCRtpFragmentationHeader alloc] initWithFragmentationHeader:fragmentation];
[[RTCRtpFragmentationHeader alloc] initWithNativeFragmentationHeader:fragmentation];
// webrtc::CodecSpecificInfo only handles a hard coded list of codecs
id<RTCCodecSpecificInfo> rtcCodecSpecificInfo = nil;

View File

@ -39,7 +39,7 @@ class ObjCVideoEncoder : public VideoEncoder {
int32_t number_of_cores,
size_t max_payload_size) {
RTCVideoEncoderSettings *settings =
[[RTCVideoEncoderSettings alloc] initWithVideoCodec:codec_settings];
[[RTCVideoEncoderSettings alloc] initWithNativeVideoCodec:codec_settings];
return [encoder_ startEncodeWithSettings:settings numberOfCores:number_of_cores];
}
@ -47,16 +47,17 @@ class ObjCVideoEncoder : public VideoEncoder {
[encoder_ setCallback:^(RTCEncodedImage *frame,
id<RTCCodecSpecificInfo> info,
RTCRtpFragmentationHeader *header) {
EncodedImage encodedImage = [frame toCpp];
EncodedImage encodedImage = [frame nativeEncodedImage];
// Handle types than can be converted into one of webrtc::CodecSpecificInfo's hard coded
// cases.
CodecSpecificInfo codecSpecificInfo;
if ([info isKindOfClass:[RTCCodecSpecificInfoH264 class]]) {
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info toCpp];
codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info nativeCodecSpecificInfo];
}
std::unique_ptr<webrtc::RTPFragmentationHeader> fragmentationHeader = [header toCpp];
std::unique_ptr<webrtc::RTPFragmentationHeader> fragmentationHeader =
[header createNativeFragmentationHeader];
callback->OnEncodedImage(encodedImage, &codecSpecificInfo, fragmentationHeader.release());
}];
@ -126,7 +127,7 @@ id<RTCVideoEncoderFactory> ObjCVideoEncoderFactory::wrapped_encoder_factory() co
webrtc::VideoEncoder *ObjCVideoEncoderFactory::CreateVideoEncoder(
const cricket::VideoCodec &codec) {
RTCVideoCodecInfo *info = [[RTCVideoCodecInfo alloc] initWithVideoCodec:codec];
RTCVideoCodecInfo *info = [[RTCVideoCodecInfo alloc] initWithNativeVideoCodec:codec];
id<RTCVideoEncoder> encoder = [encoder_factory_ createEncoder:info];
return new ObjCVideoEncoder(encoder);
}
@ -134,7 +135,7 @@ webrtc::VideoEncoder *ObjCVideoEncoderFactory::CreateVideoEncoder(
const std::vector<cricket::VideoCodec> &ObjCVideoEncoderFactory::supported_codecs() const {
supported_codecs_.clear();
for (RTCVideoCodecInfo *supportedCodec in encoder_factory_.supportedCodecs) {
cricket::VideoCodec codec = [supportedCodec toCpp];
cricket::VideoCodec codec = [supportedCodec nativeVideoCodec];
supported_codecs_.push_back(codec);
}

View File

@ -24,8 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
@class RTCVideoSource;
@class RTCVideoTrack;
@protocol RTCPeerConnectionDelegate;
@protocol RTCVideoEncoderFactory;
@protocol RTCVideoDecoderFactory;
@protocol RTCVideoEncoderFactory;
RTC_EXPORT
@interface RTCPeerConnectionFactory : NSObject

View File

@ -39,7 +39,7 @@ RTC_EXPORT
@property(nonatomic, assign) RTCFrameType frameType;
@property(nonatomic, assign) int rotation;
@property(nonatomic, assign) BOOL completeFrame;
@property(nonatomic, retain) NSNumber *qp;
@property(nonatomic, strong) NSNumber *qp;
@end
@ -88,7 +88,7 @@ RTC_EXPORT
RTC_EXPORT
@interface RTCVideoEncoderSettings : NSObject
@property(nonatomic, retain) NSString *name;
@property(nonatomic, strong) NSString *name;
@property(nonatomic, assign) unsigned short width;
@property(nonatomic, assign) unsigned short height;