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 #if defined(WEBRTC_IOS) | |
16 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h" | 15 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h" |
17 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h" | 16 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h" |
18 #endif | |
19 | 17 |
20 namespace webrtc { | 18 namespace webrtc { |
21 | 19 |
22 // VideoToolboxVideoEncoderFactory | 20 // VideoToolboxVideoEncoderFactory |
23 | 21 |
24 VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() { | 22 VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() { |
25 // Hardware H264 encoding only supported on iOS for now. | |
26 #if defined(WEBRTC_IOS) | |
27 // TODO(magjed): Enumerate actual level instead of using hardcoded level 3.1. | 23 // TODO(magjed): Enumerate actual level instead of using hardcoded level 3.1. |
28 // Level 3.1 is 1280x720@30fps which is enough for now. | 24 // Level 3.1 is 1280x720@30fps which is enough for now. |
29 const H264::Level level = H264::kLevel3_1; | 25 const H264::Level level = H264::kLevel3_1; |
30 | 26 |
31 cricket::VideoCodec constrained_high(cricket::kH264CodecName); | 27 cricket::VideoCodec constrained_high(cricket::kH264CodecName); |
32 const H264::ProfileLevelId constrained_high_profile( | 28 const H264::ProfileLevelId constrained_high_profile( |
33 H264::kProfileConstrainedHigh, level); | 29 H264::kProfileConstrainedHigh, level); |
34 constrained_high.SetParam( | 30 constrained_high.SetParam( |
35 cricket::kH264FmtpProfileLevelId, | 31 cricket::kH264FmtpProfileLevelId, |
36 *H264::ProfileLevelIdToString(constrained_high_profile)); | 32 *H264::ProfileLevelIdToString(constrained_high_profile)); |
37 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); | 33 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
38 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1"); | 34 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
39 supported_codecs_.push_back(constrained_high); | 35 supported_codecs_.push_back(constrained_high); |
40 | 36 |
41 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); | 37 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); |
42 const H264::ProfileLevelId constrained_baseline_profile( | 38 const H264::ProfileLevelId constrained_baseline_profile( |
43 H264::kProfileConstrainedBaseline, level); | 39 H264::kProfileConstrainedBaseline, level); |
44 constrained_baseline.SetParam( | 40 constrained_baseline.SetParam( |
45 cricket::kH264FmtpProfileLevelId, | 41 cricket::kH264FmtpProfileLevelId, |
46 *H264::ProfileLevelIdToString(constrained_baseline_profile)); | 42 *H264::ProfileLevelIdToString(constrained_baseline_profile)); |
47 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); | 43 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
48 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1"); | 44 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
49 supported_codecs_.push_back(constrained_baseline); | 45 supported_codecs_.push_back(constrained_baseline); |
50 #endif | |
51 } | 46 } |
52 | 47 |
53 VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {} | 48 VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {} |
54 | 49 |
55 VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder( | 50 VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder( |
56 const cricket::VideoCodec& codec) { | 51 const cricket::VideoCodec& codec) { |
57 #if defined(WEBRTC_IOS) | |
58 if (FindMatchingCodec(supported_codecs_, codec)) { | 52 if (FindMatchingCodec(supported_codecs_, codec)) { |
59 LOG(LS_INFO) << "Creating HW encoder for " << codec.name; | 53 LOG(LS_INFO) << "Creating HW encoder for " << codec.name; |
60 return new H264VideoToolboxEncoder(codec); | 54 return new H264VideoToolboxEncoder(codec); |
61 } | 55 } |
62 #endif | |
63 LOG(LS_INFO) << "No HW encoder found for codec " << codec.name; | 56 LOG(LS_INFO) << "No HW encoder found for codec " << codec.name; |
64 return nullptr; | 57 return nullptr; |
65 } | 58 } |
66 | 59 |
67 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder( | 60 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder( |
68 VideoEncoder* encoder) { | 61 VideoEncoder* encoder) { |
69 #if defined(WEBRTC_IOS) | |
70 delete encoder; | 62 delete encoder; |
71 encoder = nullptr; | 63 encoder = nullptr; |
72 #endif | |
73 } | 64 } |
74 | 65 |
75 const std::vector<cricket::VideoCodec>& | 66 const std::vector<cricket::VideoCodec>& |
76 VideoToolboxVideoEncoderFactory::supported_codecs() const { | 67 VideoToolboxVideoEncoderFactory::supported_codecs() const { |
77 return supported_codecs_; | 68 return supported_codecs_; |
78 } | 69 } |
79 | 70 |
80 // VideoToolboxVideoDecoderFactory | 71 // VideoToolboxVideoDecoderFactory |
81 | 72 |
82 VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() { | 73 VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() { |
83 #if defined(WEBRTC_IOS) | |
84 supported_codecs_.push_back(cricket::VideoCodec("H264")); | 74 supported_codecs_.push_back(cricket::VideoCodec("H264")); |
85 #endif | |
86 } | 75 } |
87 | 76 |
88 VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {} | 77 VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {} |
89 | 78 |
90 VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder( | 79 VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder( |
91 VideoCodecType type) { | 80 VideoCodecType type) { |
92 const rtc::Optional<const char*> codec_name = CodecTypeToPayloadName(type); | 81 const rtc::Optional<const char*> codec_name = CodecTypeToPayloadName(type); |
93 if (!codec_name) { | 82 if (!codec_name) { |
94 LOG(LS_ERROR) << "Invalid codec type: " << type; | 83 LOG(LS_ERROR) << "Invalid codec type: " << type; |
95 return nullptr; | 84 return nullptr; |
96 } | 85 } |
97 const cricket::VideoCodec codec(*codec_name); | 86 const cricket::VideoCodec codec(*codec_name); |
98 #if defined(WEBRTC_IOS) | |
99 if (FindMatchingCodec(supported_codecs_, codec)) { | 87 if (FindMatchingCodec(supported_codecs_, codec)) { |
100 LOG(LS_INFO) << "Creating HW decoder for " << codec.name; | 88 LOG(LS_INFO) << "Creating HW decoder for " << codec.name; |
101 return new H264VideoToolboxDecoder(); | 89 return new H264VideoToolboxDecoder(); |
102 } | 90 } |
103 #endif | |
104 LOG(LS_INFO) << "No HW decoder found for codec " << codec.name; | 91 LOG(LS_INFO) << "No HW decoder found for codec " << codec.name; |
105 return nullptr; | 92 return nullptr; |
106 } | 93 } |
107 | 94 |
108 void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder( | 95 void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder( |
109 VideoDecoder* decoder) { | 96 VideoDecoder* decoder) { |
110 #if defined(WEBRTC_IOS) | |
111 delete decoder; | 97 delete decoder; |
112 decoder = nullptr; | 98 decoder = nullptr; |
113 #endif | |
114 } | 99 } |
115 | 100 |
116 } // namespace webrtc | 101 } // namespace webrtc |
OLD | NEW |