| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #import "WebRTC/RTCVideoCodecH264.h" | 11 #import "WebRTC/RTCVideoCodecH264.h" |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #import "RTCVideoCodec+Private.h" | 15 #import "RTCVideoCodec+Private.h" |
| 16 #import "WebRTC/RTCVideoCodec.h" | 16 #import "WebRTC/RTCVideoCodec.h" |
| 17 #import "WebRTC/RTCVideoFrame.h" | 17 #import "WebRTC/RTCVideoFrame.h" |
| 18 #import "WebRTC/RTCVideoFrameBuffer.h" | 18 #import "WebRTC/RTCVideoFrameBuffer.h" |
| 19 | 19 |
| 20 #include "webrtc/rtc_base/timeutils.h" | 20 #include "webrtc/rtc_base/timeutils.h" |
| 21 #include "webrtc/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h" | 21 #include "webrtc/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h" |
| 22 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h" | 22 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h" |
| 23 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h" | 23 #include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h" |
| 24 #include "webrtc/system_wrappers/include/field_trial.h" | 24 #include "webrtc/system_wrappers/include/field_trial.h" |
| 25 | 25 |
| 26 const size_t kDefaultPayloadSize = 1440; | 26 const size_t kDefaultPayloadSize = 1440; |
| 27 | 27 |
| 28 const char kHighProfileExperiment[] = "WebRTC-H264HighProfile"; | 28 const char kHighProfileExperiment[] = "WebRTC-H264HighProfile"; |
| 29 | 29 |
| 30 // These thresholds deviate from the default h264 QP thresholds, as they have be
en found to work |
| 31 // better on devices that support VideoToolbox |
| 32 const int kLowH264QpThreshold = 28; |
| 33 const int kHighH264QpThreshold = 39; |
| 34 |
| 30 bool IsHighProfileEnabled() { | 35 bool IsHighProfileEnabled() { |
| 31 return webrtc::field_trial::IsEnabled(kHighProfileExperiment); | 36 return webrtc::field_trial::IsEnabled(kHighProfileExperiment); |
| 32 } | 37 } |
| 33 | 38 |
| 34 // H264 specific settings. | 39 // H264 specific settings. |
| 35 @implementation RTCCodecSpecificInfoH264 | 40 @implementation RTCCodecSpecificInfoH264 |
| 36 | 41 |
| 37 @synthesize packetizationMode = _packetizationMode; | 42 @synthesize packetizationMode = _packetizationMode; |
| 38 | 43 |
| 39 - (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo { | 44 - (webrtc::CodecSpecificInfo)nativeCodecSpecificInfo { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 nativeFrameTypes.push_back((webrtc::FrameType)rtcFrameType); | 169 nativeFrameTypes.push_back((webrtc::FrameType)rtcFrameType); |
| 165 } | 170 } |
| 166 | 171 |
| 167 return _videoToolboxEncoder->Encode(videoFrame, &codecSpecificInfo, &nativeFra
meTypes); | 172 return _videoToolboxEncoder->Encode(videoFrame, &codecSpecificInfo, &nativeFra
meTypes); |
| 168 } | 173 } |
| 169 | 174 |
| 170 - (BOOL)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate { | 175 - (BOOL)setBitrate:(uint32_t)bitrateKbit framerate:(uint32_t)framerate { |
| 171 return _videoToolboxEncoder->SetRates(bitrateKbit, framerate) == WEBRTC_VIDEO_
CODEC_OK; | 176 return _videoToolboxEncoder->SetRates(bitrateKbit, framerate) == WEBRTC_VIDEO_
CODEC_OK; |
| 172 } | 177 } |
| 173 | 178 |
| 179 - (RTCVideoEncoderQpThresholds *)scalingSettings { |
| 180 return [[RTCVideoEncoderQpThresholds alloc] initWithThresholdsLow:kLowH264QpTh
reshold |
| 181 high:kHighH264QpT
hreshold]; |
| 182 } |
| 183 |
| 174 @end | 184 @end |
| 175 | 185 |
| 176 // Decoder. | 186 // Decoder. |
| 177 @implementation RTCVideoDecoderH264 { | 187 @implementation RTCVideoDecoderH264 { |
| 178 webrtc::H264VideoToolboxDecoder *_videoToolboxDecoder; | 188 webrtc::H264VideoToolboxDecoder *_videoToolboxDecoder; |
| 179 H264VideoToolboxDecodeCompleteCallback *_toolboxCallback; | 189 H264VideoToolboxDecodeCompleteCallback *_toolboxCallback; |
| 180 } | 190 } |
| 181 | 191 |
| 182 - (instancetype)init { | 192 - (instancetype)init { |
| 183 if (self = [super init]) { | 193 if (self = [super init]) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 - (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info { | 295 - (id<RTCVideoDecoder>)createDecoder:(RTCVideoCodecInfo *)info { |
| 286 return [[RTCVideoDecoderH264 alloc] init]; | 296 return [[RTCVideoDecoderH264 alloc] init]; |
| 287 } | 297 } |
| 288 | 298 |
| 289 - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { | 299 - (NSArray<RTCVideoCodecInfo *> *)supportedCodecs { |
| 290 NSString *codecName = [NSString stringWithUTF8String:cricket::kH264CodecName]; | 300 NSString *codecName = [NSString stringWithUTF8String:cricket::kH264CodecName]; |
| 291 return @[ [[RTCVideoCodecInfo alloc] initWithPayload:0 name:codecName paramete
rs:@{}] ]; | 301 return @[ [[RTCVideoCodecInfo alloc] initWithPayload:0 name:codecName paramete
rs:@{}] ]; |
| 292 } | 302 } |
| 293 | 303 |
| 294 @end | 304 @end |
| OLD | NEW |