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

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

Issue 3007643002: Clean up ownership of webrtc::VideoEncoder (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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // not take the ownership of |encoder_factory|. The caller needs to make sure 115 // not take the ownership of |encoder_factory|. The caller needs to make sure
116 // that |encoder_factory| outlives the video engine. 116 // that |encoder_factory| outlives the video engine.
117 virtual void SetExternalEncoderFactory( 117 virtual void SetExternalEncoderFactory(
118 WebRtcVideoEncoderFactory* encoder_factory); 118 WebRtcVideoEncoderFactory* encoder_factory);
119 119
120 private: 120 private:
121 bool initialized_; 121 bool initialized_;
122 122
123 WebRtcVideoDecoderFactory* external_decoder_factory_; 123 WebRtcVideoDecoderFactory* external_decoder_factory_;
124 WebRtcVideoEncoderFactory* external_encoder_factory_; 124 WebRtcVideoEncoderFactory* external_encoder_factory_;
125 std::unique_ptr<WebRtcVideoEncoderFactory> simulcast_encoder_factory_;
126 }; 125 };
127 126
128 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport { 127 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
129 public: 128 public:
130 WebRtcVideoChannel(webrtc::Call* call, 129 WebRtcVideoChannel(webrtc::Call* call,
131 const MediaConfig& config, 130 const MediaConfig& config,
132 const VideoOptions& options, 131 const VideoOptions& options,
133 WebRtcVideoEncoderFactory* external_encoder_factory, 132 WebRtcVideoEncoderFactory* external_encoder_factory,
134 WebRtcVideoDecoderFactory* external_decoder_factory); 133 WebRtcVideoDecoderFactory* external_decoder_factory);
135 ~WebRtcVideoChannel() override; 134 ~WebRtcVideoChannel() override;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 VideoOptions options; 303 VideoOptions options;
305 int max_bitrate_bps; 304 int max_bitrate_bps;
306 bool conference_mode; 305 bool conference_mode;
307 rtc::Optional<VideoCodecSettings> codec_settings; 306 rtc::Optional<VideoCodecSettings> codec_settings;
308 // Sent resolutions + bitrates etc. by the underlying VideoSendStream, 307 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
309 // typically changes when setting a new resolution or reconfiguring 308 // typically changes when setting a new resolution or reconfiguring
310 // bitrates. 309 // bitrates.
311 webrtc::VideoEncoderConfig encoder_config; 310 webrtc::VideoEncoderConfig encoder_config;
312 }; 311 };
313 312
314 struct AllocatedEncoder { 313 class AllocatedEncoder {
315 AllocatedEncoder(webrtc::VideoEncoder* encoder, 314 public:
315 AllocatedEncoder() = default;
316 AllocatedEncoder(AllocatedEncoder&&) = default;
317 AllocatedEncoder& operator=(AllocatedEncoder&&) = default;
318
319 AllocatedEncoder(std::unique_ptr<webrtc::VideoEncoder> encoder,
320 std::unique_ptr<webrtc::VideoEncoder> external_encoder,
316 const cricket::VideoCodec& codec, 321 const cricket::VideoCodec& codec,
317 bool external); 322 bool has_internal_source);
318 webrtc::VideoEncoder* encoder; 323
319 webrtc::VideoEncoder* external_encoder; 324 // Returns a raw pointer to the allocated encoder. This object still has
320 cricket::VideoCodec codec; 325 // ownership of the encoder and is responsible for deleting it.
321 bool external; 326 webrtc::VideoEncoder* encoder() { return encoder_.get(); }
327
328 // Returns true if the encoder is external.
329 bool IsExternal() { return static_cast<bool>(external_encoder_); }
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 // TODO(magjed): |external_encoder_| is not used except for managing
341 // the lifetime when we use VideoEncoderSoftwareFallbackWrapper. Let
342 // VideoEncoderSoftwareFallbackWrapper own the external encoder instead
343 // and remove this member variable.
344 std::unique_ptr<webrtc::VideoEncoder> external_encoder_;
345 cricket::VideoCodec codec_;
346 bool has_internal_source_;
322 }; 347 };
323 348
324 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> 349 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
325 ConfigureVideoEncoderSettings(const VideoCodec& codec); 350 ConfigureVideoEncoderSettings(const VideoCodec& codec);
326 // If force_encoder_allocation is true, a new AllocatedEncoder is always 351 // Creates and returns a new AllocatedEncoder of the specified codec type.
327 // created. If false, the allocated encoder may be reused, if the type 352 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec);
328 // matches.
329 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec,
330 bool force_encoder_allocation);
331 void DestroyVideoEncoder(AllocatedEncoder* encoder);
332 void SetCodec(const VideoCodecSettings& codec, 353 void SetCodec(const VideoCodecSettings& codec,
333 bool force_encoder_allocation); 354 bool force_encoder_allocation);
334 void RecreateWebRtcStream(); 355 void RecreateWebRtcStream();
335 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( 356 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
336 const VideoCodec& codec) const; 357 const VideoCodec& codec) const;
337 void ReconfigureEncoder(); 358 void ReconfigureEncoder();
338 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); 359 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
339 360
340 // Calls Start or Stop according to whether or not |sending_| is true, 361 // Calls Start or Stop according to whether or not |sending_| is true,
341 // and whether or not the encoding in |rtp_parameters_| is active. 362 // and whether or not the encoding in |rtp_parameters_| is active.
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 const std::string codec_name_; 567 const std::string codec_name_;
547 const int max_qp_; 568 const int max_qp_;
548 const int max_framerate_; 569 const int max_framerate_;
549 const bool is_screencast_; 570 const bool is_screencast_;
550 const bool conference_mode_; 571 const bool conference_mode_;
551 }; 572 };
552 573
553 } // namespace cricket 574 } // namespace cricket
554 575
555 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 576 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
OLDNEW
« no previous file with comments | « webrtc/media/engine/simulcast_encoder_adapter.cc ('k') | webrtc/media/engine/webrtcvideoengine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698