Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: media/cast/sender/h264_vt_encoder.h

Issue 450693006: VideoToolbox encoder for cast senders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase build files on top of media_for_cast_ios component defined in 581803003. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <string>
miu 2014/09/24 00:10:13 This should be moved to the .cc file since std::st
9
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/threading/thread_checker.h"
12 #include "media/base/mac/videotoolbox_glue.h"
13 #include "media/cast/sender/video_encoder.h"
14
15 namespace media {
16 namespace cast {
17
18 // VideoToolbox implementation of the media::cast::VideoEncoder interface.
19 // VideoToolbox makes no guarantees that it is thread safe, so this object is
20 // pinned to the thread on which it is constructed.
21 class H264VideoToolboxEncoder : public VideoEncoder {
22 typedef CoreMediaGlue::CMSampleBufferRef CMSampleBufferRef;
23 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef;
24 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags;
25
26 public:
27 H264VideoToolboxEncoder(scoped_refptr<CastEnvironment> cast_environment,
28 const VideoSenderConfig& video_config,
29 const CastInitializationCallback& initialization_cb);
30 virtual ~H264VideoToolboxEncoder();
31
32 // After Initialize has been called, returns the compression session's
33 // internal pixel buffer pool. Clients can use it to provide video frames that
34 // will not incur a copy into encoder-accessible memory.
35 CVPixelBufferPoolRef cv_pixel_buffer_pool() const;
miu 2014/09/24 00:10:13 Style issue: This method is more complex than just
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 // Initialize the compression session.
48 bool Initialize(const VideoSenderConfig& video_config);
49
50 // Configure the compression session.
51 void ConfigureSession(const VideoSenderConfig& video_config);
52
53 // Teardown the encoder.
54 void Teardown();
55
56 // Wrap a VideoFrame in a new CVPixelBuffer
57 base::ScopedCFTypeRef<CVPixelBufferRef> WrapVideoFrame(
58 const scoped_refptr<media::VideoFrame>& frame);
59
60 // Set a compression session property.
61 bool SetSessionProperty(CFStringRef key, uint32_t value);
62 bool SetSessionProperty(CFStringRef key, bool value);
63 bool SetSessionProperty(CFStringRef key, CFStringRef value);
64
65 // Compression session callback function to handle compressed frames.
66 static void CompressionCallback(void* encoder_opaque,
67 void* frame_opaque,
68 OSStatus status,
69 VTEncodeInfoFlags info,
70 CMSampleBufferRef sbuf);
71
72 // The cast environment (contains worker threads & more).
73 const scoped_refptr<CastEnvironment> cast_environment_;
74
75 // VideoToolboxGlue provides access to VideoToolbox at runtime.
76 const VideoToolboxGlue* videotoolbox_glue_;
77
78 // Thread checker to enforce that this object is used on a specific thread.
79 base::ThreadChecker thread_checker_;
80
81 // The compression session.
82 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_;
83
84 // Frame identifier counter.
85 uint32 frame_id_;
86
87 // Force next frame to be a keyframe.
88 bool encode_next_frame_as_keyframe_;
89
90 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder);
91 };
92
93 } // namespace cast
94 } // namespace media
95
96 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698