OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 #include "webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h" |
| 11 |
| 12 #include "webrtc/base/logging.h" |
| 13 #include "webrtc/common_video/h264/profile_level_id.h" |
| 14 #include "webrtc/media/base/codec.h" |
| 15 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h" |
| 16 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h" |
| 17 #include "webrtc/system_wrappers/include/field_trial.h" |
| 18 |
| 19 namespace webrtc { |
| 20 |
| 21 namespace { |
| 22 const char kHighProfileExperiment[] = "WebRTC-H264HighProfile"; |
| 23 |
| 24 bool IsHighProfileEnabled() { |
| 25 return field_trial::IsEnabled(kHighProfileExperiment); |
| 26 } |
| 27 } |
| 28 |
| 29 // VideoToolboxVideoEncoderFactory |
| 30 |
| 31 VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() { |
| 32 } |
| 33 |
| 34 VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {} |
| 35 |
| 36 VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder( |
| 37 const cricket::VideoCodec& codec) { |
| 38 if (FindMatchingCodec(supported_codecs_, codec)) { |
| 39 LOG(LS_INFO) << "Creating HW encoder for " << codec.name; |
| 40 return new H264VideoToolboxEncoder(codec); |
| 41 } |
| 42 LOG(LS_INFO) << "No HW encoder found for codec " << codec.name; |
| 43 return nullptr; |
| 44 } |
| 45 |
| 46 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder( |
| 47 VideoEncoder* encoder) { |
| 48 delete encoder; |
| 49 encoder = nullptr; |
| 50 } |
| 51 |
| 52 const std::vector<cricket::VideoCodec>& |
| 53 VideoToolboxVideoEncoderFactory::supported_codecs() const { |
| 54 supported_codecs_.clear(); |
| 55 |
| 56 // TODO(magjed): Enumerate actual level instead of using hardcoded level 3.1. |
| 57 // Level 3.1 is 1280x720@30fps which is enough for now. |
| 58 const H264::Level level = H264::kLevel3_1; |
| 59 |
| 60 if (IsHighProfileEnabled()) { |
| 61 cricket::VideoCodec constrained_high(cricket::kH264CodecName); |
| 62 const H264::ProfileLevelId constrained_high_profile( |
| 63 H264::kProfileConstrainedHigh, level); |
| 64 constrained_high.SetParam( |
| 65 cricket::kH264FmtpProfileLevelId, |
| 66 *H264::ProfileLevelIdToString(constrained_high_profile)); |
| 67 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
| 68 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
| 69 supported_codecs_.push_back(constrained_high); |
| 70 } |
| 71 |
| 72 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); |
| 73 const H264::ProfileLevelId constrained_baseline_profile( |
| 74 H264::kProfileConstrainedBaseline, level); |
| 75 constrained_baseline.SetParam( |
| 76 cricket::kH264FmtpProfileLevelId, |
| 77 *H264::ProfileLevelIdToString(constrained_baseline_profile)); |
| 78 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
| 79 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
| 80 supported_codecs_.push_back(constrained_baseline); |
| 81 |
| 82 return supported_codecs_; |
| 83 } |
| 84 |
| 85 // VideoToolboxVideoDecoderFactory |
| 86 |
| 87 VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() { |
| 88 supported_codecs_.push_back(cricket::VideoCodec("H264")); |
| 89 } |
| 90 |
| 91 VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {} |
| 92 |
| 93 VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder( |
| 94 VideoCodecType type) { |
| 95 const rtc::Optional<const char*> codec_name = CodecTypeToPayloadName(type); |
| 96 if (!codec_name) { |
| 97 LOG(LS_ERROR) << "Invalid codec type: " << type; |
| 98 return nullptr; |
| 99 } |
| 100 const cricket::VideoCodec codec(*codec_name); |
| 101 if (FindMatchingCodec(supported_codecs_, codec)) { |
| 102 LOG(LS_INFO) << "Creating HW decoder for " << codec.name; |
| 103 return new H264VideoToolboxDecoder(); |
| 104 } |
| 105 LOG(LS_INFO) << "No HW decoder found for codec " << codec.name; |
| 106 return nullptr; |
| 107 } |
| 108 |
| 109 void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder( |
| 110 VideoDecoder* decoder) { |
| 111 delete decoder; |
| 112 decoder = nullptr; |
| 113 } |
| 114 |
| 115 } // namespace webrtc |
OLD | NEW |