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

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

Issue 3006713002: WebRtcVideoEngine: Encapsulate logic for unifying internal and external video codecs (Closed)
Patch Set: Change name from is_external to is_hardware_accelerated 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
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(webrtc::Call* call,
130 const MediaConfig& config, 131 const MediaConfig& config,
131 const VideoOptions& options, 132 const VideoOptions& options,
132 WebRtcVideoEncoderFactory* external_encoder_factory, 133 const EncoderFactoryAdapter& encoder_factory,
133 WebRtcVideoDecoderFactory* external_decoder_factory); 134 WebRtcVideoDecoderFactory* external_decoder_factory);
134 ~WebRtcVideoChannel() override; 135 ~WebRtcVideoChannel() override;
135 136
136 // VideoMediaChannel implementation 137 // VideoMediaChannel implementation
137 rtc::DiffServCodePoint PreferredDscp() const override; 138 rtc::DiffServCodePoint PreferredDscp() const override;
138 139
139 bool SetSendParameters(const VideoSendParameters& params) override; 140 bool SetSendParameters(const VideoSendParameters& params) override;
140 bool SetRecvParameters(const VideoRecvParameters& params) override; 141 bool SetRecvParameters(const VideoRecvParameters& params) override;
141 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; 142 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
142 bool SetRtpSendParameters(uint32_t ssrc, 143 bool SetRtpSendParameters(uint32_t ssrc,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 252
252 // Wrapper for the sender part. 253 // Wrapper for the sender part.
253 class WebRtcVideoSendStream 254 class WebRtcVideoSendStream
254 : public rtc::VideoSourceInterface<webrtc::VideoFrame> { 255 : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
255 public: 256 public:
256 WebRtcVideoSendStream( 257 WebRtcVideoSendStream(
257 webrtc::Call* call, 258 webrtc::Call* call,
258 const StreamParams& sp, 259 const StreamParams& sp,
259 webrtc::VideoSendStream::Config config, 260 webrtc::VideoSendStream::Config config,
260 const VideoOptions& options, 261 const VideoOptions& options,
261 WebRtcVideoEncoderFactory* external_encoder_factory, 262 const EncoderFactoryAdapter& encoder_factory,
262 bool enable_cpu_overuse_detection, 263 bool enable_cpu_overuse_detection,
263 int max_bitrate_bps, 264 int max_bitrate_bps,
264 const rtc::Optional<VideoCodecSettings>& codec_settings, 265 const rtc::Optional<VideoCodecSettings>& codec_settings,
265 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, 266 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
266 const VideoSendParameters& send_params); 267 const VideoSendParameters& send_params);
267 virtual ~WebRtcVideoSendStream(); 268 virtual ~WebRtcVideoSendStream();
268 269
269 void SetSendParameters(const ChangedSendParameters& send_params); 270 void SetSendParameters(const ChangedSendParameters& send_params);
270 bool SetRtpParameters(const webrtc::RtpParameters& parameters); 271 bool SetRtpParameters(const webrtc::RtpParameters& parameters);
271 webrtc::RtpParameters GetRtpParameters() const; 272 webrtc::RtpParameters GetRtpParameters() const;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 VideoOptions options; 304 VideoOptions options;
304 int max_bitrate_bps; 305 int max_bitrate_bps;
305 bool conference_mode; 306 bool conference_mode;
306 rtc::Optional<VideoCodecSettings> codec_settings; 307 rtc::Optional<VideoCodecSettings> codec_settings;
307 // Sent resolutions + bitrates etc. by the underlying VideoSendStream, 308 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
308 // typically changes when setting a new resolution or reconfiguring 309 // typically changes when setting a new resolution or reconfiguring
309 // bitrates. 310 // bitrates.
310 webrtc::VideoEncoderConfig encoder_config; 311 webrtc::VideoEncoderConfig encoder_config;
311 }; 312 };
312 313
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> 314 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
346 ConfigureVideoEncoderSettings(const VideoCodec& codec); 315 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, 316 void SetCodec(const VideoCodecSettings& codec,
350 bool force_encoder_allocation); 317 bool force_encoder_allocation);
351 void RecreateWebRtcStream(); 318 void RecreateWebRtcStream();
352 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( 319 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
353 const VideoCodec& codec) const; 320 const VideoCodec& codec) const;
354 void ReconfigureEncoder(); 321 void ReconfigureEncoder();
355 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); 322 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
356 323
357 // Calls Start or Stop according to whether or not |sending_| is true, 324 // Calls Start or Stop according to whether or not |sending_| is true,
358 // and whether or not the encoding in |rtp_parameters_| is active. 325 // and whether or not the encoding in |rtp_parameters_| is active.
359 void UpdateSendState(); 326 void UpdateSendState();
360 327
361 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference() 328 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
362 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_); 329 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
363 330
364 rtc::ThreadChecker thread_checker_; 331 rtc::ThreadChecker thread_checker_;
365 rtc::AsyncInvoker invoker_; 332 rtc::AsyncInvoker invoker_;
366 rtc::Thread* worker_thread_; 333 rtc::Thread* worker_thread_;
367 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); 334 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_);
368 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); 335 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_);
369 webrtc::Call* const call_; 336 webrtc::Call* const call_;
370 const bool enable_cpu_overuse_detection_; 337 const bool enable_cpu_overuse_detection_;
371 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_ 338 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
372 ACCESS_ON(&thread_checker_); 339 ACCESS_ON(&thread_checker_);
373 WebRtcVideoEncoderFactory* const external_encoder_factory_ 340 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_); 341 ACCESS_ON(&thread_checker_);
377 342
378 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); 343 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_);
379 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ 344 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
380 ACCESS_ON(&thread_checker_); 345 ACCESS_ON(&thread_checker_);
381 // Contains settings that are the same for all streams in the MediaChannel, 346 // 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 347 // such as codecs, header extensions, and the global bitrate limit for the
383 // entire channel. 348 // entire channel.
384 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); 349 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_);
385 // Contains settings that are unique for each stream, such as max_bitrate. 350 // Contains settings that are unique for each stream, such as max_bitrate.
386 // Does *not* contain codecs, however. 351 // Does *not* contain codecs, however.
387 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. 352 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
388 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only 353 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
389 // one stream per MediaChannel. 354 // one stream per MediaChannel.
390 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); 355 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_);
391 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); 356 std::unique_ptr<webrtc::VideoEncoder> allocated_encoder_
357 ACCESS_ON(&thread_checker_);
358 VideoCodec allocated_codec_ ACCESS_ON(&thread_checker_);
392 359
393 bool sending_ ACCESS_ON(&thread_checker_); 360 bool sending_ ACCESS_ON(&thread_checker_);
394 }; 361 };
395 362
396 // Wrapper for the receiver part, contains configs etc. that are needed to 363 // Wrapper for the receiver part, contains configs etc. that are needed to
397 // reconstruct the underlying VideoReceiveStream. 364 // reconstruct the underlying VideoReceiveStream.
398 class WebRtcVideoReceiveStream 365 class WebRtcVideoReceiveStream
399 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { 366 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
400 public: 367 public:
401 WebRtcVideoReceiveStream( 368 WebRtcVideoReceiveStream(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_ 489 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
523 GUARDED_BY(stream_crit_); 490 GUARDED_BY(stream_crit_);
524 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_ 491 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
525 GUARDED_BY(stream_crit_); 492 GUARDED_BY(stream_crit_);
526 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_); 493 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_);
527 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_); 494 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_);
528 495
529 rtc::Optional<VideoCodecSettings> send_codec_; 496 rtc::Optional<VideoCodecSettings> send_codec_;
530 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_; 497 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
531 498
532 WebRtcVideoEncoderFactory* const external_encoder_factory_; 499 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
533 WebRtcVideoDecoderFactory* const external_decoder_factory_; 500 WebRtcVideoDecoderFactory* const external_decoder_factory_;
534 std::vector<VideoCodecSettings> recv_codecs_; 501 std::vector<VideoCodecSettings> recv_codecs_;
535 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 502 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
536 // See reason for keeping track of the FlexFEC payload type separately in 503 // See reason for keeping track of the FlexFEC payload type separately in
537 // comment in WebRtcVideoChannel::ChangedRecvParameters. 504 // comment in WebRtcVideoChannel::ChangedRecvParameters.
538 int recv_flexfec_payload_type_; 505 int recv_flexfec_payload_type_;
539 webrtc::Call::Config::BitrateConfig bitrate_config_; 506 webrtc::Call::Config::BitrateConfig bitrate_config_;
540 // TODO(deadbeef): Don't duplicate information between 507 // TODO(deadbeef): Don't duplicate information between
541 // send_params/recv_params, rtp_extensions, options, etc. 508 // send_params/recv_params, rtp_extensions, options, etc.
542 VideoSendParameters send_params_; 509 VideoSendParameters send_params_;
(...skipping 20 matching lines...) Expand all
563 const std::string codec_name_; 530 const std::string codec_name_;
564 const int max_qp_; 531 const int max_qp_;
565 const int max_framerate_; 532 const int max_framerate_;
566 const bool is_screencast_; 533 const bool is_screencast_;
567 const bool conference_mode_; 534 const bool conference_mode_;
568 }; 535 };
569 536
570 } // namespace cricket 537 } // namespace cricket
571 538
572 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 539 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698