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(). However, due to buggy implementations (b/8125974) |
43 // codec was successfully started. | 43 // Stop() followed by Start() may not work on some devices. For reliability, |
44 virtual bool Start() = 0; | 44 // it's recommended to delete the instance and create a new one instead. |
45 | |
46 // Finishes the decode/encode session. The instance remains active | |
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; | 45 virtual void Stop() = 0; |
52 | 46 |
53 // Calls flush() on the MediaCodec. All indices previously returned in calls | 47 // Calls MediaCodec#flush(). The codec takes ownership of all input and output |
54 // to DequeueInputBuffer() and DequeueOutputBuffer() become invalid. Please | 48 // 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, | 49 // 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; | 50 virtual MediaCodecStatus Flush() = 0; |
60 | 51 |
61 // Used for getting the output size. This is valid after DequeueInputBuffer() | 52 // Returns the output size. This is valid after DequeueOutputBuffer() |
62 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED. | 53 // signals a format change by returning OUTPUT_FORMAT_CHANGED. |
63 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 54 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
64 virtual MediaCodecStatus GetOutputSize(gfx::Size* size) = 0; | 55 virtual MediaCodecStatus GetOutputSize(gfx::Size* size) = 0; |
65 | 56 |
66 // Used for checking for new sampling rate after DequeueInputBuffer() returns | 57 // Gets the sampling rate. This is valid after DequeueOutputBuffer() |
67 // INFO_OUTPUT_FORMAT_CHANGED | 58 // signals a format change by returning INFO_OUTPUT_FORMAT_CHANGED. |
68 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 59 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
69 virtual MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) = 0; | 60 virtual MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) = 0; |
70 | 61 |
71 // Fills |channel_count| with the number of audio channels. Useful after | 62 // Fills |channel_count| with the number of audio channels. This is valid |
72 // INFO_OUTPUT_FORMAT_CHANGED. | 63 // after DequeueOutputBuffer() signals a format change by returning |
73 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. | 64 // INFO_OUTPUT_FORMAT_CHANGED. Returns MEDIA_CODEC_ERROR if an error occurs, |
| 65 // or MEDIA_CODEC_OK otherwise. |
74 virtual MediaCodecStatus GetOutputChannelCount(int* channel_count) = 0; | 66 virtual MediaCodecStatus GetOutputChannelCount(int* channel_count) = 0; |
75 | 67 |
76 // Submits a byte array to the given input buffer. Call this after getting an | 68 // 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 | 69 // available buffer from DequeueInputBuffer(). If |data| is NULL, it assumes |
78 // input buffer has already been populated (but still obey |size|). | 70 // the input buffer has already been populated (but still obeys |size|). |
79 // |data_size| must be less than kint32max (because Java). | 71 // |data_size| must be less than kint32max (because Java). |
80 virtual MediaCodecStatus QueueInputBuffer( | 72 virtual MediaCodecStatus QueueInputBuffer( |
81 int index, | 73 int index, |
82 const uint8_t* data, | 74 const uint8_t* data, |
83 size_t data_size, | 75 size_t data_size, |
84 base::TimeDelta presentation_time) = 0; | 76 base::TimeDelta presentation_time) = 0; |
85 | 77 |
86 // As above but for encrypted buffers. NULL |subsamples| indicates the | 78 // As above but for encrypted buffers. NULL |subsamples| indicates the |
87 // whole buffer is encrypted. | 79 // whole buffer is encrypted. |
88 virtual MediaCodecStatus QueueSecureInputBuffer( | 80 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. | 125 // 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. | 126 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
135 virtual MediaCodecStatus CopyFromOutputBuffer(int index, | 127 virtual MediaCodecStatus CopyFromOutputBuffer(int index, |
136 size_t offset, | 128 size_t offset, |
137 void* dst, | 129 void* dst, |
138 size_t num) = 0; | 130 size_t num) = 0; |
139 | 131 |
140 // Gets the component name. Before API level 18 this returns an empty string. | 132 // Gets the component name. Before API level 18 this returns an empty string. |
141 virtual std::string GetName() = 0; | 133 virtual std::string GetName() = 0; |
142 | 134 |
| 135 // Changes the output surface for the MediaCodec. May only be used on API |
| 136 // level 23 and higher (Marshmallow). |
| 137 virtual bool SetSurface(jobject surface) = 0; |
| 138 |
| 139 // Sets the video encoder target bitrate and framerate. |
| 140 virtual void SetVideoBitrate(int bps, int frame_rate) = 0; |
| 141 |
| 142 // Requests that the video encoder insert a key frame. |
| 143 virtual void RequestKeyFrameSoon() = 0; |
| 144 |
| 145 // Returns whether the codec is configured for adaptive playback. |
| 146 virtual bool IsAdaptivePlaybackSupported() = 0; |
| 147 |
143 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); | 148 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); |
144 }; | 149 }; |
145 | 150 |
146 } // namespace media | 151 } // namespace media |
147 | 152 |
148 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 153 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
OLD | NEW |