1 /*
2  *  Copyright (c) 2018 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 #include "modules/video_coding/codecs/vp9/include/vp9.h"
12 
13 #include <memory>
14 
15 #include "api/video_codecs/sdp_video_format.h"
16 #include "modules/video_coding/codecs/vp9/vp9_impl.h"
17 #include "rtc_base/checks.h"
18 #include "vpx/vp8cx.h"
19 #include "vpx/vp8dx.h"
20 #include "vpx/vpx_codec.h"
21 
22 namespace webrtc {
23 
SupportedVP9Codecs()24 std::vector<SdpVideoFormat> SupportedVP9Codecs() {
25 #ifdef RTC_ENABLE_VP9
26   // Profile 2 might not be available on some platforms until
27   // https://bugs.chromium.org/p/webm/issues/detail?id=1544 is solved.
28   static bool vpx_supports_high_bit_depth =
29       (vpx_codec_get_caps(vpx_codec_vp9_cx()) & VPX_CODEC_CAP_HIGHBITDEPTH) !=
30           0 &&
31       (vpx_codec_get_caps(vpx_codec_vp9_dx()) & VPX_CODEC_CAP_HIGHBITDEPTH) !=
32           0;
33 
34   std::vector<SdpVideoFormat> supported_formats{SdpVideoFormat(
35       cricket::kVp9CodecName,
36       {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile0)}})};
37   if (vpx_supports_high_bit_depth) {
38     supported_formats.push_back(SdpVideoFormat(
39         cricket::kVp9CodecName,
40         {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile2)}}));
41   }
42 
43   return supported_formats;
44 #else
45   return std::vector<SdpVideoFormat>();
46 #endif
47 }
48 
SupportedVP9DecoderCodecs()49 std::vector<SdpVideoFormat> SupportedVP9DecoderCodecs() {
50 #ifdef RTC_ENABLE_VP9
51   std::vector<SdpVideoFormat> supported_formats = SupportedVP9Codecs();
52   // The WebRTC internal decoder supports VP9 profile 1. However, there's
53   // currently no way of sending VP9 profile 1 using the internal encoder.
54   // It would require extended support for I444, I422, and I440 buffers.
55   supported_formats.push_back(SdpVideoFormat(
56       cricket::kVp9CodecName,
57       {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile1)}}));
58   return supported_formats;
59 #else
60   return std::vector<SdpVideoFormat>();
61 #endif
62 }
63 
Create()64 std::unique_ptr<VP9Encoder> VP9Encoder::Create() {
65 #ifdef RTC_ENABLE_VP9
66   return std::make_unique<VP9EncoderImpl>(cricket::VideoCodec());
67 #else
68   RTC_NOTREACHED();
69   return nullptr;
70 #endif
71 }
72 
Create(const cricket::VideoCodec & codec)73 std::unique_ptr<VP9Encoder> VP9Encoder::Create(
74     const cricket::VideoCodec& codec) {
75 #ifdef RTC_ENABLE_VP9
76   return std::make_unique<VP9EncoderImpl>(codec);
77 #else
78   RTC_NOTREACHED();
79   return nullptr;
80 #endif
81 }
82 
Create()83 std::unique_ptr<VP9Decoder> VP9Decoder::Create() {
84 #ifdef RTC_ENABLE_VP9
85   return std::make_unique<VP9DecoderImpl>();
86 #else
87   RTC_NOTREACHED();
88   return nullptr;
89 #endif
90 }
91 
92 }  // namespace webrtc
93