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

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

Issue 3006713002: WebRtcVideoEngine: Encapsulate logic for unifying internal and external video codecs (Closed)
Patch Set: Fix 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
(...skipping 29 matching lines...) Expand all
40 class VideoEncoder; 40 class VideoEncoder;
41 struct MediaConfig; 41 struct MediaConfig;
42 } 42 }
43 43
44 namespace rtc { 44 namespace rtc {
45 class Thread; 45 class Thread;
46 } // namespace rtc 46 } // namespace rtc
47 47
48 namespace cricket { 48 namespace cricket {
49 49
50 class EncoderFactoryAdapter;
50 class VideoCapturer; 51 class VideoCapturer;
51 class VideoProcessor; 52 class VideoProcessor;
52 class VideoRenderer; 53 class VideoRenderer;
53 class VoiceMediaChannel; 54 class VoiceMediaChannel;
54 class WebRtcDecoderObserver; 55 class WebRtcDecoderObserver;
55 class WebRtcEncoderObserver; 56 class WebRtcEncoderObserver;
56 class WebRtcLocalStreamInfo; 57 class WebRtcLocalStreamInfo;
57 class WebRtcRenderAdapter; 58 class WebRtcRenderAdapter;
58 class WebRtcVideoChannel; 59 class WebRtcVideoChannel;
59 class WebRtcVideoChannelRecvInfo; 60 class WebRtcVideoChannelRecvInfo;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does 115 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
115 // not take the ownership of |encoder_factory|. The caller needs to make sure 116 // not take the ownership of |encoder_factory|. The caller needs to make sure
116 // that |encoder_factory| outlives the video engine. 117 // that |encoder_factory| outlives the video engine.
117 virtual void SetExternalEncoderFactory( 118 virtual void SetExternalEncoderFactory(
118 WebRtcVideoEncoderFactory* encoder_factory); 119 WebRtcVideoEncoderFactory* encoder_factory);
119 120
120 private: 121 private:
121 bool initialized_; 122 bool initialized_;
122 123
123 WebRtcVideoDecoderFactory* external_decoder_factory_; 124 WebRtcVideoDecoderFactory* external_decoder_factory_;
124 WebRtcVideoEncoderFactory* external_encoder_factory_; 125 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
125 }; 126 };
126 127
127 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport { 128 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
128 public: 129 public:
129 WebRtcVideoChannel(webrtc::Call* call, 130 WebRtcVideoChannel(
130 const MediaConfig& config, 131 webrtc::Call* call,
131 const VideoOptions& options, 132 const MediaConfig& config,
132 WebRtcVideoEncoderFactory* external_encoder_factory, 133 const VideoOptions& options,
133 WebRtcVideoDecoderFactory* external_decoder_factory); 134 const EncoderFactoryAdapter& encoder_factory,
135 WebRtcVideoDecoderFactory* external_decoder_factory);
134 ~WebRtcVideoChannel() override; 136 ~WebRtcVideoChannel() override;
135 137
136 // VideoMediaChannel implementation 138 // VideoMediaChannel implementation
137 rtc::DiffServCodePoint PreferredDscp() const override; 139 rtc::DiffServCodePoint PreferredDscp() const override;
138 140
139 bool SetSendParameters(const VideoSendParameters& params) override; 141 bool SetSendParameters(const VideoSendParameters& params) override;
140 bool SetRecvParameters(const VideoRecvParameters& params) override; 142 bool SetRecvParameters(const VideoRecvParameters& params) override;
141 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; 143 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
142 bool SetRtpSendParameters(uint32_t ssrc, 144 bool SetRtpSendParameters(uint32_t ssrc,
143 const webrtc::RtpParameters& parameters) override; 145 const webrtc::RtpParameters& parameters) override;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 253
252 // Wrapper for the sender part. 254 // Wrapper for the sender part.
253 class WebRtcVideoSendStream 255 class WebRtcVideoSendStream
254 : public rtc::VideoSourceInterface<webrtc::VideoFrame> { 256 : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
255 public: 257 public:
256 WebRtcVideoSendStream( 258 WebRtcVideoSendStream(
257 webrtc::Call* call, 259 webrtc::Call* call,
258 const StreamParams& sp, 260 const StreamParams& sp,
259 webrtc::VideoSendStream::Config config, 261 webrtc::VideoSendStream::Config config,
260 const VideoOptions& options, 262 const VideoOptions& options,
261 WebRtcVideoEncoderFactory* external_encoder_factory, 263 const EncoderFactoryAdapter& encoder_factory,
262 bool enable_cpu_overuse_detection, 264 bool enable_cpu_overuse_detection,
263 int max_bitrate_bps, 265 int max_bitrate_bps,
264 const rtc::Optional<VideoCodecSettings>& codec_settings, 266 const rtc::Optional<VideoCodecSettings>& codec_settings,
265 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, 267 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
266 const VideoSendParameters& send_params); 268 const VideoSendParameters& send_params);
267 virtual ~WebRtcVideoSendStream(); 269 virtual ~WebRtcVideoSendStream();
268 270
269 void SetSendParameters(const ChangedSendParameters& send_params); 271 void SetSendParameters(const ChangedSendParameters& send_params);
270 bool SetRtpParameters(const webrtc::RtpParameters& parameters); 272 bool SetRtpParameters(const webrtc::RtpParameters& parameters);
271 webrtc::RtpParameters GetRtpParameters() const; 273 webrtc::RtpParameters GetRtpParameters() const;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 VideoOptions options; 305 VideoOptions options;
304 int max_bitrate_bps; 306 int max_bitrate_bps;
305 bool conference_mode; 307 bool conference_mode;
306 rtc::Optional<VideoCodecSettings> codec_settings; 308 rtc::Optional<VideoCodecSettings> codec_settings;
307 // Sent resolutions + bitrates etc. by the underlying VideoSendStream, 309 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
308 // typically changes when setting a new resolution or reconfiguring 310 // typically changes when setting a new resolution or reconfiguring
309 // bitrates. 311 // bitrates.
310 webrtc::VideoEncoderConfig encoder_config; 312 webrtc::VideoEncoderConfig encoder_config;
311 }; 313 };
312 314
313 class AllocatedEncoder {
314 public:
315 AllocatedEncoder() = default;
316 AllocatedEncoder(AllocatedEncoder&&) = default;
317 AllocatedEncoder& operator=(AllocatedEncoder&&) = default;
318
319 AllocatedEncoder(std::unique_ptr<webrtc::VideoEncoder> encoder,
320 bool is_external,
321 const cricket::VideoCodec& codec,
322 bool has_internal_source);
323
324 // Returns a raw pointer to the allocated encoder. This object still has
325 // ownership of the encoder and is responsible for deleting it.
326 webrtc::VideoEncoder* encoder() { return encoder_.get(); }
327
328 // Returns true if the encoder is external.
329 bool IsExternal() { return is_external_; }
330
331 cricket::VideoCodec codec() { return codec_; }
332
333 bool HasInternalSource() { return has_internal_source_; }
334
335 // Release the encoders this object manages.
336 void Reset();
337
338 private:
339 std::unique_ptr<webrtc::VideoEncoder> encoder_;
340 bool is_external_;
341 cricket::VideoCodec codec_;
342 bool has_internal_source_;
343 };
344
345 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> 315 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
346 ConfigureVideoEncoderSettings(const VideoCodec& codec); 316 ConfigureVideoEncoderSettings(const VideoCodec& codec);
347 // Creates and returns a new AllocatedEncoder of the specified codec type.
348 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec);
349 void SetCodec(const VideoCodecSettings& codec, 317 void SetCodec(const VideoCodecSettings& codec,
350 bool force_encoder_allocation); 318 bool force_encoder_allocation);
351 void RecreateWebRtcStream(); 319 void RecreateWebRtcStream();
352 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( 320 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
353 const VideoCodec& codec) const; 321 const VideoCodec& codec) const;
354 void ReconfigureEncoder(); 322 void ReconfigureEncoder();
355 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); 323 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
356 324
357 // Calls Start or Stop according to whether or not |sending_| is true, 325 // Calls Start or Stop according to whether or not |sending_| is true,
358 // and whether or not the encoding in |rtp_parameters_| is active. 326 // and whether or not the encoding in |rtp_parameters_| is active.
359 void UpdateSendState(); 327 void UpdateSendState();
360 328
361 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference() 329 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
362 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_); 330 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
363 331
364 rtc::ThreadChecker thread_checker_; 332 rtc::ThreadChecker thread_checker_;
365 rtc::AsyncInvoker invoker_; 333 rtc::AsyncInvoker invoker_;
366 rtc::Thread* worker_thread_; 334 rtc::Thread* worker_thread_;
367 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); 335 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_);
368 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); 336 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_);
369 webrtc::Call* const call_; 337 webrtc::Call* const call_;
370 const bool enable_cpu_overuse_detection_; 338 const bool enable_cpu_overuse_detection_;
371 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_ 339 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
372 ACCESS_ON(&thread_checker_); 340 ACCESS_ON(&thread_checker_);
373 WebRtcVideoEncoderFactory* const external_encoder_factory_ 341 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_
374 ACCESS_ON(&thread_checker_);
375 const std::unique_ptr<WebRtcVideoEncoderFactory> internal_encoder_factory_
376 ACCESS_ON(&thread_checker_); 342 ACCESS_ON(&thread_checker_);
377 343
378 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); 344 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_);
379 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ 345 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
380 ACCESS_ON(&thread_checker_); 346 ACCESS_ON(&thread_checker_);
381 // Contains settings that are the same for all streams in the MediaChannel, 347 // Contains settings that are the same for all streams in the MediaChannel,
382 // such as codecs, header extensions, and the global bitrate limit for the 348 // such as codecs, header extensions, and the global bitrate limit for the
383 // entire channel. 349 // entire channel.
384 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); 350 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_);
385 // Contains settings that are unique for each stream, such as max_bitrate. 351 // Contains settings that are unique for each stream, such as max_bitrate.
386 // Does *not* contain codecs, however. 352 // Does *not* contain codecs, however.
387 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. 353 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
388 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only 354 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
389 // one stream per MediaChannel. 355 // one stream per MediaChannel.
390 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); 356 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_);
391 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); 357 std::unique_ptr<webrtc::VideoEncoder> allocated_encoder_
358 ACCESS_ON(&thread_checker_);
359 VideoCodec allocated_codec_ ACCESS_ON(&thread_checker_);
392 360
393 bool sending_ ACCESS_ON(&thread_checker_); 361 bool sending_ ACCESS_ON(&thread_checker_);
394 }; 362 };
395 363
396 // Wrapper for the receiver part, contains configs etc. that are needed to 364 // Wrapper for the receiver part, contains configs etc. that are needed to
397 // reconstruct the underlying VideoReceiveStream. 365 // reconstruct the underlying VideoReceiveStream.
398 class WebRtcVideoReceiveStream 366 class WebRtcVideoReceiveStream
399 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { 367 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
400 public: 368 public:
401 WebRtcVideoReceiveStream( 369 WebRtcVideoReceiveStream(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_ 490 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
523 GUARDED_BY(stream_crit_); 491 GUARDED_BY(stream_crit_);
524 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_ 492 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
525 GUARDED_BY(stream_crit_); 493 GUARDED_BY(stream_crit_);
526 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_); 494 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_);
527 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_); 495 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_);
528 496
529 rtc::Optional<VideoCodecSettings> send_codec_; 497 rtc::Optional<VideoCodecSettings> send_codec_;
530 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_; 498 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
531 499
532 WebRtcVideoEncoderFactory* const external_encoder_factory_; 500 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
533 WebRtcVideoDecoderFactory* const external_decoder_factory_; 501 WebRtcVideoDecoderFactory* const external_decoder_factory_;
534 std::vector<VideoCodecSettings> recv_codecs_; 502 std::vector<VideoCodecSettings> recv_codecs_;
535 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 503 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
536 // See reason for keeping track of the FlexFEC payload type separately in 504 // See reason for keeping track of the FlexFEC payload type separately in
537 // comment in WebRtcVideoChannel::ChangedRecvParameters. 505 // comment in WebRtcVideoChannel::ChangedRecvParameters.
538 int recv_flexfec_payload_type_; 506 int recv_flexfec_payload_type_;
539 webrtc::Call::Config::BitrateConfig bitrate_config_; 507 webrtc::Call::Config::BitrateConfig bitrate_config_;
540 // TODO(deadbeef): Don't duplicate information between 508 // TODO(deadbeef): Don't duplicate information between
541 // send_params/recv_params, rtp_extensions, options, etc. 509 // send_params/recv_params, rtp_extensions, options, etc.
542 VideoSendParameters send_params_; 510 VideoSendParameters send_params_;
(...skipping 20 matching lines...) Expand all
563 const std::string codec_name_; 531 const std::string codec_name_;
564 const int max_qp_; 532 const int max_qp_;
565 const int max_framerate_; 533 const int max_framerate_;
566 const bool is_screencast_; 534 const bool is_screencast_;
567 const bool conference_mode_; 535 const bool conference_mode_;
568 }; 536 };
569 537
570 } // namespace cricket 538 } // namespace cricket
571 539
572 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 540 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine.cc » ('j') | webrtc/media/engine/webrtcvideoengine.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698