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..b72fb847efb4f45ed67ffc38bc0e2cabeff25d59 |
| --- /dev/null |
| +++ b/media/cast/sender/h264_vt_encoder.h |
| @@ -0,0 +1,113 @@ |
| +// 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 "base/mac/scoped_cftyperef.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "media/cast/sender/video_encoder.h" |
| + |
| +// From CoreMedia, CoreVideo and VideoToolbox |
| +typedef struct opaqueCMSampleBuffer* CMSampleBufferRef; |
| +typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef; |
| +typedef struct OpaqueVTCompressionSession* VTCompressionSessionRef; |
| +typedef UInt32 VTEncodeInfoFlags; |
| + |
| +namespace media { |
| +namespace cast { |
| + |
| +// VideoToolbox implementation of the VideoEncoder interface. |
| +class H264VideoToolboxEncoder : public VideoEncoder { |
| + public: |
| + typedef base::ScopedCFTypeRef<CVPixelBufferRef> PixelBufferPtr; |
| + |
| + explicit H264VideoToolboxEncoder( |
|
miu
2014/08/08 17:53:09
Don't need 'explicit' with 2-arg ctor.
jfroy
2014/08/11 20:49:13
Acknowledged.
|
| + scoped_refptr<CastEnvironment> cast_environment, |
| + const VideoSenderConfig& video_config); |
| + virtual ~H264VideoToolboxEncoder(); |
| + |
| + // After Initialize has been called, this will return the compression |
| + // session's internal pixel buffer pool. Clients that create this encoder |
| + // explicitly probably have knowledge of CoreVideo and can use this pool to |
| + // ensure they send compatible and optimized buffers to the encoder. |
| + CVPixelBufferPoolRef cv_pixel_buffer_pool() const; |
| + |
| + // 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: |
| + typedef base::ScopedCFTypeRef<CFDictionaryRef> DictionaryPtr; |
| + struct FrameContext; |
| + |
| + // Initialize the compression session. |
| + void Initialize(); |
| + |
| + // Configures the compression session. |
| + void ConfigureSession(); |
| + |
| + // Teardown the encoder. |
| + void Teardown(); |
| + |
| + // Wrap a VideoFrame in a new CVPixelBuffer |
| + PixelBufferPtr WrapVideoFrame(media::VideoFrame& frame); |
| + |
| + // Compression session callback function to handle compressed frames. |
| + static void CompressionCallback(void* encoder_opaque, |
| + void* frame_opaque, |
| + OSStatus status, |
| + VTEncodeInfoFlags info, |
| + CMSampleBufferRef sbuf); |
| + |
| + // Copies an H264 frame stored in a CM sample buffer to an Annex B buffer. |
| + // Copies parameter sets for keyframes before the frame data. |
| + static void CopySampleBufferToAnnexBBuffer(CMSampleBufferRef sbuf, |
| + std::string& annexb_buffer, |
| + bool keyframe); |
| + |
| + // The cast environment (contains worker threads & more). |
| + scoped_refptr<CastEnvironment> cast_environment_; |
|
miu
2014/08/08 17:53:09
nit: const scoped_refptr<CastEnvironment> cast_env
jfroy
2014/08/11 20:49:13
Acknowledged.
|
| + |
| + // The cast video configuration (contains resolution, bitrate & more). |
| + const VideoSenderConfig cast_config_; |
| + |
| + // Additional properties to apply on the compression session. See |
| + // VTCompressionSessionProperties.h. Will override any properties set by the |
| + // this class (i.e. this dictionary is applied last without filtering). |
| + DictionaryPtr compression_properties_; |
| + |
| + // VideoToolbox makes no guarantees that it is thread safe, so use a thread |
| + // checker to enforce that this object is pinned on a specific thread. The |
| + // binding occurs in Initialize(), not the ctor. |
| + base::ThreadChecker thread_checker_; |
| + |
| + // The compression session. |
| + base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; |
| + |
| + // Frame identifier counter. |
| + uint32 frame_id_; |
| + |
| + // Frame identifier of the last encoded keyframe. |
| + uint32 last_keyframe_id_; |
| + |
| + // Are we actually using a hardware encoder. On some platforms under certain |
| + // conditions, VT will fallback to software. |
| + bool using_hardware_; |
|
miu
2014/08/08 17:53:09
It doesn't look like this is being used for anythi
jfroy
2014/08/11 20:50:06
Acknowledged.
|
| + |
| + // 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_ |