Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aef9dabd0d43c633e20205dd707b9bf092e7ed11 |
| --- /dev/null |
| +++ b/media/cast/sender/h264_vt_encoder.h |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| +#define MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |
| + |
| +#include <string> |
|
miu
2014/09/24 00:10:13
This should be moved to the .cc file since std::st
|
| + |
| +#include "base/mac/scoped_cftyperef.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "media/base/mac/videotoolbox_glue.h" |
| +#include "media/cast/sender/video_encoder.h" |
| + |
| +namespace media { |
| +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 { |
| + typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; |
| + typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; |
| + typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; |
| + |
| + public: |
| + H264VideoToolboxEncoder(scoped_refptr<CastEnvironment> cast_environment, |
| + const VideoSenderConfig& video_config, |
| + const CastInitializationCallback& initialization_cb); |
| + virtual ~H264VideoToolboxEncoder(); |
| + |
| + // After Initialize has been called, returns the compression session's |
| + // internal pixel buffer pool. Clients can use it to provide video frames that |
| + // will not incur a copy into encoder-accessible memory. |
| + CVPixelBufferPoolRef cv_pixel_buffer_pool() const; |
|
miu
2014/09/24 00:10:13
Style issue: This method is more complex than just
|
| + |
| + // media::cast::VideoEncoder implementation |
| + virtual bool EncodeVideoFrame( |
| + const scoped_refptr<media::VideoFrame>& video_frame, |
| + const base::TimeTicks& capture_time, |
| + const FrameEncodedCallback& frame_encoded_callback) OVERRIDE; |
| + virtual void SetBitRate(int new_bit_rate) OVERRIDE; |
| + virtual void GenerateKeyFrame() OVERRIDE; |
| + virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE; |
| + |
| + private: |
| + // Initialize the compression session. |
| + bool Initialize(const VideoSenderConfig& video_config); |
| + |
| + // Configure the compression session. |
| + void ConfigureSession(const VideoSenderConfig& video_config); |
| + |
| + // Teardown the encoder. |
| + void Teardown(); |
| + |
| + // Wrap a VideoFrame in a new CVPixelBuffer |
| + base::ScopedCFTypeRef<CVPixelBufferRef> WrapVideoFrame( |
| + const scoped_refptr<media::VideoFrame>& frame); |
| + |
| + // Set a compression session property. |
| + bool SetSessionProperty(CFStringRef key, uint32_t value); |
| + bool SetSessionProperty(CFStringRef key, bool value); |
| + bool SetSessionProperty(CFStringRef key, CFStringRef value); |
| + |
| + // Compression session callback function to handle compressed frames. |
| + static void CompressionCallback(void* encoder_opaque, |
| + void* frame_opaque, |
| + OSStatus status, |
| + VTEncodeInfoFlags info, |
| + CMSampleBufferRef sbuf); |
| + |
| + // The cast environment (contains worker threads & more). |
| + const scoped_refptr<CastEnvironment> cast_environment_; |
| + |
| + // VideoToolboxGlue provides access to VideoToolbox at runtime. |
| + const VideoToolboxGlue* videotoolbox_glue_; |
| + |
| + // Thread checker to enforce that this object is used on a specific thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + // The compression session. |
| + base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; |
| + |
| + // Frame identifier counter. |
| + uint32 frame_id_; |
| + |
| + // Force next frame to be a keyframe. |
| + bool encode_next_frame_as_keyframe_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); |
| +}; |
| + |
| +} // namespace cast |
| +} // namespace media |
| + |
| +#endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ |