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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: media/base/android/media_codec_bridge.h
diff --git a/media/base/android/media_codec_bridge.h b/media/base/android/media_codec_bridge.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb3ae8c238b486009f205703575d835e7e36ca3b
--- /dev/null
+++ b/media/base/android/media_codec_bridge.h
@@ -0,0 +1,123 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
+#define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
+
+#include <jni.h>
+#include <string>
+
+#include "base/android/scoped_java_ref.h"
+#include "ui/gfx/size.h"
+
+namespace media {
+
+// This class serves as a bridge for native code to call java functions inside
+// Android MediaCodec class. For more information on Android MediaCodec, check
+// http://developer.android.com/reference/android/media/MediaCodec.html
+class MediaCodecBridge {
+ public:
+ enum Codec {
+ AUDIO_MPEG,
+ VIDEO_H264,
+ VIDEO_VP8,
+ 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.
+ };
+
+ enum BufferFlag {
+ BUFFER_FLAG_END_OF_STREAM = 4,
+ BUFFER_FLAG_CODEC_CONFIG = 2,
+ BUFFER_FLAG_FLAG_SYNC_FRAME = 1,
+ };
+
+ enum DequeueBufferInfo {
+ INFO_OUTPUT_BUFFERS_CHANGED = -3,
+ INFO_OUTPUT_FORMAT_CHANGED = -2,
+ INFO_TRY_AGAIN_LATER = -1,
+ };
+
+ enum TimeOut {
+ TIMEOUT_INFINITY = -1,
+ };
+
+ explicit MediaCodecBridge(const Codec codec);
+
+ ~MediaCodecBridge();
+
+ // 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.
+ // XXX: merge the following configure methods by introducing
+ // MediaFormatBridge.
+ void ConfigureAudio(
+ const Codec codec, int sample_rate, int channel_count);
+ void ConfigureVideo(
+ const Codec codec, const gfx::Size& size, jobject surface);
+
+ // Flushes both input and output, all indices previously returned in calls to
+ // DequeueInputBuffer() and DequeueOutputBuffer() become invalid.
+ // Please note that this clears all the inputs in the media codec. In other
+ // 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
+ void Flush();
+
+ // 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(
+ void Stop();
+
+ // Used for getting output format. This is valid after DequeueInputBuffer()
+ // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED
+ void GetOutputFormat(int* format, int* width, int* height);
+
+ // Submit the given buffer to media codec. Call this after filling the input
+ // buffer at the specified index
+ void QueueInputBuffer(int index, int offset, int size,
+ 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.
+
+ // Returns the index of an input buffer to be filled with valid data or
+ // INFO_TRY_AGAIN_LATER if no such buffer is currently available.
+ // TIMEOUT_INFINITY for |timeout_us| indicates infinite.
+ int DequeueInputBuffer(int64 timeout_us);
+
+ // Dequeues an output buffer, block at most timeout_us microseconds.
+ // Returns the index of an output buffer that has been successfully decoded
+ // or one of DequeueBufferInfo above.
+ // TIMEOUT_INFINITY for |timeout_us| indicates infinite.
+ int DequeueOutputBuffer(
+ int64 timeout_us, int* offset, int* size, int64* presentation_time_us,
+ int* flags);
+
+ // Returns the buffer to the codec. If you previously specified a surface
+ // when configuring this video decoder you can optionally render the buffer.
+ void ReleaseOutputBuffer(int index, bool render);
+
+ // Gets input buffers from media codec and keeps them inside this class.
+ // To access them, use DequeueInputBuffer(), PutToInputBuffer() and
+ // QueueInputBuffer().
+ int GetInputBuffers();
+
+ // Gets output buffers from media codec and keeps them inside this class.
+ // To access them, use DequeueOutputBuffer() and GetFromOutputBuffer().
+ int GetOutputBuffers();
+
+ // Puts a byte array to the given input buffer.
+ void PutToInputBuffer(int index, const uint8* data, int size);
+
+ // 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.
+ void GetFromOutputBuffer(int index, int offset, uint8* data, int size);
+
+ private:
+
+ // Java MediaCodec instance.
+ base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
+
+ // Input buffers used for *InputBuffer() methods.
+ base::android::ScopedJavaGlobalRef<jobjectArray> j_input_buffers_;
+
+ // Output buffers used for *InputBuffer() methods.
+ base::android::ScopedJavaGlobalRef<jobjectArray> j_output_buffers_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
+

Powered by Google App Engine
This is Rietveld 408576698