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

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: marking XXX for issues should be resolved before committing. 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 "ui/gfx/size.h"
13
14 namespace media {
15
16 // This class serves as a bridge for native code to call java functions inside
17 // Android MediaCodec class. For more information on Android MediaCodec, check
18 // http://developer.android.com/reference/android/media/MediaCodec.html
19 class MediaCodecBridge {
20 public:
21 enum Codec {
22 AUDIO_MPEG,
23 VIDEO_H264,
24 VIDEO_VP8,
25 UNKNOWN
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 This isn't buying you anything except for extra ca
dwkang1 2013/02/04 14:08:26 Done.
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,
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 enum TimeOut {
41 TIMEOUT_INFINITY = -1,
42 };
43
44 explicit MediaCodecBridge(const Codec codec);
45
46 ~MediaCodecBridge();
47
48 // Configures MediaCodec with the given codec params.
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 These do more than configure; they also Start().
dwkang1 2013/02/04 14:08:26 Done.
49 // XXX: merge the following configure methods by introducing
50 // MediaFormatBridge.
51 void ConfigureAudio(
52 const Codec codec, int sample_rate, int channel_count);
53 void ConfigureVideo(
54 const Codec codec, const gfx::Size& size, jobject surface);
55
56 // Flushes both input and output, all indices previously returned in calls to
57 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid.
58 // Please note that this clears all the inputs in the media codec. In other
59 // words, there will be no outputs until new input is provided.
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 How is this different from what media code calls R
dwkang1 2013/02/04 14:08:26 It should be the same. But, there is a difference
60 void Flush();
61
62 // Finishes the decode session.
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 This is not informative. What happens to pending i
dwkang1 2013/02/04 14:08:26 More description is added, but when I tested stop(
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 // Submit 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 int64 presentation_time_us, int flags);
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 Here & elsewhere, chromium code prefers base::Time
dwkang1 2013/02/04 14:08:26 Done.
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 // TIMEOUT_INFINITY for |timeout_us| indicates infinite.
77 int DequeueInputBuffer(int64 timeout_us);
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 // TIMEOUT_INFINITY for |timeout_us| indicates infinite.
83 int DequeueOutputBuffer(
84 int64 timeout_us, int* offset, int* size, int64* presentation_time_us,
85 int* flags);
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 // Gets input buffers from media codec and keeps them inside this class.
92 // To access them, use DequeueInputBuffer(), PutToInputBuffer() and
93 // QueueInputBuffer().
94 int GetInputBuffers();
95
96 // Gets output buffers from media codec and keeps them inside this class.
97 // To access them, use DequeueOutputBuffer() and GetFromOutputBuffer().
98 int GetOutputBuffers();
99
100 // Puts a byte array to the given input buffer.
101 void PutToInputBuffer(int index, const uint8* data, int size);
102
103 // Gets the data in the given output buffer.
Ami GONE FROM CHROMIUM 2013/01/28 19:49:45 s/\.$/ (unnecessary when decoding video to a surfa
dwkang1 2013/02/04 14:08:26 Done.
104 void GetFromOutputBuffer(int index, int offset, uint8* data, int size);
105
106 private:
107
108 // Java MediaCodec instance.
109 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
110
111 // Input buffers used for *InputBuffer() methods.
112 base::android::ScopedJavaGlobalRef<jobjectArray> j_input_buffers_;
113
114 // Output buffers used for *InputBuffer() methods.
115 base::android::ScopedJavaGlobalRef<jobjectArray> j_output_buffers_;
116
117 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge);
118 };
119
120 } // namespace media
121
122 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
123
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698