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/base/mac/videotoolbox_glue.h" | |
11 #include "media/cast/sender/video_encoder.h" | |
12 | |
13 namespace media { | |
14 namespace cast { | |
15 | |
16 // VideoToolbox implementation of the media::cast::VideoEncoder interface. | |
17 // VideoToolbox makes no guarantees that it is thread safe, so this object is | |
18 // pinned to the thread on which it is constructed. | |
19 class H264VideoToolboxEncoder : public VideoEncoder { | |
20 typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef; | |
miu
2014/11/20 23:16:55
nit (for simplicity):
using CoreMediaGlue::CMSamp
| |
21 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef; | |
22 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags; | |
23 | |
24 public: | |
25 H264VideoToolboxEncoder(scoped_refptr<CastEnvironment> cast_environment, | |
miu
2014/11/20 23:16:55
const scoped_refptr<CastEnvironment>&
| |
26 const VideoSenderConfig& video_config, | |
27 const CastInitializationCallback& initialization_cb); | |
28 virtual ~H264VideoToolboxEncoder(); | |
29 | |
30 // media::cast::VideoEncoder implementation | |
31 bool EncodeVideoFrame( | |
32 const scoped_refptr<media::VideoFrame>& video_frame, | |
33 const base::TimeTicks& reference_time, | |
34 const FrameEncodedCallback& frame_encoded_callback) override; | |
35 void SetBitRate(int new_bit_rate) override; | |
36 void GenerateKeyFrame() override; | |
37 void LatestFrameIdToReference(uint32 frame_id) override; | |
38 scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override; | |
39 | |
40 private: | |
41 // Initialize the compression session. | |
42 bool Initialize(const VideoSenderConfig& video_config); | |
43 | |
44 // Configure the compression session. | |
45 void ConfigureSession(const VideoSenderConfig& video_config); | |
46 | |
47 // Teardown the encoder. | |
48 void Teardown(); | |
49 | |
50 // Set a compression session property. | |
51 bool SetSessionProperty(CFStringRef key, int32_t value); | |
52 bool SetSessionProperty(CFStringRef key, bool value); | |
53 bool SetSessionProperty(CFStringRef key, CFStringRef value); | |
54 | |
55 // Compression session callback function to handle compressed frames. | |
56 static void CompressionCallback(void* encoder_opaque, | |
57 void* request_opaque, | |
58 OSStatus status, | |
59 VTEncodeInfoFlags info, | |
60 CMSampleBufferRef sbuf); | |
61 | |
62 // The cast environment (contains worker threads & more). | |
63 const scoped_refptr<CastEnvironment> cast_environment_; | |
64 | |
65 // VideoToolboxGlue provides access to VideoToolbox at runtime. | |
66 const VideoToolboxGlue* videotoolbox_glue_; | |
67 | |
68 // Thread checker to enforce that this object is used on a specific thread. | |
69 base::ThreadChecker thread_checker_; | |
70 | |
71 // The compression session. | |
72 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_; | |
73 | |
74 // Frame identifier counter. | |
75 uint32 frame_id_; | |
76 | |
77 // Force next frame to be a keyframe. | |
78 bool encode_next_frame_as_keyframe_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder); | |
81 }; | |
82 | |
83 } // namespace cast | |
84 } // namespace media | |
85 | |
86 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_ | |
OLD | NEW |