| Index: media/cast/sender/h264_vt_encoder.h
|
| diff --git a/media/cast/sender/h264_vt_encoder.h b/media/cast/sender/h264_vt_encoder.h
|
| index ece6ab38b1a6f362cdd27207a1b48ad9c284668d..7ae2f0545b337b24d733837cac06046c8d25209d 100644
|
| --- a/media/cast/sender/h264_vt_encoder.h
|
| +++ b/media/cast/sender/h264_vt_encoder.h
|
| @@ -16,13 +16,17 @@ namespace cast {
|
|
|
| // VideoToolbox implementation of the media::cast::VideoEncoder interface.
|
| // VideoToolbox makes no guarantees that it is thread safe, so this object is
|
| -// pinned to the thread on which it is constructed.
|
| +// pinned to the thread on which it is constructed. Supports changing frame
|
| +// sizes directly.
|
| class H264VideoToolboxEncoder : public VideoEncoder {
|
| typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef;
|
| typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef;
|
| typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags;
|
|
|
| public:
|
| + // VideoFrameFactory tied to the VideoToolbox encoder.
|
| + class VideoFrameFactoryImpl;
|
| +
|
| // Returns true if the current platform and system configuration supports
|
| // using H264VideoToolboxEncoder with the given |video_config|.
|
| static bool IsSupported(const VideoSenderConfig& video_config);
|
| @@ -30,8 +34,6 @@ class H264VideoToolboxEncoder : public VideoEncoder {
|
| H264VideoToolboxEncoder(
|
| const scoped_refptr<CastEnvironment>& cast_environment,
|
| const VideoSenderConfig& video_config,
|
| - const gfx::Size& frame_size,
|
| - uint32 first_frame_id,
|
| const StatusChangeCallback& status_change_cb);
|
| ~H264VideoToolboxEncoder() override;
|
|
|
| @@ -47,14 +49,22 @@ class H264VideoToolboxEncoder : public VideoEncoder {
|
| void EmitFrames() override;
|
|
|
| private:
|
| - // Initialize the compression session.
|
| - bool Initialize(const VideoSenderConfig& video_config);
|
| + // Reset the encoder's compression session by destroying the existing one
|
| + // using DestroyCompressionSession() and creating a new one. The new session
|
| + // is configured using ConfigureCompressionSession().
|
| + void ResetCompressionSession();
|
| +
|
| + // Configure the current compression session using current encoder settings.
|
| + void ConfigureCompressionSession();
|
|
|
| - // Configure the compression session.
|
| - void ConfigureSession(const VideoSenderConfig& video_config);
|
| + // Destroy the current compression session if any. Blocks until all pending
|
| + // frames have been flushed out (similar to EmitFrames without doing any
|
| + // encoding work).
|
| + void DestroyCompressionSession();
|
|
|
| - // Teardown the encoder.
|
| - void Teardown();
|
| + // Update the encoder's target frame size by resetting the compression
|
| + // session. This will also update the video frame factory.
|
| + void UpdateFrameSize(const gfx::Size& size_needed);
|
|
|
| // Set a compression session property.
|
| bool SetSessionProperty(CFStringRef key, int32_t value);
|
| @@ -74,8 +84,14 @@ class H264VideoToolboxEncoder : public VideoEncoder {
|
| // VideoToolboxGlue provides access to VideoToolbox at runtime.
|
| const VideoToolboxGlue* const videotoolbox_glue_;
|
|
|
| - // The size of the visible region of the video frames to be encoded.
|
| - const gfx::Size frame_size_;
|
| + // VideoSenderConfig copy so we can create compression sessions on demand.
|
| + // This is needed to recover from backgrounding and other events that can
|
| + // invalidate compression sessions.
|
| + const VideoSenderConfig video_config_;
|
| +
|
| + // Frame size of the current compression session. Can be changed by submitting
|
| + // a frame of a different size, which will cause a compression session reset.
|
| + gfx::Size frame_size_;
|
|
|
| // Callback used to report initialization status and runtime errors.
|
| const StatusChangeCallback status_change_cb_;
|
| @@ -86,41 +102,19 @@ class H264VideoToolboxEncoder : public VideoEncoder {
|
| // The compression session.
|
| base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_;
|
|
|
| - // Frame identifier counter.
|
| - uint32 next_frame_id_;
|
| + // Video frame factory tied to the encoder.
|
| + scoped_refptr<VideoFrameFactoryImpl> video_frame_factory_;
|
| +
|
| + // The ID of the last frame that was emitted.
|
| + uint32 last_frame_id_;
|
|
|
| // Force next frame to be a keyframe.
|
| bool encode_next_frame_as_keyframe_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder);
|
| -};
|
| + // NOTE: Weak pointers must be invalidated before all other member variables.
|
| + base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_;
|
|
|
| -// An implementation of SizeAdaptableVideoEncoderBase to proxy for
|
| -// H264VideoToolboxEncoder instances.
|
| -class SizeAdaptableH264VideoToolboxVideoEncoder
|
| - : public SizeAdaptableVideoEncoderBase {
|
| - public:
|
| - SizeAdaptableH264VideoToolboxVideoEncoder(
|
| - const scoped_refptr<CastEnvironment>& cast_environment,
|
| - const VideoSenderConfig& video_config,
|
| - const StatusChangeCallback& status_change_cb);
|
| -
|
| - ~SizeAdaptableH264VideoToolboxVideoEncoder() override;
|
| -
|
| - scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override;
|
| -
|
| - protected:
|
| - scoped_ptr<VideoEncoder> CreateEncoder() override;
|
| - void OnEncoderReplaced(VideoEncoder* replacement_encoder) override;
|
| - void DestroyEncoder() override;
|
| -
|
| - private:
|
| - struct FactoryHolder;
|
| - class VideoFrameFactoryProxy;
|
| -
|
| - const scoped_refptr<FactoryHolder> holder_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(SizeAdaptableH264VideoToolboxVideoEncoder);
|
| + DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder);
|
| };
|
|
|
| } // namespace cast
|
|
|