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

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: Modernize to C++11 per the rules at http://chromium-cpp.appspot.com/ Created 6 years, 2 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 "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;
21 typedef VideoToolboxGlue::VTCompressionSessionRef VTCompressionSessionRef;
22 typedef VideoToolboxGlue::VTEncodeInfoFlags VTEncodeInfoFlags;
23
24 public:
25 H264VideoToolboxEncoder(scoped_refptr<CastEnvironment> cast_environment,
26 const VideoSenderConfig& video_config,
27 const CastInitializationCallback& initialization_cb);
28 virtual ~H264VideoToolboxEncoder();
29
30 // After Initialize has been called, returns the compression session's
31 // internal pixel buffer pool. Clients can use it to provide video frames that
32 // will not incur a copy into encoder-accessible memory.
33 CVPixelBufferPoolRef GetCvPixelBufferPool() const;
34
35 // media::cast::VideoEncoder implementation
36 virtual bool EncodeVideoFrame(
37 const scoped_refptr<media::VideoFrame>& video_frame,
38 const base::TimeTicks& capture_time,
39 const FrameEncodedCallback& frame_encoded_callback) override;
40 virtual void SetBitRate(int new_bit_rate) override;
41 virtual void GenerateKeyFrame() override;
42 virtual void LatestFrameIdToReference(uint32 frame_id) override;
43
44 private:
45 // Initialize the compression session.
46 bool Initialize(const VideoSenderConfig& video_config);
47
48 // Configure the compression session.
49 void ConfigureSession(const VideoSenderConfig& video_config);
50
51 // Teardown the encoder.
52 void Teardown();
53
54 // Wrap a VideoFrame in a new CVPixelBuffer
55 base::ScopedCFTypeRef<CVPixelBufferRef> WrapVideoFrame(
56 const scoped_refptr<media::VideoFrame>& frame);
57
58 // Set a compression session property.
59 bool SetSessionProperty(CFStringRef key, int32_t value);
60 bool SetSessionProperty(CFStringRef key, bool value);
61 bool SetSessionProperty(CFStringRef key, CFStringRef value);
62
63 // Compression session callback function to handle compressed frames.
64 static void CompressionCallback(void* encoder_opaque,
65 void* frame_opaque,
66 OSStatus status,
67 VTEncodeInfoFlags info,
68 CMSampleBufferRef sbuf);
69
70 // The cast environment (contains worker threads & more).
71 const scoped_refptr<CastEnvironment> cast_environment_;
72
73 // VideoToolboxGlue provides access to VideoToolbox at runtime.
74 const VideoToolboxGlue* videotoolbox_glue_;
75
76 // Thread checker to enforce that this object is used on a specific thread.
77 base::ThreadChecker thread_checker_;
78
79 // The compression session.
80 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_;
81
82 // Frame identifier counter.
83 uint32 frame_id_;
84
85 // Force next frame to be a keyframe.
86 bool encode_next_frame_as_keyframe_;
87
88 DISALLOW_COPY_AND_ASSIGN(H264VideoToolboxEncoder);
89 };
90
91 } // namespace cast
92 } // namespace media
93
94 #endif // MEDIA_CAST_SENDER_H264_VT_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698