| 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..c1872199a5f7dc40bad2d8ac373e971452915470
|
| --- /dev/null
|
| +++ b/media/cast/sender/h264_vt_encoder.h
|
| @@ -0,0 +1,110 @@
|
| +// 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 <CoreMedia/CoreMedia.h>
|
| +#include <VideoToolbox/VideoToolbox.h>
|
| +#include <string>
|
| +
|
| +#include "base/mac/scoped_cftyperef.h"
|
| +#include "base/threading/thread_checker.h"
|
| +#include "media/cast/sender/video_encoder.h"
|
| +
|
| +namespace media {
|
| +namespace cast {
|
| +
|
| +// VideoToolbox implementation of the media::cast::VideoEncoder interface.
|
| +class H264VideoToolboxEncoder : public VideoEncoder {
|
| + public:
|
| + typedef base::ScopedCFTypeRef<CVPixelBufferRef> PixelBufferPtr;
|
| +
|
| + explicit H264VideoToolboxEncoder(
|
| + scoped_refptr<CastEnvironment> cast_environment,
|
| + const VideoSenderConfig& video_config);
|
| + 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;
|
| +
|
| + // 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();
|
| +
|
| + // Configure the compression session.
|
| + void ConfigureSession();
|
| +
|
| + // Teardown the encoder.
|
| + void Teardown();
|
| +
|
| + // Wrap a VideoFrame in a new CVPixelBuffer
|
| + PixelBufferPtr WrapVideoFrame(const scoped_refptr<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);
|
| +
|
| + // Copy a H.264 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_;
|
| +
|
| + // 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_;
|
| +
|
| + // 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_
|
|
|