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

Side by Side Diff: media/base/android/media_codec_bridge.h

Issue 11973010: AndroidVDA by using Android's MediaCodec API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: using flush() for reset(). Created 7 years, 10 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 (c) 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 MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
7
8 #include <jni.h>
9 #include <string>
10
11 #include "base/android/scoped_java_ref.h"
12 #include "base/time.h"
13 #include "ui/gfx/size.h"
14
15 namespace media {
16
17 // This class serves as a bridge for native code to call java functions inside
18 // Android MediaCodec class. For more information on Android MediaCodec, check
19 // http://developer.android.com/reference/android/media/MediaCodec.html
20 class MediaCodecBridge {
21 public:
22 enum Codec {
23 AUDIO_MPEG,
24 VIDEO_H264,
25 VIDEO_VP8,
26 };
27
28 enum BufferFlag {
29 BUFFER_FLAG_END_OF_STREAM = 4,
30 BUFFER_FLAG_CODEC_CONFIG = 2,
31 BUFFER_FLAG_FLAG_SYNC_FRAME = 1,
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 Neither of the latter two flags is used. Are you
dwkang1 2013/02/07 14:01:36 Removed.
32 };
33
34 enum DequeueBufferInfo {
35 INFO_OUTPUT_BUFFERS_CHANGED = -3,
36 INFO_OUTPUT_FORMAT_CHANGED = -2,
37 INFO_TRY_AGAIN_LATER = -1,
38 };
39
40 static const base::TimeDelta kTimeOutInfinity;
41
42 explicit MediaCodecBridge(const Codec codec);
43
44 ~MediaCodecBridge();
45
46 // Starts decoding with the given codec params.
47 void StartAudio(
48 const Codec codec, int sample_rate, int channel_count);
49 void StartVideo(
50 const Codec codec, const gfx::Size& size, jobject surface);
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 Actually, instead of feeding in a dummy size, how
51
52 // Flushes both input and output, all indices previously returned in calls to
53 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid.
54 // Please note that this clears all the inputs in the media codec. In other
55 // words, there will be no outputs until new input is provided.
56 void Flush();
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 My point was that this would be better named Reset
dwkang1 2013/02/07 14:01:36 Ah, I am poor at getting the real meaning of the s
57
58 // Finishes the decode/encode session. The instance remains active
59 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy
60 // vendor's implementation, Stop() -> StartAudio/Video() may not work on some
61 // devices. For reliability, Stop() -> delete and recreate new instance ->
62 // StartAudio/Video() is recommended.
63 void Stop();
64
65 // Used for getting output format. This is valid after DequeueInputBuffer()
66 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED
67 void GetOutputFormat(int* format, int* width, int* height);
68
69 // Submits the given buffer to media codec. Call this after filling the input
70 // buffer at the specified index
71 void QueueInputBuffer(int index, int offset, int size,
72 base::TimeDelta presentation_time, int flags);
73
74 // Returns the index of an input buffer to be filled with valid data or
75 // INFO_TRY_AGAIN_LATER if no such buffer is currently available.
76 // Use kTimeOutInfinity for infinite timeout.
77 int DequeueInputBuffer(base::TimeDelta timeout);
78
79 // Dequeues an output buffer, block at most timeout_us microseconds.
80 // Returns the index of an output buffer that has been successfully decoded
81 // or one of DequeueBufferInfo above.
82 // Use kTimeOutInfinity for infinite timeout.
83 int DequeueOutputBuffer(
84 base::TimeDelta timeout, int* offset, int* size,
85 base::TimeDelta& presentation_time, int* flags);
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 style: no non-const refs in chromium. s/base::Tim
dwkang1 2013/02/07 14:01:36 Done.
86
87 // Returns the buffer to the codec. If you previously specified a surface
88 // when configuring this video decoder you can optionally render the buffer.
89 void ReleaseOutputBuffer(int index, bool render);
90
91 // Puts a byte array to the given input buffer. Returns the number of bytes
92 // put to the input buffer.
93 size_t PutToInputBuffer(int index, const uint8* data, int size);
Ami GONE FROM CHROMIUM 2013/02/05 20:24:33 Why does GIB() still make sense as an API? Wouldn
dwkang1 2013/02/07 14:01:36 I don't think so. we can just call GIB() once afte
94
95 // Gets input buffers from media codec and keeps them inside this class.
96 // To access them, use DequeueInputBuffer(), PutToInputBuffer() and
97 // QueueInputBuffer().
98 int GetInputBuffers();
99
100 // Gets output buffers from media codec and keeps them inside this class.
101 // To access them, use DequeueOutputBuffer() and GetFromOutputBuffer().
102 int GetOutputBuffers();
103
104 private:
105
106 // Calls start() against the media codec instance. Used in StartXXX() after
107 // configuring media codec.
108 void Start();
109
110 // Java MediaCodec instance.
111 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
112
113 // Input buffers used for *InputBuffer() methods.
114 base::android::ScopedJavaGlobalRef<jobjectArray> j_input_buffers_;
115
116 // Output buffers used for *InputBuffer() methods.
117 base::android::ScopedJavaGlobalRef<jobjectArray> j_output_buffers_;
118
119 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge);
120 };
121
122 } // namespace media
123
124 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
125
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698