Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | |
| 6 #define MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | |
| 7 | |
| 8 #include "base/mac/scoped_cftyperef.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "media/cast/sender/video_encoder.h" | |
| 11 | |
| 12 // From CoreMedia, CoreVideo and VideoToolbox | |
| 13 typedef struct opaqueCMSampleBuffer* CMSampleBufferRef; | |
| 14 typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef; | |
| 15 typedef struct OpaqueVTCompressionSession* VTCompressionSessionRef; | |
| 16 typedef UInt32 VTEncodeInfoFlags; | |
| 17 | |
| 18 namespace media { | |
| 19 namespace cast { | |
| 20 | |
| 21 // VideoToolbox implementation of the VideoEncoder interface. | |
| 22 class H264VideoToolboxEncoder : public VideoEncoder { | |
| 23 public: | |
| 24 typedef base::ScopedCFTypeRef<CVPixelBufferRef> PixelBufferPtr; | |
| 25 | |
| 26 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.
| |
| 27 scoped_refptr<CastEnvironment> cast_environment, | |
| 28 const VideoSenderConfig& video_config); | |
| 29 virtual ~H264VideoToolboxEncoder(); | |
| 30 | |
| 31 // After Initialize has been called, this will return the compression | |
| 32 // session's internal pixel buffer pool. Clients that create this encoder | |
| 33 // explicitly probably have knowledge of CoreVideo and can use this pool to | |
| 34 // ensure they send compatible and optimized buffers to the encoder. | |
| 35 CVPixelBufferPoolRef cv_pixel_buffer_pool() const; | |
| 36 | |
| 37 // media::cast::VideoEncoder implementation | |
| 38 virtual bool EncodeVideoFrame( | |
| 39 const scoped_refptr<media::VideoFrame>& video_frame, | |
| 40 const base::TimeTicks& capture_time, | |
| 41 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE; | |
| 42 virtual void SetBitRate(int new_bit_rate) OVERRIDE; | |
| 43 virtual void GenerateKeyFrame() OVERRIDE; | |
| 44 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE; | |
| 45 | |
| 46 private: | |
| 47 typedef base::ScopedCFTypeRef<CFDictionaryRef> DictionaryPtr; | |
| 48 struct FrameContext; | |
| 49 | |
| 50 // Initialize the compression session. | |
| 51 void Initialize(); | |
| 52 | |
| 53 // Configures the compression session. | |
| 54 void ConfigureSession(); | |
| 55 | |
| 56 // Teardown the encoder. | |
| 57 void Teardown(); | |
| 58 | |
| 59 // Wrap a VideoFrame in a new CVPixelBuffer | |
| 60 PixelBufferPtr WrapVideoFrame(media::VideoFrame& frame); | |
| 61 | |
| 62 // Compression session callback function to handle compressed frames. | |
| 63 static void CompressionCallback(void* encoder_opaque, | |
| 64 void* frame_opaque, | |
| 65 OSStatus status, | |
| 66 VTEncodeInfoFlags info, | |
| 67 CMSampleBufferRef sbuf); | |
| 68 | |
| 69 // Copies an H264 frame stored in a CM sample buffer to an Annex B buffer. | |
| 70 // Copies parameter sets for keyframes before the frame data. | |
| 71 static void CopySampleBufferToAnnexBBuffer(CMSampleBufferRef sbuf, | |
| 72 std::string& annexb_buffer, | |
| 73 bool keyframe); | |
| 74 | |
| 75 // The cast environment (contains worker threads & more). | |
| 76 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.
| |
| 77 | |
| 78 // The cast video configuration (contains resolution, bitrate & more). | |
| 79 const VideoSenderConfig cast_config_; | |
| 80 | |
| 81 // Additional properties to apply on the compression session. See | |
| 82 // VTCompressionSessionProperties.h. Will override any properties set by the | |
| 83 // this class (i.e. this dictionary is applied last without filtering). | |
| 84 DictionaryPtr compression_properties_; | |
| 85 | |
| 86 // VideoToolbox makes no guarantees that it is thread safe, so use a thread | |
| 87 // checker to enforce that this object is pinned on a specific thread. The | |
| 88 // binding occurs in Initialize(), not the ctor. | |
| 89 base::ThreadChecker thread_checker_; | |
| 90 | |
| 91 // The compression session. | |
| 92 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; | |
| 93 | |
| 94 // Frame identifier counter. | |
| 95 uint32 frame_id_; | |
| 96 | |
| 97 // Frame identifier of the last encoded keyframe. | |
| 98 uint32 last_keyframe_id_; | |
| 99 | |
| 100 // Are we actually using a hardware encoder. On some platforms under certain | |
| 101 // conditions, VT will fallback to software. | |
| 102 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.
| |
| 103 | |
| 104 // Force next frame to be a keyframe. | |
| 105 bool encode_next_frame_as_keyframe_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); | |
| 108 }; | |
| 109 | |
| 110 } // namespace cast | |
| 111 } // namespace media | |
| 112 | |
| 113 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | |
| OLD | NEW |