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