OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/android/jni_android.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 class EncryptionScheme; | 22 class EncryptionScheme; |
22 struct SubsampleEntry; | 23 struct SubsampleEntry; |
23 | 24 |
24 // These must be in sync with MediaCodecBridge.MEDIA_CODEC_XXX constants in | 25 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media |
25 // MediaCodecBridge.java. | 26 // GENERATED_JAVA_PREFIX_TO_STRIP: MEDIA_CODEC_ |
26 enum MediaCodecStatus { | 27 enum MediaCodecStatus { |
27 MEDIA_CODEC_OK, | 28 MEDIA_CODEC_OK, |
28 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, | 29 MEDIA_CODEC_TRY_AGAIN_LATER, |
29 MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER, | |
30 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, | 30 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, |
31 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, | 31 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, |
32 MEDIA_CODEC_NO_KEY, | 32 MEDIA_CODEC_NO_KEY, |
33 MEDIA_CODEC_ERROR | 33 MEDIA_CODEC_ERROR |
34 }; | 34 }; |
35 | 35 |
36 // An interface for a bridge to an Android MediaCodec. | 36 // An interface for a bridge to an Android MediaCodec. |
37 class MEDIA_EXPORT MediaCodecBridge { | 37 class MEDIA_EXPORT MediaCodecBridge { |
38 public: | 38 public: |
39 MediaCodecBridge() = default; | 39 MediaCodecBridge() = default; |
40 virtual ~MediaCodecBridge() = default; | 40 virtual ~MediaCodecBridge() = default; |
41 | 41 |
42 // Calls start() against the media codec instance. Returns whether media | 42 // Calls MediaCodec#stop(). The codec remains ready to be started again with |
43 // codec was successfully started. | 43 // Start(). HOWEVER, due to the buggy vendor's implementation , b/8125974, |
44 virtual bool Start() = 0; | 44 // Stop() -> StartAudio/Video() may not work on some devices. For reliability, |
45 | 45 // Stop() -> delete and recreate new instance -> StartAudio/Video() is |
46 // Finishes the decode/encode session. The instance remains active | 46 // recommended. |
47 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy | |
48 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not | |
49 // work on some devices. For reliability, Stop() -> delete and recreate new | |
50 // instance -> StartAudio/Video() is recommended. | |
51 virtual void Stop() = 0; | 47 virtual void Stop() = 0; |
52 | 48 |
53 // Calls flush() on the MediaCodec. All indices previously returned in calls | 49 // Calls MediaCodec#flush(). The codec takes ownership of all input and output |
54 // to DequeueInputBuffer() and DequeueOutputBuffer() become invalid. Please | 50 // buffers previously dequeued when this is called. Returns MEDIA_CODEC_ERROR |
55 // note that this clears all the inputs in the media codec. In other words, | 51 // if an unexpected error happens, or MEDIA_CODEC_OK otherwise. |
56 // there will be no outputs until new input is provided. Returns | |
57 // MEDIA_CODEC_ERROR if an unexpected error happens, or MEDIA_CODEC_OK | |
58 // otherwise. | |
59 virtual MediaCodecStatus Flush() = 0; | 52 virtual MediaCodecStatus Flush() = 0; |
60 | 53 |
61 // Used for getting the output size. This is valid after DequeueInputBuffer() | 54 // Returns the output size. This is valid after DequeueOutputBuffer() |
62 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED. | 55 // signals a format change by returning INFO_OUTPUT_FORMAT_CHANGED. |
63 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 56 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
64 virtual MediaCodecStatus GetOutputSize(gfx::Size* size) = 0; | 57 virtual MediaCodecStatus GetOutputSize(gfx::Size* size) = 0; |
65 | 58 |
66 // Used for checking for new sampling rate after DequeueInputBuffer() returns | 59 // Gets the sampling rate. This is valid after DequeueOutputBuffer() |
67 // INFO_OUTPUT_FORMAT_CHANGED | 60 // signals a format change by returning INFO_OUTPUT_FORMAT_CHANGED. |
68 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 61 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
69 virtual MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) = 0; | 62 virtual MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) = 0; |
70 | 63 |
71 // Fills |channel_count| with the number of audio channels. Useful after | 64 // Fills |channel_count| with the number of audio channels. This is valid |
72 // INFO_OUTPUT_FORMAT_CHANGED. | 65 // after DequeueOutputBuffer() signals a format change by returning |
73 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 66 // INFO_OUTPUT_FORMAT_CHANGED. Returns MEDIA_CODEC_ERROR if an error occurs, |
| 67 // or MEDIA_CODEC_OK otherwise. |
74 virtual MediaCodecStatus GetOutputChannelCount(int* channel_count) = 0; | 68 virtual MediaCodecStatus GetOutputChannelCount(int* channel_count) = 0; |
75 | 69 |
76 // Submits a byte array to the given input buffer. Call this after getting an | 70 // Submits a byte array to the given input buffer. Call this after getting an |
77 // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the | 71 // available buffer from DequeueInputBuffer(). If |data| is NULL, it assumes |
78 // input buffer has already been populated (but still obey |size|). | 72 // the input buffer has already been populated (but still obeys |size|). |
79 // |data_size| must be less than kint32max (because Java). | 73 // |data_size| must be less than kint32max (because Java). |
80 virtual MediaCodecStatus QueueInputBuffer( | 74 virtual MediaCodecStatus QueueInputBuffer( |
81 int index, | 75 int index, |
82 const uint8_t* data, | 76 const uint8_t* data, |
83 size_t data_size, | 77 size_t data_size, |
84 base::TimeDelta presentation_time) = 0; | 78 base::TimeDelta presentation_time) = 0; |
85 | 79 |
86 // As above but for encrypted buffers. NULL |subsamples| indicates the | 80 // As above but for encrypted buffers. NULL |subsamples| indicates the |
87 // whole buffer is encrypted. | 81 // whole buffer is encrypted. |
88 virtual MediaCodecStatus QueueSecureInputBuffer( | 82 virtual MediaCodecStatus QueueSecureInputBuffer( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // and destination must be at least |num| bytes, and should not overlap. | 127 // and destination must be at least |num| bytes, and should not overlap. |
134 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 128 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
135 virtual MediaCodecStatus CopyFromOutputBuffer(int index, | 129 virtual MediaCodecStatus CopyFromOutputBuffer(int index, |
136 size_t offset, | 130 size_t offset, |
137 void* dst, | 131 void* dst, |
138 size_t num) = 0; | 132 size_t num) = 0; |
139 | 133 |
140 // Gets the component name. Before API level 18 this returns an empty string. | 134 // Gets the component name. Before API level 18 this returns an empty string. |
141 virtual std::string GetName() = 0; | 135 virtual std::string GetName() = 0; |
142 | 136 |
| 137 // Changes the output surface for the MediaCodec. May only be used on API |
| 138 // level 23 and higher (Marshmallow). |
| 139 virtual bool SetSurface(jobject surface) = 0; |
| 140 |
| 141 // Sets the video encoder target bitrate and framerate. |
| 142 virtual void SetVideoBitrate(int bps, int frame_rate) = 0; |
| 143 |
| 144 // Requests that the video encoder insert a key frame. |
| 145 virtual void RequestKeyFrameSoon() = 0; |
| 146 |
| 147 // Returns whether the codec is configured for adaptive playback. |
| 148 virtual bool IsAdaptivePlaybackSupported() = 0; |
| 149 |
143 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); | 150 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); |
144 }; | 151 }; |
145 | 152 |
146 } // namespace media | 153 } // namespace media |
147 | 154 |
148 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 155 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
OLD | NEW |