blob: c24162d8904e0389cc83b456193ef336ea79f46d [file] [log] [blame]
Zeke Chin71f6f442015-06-29 14:34:58 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020012#include "modules/video_coding/codecs/h264/include/h264.h"
Zeke Chin71f6f442015-06-29 14:34:58 -070013
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020014#include "api/video_codecs/sdp_video_format.h"
15
hbos9dc59282016-02-03 05:09:37 -080016#if defined(WEBRTC_USE_H264)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/codecs/h264/h264_decoder_impl.h"
18#include "modules/video_coding/codecs/h264/h264_encoder_impl.h"
hbosbab934b2016-01-27 01:36:03 -080019#endif
Zeke Chin71f6f442015-06-29 14:34:58 -070020
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/checks.h"
22#include "rtc_base/logging.h"
Zeke Chin71f6f442015-06-29 14:34:58 -070023
24namespace webrtc {
25
hbos9dc59282016-02-03 05:09:37 -080026namespace {
27
28#if defined(WEBRTC_USE_H264)
29bool g_rtc_use_h264 = true;
30#endif
31
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020032// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg).
33bool IsH264CodecSupported() {
34#if defined(WEBRTC_USE_H264)
35 return g_rtc_use_h264;
36#else
37 return false;
38#endif
39}
40
hbos9dc59282016-02-03 05:09:37 -080041} // namespace
42
43void DisableRtcUseH264() {
44#if defined(WEBRTC_USE_H264)
45 g_rtc_use_h264 = false;
46#endif
47}
48
Magnus Jedvert849b3ae2017-09-29 17:54:09 +020049std::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 Chin71f6f442015-06-29 14:34:58 -070061}
62
magjedceecea42016-11-28 07:20:21 -080063H264Encoder* H264Encoder::Create(const cricket::VideoCodec& codec) {
henrikg91d6ede2015-09-17 00:24:34 -070064 RTC_DCHECK(H264Encoder::IsSupported());
hbos9dc59282016-02-03 05:09:37 -080065#if defined(WEBRTC_USE_H264)
66 RTC_CHECK(g_rtc_use_h264);
hbosbab934b2016-01-27 01:36:03 -080067 LOG(LS_INFO) << "Creating H264EncoderImpl.";
hta9aa96882016-12-06 05:36:03 -080068 return new H264EncoderImpl(codec);
Zeke Chin71f6f442015-06-29 14:34:58 -070069#else
70 RTC_NOTREACHED();
71 return nullptr;
72#endif
73}
74
75bool H264Encoder::IsSupported() {
76 return IsH264CodecSupported();
77}
78
79H264Decoder* H264Decoder::Create() {
henrikg91d6ede2015-09-17 00:24:34 -070080 RTC_DCHECK(H264Decoder::IsSupported());
hbos9dc59282016-02-03 05:09:37 -080081#if defined(WEBRTC_USE_H264)
82 RTC_CHECK(g_rtc_use_h264);
hbosbab934b2016-01-27 01:36:03 -080083 LOG(LS_INFO) << "Creating H264DecoderImpl.";
84 return new H264DecoderImpl();
Zeke Chin71f6f442015-06-29 14:34:58 -070085#else
86 RTC_NOTREACHED();
87 return nullptr;
88#endif
89}
90
91bool H264Decoder::IsSupported() {
92 return IsH264CodecSupported();
93}
94
95} // namespace webrtc