Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 | */ |
| 11 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 12 | #include "modules/video_coding/codecs/h264/include/h264.h" |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 13 | |
Magnus Jedvert | 849b3ae | 2017-09-29 17:54:09 +0200 | [diff] [blame^] | 14 | #include "api/video_codecs/sdp_video_format.h" |
| 15 | |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 16 | #if defined(WEBRTC_USE_H264) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/codecs/h264/h264_decoder_impl.h" |
| 18 | #include "modules/video_coding/codecs/h264/h264_encoder_impl.h" |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 19 | #endif |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 20 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
| 22 | #include "rtc_base/logging.h" |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | #if defined(WEBRTC_USE_H264) |
| 29 | bool g_rtc_use_h264 = true; |
| 30 | #endif |
| 31 | |
Magnus Jedvert | 849b3ae | 2017-09-29 17:54:09 +0200 | [diff] [blame^] | 32 | // If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg). |
| 33 | bool IsH264CodecSupported() { |
| 34 | #if defined(WEBRTC_USE_H264) |
| 35 | return g_rtc_use_h264; |
| 36 | #else |
| 37 | return false; |
| 38 | #endif |
| 39 | } |
| 40 | |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 41 | } // namespace |
| 42 | |
| 43 | void DisableRtcUseH264() { |
| 44 | #if defined(WEBRTC_USE_H264) |
| 45 | g_rtc_use_h264 = false; |
| 46 | #endif |
| 47 | } |
| 48 | |
Magnus Jedvert | 849b3ae | 2017-09-29 17:54:09 +0200 | [diff] [blame^] | 49 | std::vector<SdpVideoFormat> SupportedH264Codecs() { |
| 50 | if (!IsH264CodecSupported()) |
| 51 | return std::vector<SdpVideoFormat>(); |
| 52 | std::vector<SdpVideoFormat> codecs; |
| 53 | |
| 54 | codecs.push_back(SdpVideoFormat( |
| 55 | cricket::kH264CodecName, {{cricket::kH264FmtpProfileLevelId, |
| 56 | cricket::kH264ProfileLevelConstrainedBaseline}, |
| 57 | {cricket::kH264FmtpLevelAsymmetryAllowed, "1"}, |
| 58 | {cricket::kH264FmtpPacketizationMode, "1"}})); |
| 59 | |
| 60 | return codecs; |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 61 | } |
| 62 | |
magjed | ceecea4 | 2016-11-28 07:20:21 -0800 | [diff] [blame] | 63 | H264Encoder* H264Encoder::Create(const cricket::VideoCodec& codec) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 64 | RTC_DCHECK(H264Encoder::IsSupported()); |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 65 | #if defined(WEBRTC_USE_H264) |
| 66 | RTC_CHECK(g_rtc_use_h264); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 67 | LOG(LS_INFO) << "Creating H264EncoderImpl."; |
hta | 9aa9688 | 2016-12-06 05:36:03 -0800 | [diff] [blame] | 68 | return new H264EncoderImpl(codec); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 69 | #else |
| 70 | RTC_NOTREACHED(); |
| 71 | return nullptr; |
| 72 | #endif |
| 73 | } |
| 74 | |
| 75 | bool H264Encoder::IsSupported() { |
| 76 | return IsH264CodecSupported(); |
| 77 | } |
| 78 | |
| 79 | H264Decoder* H264Decoder::Create() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 80 | RTC_DCHECK(H264Decoder::IsSupported()); |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 81 | #if defined(WEBRTC_USE_H264) |
| 82 | RTC_CHECK(g_rtc_use_h264); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 83 | LOG(LS_INFO) << "Creating H264DecoderImpl."; |
| 84 | return new H264DecoderImpl(); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 85 | #else |
| 86 | RTC_NOTREACHED(); |
| 87 | return nullptr; |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | bool H264Decoder::IsSupported() { |
| 92 | return IsH264CodecSupported(); |
| 93 | } |
| 94 | |
| 95 | } // namespace webrtc |