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

Unified Diff: media/cast/sender/h264_vt_encoder.h

Issue 1100763002: Inject CanAddURLToHistory into TopSitesImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs
Patch Set: Fix error introduced during rebase Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.cc ('k') | media/cast/sender/h264_vt_encoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4df932069521771ab5e3e2cd7f22c7009802e2ea 100644
--- a/media/cast/sender/h264_vt_encoder.h
+++ b/media/cast/sender/h264_vt_encoder.h
@@ -6,6 +6,7 @@
#define MEDIA_CAST_SENDER_H264_VT_ENCODER_H_
#include "base/mac/scoped_cftyperef.h"
+#include "base/power_monitor/power_observer.h"
#include "base/threading/thread_checker.h"
#include "media/base/mac/videotoolbox_glue.h"
#include "media/cast/sender/size_adaptable_video_encoder_base.h"
@@ -16,8 +17,11 @@ 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.
-class H264VideoToolboxEncoder : public VideoEncoder {
+// pinned to the thread on which it is constructed. Supports changing frame
+// sizes directly. Implements the base::PowerObserver interface to reset the
+// compression session when the host process is suspended.
+class H264VideoToolboxEncoder : public VideoEncoder,
+ public base::PowerObserver {
typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef;
typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef;
typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags;
@@ -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;
@@ -46,15 +48,30 @@ class H264VideoToolboxEncoder : public VideoEncoder {
scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override;
void EmitFrames() override;
+ // base::PowerObserver
+ void OnSuspend() override;
+ void OnResume() override;
+
private:
- // Initialize the compression session.
- bool Initialize(const VideoSenderConfig& video_config);
+ // VideoFrameFactory tied to the VideoToolbox encoder.
+ class VideoFrameFactoryImpl;
+
+ // 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 +91,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 +109,22 @@ 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);
-};
+ // Power suspension state.
+ bool power_suspended_;
-// 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;
+ // NOTE: Weak pointers must be invalidated before all other member variables.
+ base::WeakPtrFactory<H264VideoToolboxEncoder> weak_factory_;
- private:
- struct FactoryHolder;
- class VideoFrameFactoryProxy;
-
- const scoped_refptr<FactoryHolder> holder_;
-
- DISALLOW_COPY_AND_ASSIGN(SizeAdaptableH264VideoToolboxVideoEncoder);
+ DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder);
};
} // namespace cast
« no previous file with comments | « media/blink/webcontentdecryptionmodulesession_impl.cc ('k') | media/cast/sender/h264_vt_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698