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

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: fixing android_clang build error. Created 7 years, 9 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 // Note: MediaCodec is only available on JB and greater.
21 class MediaCodecBridge {
22 public:
23 enum Codec {
24 AUDIO_MPEG,
25 VIDEO_H264,
26 VIDEO_VP8,
27 };
28
29 enum DequeueBufferInfo {
30 INFO_OUTPUT_BUFFERS_CHANGED = -3,
31 INFO_OUTPUT_FORMAT_CHANGED = -2,
32 INFO_TRY_AGAIN_LATER = -1,
33 };
34
35 static const base::TimeDelta kTimeOutInfinity;
36 static const base::TimeDelta kTimeOutNoWait;
37
38 // Returns true if MediaCodec is available on the device.
39 static bool IsAvailable();
40
41 explicit MediaCodecBridge(const Codec codec);
42
43 ~MediaCodecBridge();
44
45 // Starts decoding with the given codec params.
46 void StartAudio(
47 const Codec codec, int sample_rate, int channel_count);
48 void StartVideo(
49 const Codec codec, const gfx::Size& size, jobject surface);
50
51 // Resets both input and output, all indices previously returned in calls to
52 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid.
53 // Please note that this clears all the inputs in the media codec. In other
54 // words, there will be no outputs until new input is provided.
55 void Reset();
56
57 // Finishes the decode/encode session. The instance remains active
58 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy
59 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not
60 // work on some devices. For reliability, Stop() -> delete and recreate new
61 // instance -> StartAudio/Video() is recommended.
62 void Stop();
63
64 // Used for getting output format. This is valid after DequeueInputBuffer()
65 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED
66 void GetOutputFormat(int* width, int* height);
67
68 // Submits a byte array to the given input buffer. Call this after getting an
69 // available buffer from DequeueInputBuffer(). Returns the number of bytes
70 // put to the input buffer.
71 size_t QueueInputBuffer(int index, const uint8* data, int size,
72 const base::TimeDelta& presentation_time);
73
74 // Submits an empty buffer with a EOS (END OF STREAM) flag.
75 void QueueEOS(int input_buffer_index);
76
77 // Returns the index of an input buffer to be filled with valid data or
78 // INFO_TRY_AGAIN_LATER if no such buffer is currently available.
79 // Use kTimeOutInfinity for infinite timeout.
80 int DequeueInputBuffer(base::TimeDelta timeout);
81
82 // Dequeues an output buffer, block at most timeout_us microseconds.
83 // Returns the index of an output buffer that has been successfully decoded
84 // or one of DequeueBufferInfo above.
85 // Use kTimeOutInfinity for infinite timeout.
86 int DequeueOutputBuffer(
87 base::TimeDelta timeout, int* offset, int* size,
88 base::TimeDelta* presentation_time, bool* end_of_stream);
89
90 // Returns the buffer to the codec. If you previously specified a surface
91 // when configuring this video decoder you can optionally render the buffer.
92 void ReleaseOutputBuffer(int index, bool render);
93
94 // Gets output buffers from media codec and keeps them inside this class.
95 // To access them, use DequeueOutputBuffer() and GetFromOutputBuffer().
96 int GetOutputBuffers();
97
98 private:
99
100 // Calls start() against the media codec instance. Used in StartXXX() after
101 // configuring media codec.
102 void Start();
103
104 // Gets input buffers from media codec and keeps them inside this class.
105 // To access them, use DequeueInputBuffer(), PutToInputBuffer() and
106 // QueueInputBuffer().
107 int GetInputBuffers();
108
109 // Java MediaCodec instance.
110 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
111
112 // Input buffers used for *InputBuffer() methods.
113 base::android::ScopedJavaGlobalRef<jobjectArray> j_input_buffers_;
114
115 // Output buffers used for *InputBuffer() methods.
116 base::android::ScopedJavaGlobalRef<jobjectArray> j_output_buffers_;
117
118 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge);
119 };
120
121 } // namespace media
122
123 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
124
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | media/base/android/media_codec_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698