Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine.cc

Issue 3007073002: Add new video codec factories (Closed)
Patch Set: Add tests Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/video_decoder.h" 20 #include "webrtc/api/video_codecs/video_decoder.h"
21 #include "webrtc/api/video_codecs/video_decoder_factory.h"
21 #include "webrtc/api/video_codecs/video_encoder.h" 22 #include "webrtc/api/video_codecs/video_encoder.h"
23 #include "webrtc/api/video_codecs/video_encoder_factory.h"
22 #include "webrtc/call/call.h" 24 #include "webrtc/call/call.h"
23 #include "webrtc/common_video/h264/profile_level_id.h" 25 #include "webrtc/common_video/h264/profile_level_id.h"
24 #include "webrtc/media/engine/constants.h" 26 #include "webrtc/media/engine/constants.h"
25 #include "webrtc/media/engine/internaldecoderfactory.h" 27 #include "webrtc/media/engine/internaldecoderfactory.h"
26 #include "webrtc/media/engine/internalencoderfactory.h" 28 #include "webrtc/media/engine/internalencoderfactory.h"
27 #include "webrtc/media/engine/scopedvideodecoder.h" 29 #include "webrtc/media/engine/scopedvideodecoder.h"
28 #include "webrtc/media/engine/scopedvideoencoder.h" 30 #include "webrtc/media/engine/scopedvideoencoder.h"
29 #include "webrtc/media/engine/simulcast.h" 31 #include "webrtc/media/engine/simulcast.h"
30 #include "webrtc/media/engine/simulcast_encoder_adapter.h" 32 #include "webrtc/media/engine/simulcast_encoder_adapter.h"
31 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" 33 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 const VideoDecoderParams& decoder_params) const = 0; 81 const VideoDecoderParams& decoder_params) const = 0;
80 }; 82 };
81 83
82 namespace { 84 namespace {
83 85
84 std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs( 86 std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs(
85 const std::vector<VideoCodec>& input_codecs); 87 const std::vector<VideoCodec>& input_codecs);
86 88
87 // Wraps cricket::WebRtcVideoEncoderFactory* into common EncoderFactoryAdapter 89 // Wraps cricket::WebRtcVideoEncoderFactory* into common EncoderFactoryAdapter
88 // interface. 90 // interface.
89 // TODO(magjed): Add wrapper class for future webrtc::VideoEncoderFactory 91 // TODO(magjed): Remove once WebRtcVideoEncoderFactory* is deprecated and
90 // interface, https://bugs.chromium.org/p/webrtc/issues/detail?id=7925. 92 // webrtc:7925 is fixed.
91 class CricketEncoderFactoryAdapter : public EncoderFactoryAdapter { 93 class CricketEncoderFactoryAdapter : public EncoderFactoryAdapter {
92 public: 94 public:
93 explicit CricketEncoderFactoryAdapter( 95 explicit CricketEncoderFactoryAdapter(
94 WebRtcVideoEncoderFactory* external_encoder_factory) 96 WebRtcVideoEncoderFactory* external_encoder_factory)
95 : internal_encoder_factory_(new InternalEncoderFactory()), 97 : internal_encoder_factory_(new InternalEncoderFactory()),
96 external_encoder_factory_(external_encoder_factory) {} 98 external_encoder_factory_(external_encoder_factory) {}
97 99
98 private: 100 private:
99 explicit CricketEncoderFactoryAdapter( 101 explicit CricketEncoderFactoryAdapter(
100 const CricketEncoderFactoryAdapter& other) 102 const CricketEncoderFactoryAdapter& other)
(...skipping 22 matching lines...) Expand all
123 : CricketDecoderFactoryAdapter(other.external_decoder_factory_) {} 125 : CricketDecoderFactoryAdapter(other.external_decoder_factory_) {}
124 126
125 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( 127 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
126 const VideoCodec& codec, 128 const VideoCodec& codec,
127 const VideoDecoderParams& decoder_params) const override; 129 const VideoDecoderParams& decoder_params) const override;
128 130
129 const std::unique_ptr<WebRtcVideoDecoderFactory> internal_decoder_factory_; 131 const std::unique_ptr<WebRtcVideoDecoderFactory> internal_decoder_factory_;
130 WebRtcVideoDecoderFactory* const external_decoder_factory_; 132 WebRtcVideoDecoderFactory* const external_decoder_factory_;
131 }; 133 };
132 134
135 // Wraps webrtc::VideoEncoderFactory into common EncoderFactoryAdapter
136 // interface.
137 class WebRtcEncoderFactoryAdapter : public EncoderFactoryAdapter {
138 public:
139 explicit WebRtcEncoderFactoryAdapter(
140 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory)
141 : encoder_factory_(std::move(encoder_factory)) {}
142
143 private:
144 AllocatedEncoder CreateVideoEncoder(
145 const VideoCodec& codec,
146 bool is_conference_mode_screenshare) const override {
147 if (!encoder_factory_)
148 return AllocatedEncoder();
149 const webrtc::VideoEncoderFactory::CodecInfo info =
150 encoder_factory_->QueryVideoEncoder(codec);
151 return AllocatedEncoder(encoder_factory_->CreateVideoEncoder(codec),
152 info.is_hardware_accelerated,
153 info.has_internal_source);
154 }
155
156 std::vector<VideoCodec> GetSupportedCodecs() const override {
157 return encoder_factory_ ? AssignPayloadTypesAndAddAssociatedRtxCodecs(
158 encoder_factory_->GetSupportedCodecs())
159 : std::vector<VideoCodec>();
160 }
161
162 private:
stefan-webrtc 2017/09/06 12:40:42 No need for private here and at line 143, right? S
magjed_webrtc 2017/09/10 15:27:49 Ops, thanks.
163 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_;
164 };
165
166 // Wraps webrtc::VideoDecoderFactory into common DecoderFactoryAdapter
167 // interface.
168 class WebRtcDecoderFactoryAdapter : public DecoderFactoryAdapter {
169 public:
170 explicit WebRtcDecoderFactoryAdapter(
171 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory)
172 : decoder_factory_(std::move(decoder_factory)) {}
173
174 private:
175 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
176 const VideoCodec& codec,
177 const VideoDecoderParams& decoder_params) const override {
178 return decoder_factory_ ? decoder_factory_->CreateVideoDecoder(codec)
179 : nullptr;
180 }
181
182 private:
183 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory_;
184 };
185
133 // If this field trial is enabled, we will enable sending FlexFEC and disable 186 // 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. 187 // sending ULPFEC whenever the former has been negotiated in the SDPs.
135 bool IsFlexfecFieldTrialEnabled() { 188 bool IsFlexfecFieldTrialEnabled() {
136 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03"); 189 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03");
137 } 190 }
138 191
139 // If this field trial is enabled, the "flexfec-03" codec may have been 192 // 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 193 // advertised as being supported in the local SDP. That means that we must be
141 // ready to receive FlexFEC packets. See internalencoderfactory.cc. 194 // ready to receive FlexFEC packets. See internalencoderfactory.cc.
142 bool IsFlexfecAdvertisedFieldTrialEnabled() { 195 bool IsFlexfecAdvertisedFieldTrialEnabled() {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 WebRtcVideoEngine::WebRtcVideoEngine( 447 WebRtcVideoEngine::WebRtcVideoEngine(
395 WebRtcVideoEncoderFactory* external_video_encoder_factory, 448 WebRtcVideoEncoderFactory* external_video_encoder_factory,
396 WebRtcVideoDecoderFactory* external_video_decoder_factory) 449 WebRtcVideoDecoderFactory* external_video_decoder_factory)
397 : decoder_factory_( 450 : decoder_factory_(
398 new CricketDecoderFactoryAdapter(external_video_decoder_factory)), 451 new CricketDecoderFactoryAdapter(external_video_decoder_factory)),
399 encoder_factory_( 452 encoder_factory_(
400 new CricketEncoderFactoryAdapter(external_video_encoder_factory)) { 453 new CricketEncoderFactoryAdapter(external_video_encoder_factory)) {
401 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; 454 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()";
402 } 455 }
403 456
457 WebRtcVideoEngine::WebRtcVideoEngine(
458 std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
459 std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory)
460 : decoder_factory_(
461 new WebRtcDecoderFactoryAdapter(std::move(video_decoder_factory))),
462 encoder_factory_(
463 new WebRtcEncoderFactoryAdapter(std::move(video_encoder_factory))) {
464 LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()";
465 }
466
404 WebRtcVideoEngine::~WebRtcVideoEngine() { 467 WebRtcVideoEngine::~WebRtcVideoEngine() {
405 LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine"; 468 LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine";
406 } 469 }
407 470
408 WebRtcVideoChannel* WebRtcVideoEngine::CreateChannel( 471 WebRtcVideoChannel* WebRtcVideoEngine::CreateChannel(
409 webrtc::Call* call, 472 webrtc::Call* call,
410 const MediaConfig& config, 473 const MediaConfig& config,
411 const VideoOptions& options) { 474 const VideoOptions& options) {
412 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); 475 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString();
413 return new WebRtcVideoChannel(call, config, options, encoder_factory_.get(), 476 return new WebRtcVideoChannel(call, config, options, encoder_factory_.get(),
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - 2666 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() -
2604 1); 2667 1);
2605 } 2668 }
2606 2669
2607 std::vector<webrtc::VideoStream> streams; 2670 std::vector<webrtc::VideoStream> streams;
2608 streams.push_back(stream); 2671 streams.push_back(stream);
2609 return streams; 2672 return streams;
2610 } 2673 }
2611 2674
2612 } // namespace cricket 2675 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698