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..c90242b34db86581d458e05b863aeb4a011b42a2 |
--- /dev/null |
+++ b/media/base/android/media_codec_bridge.h |
@@ -0,0 +1,125 @@ |
+// 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 "base/time.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, |
+ }; |
+ |
+ enum BufferFlag { |
+ BUFFER_FLAG_END_OF_STREAM = 4, |
+ BUFFER_FLAG_CODEC_CONFIG = 2, |
+ 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.
|
+ }; |
+ |
+ enum DequeueBufferInfo { |
+ INFO_OUTPUT_BUFFERS_CHANGED = -3, |
+ INFO_OUTPUT_FORMAT_CHANGED = -2, |
+ INFO_TRY_AGAIN_LATER = -1, |
+ }; |
+ |
+ static const base::TimeDelta kTimeOutInfinity; |
+ |
+ explicit MediaCodecBridge(const Codec codec); |
+ |
+ ~MediaCodecBridge(); |
+ |
+ // Starts decoding with the given codec params. |
+ void StartAudio( |
+ const Codec codec, int sample_rate, int channel_count); |
+ void StartVideo( |
+ 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
|
+ |
+ // 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. |
+ 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
|
+ |
+ // Finishes the decode/encode session. The instance remains active |
+ // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy |
+ // vendor's implementation, Stop() -> StartAudio/Video() may not work on some |
+ // devices. For reliability, Stop() -> delete and recreate new instance -> |
+ // StartAudio/Video() is recommended. |
+ 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); |
+ |
+ // Submits 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, |
+ base::TimeDelta presentation_time, int flags); |
+ |
+ // 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. |
+ // Use kTimeOutInfinity for infinite timeout. |
+ int DequeueInputBuffer(base::TimeDelta timeout); |
+ |
+ // 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. |
+ // Use kTimeOutInfinity for infinite timeout. |
+ int DequeueOutputBuffer( |
+ base::TimeDelta timeout, int* offset, int* size, |
+ 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.
|
+ |
+ // 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); |
+ |
+ // Puts a byte array to the given input buffer. Returns the number of bytes |
+ // put to the input buffer. |
+ 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
|
+ |
+ // 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(); |
+ |
+ private: |
+ |
+ // Calls start() against the media codec instance. Used in StartXXX() after |
+ // configuring media codec. |
+ void Start(); |
+ |
+ // 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_ |
+ |