OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 | 10 |
11 #include "webrtc/media/engine/webrtcvideoengine.h" | 11 #include "webrtc/media/engine/webrtcvideoengine.h" |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <set> | 15 #include <set> |
16 #include <string> | 16 #include <string> |
17 #include <utility> | 17 #include <utility> |
18 | 18 |
19 #include "webrtc/api/video/i420_buffer.h" | 19 #include "webrtc/api/video/i420_buffer.h" |
| 20 #include "webrtc/api/video_codecs/sdp_video_format.h" |
20 #include "webrtc/api/video_codecs/video_decoder.h" | 21 #include "webrtc/api/video_codecs/video_decoder.h" |
| 22 #include "webrtc/api/video_codecs/video_decoder_factory.h" |
21 #include "webrtc/api/video_codecs/video_encoder.h" | 23 #include "webrtc/api/video_codecs/video_encoder.h" |
| 24 #include "webrtc/api/video_codecs/video_encoder_factory.h" |
22 #include "webrtc/call/call.h" | 25 #include "webrtc/call/call.h" |
23 #include "webrtc/common_video/h264/profile_level_id.h" | 26 #include "webrtc/common_video/h264/profile_level_id.h" |
24 #include "webrtc/media/engine/constants.h" | 27 #include "webrtc/media/engine/constants.h" |
25 #include "webrtc/media/engine/internaldecoderfactory.h" | 28 #include "webrtc/media/engine/internaldecoderfactory.h" |
26 #include "webrtc/media/engine/internalencoderfactory.h" | 29 #include "webrtc/media/engine/internalencoderfactory.h" |
27 #include "webrtc/media/engine/scopedvideodecoder.h" | 30 #include "webrtc/media/engine/scopedvideodecoder.h" |
28 #include "webrtc/media/engine/scopedvideoencoder.h" | 31 #include "webrtc/media/engine/scopedvideoencoder.h" |
29 #include "webrtc/media/engine/simulcast.h" | 32 #include "webrtc/media/engine/simulcast.h" |
30 #include "webrtc/media/engine/simulcast_encoder_adapter.h" | 33 #include "webrtc/media/engine/simulcast_encoder_adapter.h" |
31 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" | 34 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const VideoDecoderParams& decoder_params) const = 0; | 82 const VideoDecoderParams& decoder_params) const = 0; |
80 }; | 83 }; |
81 | 84 |
82 namespace { | 85 namespace { |
83 | 86 |
84 std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs( | 87 std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs( |
85 const std::vector<VideoCodec>& input_codecs); | 88 const std::vector<VideoCodec>& input_codecs); |
86 | 89 |
87 // Wraps cricket::WebRtcVideoEncoderFactory* into common EncoderFactoryAdapter | 90 // Wraps cricket::WebRtcVideoEncoderFactory* into common EncoderFactoryAdapter |
88 // interface. | 91 // interface. |
89 // TODO(magjed): Add wrapper class for future webrtc::VideoEncoderFactory | 92 // TODO(magjed): Remove once WebRtcVideoEncoderFactory* is deprecated and |
90 // interface, https://bugs.chromium.org/p/webrtc/issues/detail?id=7925. | 93 // webrtc:7925 is fixed. |
91 class CricketEncoderFactoryAdapter : public EncoderFactoryAdapter { | 94 class CricketEncoderFactoryAdapter : public EncoderFactoryAdapter { |
92 public: | 95 public: |
93 explicit CricketEncoderFactoryAdapter( | 96 explicit CricketEncoderFactoryAdapter( |
94 WebRtcVideoEncoderFactory* external_encoder_factory) | 97 WebRtcVideoEncoderFactory* external_encoder_factory) |
95 : internal_encoder_factory_(new InternalEncoderFactory()), | 98 : internal_encoder_factory_(new InternalEncoderFactory()), |
96 external_encoder_factory_(external_encoder_factory) {} | 99 external_encoder_factory_(external_encoder_factory) {} |
97 | 100 |
98 private: | 101 private: |
99 explicit CricketEncoderFactoryAdapter( | 102 explicit CricketEncoderFactoryAdapter( |
100 const CricketEncoderFactoryAdapter& other) | 103 const CricketEncoderFactoryAdapter& other) |
(...skipping 22 matching lines...) Expand all Loading... |
123 : CricketDecoderFactoryAdapter(other.external_decoder_factory_) {} | 126 : CricketDecoderFactoryAdapter(other.external_decoder_factory_) {} |
124 | 127 |
125 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( | 128 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( |
126 const VideoCodec& codec, | 129 const VideoCodec& codec, |
127 const VideoDecoderParams& decoder_params) const override; | 130 const VideoDecoderParams& decoder_params) const override; |
128 | 131 |
129 const std::unique_ptr<WebRtcVideoDecoderFactory> internal_decoder_factory_; | 132 const std::unique_ptr<WebRtcVideoDecoderFactory> internal_decoder_factory_; |
130 WebRtcVideoDecoderFactory* const external_decoder_factory_; | 133 WebRtcVideoDecoderFactory* const external_decoder_factory_; |
131 }; | 134 }; |
132 | 135 |
| 136 // Wraps webrtc::VideoEncoderFactory into common EncoderFactoryAdapter |
| 137 // interface. |
| 138 class WebRtcEncoderFactoryAdapter : public EncoderFactoryAdapter { |
| 139 public: |
| 140 explicit WebRtcEncoderFactoryAdapter( |
| 141 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory) |
| 142 : encoder_factory_(std::move(encoder_factory)) {} |
| 143 |
| 144 private: |
| 145 AllocatedEncoder CreateVideoEncoder( |
| 146 const VideoCodec& codec, |
| 147 bool is_conference_mode_screenshare) const override { |
| 148 if (!encoder_factory_) |
| 149 return AllocatedEncoder(); |
| 150 const webrtc::SdpVideoFormat format(codec.name, codec.params); |
| 151 const webrtc::VideoEncoderFactory::CodecInfo info = |
| 152 encoder_factory_->QueryVideoEncoder(format); |
| 153 return AllocatedEncoder(encoder_factory_->CreateVideoEncoder(format), |
| 154 info.is_hardware_accelerated, |
| 155 info.has_internal_source); |
| 156 } |
| 157 |
| 158 std::vector<VideoCodec> GetSupportedCodecs() const override { |
| 159 if (!encoder_factory_) |
| 160 return std::vector<VideoCodec>(); |
| 161 std::vector<VideoCodec> codecs; |
| 162 for (const webrtc::SdpVideoFormat& format : |
| 163 encoder_factory_->GetSupportedFormats()) { |
| 164 VideoCodec codec; |
| 165 codec.name = format.name; |
| 166 codec.params = format.parameters; |
| 167 codecs.push_back(codec); |
| 168 } |
| 169 return AssignPayloadTypesAndAddAssociatedRtxCodecs(codecs); |
| 170 } |
| 171 |
| 172 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_; |
| 173 }; |
| 174 |
| 175 // Wraps webrtc::VideoDecoderFactory into common DecoderFactoryAdapter |
| 176 // interface. |
| 177 class WebRtcDecoderFactoryAdapter : public DecoderFactoryAdapter { |
| 178 public: |
| 179 explicit WebRtcDecoderFactoryAdapter( |
| 180 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory) |
| 181 : decoder_factory_(std::move(decoder_factory)) {} |
| 182 |
| 183 private: |
| 184 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( |
| 185 const VideoCodec& codec, |
| 186 const VideoDecoderParams& decoder_params) const override { |
| 187 return decoder_factory_ |
| 188 ? decoder_factory_->CreateVideoDecoder( |
| 189 webrtc::SdpVideoFormat(codec.name, codec.params)) |
| 190 : nullptr; |
| 191 } |
| 192 |
| 193 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory_; |
| 194 }; |
| 195 |
133 // If this field trial is enabled, we will enable sending FlexFEC and disable | 196 // If this field trial is enabled, we will enable sending FlexFEC and disable |
134 // sending ULPFEC whenever the former has been negotiated in the SDPs. | 197 // sending ULPFEC whenever the former has been negotiated in the SDPs. |
135 bool IsFlexfecFieldTrialEnabled() { | 198 bool IsFlexfecFieldTrialEnabled() { |
136 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03"); | 199 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03"); |
137 } | 200 } |
138 | 201 |
139 // If this field trial is enabled, the "flexfec-03" codec may have been | 202 // If this field trial is enabled, the "flexfec-03" codec may have been |
140 // advertised as being supported in the local SDP. That means that we must be | 203 // advertised as being supported in the local SDP. That means that we must be |
141 // ready to receive FlexFEC packets. See internalencoderfactory.cc. | 204 // ready to receive FlexFEC packets. See internalencoderfactory.cc. |
142 bool IsFlexfecAdvertisedFieldTrialEnabled() { | 205 bool IsFlexfecAdvertisedFieldTrialEnabled() { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 WebRtcVideoEngine::WebRtcVideoEngine( | 457 WebRtcVideoEngine::WebRtcVideoEngine( |
395 WebRtcVideoEncoderFactory* external_video_encoder_factory, | 458 WebRtcVideoEncoderFactory* external_video_encoder_factory, |
396 WebRtcVideoDecoderFactory* external_video_decoder_factory) | 459 WebRtcVideoDecoderFactory* external_video_decoder_factory) |
397 : decoder_factory_( | 460 : decoder_factory_( |
398 new CricketDecoderFactoryAdapter(external_video_decoder_factory)), | 461 new CricketDecoderFactoryAdapter(external_video_decoder_factory)), |
399 encoder_factory_( | 462 encoder_factory_( |
400 new CricketEncoderFactoryAdapter(external_video_encoder_factory)) { | 463 new CricketEncoderFactoryAdapter(external_video_encoder_factory)) { |
401 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; | 464 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; |
402 } | 465 } |
403 | 466 |
| 467 WebRtcVideoEngine::WebRtcVideoEngine( |
| 468 std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory, |
| 469 std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory) |
| 470 : decoder_factory_( |
| 471 new WebRtcDecoderFactoryAdapter(std::move(video_decoder_factory))), |
| 472 encoder_factory_( |
| 473 new WebRtcEncoderFactoryAdapter(std::move(video_encoder_factory))) { |
| 474 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; |
| 475 } |
| 476 |
404 WebRtcVideoEngine::~WebRtcVideoEngine() { | 477 WebRtcVideoEngine::~WebRtcVideoEngine() { |
405 LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine"; | 478 LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine"; |
406 } | 479 } |
407 | 480 |
408 WebRtcVideoChannel* WebRtcVideoEngine::CreateChannel( | 481 WebRtcVideoChannel* WebRtcVideoEngine::CreateChannel( |
409 webrtc::Call* call, | 482 webrtc::Call* call, |
410 const MediaConfig& config, | 483 const MediaConfig& config, |
411 const VideoOptions& options) { | 484 const VideoOptions& options) { |
412 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); | 485 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
413 return new WebRtcVideoChannel(call, config, options, encoder_factory_.get(), | 486 return new WebRtcVideoChannel(call, config, options, encoder_factory_.get(), |
(...skipping 2194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2608 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - | 2681 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - |
2609 1); | 2682 1); |
2610 } | 2683 } |
2611 | 2684 |
2612 std::vector<webrtc::VideoStream> streams; | 2685 std::vector<webrtc::VideoStream> streams; |
2613 streams.push_back(stream); | 2686 streams.push_back(stream); |
2614 return streams; | 2687 return streams; |
2615 } | 2688 } |
2616 | 2689 |
2617 } // namespace cricket | 2690 } // namespace cricket |
OLD | NEW |