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

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: Remove scoped CF pointer typedefs, cleanup SetSessionProperty, fix compile errors. Created 6 years, 4 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 <CoreMedia/CoreMedia.h>
9 #include <VideoToolbox/VideoToolbox.h>
10 #include <string>
11
12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/threading/thread_checker.h"
14 #include "media/cast/sender/video_encoder.h"
15
16 namespace media {
17 namespace cast {
18
19 // VideoToolbox implementation of the media::cast::VideoEncoder interface.
Robert Sesek 2014/08/12 00:06:12 Hoist the comment about thread safety up to this c
jfroy 2014/08/12 01:04:15 Acknowledged.
20 class H264VideoToolboxEncoder : public VideoEncoder {
21 public:
22 H264VideoToolboxEncoder(scoped_refptr<CastEnvironment> cast_environment,
23 const VideoSenderConfig& video_config);
24 virtual ~H264VideoToolboxEncoder();
25
26 // After Initialize has been called, returns the compression session's
27 // internal pixel buffer pool. Clients can use it to provide video frames that
28 // will not incur a copy into encoder-accessible memory.
29 CVPixelBufferPoolRef cv_pixel_buffer_pool() const;
30
31 // media::cast::VideoEncoder implementation
32 virtual bool EncodeVideoFrame(
33 const scoped_refptr<media::VideoFrame>& video_frame,
34 const base::TimeTicks& capture_time,
35 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE;
36 virtual void SetBitRate(int new_bit_rate) OVERRIDE;
37 virtual void GenerateKeyFrame() OVERRIDE;
38 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE;
39
40 private:
41 // Initialize the compression session.
42 void Initialize();
43
44 // Configure the compression session.
45 void ConfigureSession();
46
47 // Teardown the encoder.
48 void Teardown();
49
50 // Wrap a VideoFrame in a new CVPixelBuffer
51 base::ScopedCFTypeRef<CVPixelBufferRef> WrapVideoFrame(
52 const scoped_refptr<media::VideoFrame>& frame);
53
54 // Compression session callback function to handle compressed frames.
55 static void CompressionCallback(void* encoder_opaque,
56 void* frame_opaque,
57 OSStatus status,
58 VTEncodeInfoFlags info,
59 CMSampleBufferRef sbuf);
60
61 // Copy a H.264 frame stored in a CM sample buffer to an Annex B buffer.
62 // Copies parameter sets for keyframes before the frame data.
63 static void CopySampleBufferToAnnexBBuffer(CMSampleBufferRef sbuf,
64 std::string* annexb_buffer,
65 bool keyframe);
66
67 // The cast environment (contains worker threads & more).
68 const scoped_refptr<CastEnvironment> cast_environment_;
69
70 // The cast video configuration (contains resolution, bitrate & more).
71 const VideoSenderConfig cast_config_;
72
73 // VideoToolbox makes no guarantees that it is thread safe, so use a thread
74 // checker to enforce that this object is pinned on a specific thread. The
75 // binding occurs in Initialize(), not the ctor.
Robert Sesek 2014/08/12 00:06:12 This comment is misleading, since Initialize is on
jfroy 2014/08/12 01:04:15 Acknowledged.
76 base::ThreadChecker thread_checker_;
77
78 // The compression session.
79 base::ScopedCFTypeRef<VTCompressionSessionRef> compression_session_;
80
81 // Frame identifier counter.
82 uint32 frame_id_;
83
84 // Frame identifier of the last encoded keyframe.
85 uint32 last_keyframe_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
« no previous file with comments | « no previous file | media/cast/sender/h264_vt_encoder.cc » ('j') | media/cast/sender/h264_vt_encoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698