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 BufferFlag { | |
29 BUFFER_FLAG_END_OF_STREAM = 4, | |
30 }; | |
31 | |
32 enum DequeueBufferInfo { | |
33 INFO_OUTPUT_BUFFERS_CHANGED = -3, | |
34 INFO_OUTPUT_FORMAT_CHANGED = -2, | |
35 INFO_TRY_AGAIN_LATER = -1, | |
36 }; | |
37 | |
38 static const base::TimeDelta kTimeOutInfinity; | |
39 static const base::TimeDelta kTimeOutNoWait; | |
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 the given buffer to media codec. Call this after filling the input | |
69 // buffer at the specified index | |
70 void QueueInputBuffer(int index, int offset, int size, | |
71 base::TimeDelta presentation_time, int flags); | |
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, int* flags); | |
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 // Puts a byte array to the given input buffer. Returns the number of bytes | |
91 // put to the input buffer. | |
92 size_t PutToInputBuffer(int index, const uint8* data, int size); | |
Ami GONE FROM CHROMIUM
2013/02/07 19:40:16
Yes, that's what I meant.
dwkang1
2013/02/13 12:57:19
Done.
| |
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 | |
OLD | NEW |