Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 DequeueBufferInfo { | |
| 29 INFO_OUTPUT_BUFFERS_CHANGED = -3, | |
| 30 INFO_OUTPUT_FORMAT_CHANGED = -2, | |
| 31 INFO_TRY_AGAIN_LATER = -1, | |
| 32 }; | |
| 33 | |
| 34 static const base::TimeDelta kTimeOutInfinity; | |
| 35 static const base::TimeDelta kTimeOutNoWait; | |
| 36 | |
| 37 explicit MediaCodecBridge(const Codec codec); | |
| 38 | |
| 39 ~MediaCodecBridge(); | |
| 40 | |
| 41 // Starts decoding with the given codec params. | |
| 42 void StartAudio( | |
| 43 const Codec codec, int sample_rate, int channel_count); | |
| 44 void StartVideo( | |
| 45 const Codec codec, const gfx::Size& size, jobject surface); | |
| 46 | |
| 47 // Resets both input and output, all indices previously returned in calls to | |
| 48 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid. | |
| 49 // Please note that this clears all the inputs in the media codec. In other | |
| 50 // words, there will be no outputs until new input is provided. | |
| 51 void Reset(); | |
| 52 | |
| 53 // Finishes the decode/encode session. The instance remains active | |
| 54 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy | |
| 55 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not | |
| 56 // work on some devices. For reliability, Stop() -> delete and recreate new | |
| 57 // instance -> StartAudio/Video() is recommended. | |
| 58 void Stop(); | |
| 59 | |
| 60 // Used for getting output format. This is valid after DequeueInputBuffer() | |
| 61 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED | |
| 62 void GetOutputFormat(int* width, int* height); | |
| 63 | |
| 64 // Submits a byte array to the given input buffer. Call this after getting an | |
| 65 // available buffer from DequeueInputBuffer(). Returns the number of bytes | |
| 66 // put to the input buffer. | |
| 67 size_t QueueInputBuffer(int index, const uint8* data, int size, | |
|
Ami GONE FROM CHROMIUM
2013/02/13 18:07:11
nit: Is there any reason to keep DequeueInputBuffe
dwkang1
2013/02/16 11:30:31
Tried to apply it, but I realized that the current
| |
| 68 const base::TimeDelta& presentation_time); | |
| 69 | |
| 70 // Submits an empty buffer with a EOS (END OF STREAM) flag. | |
| 71 void QueueEOS(int input_buffer_index); | |
| 72 | |
| 73 // Returns the index of an input buffer to be filled with valid data or | |
| 74 // INFO_TRY_AGAIN_LATER if no such buffer is currently available. | |
| 75 // Use kTimeOutInfinity for infinite timeout. | |
| 76 int DequeueInputBuffer(base::TimeDelta timeout); | |
| 77 | |
| 78 // Dequeues an output buffer, block at most timeout_us microseconds. | |
| 79 // Returns the index of an output buffer that has been successfully decoded | |
| 80 // or one of DequeueBufferInfo above. | |
| 81 // Use kTimeOutInfinity for infinite timeout. | |
| 82 int DequeueOutputBuffer( | |
| 83 base::TimeDelta timeout, int* offset, int* size, | |
| 84 base::TimeDelta* presentation_time, bool* end_of_stream); | |
| 85 | |
| 86 // Returns the buffer to the codec. If you previously specified a surface | |
| 87 // when configuring this video decoder you can optionally render the buffer. | |
| 88 void ReleaseOutputBuffer(int index, bool render); | |
| 89 | |
| 90 // Gets output buffers from media codec and keeps them inside this class. | |
| 91 // To access them, use DequeueOutputBuffer() and GetFromOutputBuffer(). | |
| 92 int GetOutputBuffers(); | |
| 93 | |
| 94 private: | |
| 95 | |
| 96 enum BufferFlag { | |
|
Ami GONE FROM CHROMIUM
2013/02/13 18:07:11
nit: can go in the .cc file?
dwkang1
2013/02/16 11:30:31
Done.
| |
| 97 BUFFER_FLAG_END_OF_STREAM = 4, | |
| 98 }; | |
| 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 | |
| OLD | NEW |