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

Side by Side Diff: content/common/gpu/media/android_video_encode_accelerator.h

Issue 74563002: AndroidVideoEncodeAccelerator is born! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_
7
8 #include <list>
9 #include <queue>
10 #include <vector>
11
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/timer/timer.h"
15 #include "base/tuple.h"
16 #include "content/common/content_export.h"
17 #include "media/base/android/media_codec_bridge.h"
18 #include "media/video/video_encode_accelerator.h"
19
20 namespace base {
21 class MessageLoopProxy;
xhwang 2013/11/19 00:11:25 not used?
Ami GONE FROM CHROMIUM 2013/11/21 22:59:07 Done.
22 } // namespace base
23
24 namespace media {
25 class BitstreamBuffer;
26 } // namespace media
27
28 namespace content {
29
30 // Android-specific implementation of media::VideoEncodeAccelerator, enabling
31 // hardware-acceleration of video encoding, based on Android's MediaCodec class
32 // (http://developer.android.com/reference/android/media/MediaCodec.html). This
33 // class expects to live and be called on a single thread (the GPU process'
34 // ChildThread).
35 class CONTENT_EXPORT AndroidVideoEncodeAccelerator
36 : public media::VideoEncodeAccelerator {
37 public:
38 explicit AndroidVideoEncodeAccelerator(
39 media::VideoEncodeAccelerator::Client* client);
40 virtual ~AndroidVideoEncodeAccelerator();
41
42 static std::vector<media::VideoEncodeAccelerator::SupportedProfile>
43 GetSupportedProfiles();
44
45 // media::VideoEncodeAccelerator implementation.
46 virtual void Initialize(media::VideoFrame::Format format,
47 const gfx::Size& input_visible_size,
48 media::VideoCodecProfile output_profile,
49 uint32 initial_bitrate) OVERRIDE;
50 virtual void Encode(const scoped_refptr<media::VideoFrame>& frame,
51 bool force_keyframe) OVERRIDE;
52 virtual void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer)
53 OVERRIDE;
54 virtual void RequestEncodingParametersChange(uint32 bitrate,
55 uint32 framerate) OVERRIDE;
56 virtual void Destroy() OVERRIDE;
57
58 private:
59 enum {
60 // Arbitrary choice.
61 kInitialFramerate = 30,
62 // Until there are non-realtime users, no need for unrequested I-frames.
63 kIFrameInterval = kint32max,
xhwang 2013/11/19 00:11:25 we use UPPER_CASE format for enums (from http://ww
Ami GONE FROM CHROMIUM 2013/11/21 22:59:07 Done.
64 };
65
66 // Impedance-mismatch fixers: MediaCodec is a poll-based API but VEA is a
67 // push-based API; these methods turn the crank to make the two work together.
68 void DoIOTask();
69 void QueueInput();
70 void DequeueOutput();
71
72 // Returns true if we don't need more or bigger output buffers.
73 bool DoOutputBuffersSuffice();
74
75 // Start & stop |io_timer_| if the time seems right.
76 void MaybeStartIOTimer();
77 void MaybeStopIOTimer();
78
79 // Used to DCHECK that we are called on the correct thread.
80 base::ThreadChecker thread_checker_;
81
82 // VideoDecodeAccelerator::Client callbacks go here. Invalidated once any
83 // error triggers.
84 base::WeakPtrFactory<Client> client_ptr_factory_;
85
86 scoped_ptr<media::VideoCodecBridge> media_codec_;
87
88 // Bitstream buffers waiting to be populated & returned to the client.
89 std::vector<media::BitstreamBuffer> available_bitstream_buffers_;
90
91 // Frames waiting to be passed to the codec, queued until an input buffer is
92 // available. Each element is a tuple of <Frame, key_frame, enqueue_time>.
93 typedef std::queue<Tuple3<scoped_refptr<media::VideoFrame>, bool,
94 base::Time> > PendingFrames;
95 PendingFrames pending_frames_;
96
97 // Repeating timer responsible for draining pending IO to the codec.
98 base::RepeatingTimer<AndroidVideoEncodeAccelerator> io_timer_;
99
100 // The difference between number of buffers queued & dequeued at the codec.
101 int32 num_buffers_at_codec_;
102
103 // A monotonically-growing value, used as a fake timestamp just to keep things
104 // appearing to move forward.
105 base::TimeDelta fake_input_timestamp_;
106
107 // Number of requested output buffers and their capacity.
108 int num_output_buffers_; // -1 until RequireBitstreamBuffers.
109 size_t output_buffers_capacity_; // 0 until RequireBitstreamBuffers.
110
111 uint32 last_set_bitrate_;
xhwang 2013/11/19 00:11:25 unit? in bps?
Ami GONE FROM CHROMIUM 2013/11/21 22:59:07 Done.
112
113 DISALLOW_COPY_AND_ASSIGN(AndroidVideoEncodeAccelerator);
114 };
115
116 } // namespace content
117
118 #endif // CONTENT_COMMON_GPU_MEDIA_ANDROID_VIDEO_ENCODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698