Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: media/base/android/sdk_media_codec_bridge.h

Issue 2672313006: media: Remove the unused NdkMediaCodecBridge (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_SDK_MEDIA_CODEC_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_
7
8 #include <jni.h>
9 #include <stddef.h>
10 #include <stdint.h>
11
12 #include <set>
13 #include <string>
14
15 #include "base/android/scoped_java_ref.h"
16 #include "base/macros.h"
17 #include "base/time/time.h"
18 #include "media/base/android/media_codec_bridge.h"
19 #include "media/base/audio_decoder_config.h"
20 #include "media/base/media_export.h"
21 #include "media/base/video_decoder_config.h"
22 #include "ui/gfx/geometry/size.h"
23
24 namespace media {
25
26 // This class implements MediaCodecBridge using android MediaCodec SDK APIs.
27 class MEDIA_EXPORT SdkMediaCodecBridge : public MediaCodecBridge {
28 public:
29 ~SdkMediaCodecBridge() override;
30
31 // MediaCodecBridge implementations.
32 bool Start() override;
33 void Stop() override;
34 MediaCodecStatus Flush() override;
35 MediaCodecStatus GetOutputSize(gfx::Size* size) override;
36 MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) override;
37 MediaCodecStatus GetOutputChannelCount(int* channel_count) override;
38 MediaCodecStatus QueueInputBuffer(int index,
39 const uint8_t* data,
40 size_t data_size,
41 base::TimeDelta presentation_time) override;
42 using MediaCodecBridge::QueueSecureInputBuffer;
43 MediaCodecStatus QueueSecureInputBuffer(
44 int index,
45 const uint8_t* data,
46 size_t data_size,
47 const std::vector<char>& key_id,
48 const std::vector<char>& iv,
49 const SubsampleEntry* subsamples,
50 int subsamples_size,
51 const EncryptionScheme& encryption_scheme,
52 base::TimeDelta presentation_time) override;
53 void QueueEOS(int input_buffer_index) override;
54 MediaCodecStatus DequeueInputBuffer(base::TimeDelta timeout,
55 int* index) override;
56 MediaCodecStatus DequeueOutputBuffer(base::TimeDelta timeout,
57 int* index,
58 size_t* offset,
59 size_t* size,
60 base::TimeDelta* presentation_time,
61 bool* end_of_stream,
62 bool* key_frame) override;
63 void ReleaseOutputBuffer(int index, bool render) override;
64 MediaCodecStatus GetInputBuffer(int input_buffer_index,
65 uint8_t** data,
66 size_t* capacity) override;
67 MediaCodecStatus GetOutputBufferAddress(int index,
68 size_t offset,
69 const uint8_t** addr,
70 size_t* capacity) override;
71 std::string GetName() override;
72
73 protected:
74 SdkMediaCodecBridge(const std::string& mime,
75 bool is_secure,
76 MediaCodecDirection direction,
77 bool require_software_codec);
78
79 jobject media_codec() { return j_media_codec_.obj(); }
80 MediaCodecDirection direction_;
81
82 private:
83 // Java MediaCodec instance.
84 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
85
86 DISALLOW_COPY_AND_ASSIGN(SdkMediaCodecBridge);
87 };
88
89 // Class for handling audio decoding using android MediaCodec APIs.
90 // TODO(qinmin): implement the logic to switch between NDK and SDK
91 // MediaCodecBridge.
92 class MEDIA_EXPORT AudioCodecBridge : public SdkMediaCodecBridge {
93 public:
94 // Returns an AudioCodecBridge instance if |codec| is supported, or a NULL
95 // pointer otherwise.
96 static AudioCodecBridge* Create(const AudioCodec& codec);
97
98 // See MediaCodecUtil::IsKnownUnaccelerated().
99 static bool IsKnownUnaccelerated(const AudioCodec& codec);
100
101 // Starts the audio codec bridge.
102 bool ConfigureAndStart(const AudioDecoderConfig& config,
103 jobject media_crypto);
104
105 // An overloaded variant used by AudioDecoderJob and AudioMediaCodecDecoder.
106 // TODO(timav): Modify the above mentioned classes to pass parameters as
107 // AudioDecoderConfig and remove this method.
108 bool ConfigureAndStart(const AudioCodec& codec,
109 int sample_rate,
110 int channel_count,
111 const uint8_t* extra_data,
112 size_t extra_data_size,
113 int64_t codec_delay_ns,
114 int64_t seek_preroll_ns,
115 jobject media_crypto) WARN_UNUSED_RESULT;
116
117 private:
118 explicit AudioCodecBridge(const std::string& mime);
119
120 // Configure the java MediaFormat object with the extra codec data passed in.
121 bool ConfigureMediaFormat(jobject j_format,
122 const AudioCodec& codec,
123 const uint8_t* extra_data,
124 size_t extra_data_size,
125 int64_t codec_delay_ns,
126 int64_t seek_preroll_ns);
127 };
128
129 // Class for handling video encoding/decoding using android MediaCodec APIs.
130 // TODO(qinmin): implement the logic to switch between NDK and SDK
131 // MediaCodecBridge.
132 class MEDIA_EXPORT VideoCodecBridge : public SdkMediaCodecBridge {
133 public:
134 // See MediaCodecUtil::IsKnownUnaccelerated().
135 static bool IsKnownUnaccelerated(const VideoCodec& codec,
136 MediaCodecDirection direction);
137
138 // Create, start, and return a VideoCodecBridge decoder or NULL on failure.
139 static VideoCodecBridge* CreateDecoder(
140 const VideoCodec& codec,
141 bool is_secure, // Will be used with encrypted content.
142 const gfx::Size& size, // Output frame size.
143 jobject surface, // Output surface, optional.
144 jobject media_crypto, // MediaCrypto object, optional.
145 // Codec specific data. See MediaCodec docs.
146 const std::vector<uint8_t>& csd0,
147 const std::vector<uint8_t>& csd1,
148 // Should adaptive playback be allowed if supported.
149 bool allow_adaptive_playback = true,
150 bool require_software_codec = false);
151
152 // Create, start, and return a VideoCodecBridge encoder or NULL on failure.
153 static VideoCodecBridge* CreateEncoder(
154 const VideoCodec& codec, // e.g. media::kCodecVP8
155 const gfx::Size& size, // input frame size
156 int bit_rate, // bits/second
157 int frame_rate, // frames/second
158 int i_frame_interval, // count
159 int color_format); // MediaCodecInfo.CodecCapabilities.
160
161 void SetVideoBitrate(int bps, int frame_rate);
162 void RequestKeyFrameSoon();
163
164 // Returns whether adaptive playback is supported for this object given
165 // the new size.
166 bool IsAdaptivePlaybackSupported(int width, int height);
167
168 // Changes the output surface for the MediaCodec. May only be used on API
169 // level 23 and higher (Marshmallow).
170 bool SetSurface(jobject surface);
171
172 // Test-only method to set the return value of IsAdaptivePlaybackSupported().
173 // Without this function, the return value of that function will be device
174 // dependent. If |adaptive_playback_supported| is equal to 0, the return value
175 // will be false. If |adaptive_playback_supported| is larger than 0, the
176 // return value will be true.
177 void set_adaptive_playback_supported_for_testing(
178 int adaptive_playback_supported) {
179 adaptive_playback_supported_for_testing_ = adaptive_playback_supported;
180 }
181
182 private:
183 VideoCodecBridge(const std::string& mime,
184 bool is_secure,
185 MediaCodecDirection direction,
186 bool require_software_codec);
187
188 int adaptive_playback_supported_for_testing_;
189 };
190
191 } // namespace media
192
193 #endif // MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698