blob: c4c6cb385ff02eec5dfcf2d031c28efba54c7083 [file] [log] [blame]
Andreas Huberbe06d262009-08-14 14:37:10 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "OMXCodec"
19#include <utils/Log.h>
20
Andreas Huberdacaa732009-12-07 09:56:32 -080021#include "include/AACDecoder.h"
James Dong17299ab2010-05-14 15:45:22 -070022#include "include/AACEncoder.h"
Andreas Hubera30d4002009-12-08 15:40:06 -080023#include "include/AMRNBDecoder.h"
Andreas Huberd49b526dd2009-12-11 15:07:25 -080024#include "include/AMRNBEncoder.h"
Andreas Hubera30d4002009-12-08 15:40:06 -080025#include "include/AMRWBDecoder.h"
James Dong17299ab2010-05-14 15:45:22 -070026#include "include/AMRWBEncoder.h"
Andreas Huber4a0ec3f2009-12-10 09:44:29 -080027#include "include/AVCDecoder.h"
James Dong1cc31e62010-07-02 17:44:44 -070028#include "include/AVCEncoder.h"
Andreas Huber520b2a72010-08-09 09:54:59 -070029#include "include/G711Decoder.h"
James Dong02f5b542009-12-15 16:26:55 -080030#include "include/M4vH263Decoder.h"
James Dong42ef0c72010-07-12 21:46:25 -070031#include "include/M4vH263Encoder.h"
Andreas Huber250f2432009-12-07 14:22:35 -080032#include "include/MP3Decoder.h"
Andreas Huber388379f2010-05-07 10:35:13 -070033#include "include/VorbisDecoder.h"
Andreas Huber47ba30e2010-05-24 14:38:02 -070034#include "include/VPXDecoder.h"
Andreas Huber8c7ab032009-12-07 11:23:44 -080035
Andreas Huberbd7b43b2009-10-13 10:22:55 -070036#include "include/ESDS.h"
37
Andreas Huberbe06d262009-08-14 14:37:10 -070038#include <binder/IServiceManager.h>
39#include <binder/MemoryDealer.h>
40#include <binder/ProcessState.h>
41#include <media/IMediaPlayerService.h>
Andreas Huberbe06d262009-08-14 14:37:10 -070042#include <media/stagefright/MediaBuffer.h>
43#include <media/stagefright/MediaBufferGroup.h>
44#include <media/stagefright/MediaDebug.h>
Andreas Hubere6c40962009-09-10 14:13:30 -070045#include <media/stagefright/MediaDefs.h>
Andreas Huberbe06d262009-08-14 14:37:10 -070046#include <media/stagefright/MediaExtractor.h>
47#include <media/stagefright/MetaData.h>
Andreas Huberbe06d262009-08-14 14:37:10 -070048#include <media/stagefright/OMXCodec.h>
Andreas Huberebf66ea2009-08-19 13:32:58 -070049#include <media/stagefright/Utils.h>
Andreas Huberbe06d262009-08-14 14:37:10 -070050#include <utils/Vector.h>
51
52#include <OMX_Audio.h>
53#include <OMX_Component.h>
54
55namespace android {
56
Andreas Huber8b432b12009-10-07 13:36:52 -070057static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
58
Andreas Huberbe06d262009-08-14 14:37:10 -070059struct CodecInfo {
60 const char *mime;
61 const char *codec;
62};
63
Andreas Huberfb1c2f82009-12-15 13:25:11 -080064#define FACTORY_CREATE(name) \
65static sp<MediaSource> Make##name(const sp<MediaSource> &source) { \
66 return new name(source); \
67}
68
James Dong17299ab2010-05-14 15:45:22 -070069#define FACTORY_CREATE_ENCODER(name) \
70static sp<MediaSource> Make##name(const sp<MediaSource> &source, const sp<MetaData> &meta) { \
71 return new name(source, meta); \
72}
73
Andreas Huberfb1c2f82009-12-15 13:25:11 -080074#define FACTORY_REF(name) { #name, Make##name },
75
76FACTORY_CREATE(MP3Decoder)
77FACTORY_CREATE(AMRNBDecoder)
78FACTORY_CREATE(AMRWBDecoder)
79FACTORY_CREATE(AACDecoder)
80FACTORY_CREATE(AVCDecoder)
Andreas Huber520b2a72010-08-09 09:54:59 -070081FACTORY_CREATE(G711Decoder)
James Dong02f5b542009-12-15 16:26:55 -080082FACTORY_CREATE(M4vH263Decoder)
Andreas Huber388379f2010-05-07 10:35:13 -070083FACTORY_CREATE(VorbisDecoder)
Andreas Huber47ba30e2010-05-24 14:38:02 -070084FACTORY_CREATE(VPXDecoder)
James Dong17299ab2010-05-14 15:45:22 -070085FACTORY_CREATE_ENCODER(AMRNBEncoder)
86FACTORY_CREATE_ENCODER(AMRWBEncoder)
87FACTORY_CREATE_ENCODER(AACEncoder)
James Dong1cc31e62010-07-02 17:44:44 -070088FACTORY_CREATE_ENCODER(AVCEncoder)
James Dong42ef0c72010-07-12 21:46:25 -070089FACTORY_CREATE_ENCODER(M4vH263Encoder)
James Dong17299ab2010-05-14 15:45:22 -070090
91static sp<MediaSource> InstantiateSoftwareEncoder(
92 const char *name, const sp<MediaSource> &source,
93 const sp<MetaData> &meta) {
94 struct FactoryInfo {
95 const char *name;
96 sp<MediaSource> (*CreateFunc)(const sp<MediaSource> &, const sp<MetaData> &);
97 };
98
99 static const FactoryInfo kFactoryInfo[] = {
100 FACTORY_REF(AMRNBEncoder)
101 FACTORY_REF(AMRWBEncoder)
102 FACTORY_REF(AACEncoder)
James Dong1cc31e62010-07-02 17:44:44 -0700103 FACTORY_REF(AVCEncoder)
James Dong42ef0c72010-07-12 21:46:25 -0700104 FACTORY_REF(M4vH263Encoder)
James Dong17299ab2010-05-14 15:45:22 -0700105 };
106 for (size_t i = 0;
107 i < sizeof(kFactoryInfo) / sizeof(kFactoryInfo[0]); ++i) {
108 if (!strcmp(name, kFactoryInfo[i].name)) {
109 return (*kFactoryInfo[i].CreateFunc)(source, meta);
110 }
111 }
112
113 return NULL;
114}
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800115
116static sp<MediaSource> InstantiateSoftwareCodec(
117 const char *name, const sp<MediaSource> &source) {
118 struct FactoryInfo {
119 const char *name;
120 sp<MediaSource> (*CreateFunc)(const sp<MediaSource> &);
121 };
122
123 static const FactoryInfo kFactoryInfo[] = {
124 FACTORY_REF(MP3Decoder)
125 FACTORY_REF(AMRNBDecoder)
126 FACTORY_REF(AMRWBDecoder)
127 FACTORY_REF(AACDecoder)
128 FACTORY_REF(AVCDecoder)
Andreas Huber520b2a72010-08-09 09:54:59 -0700129 FACTORY_REF(G711Decoder)
James Dong02f5b542009-12-15 16:26:55 -0800130 FACTORY_REF(M4vH263Decoder)
Andreas Huber388379f2010-05-07 10:35:13 -0700131 FACTORY_REF(VorbisDecoder)
Andreas Huber47ba30e2010-05-24 14:38:02 -0700132 FACTORY_REF(VPXDecoder)
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800133 };
134 for (size_t i = 0;
135 i < sizeof(kFactoryInfo) / sizeof(kFactoryInfo[0]); ++i) {
136 if (!strcmp(name, kFactoryInfo[i].name)) {
137 return (*kFactoryInfo[i].CreateFunc)(source);
138 }
139 }
140
141 return NULL;
142}
143
144#undef FACTORY_REF
145#undef FACTORY_CREATE
146
Andreas Huberbe06d262009-08-14 14:37:10 -0700147static const CodecInfo kDecoderInfo[] = {
Andreas Hubere6c40962009-09-10 14:13:30 -0700148 { MEDIA_MIMETYPE_IMAGE_JPEG, "OMX.TI.JPEG.decode" },
James Dong374aee62010-04-26 10:23:30 -0700149// { MEDIA_MIMETYPE_AUDIO_MPEG, "OMX.TI.MP3.decode" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800150 { MEDIA_MIMETYPE_AUDIO_MPEG, "MP3Decoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700151// { MEDIA_MIMETYPE_AUDIO_MPEG, "OMX.PV.mp3dec" },
Andreas Hubera4357ad2010-04-02 12:49:54 -0700152// { MEDIA_MIMETYPE_AUDIO_AMR_NB, "OMX.TI.AMR.decode" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800153 { MEDIA_MIMETYPE_AUDIO_AMR_NB, "AMRNBDecoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700154// { MEDIA_MIMETYPE_AUDIO_AMR_NB, "OMX.PV.amrdec" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700155 { MEDIA_MIMETYPE_AUDIO_AMR_WB, "OMX.TI.WBAMR.decode" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800156 { MEDIA_MIMETYPE_AUDIO_AMR_WB, "AMRWBDecoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700157// { MEDIA_MIMETYPE_AUDIO_AMR_WB, "OMX.PV.amrdec" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700158 { MEDIA_MIMETYPE_AUDIO_AAC, "OMX.TI.AAC.decode" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800159 { MEDIA_MIMETYPE_AUDIO_AAC, "AACDecoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700160// { MEDIA_MIMETYPE_AUDIO_AAC, "OMX.PV.aacdec" },
Andreas Huber520b2a72010-08-09 09:54:59 -0700161 { MEDIA_MIMETYPE_AUDIO_G711_ALAW, "G711Decoder" },
162 { MEDIA_MIMETYPE_AUDIO_G711_MLAW, "G711Decoder" },
pgudadhe6ad2c352010-07-26 15:04:33 -0700163 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.Nvidia.mp4.decode" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700164 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.7x30.video.decoder.mpeg4" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700165 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.video.decoder.mpeg4" },
166 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.TI.Video.Decoder" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800167 { MEDIA_MIMETYPE_VIDEO_MPEG4, "M4vH263Decoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700168// { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.PV.mpeg4dec" },
pgudadhe6ad2c352010-07-26 15:04:33 -0700169 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.Nvidia.h263.decode" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700170 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.7x30.video.decoder.h263" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700171 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.video.decoder.h263" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800172 { MEDIA_MIMETYPE_VIDEO_H263, "M4vH263Decoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700173// { MEDIA_MIMETYPE_VIDEO_H263, "OMX.PV.h263dec" },
pgudadhe6ad2c352010-07-26 15:04:33 -0700174 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.Nvidia.h264.decode" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700175 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.qcom.7x30.video.decoder.avc" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700176 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.qcom.video.decoder.avc" },
177 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.TI.Video.Decoder" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800178 { MEDIA_MIMETYPE_VIDEO_AVC, "AVCDecoder" },
Andreas Huber1a189a82010-03-24 13:49:20 -0700179// { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.PV.avcdec" },
Andreas Huber388379f2010-05-07 10:35:13 -0700180 { MEDIA_MIMETYPE_AUDIO_VORBIS, "VorbisDecoder" },
Andreas Huber47ba30e2010-05-24 14:38:02 -0700181 { MEDIA_MIMETYPE_VIDEO_VPX, "VPXDecoder" },
Andreas Huberbe06d262009-08-14 14:37:10 -0700182};
183
184static const CodecInfo kEncoderInfo[] = {
Andreas Hubere6c40962009-09-10 14:13:30 -0700185 { MEDIA_MIMETYPE_AUDIO_AMR_NB, "OMX.TI.AMR.encode" },
Andreas Huberacfbc802010-02-04 10:48:37 -0800186 { MEDIA_MIMETYPE_AUDIO_AMR_NB, "AMRNBEncoder" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700187 { MEDIA_MIMETYPE_AUDIO_AMR_WB, "OMX.TI.WBAMR.encode" },
James Dong17299ab2010-05-14 15:45:22 -0700188 { MEDIA_MIMETYPE_AUDIO_AMR_WB, "AMRWBEncoder" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700189 { MEDIA_MIMETYPE_AUDIO_AAC, "OMX.TI.AAC.encode" },
James Dong17299ab2010-05-14 15:45:22 -0700190 { MEDIA_MIMETYPE_AUDIO_AAC, "AACEncoder" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700191// { MEDIA_MIMETYPE_AUDIO_AAC, "OMX.PV.aacenc" },
192 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.7x30.video.encoder.mpeg4" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700193 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.qcom.video.encoder.mpeg4" },
194 { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.TI.Video.encoder" },
James Dong42ef0c72010-07-12 21:46:25 -0700195 { MEDIA_MIMETYPE_VIDEO_MPEG4, "M4vH263Encoder" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700196// { MEDIA_MIMETYPE_VIDEO_MPEG4, "OMX.PV.mpeg4enc" },
197 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.7x30.video.encoder.h263" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700198 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.qcom.video.encoder.h263" },
199 { MEDIA_MIMETYPE_VIDEO_H263, "OMX.TI.Video.encoder" },
James Dong42ef0c72010-07-12 21:46:25 -0700200 { MEDIA_MIMETYPE_VIDEO_H263, "M4vH263Encoder" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700201// { MEDIA_MIMETYPE_VIDEO_H263, "OMX.PV.h263enc" },
202 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.qcom.7x30.video.encoder.avc" },
Andreas Huber71c27d92010-03-19 11:43:15 -0700203 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.qcom.video.encoder.avc" },
Andreas Hubere6c40962009-09-10 14:13:30 -0700204 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.TI.Video.encoder" },
pgudadhe9c305322010-07-26 13:59:29 -0700205 { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.Nvidia.h264.encoder" },
James Dong1cc31e62010-07-02 17:44:44 -0700206 { MEDIA_MIMETYPE_VIDEO_AVC, "AVCEncoder" },
Andreas Huber8ef64c92010-06-29 09:14:00 -0700207// { MEDIA_MIMETYPE_VIDEO_AVC, "OMX.PV.avcenc" },
Andreas Huberbe06d262009-08-14 14:37:10 -0700208};
209
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800210#undef OPTIONAL
211
Andreas Hubere0873732009-09-10 09:57:53 -0700212#define CODEC_LOGI(x, ...) LOGI("[%s] "x, mComponentName, ##__VA_ARGS__)
Andreas Huber4c483422009-09-02 16:05:36 -0700213#define CODEC_LOGV(x, ...) LOGV("[%s] "x, mComponentName, ##__VA_ARGS__)
Andreas Huber42c444a2010-02-09 10:20:00 -0800214#define CODEC_LOGE(x, ...) LOGE("[%s] "x, mComponentName, ##__VA_ARGS__)
Andreas Huber4c483422009-09-02 16:05:36 -0700215
Andreas Huberbe06d262009-08-14 14:37:10 -0700216struct OMXCodecObserver : public BnOMXObserver {
Andreas Huber784202e2009-10-15 13:46:54 -0700217 OMXCodecObserver() {
218 }
219
220 void setCodec(const sp<OMXCodec> &target) {
221 mTarget = target;
Andreas Huberbe06d262009-08-14 14:37:10 -0700222 }
223
224 // from IOMXObserver
Andreas Huber784202e2009-10-15 13:46:54 -0700225 virtual void onMessage(const omx_message &msg) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700226 sp<OMXCodec> codec = mTarget.promote();
227
228 if (codec.get() != NULL) {
229 codec->on_message(msg);
230 }
231 }
232
233protected:
234 virtual ~OMXCodecObserver() {}
235
236private:
237 wp<OMXCodec> mTarget;
238
239 OMXCodecObserver(const OMXCodecObserver &);
240 OMXCodecObserver &operator=(const OMXCodecObserver &);
241};
242
243static const char *GetCodec(const CodecInfo *info, size_t numInfos,
244 const char *mime, int index) {
245 CHECK(index >= 0);
246 for(size_t i = 0; i < numInfos; ++i) {
247 if (!strcasecmp(mime, info[i].mime)) {
248 if (index == 0) {
249 return info[i].codec;
250 }
251
252 --index;
253 }
254 }
255
256 return NULL;
257}
258
Andreas Huberebf66ea2009-08-19 13:32:58 -0700259enum {
260 kAVCProfileBaseline = 0x42,
261 kAVCProfileMain = 0x4d,
262 kAVCProfileExtended = 0x58,
263 kAVCProfileHigh = 0x64,
264 kAVCProfileHigh10 = 0x6e,
265 kAVCProfileHigh422 = 0x7a,
266 kAVCProfileHigh444 = 0xf4,
267 kAVCProfileCAVLC444Intra = 0x2c
268};
269
270static const char *AVCProfileToString(uint8_t profile) {
271 switch (profile) {
272 case kAVCProfileBaseline:
273 return "Baseline";
274 case kAVCProfileMain:
275 return "Main";
276 case kAVCProfileExtended:
277 return "Extended";
278 case kAVCProfileHigh:
279 return "High";
280 case kAVCProfileHigh10:
281 return "High 10";
282 case kAVCProfileHigh422:
283 return "High 422";
284 case kAVCProfileHigh444:
285 return "High 444";
286 case kAVCProfileCAVLC444Intra:
287 return "CAVLC 444 Intra";
288 default: return "Unknown";
289 }
290}
291
Andreas Huber4c483422009-09-02 16:05:36 -0700292template<class T>
293static void InitOMXParams(T *params) {
294 params->nSize = sizeof(T);
295 params->nVersion.s.nVersionMajor = 1;
296 params->nVersion.s.nVersionMinor = 0;
297 params->nVersion.s.nRevision = 0;
298 params->nVersion.s.nStep = 0;
299}
300
Andreas Hubere13526a2009-10-22 10:43:34 -0700301static bool IsSoftwareCodec(const char *componentName) {
302 if (!strncmp("OMX.PV.", componentName, 7)) {
303 return true;
Andreas Huberbe06d262009-08-14 14:37:10 -0700304 }
305
Andreas Hubere13526a2009-10-22 10:43:34 -0700306 return false;
307}
308
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800309// A sort order in which non-OMX components are first,
310// followed by software codecs, i.e. OMX.PV.*, followed
311// by all the others.
Andreas Hubere13526a2009-10-22 10:43:34 -0700312static int CompareSoftwareCodecsFirst(
313 const String8 *elem1, const String8 *elem2) {
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800314 bool isNotOMX1 = strncmp(elem1->string(), "OMX.", 4);
315 bool isNotOMX2 = strncmp(elem2->string(), "OMX.", 4);
316
317 if (isNotOMX1) {
318 if (isNotOMX2) { return 0; }
319 return -1;
320 }
321 if (isNotOMX2) {
322 return 1;
323 }
324
Andreas Hubere13526a2009-10-22 10:43:34 -0700325 bool isSoftwareCodec1 = IsSoftwareCodec(elem1->string());
326 bool isSoftwareCodec2 = IsSoftwareCodec(elem2->string());
327
328 if (isSoftwareCodec1) {
329 if (isSoftwareCodec2) { return 0; }
330 return -1;
331 }
332
333 if (isSoftwareCodec2) {
334 return 1;
335 }
336
337 return 0;
338}
339
340// static
341uint32_t OMXCodec::getComponentQuirks(const char *componentName) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700342 uint32_t quirks = 0;
Andreas Hubere13526a2009-10-22 10:43:34 -0700343
Andreas Huberbe06d262009-08-14 14:37:10 -0700344 if (!strcmp(componentName, "OMX.PV.avcdec")) {
Andreas Huber4f5e6022009-08-19 09:29:34 -0700345 quirks |= kWantsNALFragments;
Andreas Huberbe06d262009-08-14 14:37:10 -0700346 }
347 if (!strcmp(componentName, "OMX.TI.MP3.decode")) {
348 quirks |= kNeedsFlushBeforeDisable;
Andreas Hubere331c7b2010-02-01 10:51:50 -0800349 quirks |= kDecoderLiesAboutNumberOfChannels;
Andreas Huberbe06d262009-08-14 14:37:10 -0700350 }
351 if (!strcmp(componentName, "OMX.TI.AAC.decode")) {
352 quirks |= kNeedsFlushBeforeDisable;
Andreas Huber404cc412009-08-25 14:26:05 -0700353 quirks |= kRequiresFlushCompleteEmulation;
Andreas Hubera4357ad2010-04-02 12:49:54 -0700354 quirks |= kSupportsMultipleFramesPerInputBuffer;
Andreas Huberbe06d262009-08-14 14:37:10 -0700355 }
356 if (!strncmp(componentName, "OMX.qcom.video.encoder.", 23)) {
357 quirks |= kRequiresLoadedToIdleAfterAllocation;
358 quirks |= kRequiresAllocateBufferOnInputPorts;
Andreas Huberb482ce82009-10-29 12:02:48 -0700359 quirks |= kRequiresAllocateBufferOnOutputPorts;
Andreas Huberbe06d262009-08-14 14:37:10 -0700360 }
Andreas Huber8ef64c92010-06-29 09:14:00 -0700361 if (!strncmp(componentName, "OMX.qcom.7x30.video.encoder.", 28)) {
362 }
Andreas Hubera7d0cf42009-09-04 07:48:51 -0700363 if (!strncmp(componentName, "OMX.qcom.video.decoder.", 23)) {
Andreas Hubera7d0cf42009-09-04 07:48:51 -0700364 quirks |= kRequiresAllocateBufferOnOutputPorts;
Andreas Huber52733b82010-01-25 10:41:35 -0800365 quirks |= kDefersOutputBufferAllocation;
Andreas Hubera7d0cf42009-09-04 07:48:51 -0700366 }
Andreas Huber8ef64c92010-06-29 09:14:00 -0700367 if (!strncmp(componentName, "OMX.qcom.7x30.video.decoder.", 28)) {
368 quirks |= kRequiresAllocateBufferOnInputPorts;
369 quirks |= kRequiresAllocateBufferOnOutputPorts;
370 quirks |= kDefersOutputBufferAllocation;
371 }
Andreas Huberbe06d262009-08-14 14:37:10 -0700372
Andreas Huber2dc64d82009-09-11 12:58:53 -0700373 if (!strncmp(componentName, "OMX.TI.", 7)) {
374 // Apparently I must not use OMX_UseBuffer on either input or
375 // output ports on any of the TI components or quote:
376 // "(I) may have unexpected problem (sic) which can be timing related
377 // and hard to reproduce."
378
379 quirks |= kRequiresAllocateBufferOnInputPorts;
380 quirks |= kRequiresAllocateBufferOnOutputPorts;
James Dongdca66e12010-06-14 11:14:38 -0700381 if (!strncmp(componentName, "OMX.TI.Video.encoder", 20)) {
James Dong4f501f02010-06-07 14:41:41 -0700382 quirks |= kAvoidMemcopyInputRecordingFrames;
383 }
Andreas Huber2dc64d82009-09-11 12:58:53 -0700384 }
385
Andreas Huberb8de9572010-02-22 14:58:45 -0800386 if (!strcmp(componentName, "OMX.TI.Video.Decoder")) {
387 quirks |= kInputBufferSizesAreBogus;
388 }
389
Andreas Hubere13526a2009-10-22 10:43:34 -0700390 return quirks;
391}
392
393// static
394void OMXCodec::findMatchingCodecs(
395 const char *mime,
396 bool createEncoder, const char *matchComponentName,
397 uint32_t flags,
398 Vector<String8> *matchingCodecs) {
399 matchingCodecs->clear();
400
401 for (int index = 0;; ++index) {
402 const char *componentName;
403
404 if (createEncoder) {
405 componentName = GetCodec(
406 kEncoderInfo,
407 sizeof(kEncoderInfo) / sizeof(kEncoderInfo[0]),
408 mime, index);
409 } else {
410 componentName = GetCodec(
411 kDecoderInfo,
412 sizeof(kDecoderInfo) / sizeof(kDecoderInfo[0]),
413 mime, index);
414 }
415
416 if (!componentName) {
417 break;
418 }
419
420 // If a specific codec is requested, skip the non-matching ones.
421 if (matchComponentName && strcmp(componentName, matchComponentName)) {
422 continue;
423 }
424
425 matchingCodecs->push(String8(componentName));
426 }
427
428 if (flags & kPreferSoftwareCodecs) {
429 matchingCodecs->sort(CompareSoftwareCodecsFirst);
430 }
431}
432
433// static
Andreas Huber91eb0352009-12-07 09:43:00 -0800434sp<MediaSource> OMXCodec::Create(
Andreas Hubere13526a2009-10-22 10:43:34 -0700435 const sp<IOMX> &omx,
436 const sp<MetaData> &meta, bool createEncoder,
437 const sp<MediaSource> &source,
438 const char *matchComponentName,
439 uint32_t flags) {
440 const char *mime;
441 bool success = meta->findCString(kKeyMIMEType, &mime);
442 CHECK(success);
443
444 Vector<String8> matchingCodecs;
445 findMatchingCodecs(
446 mime, createEncoder, matchComponentName, flags, &matchingCodecs);
447
448 if (matchingCodecs.isEmpty()) {
449 return NULL;
450 }
451
452 sp<OMXCodecObserver> observer = new OMXCodecObserver;
453 IOMX::node_id node = 0;
Andreas Hubere13526a2009-10-22 10:43:34 -0700454
455 const char *componentName;
456 for (size_t i = 0; i < matchingCodecs.size(); ++i) {
457 componentName = matchingCodecs[i].string();
458
James Dong17299ab2010-05-14 15:45:22 -0700459 sp<MediaSource> softwareCodec = createEncoder?
460 InstantiateSoftwareEncoder(componentName, source, meta):
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800461 InstantiateSoftwareCodec(componentName, source);
462
463 if (softwareCodec != NULL) {
464 LOGV("Successfully allocated software codec '%s'", componentName);
465
466 return softwareCodec;
467 }
Andreas Huberfb1c2f82009-12-15 13:25:11 -0800468
Andreas Hubere13526a2009-10-22 10:43:34 -0700469 LOGV("Attempting to allocate OMX node '%s'", componentName);
470
471 status_t err = omx->allocateNode(componentName, observer, &node);
472 if (err == OK) {
473 LOGV("Successfully allocated OMX node '%s'", componentName);
474
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700475 sp<OMXCodec> codec = new OMXCodec(
476 omx, node, getComponentQuirks(componentName),
477 createEncoder, mime, componentName,
478 source);
479
480 observer->setCodec(codec);
481
482 err = codec->configureCodec(meta);
483
484 if (err == OK) {
485 return codec;
486 }
487
488 LOGV("Failed to configure codec '%s'", componentName);
Andreas Hubere13526a2009-10-22 10:43:34 -0700489 }
490 }
491
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700492 return NULL;
493}
Andreas Hubere13526a2009-10-22 10:43:34 -0700494
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700495status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700496 uint32_t type;
497 const void *data;
498 size_t size;
499 if (meta->findData(kKeyESDS, &type, &data, &size)) {
500 ESDS esds((const char *)data, size);
501 CHECK_EQ(esds.InitCheck(), OK);
502
503 const void *codec_specific_data;
504 size_t codec_specific_data_size;
505 esds.getCodecSpecificInfo(
506 &codec_specific_data, &codec_specific_data_size);
507
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700508 addCodecSpecificData(
Andreas Huberbe06d262009-08-14 14:37:10 -0700509 codec_specific_data, codec_specific_data_size);
510 } else if (meta->findData(kKeyAVCC, &type, &data, &size)) {
Andreas Huberebf66ea2009-08-19 13:32:58 -0700511 // Parse the AVCDecoderConfigurationRecord
512
513 const uint8_t *ptr = (const uint8_t *)data;
514
515 CHECK(size >= 7);
516 CHECK_EQ(ptr[0], 1); // configurationVersion == 1
517 uint8_t profile = ptr[1];
518 uint8_t level = ptr[3];
519
Andreas Huber44e15c42009-11-23 14:39:38 -0800520 // There is decodable content out there that fails the following
521 // assertion, let's be lenient for now...
522 // CHECK((ptr[4] >> 2) == 0x3f); // reserved
Andreas Huberebf66ea2009-08-19 13:32:58 -0700523
524 size_t lengthSize = 1 + (ptr[4] & 3);
525
526 // commented out check below as H264_QVGA_500_NO_AUDIO.3gp
527 // violates it...
528 // CHECK((ptr[5] >> 5) == 7); // reserved
529
530 size_t numSeqParameterSets = ptr[5] & 31;
531
532 ptr += 6;
Andreas Huberbe06d262009-08-14 14:37:10 -0700533 size -= 6;
Andreas Huberebf66ea2009-08-19 13:32:58 -0700534
535 for (size_t i = 0; i < numSeqParameterSets; ++i) {
536 CHECK(size >= 2);
537 size_t length = U16_AT(ptr);
Andreas Huberbe06d262009-08-14 14:37:10 -0700538
539 ptr += 2;
540 size -= 2;
541
Andreas Huberbe06d262009-08-14 14:37:10 -0700542 CHECK(size >= length);
543
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700544 addCodecSpecificData(ptr, length);
Andreas Huberbe06d262009-08-14 14:37:10 -0700545
546 ptr += length;
547 size -= length;
Andreas Huberebf66ea2009-08-19 13:32:58 -0700548 }
Andreas Huberbe06d262009-08-14 14:37:10 -0700549
Andreas Huberebf66ea2009-08-19 13:32:58 -0700550 CHECK(size >= 1);
551 size_t numPictureParameterSets = *ptr;
552 ++ptr;
553 --size;
Andreas Huberbe06d262009-08-14 14:37:10 -0700554
Andreas Huberebf66ea2009-08-19 13:32:58 -0700555 for (size_t i = 0; i < numPictureParameterSets; ++i) {
556 CHECK(size >= 2);
557 size_t length = U16_AT(ptr);
558
559 ptr += 2;
560 size -= 2;
561
562 CHECK(size >= length);
563
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700564 addCodecSpecificData(ptr, length);
Andreas Huberebf66ea2009-08-19 13:32:58 -0700565
566 ptr += length;
567 size -= length;
568 }
569
Andreas Hubere2f85072010-06-10 09:51:27 -0700570 CODEC_LOGV(
571 "AVC profile = %d (%s), level = %d",
572 (int)profile, AVCProfileToString(profile), level);
Andreas Huberebf66ea2009-08-19 13:32:58 -0700573
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700574 if (!strcmp(mComponentName, "OMX.TI.Video.Decoder")
Andreas Hubere2f85072010-06-10 09:51:27 -0700575 && (profile != kAVCProfileBaseline || level > 30)) {
Andreas Huber784202e2009-10-15 13:46:54 -0700576 // This stream exceeds the decoder's capabilities. The decoder
577 // does not handle this gracefully and would clobber the heap
578 // and wreak havoc instead...
Andreas Huberebf66ea2009-08-19 13:32:58 -0700579
580 LOGE("Profile and/or level exceed the decoder's capabilities.");
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700581 return ERROR_UNSUPPORTED;
Andreas Huberbe06d262009-08-14 14:37:10 -0700582 }
583 }
584
James Dong17299ab2010-05-14 15:45:22 -0700585 int32_t bitRate = 0;
586 if (mIsEncoder) {
587 CHECK(meta->findInt32(kKeyBitRate, &bitRate));
588 }
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700589 if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mMIME)) {
James Dong17299ab2010-05-14 15:45:22 -0700590 setAMRFormat(false /* isWAMR */, bitRate);
Andreas Huberbe06d262009-08-14 14:37:10 -0700591 }
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700592 if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mMIME)) {
James Dong17299ab2010-05-14 15:45:22 -0700593 setAMRFormat(true /* isWAMR */, bitRate);
Andreas Huberee606e62009-09-08 10:19:21 -0700594 }
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700595 if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mMIME)) {
Andreas Huber43ad6eaf2009-09-01 16:02:43 -0700596 int32_t numChannels, sampleRate;
597 CHECK(meta->findInt32(kKeyChannelCount, &numChannels));
598 CHECK(meta->findInt32(kKeySampleRate, &sampleRate));
599
James Dong17299ab2010-05-14 15:45:22 -0700600 setAACFormat(numChannels, sampleRate, bitRate);
Andreas Huberbe06d262009-08-14 14:37:10 -0700601 }
James Dongabed93a2010-04-22 17:27:04 -0700602
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700603 if (!strncasecmp(mMIME, "video/", 6)) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700604
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700605 if (mIsEncoder) {
James Dong1244eab2010-06-08 11:58:53 -0700606 setVideoInputFormat(mMIME, meta);
Andreas Huberbe06d262009-08-14 14:37:10 -0700607 } else {
James Dong1244eab2010-06-08 11:58:53 -0700608 int32_t width, height;
609 bool success = meta->findInt32(kKeyWidth, &width);
610 success = success && meta->findInt32(kKeyHeight, &height);
611 CHECK(success);
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700612 status_t err = setVideoOutputFormat(
613 mMIME, width, height);
614
615 if (err != OK) {
616 return err;
617 }
Andreas Huberbe06d262009-08-14 14:37:10 -0700618 }
619 }
Andreas Hubera4357ad2010-04-02 12:49:54 -0700620
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700621 if (!strcasecmp(mMIME, MEDIA_MIMETYPE_IMAGE_JPEG)
622 && !strcmp(mComponentName, "OMX.TI.JPEG.decode")) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700623 OMX_COLOR_FORMATTYPE format =
624 OMX_COLOR_Format32bitARGB8888;
625 // OMX_COLOR_FormatYUV420PackedPlanar;
626 // OMX_COLOR_FormatCbYCrY;
627 // OMX_COLOR_FormatYUV411Planar;
628
629 int32_t width, height;
630 bool success = meta->findInt32(kKeyWidth, &width);
631 success = success && meta->findInt32(kKeyHeight, &height);
Andreas Huber5c0a9132009-08-20 11:16:40 -0700632
633 int32_t compressedSize;
634 success = success && meta->findInt32(
Andreas Huberda050cf22009-09-02 14:01:43 -0700635 kKeyMaxInputSize, &compressedSize);
Andreas Huber5c0a9132009-08-20 11:16:40 -0700636
637 CHECK(success);
638 CHECK(compressedSize > 0);
Andreas Huberbe06d262009-08-14 14:37:10 -0700639
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700640 setImageOutputFormat(format, width, height);
641 setJPEGInputFormat(width, height, (OMX_U32)compressedSize);
Andreas Huberbe06d262009-08-14 14:37:10 -0700642 }
643
Andreas Huberda050cf22009-09-02 14:01:43 -0700644 int32_t maxInputSize;
Andreas Huber1bceff92009-11-23 14:03:32 -0800645 if (meta->findInt32(kKeyMaxInputSize, &maxInputSize)) {
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700646 setMinBufferSize(kPortIndexInput, (OMX_U32)maxInputSize);
Andreas Huberda050cf22009-09-02 14:01:43 -0700647 }
648
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700649 if (!strcmp(mComponentName, "OMX.TI.AMR.encode")
James Dongabed93a2010-04-22 17:27:04 -0700650 || !strcmp(mComponentName, "OMX.TI.WBAMR.encode")
651 || !strcmp(mComponentName, "OMX.TI.AAC.encode")) {
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700652 setMinBufferSize(kPortIndexOutput, 8192); // XXX
Andreas Huberda050cf22009-09-02 14:01:43 -0700653 }
654
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700655 initOutputFormat(meta);
Andreas Huberbe06d262009-08-14 14:37:10 -0700656
Andreas Huber2a09c7e2010-03-16 11:44:07 -0700657 return OK;
Andreas Huberbe06d262009-08-14 14:37:10 -0700658}
659
Andreas Huberda050cf22009-09-02 14:01:43 -0700660void OMXCodec::setMinBufferSize(OMX_U32 portIndex, OMX_U32 size) {
661 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -0700662 InitOMXParams(&def);
Andreas Huberda050cf22009-09-02 14:01:43 -0700663 def.nPortIndex = portIndex;
664
Andreas Huber784202e2009-10-15 13:46:54 -0700665 status_t err = mOMX->getParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -0700666 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
667 CHECK_EQ(err, OK);
668
Andreas Huberb8de9572010-02-22 14:58:45 -0800669 if ((portIndex == kPortIndexInput && (mQuirks & kInputBufferSizesAreBogus))
670 || (def.nBufferSize < size)) {
Andreas Huberda050cf22009-09-02 14:01:43 -0700671 def.nBufferSize = size;
Andreas Huberda050cf22009-09-02 14:01:43 -0700672 }
673
Andreas Huber784202e2009-10-15 13:46:54 -0700674 err = mOMX->setParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -0700675 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
676 CHECK_EQ(err, OK);
Andreas Huber1bceff92009-11-23 14:03:32 -0800677
678 err = mOMX->getParameter(
679 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
680 CHECK_EQ(err, OK);
681
682 // Make sure the setting actually stuck.
Andreas Huberb8de9572010-02-22 14:58:45 -0800683 if (portIndex == kPortIndexInput
684 && (mQuirks & kInputBufferSizesAreBogus)) {
685 CHECK_EQ(def.nBufferSize, size);
686 } else {
687 CHECK(def.nBufferSize >= size);
688 }
Andreas Huberda050cf22009-09-02 14:01:43 -0700689}
690
Andreas Huberbe06d262009-08-14 14:37:10 -0700691status_t OMXCodec::setVideoPortFormatType(
692 OMX_U32 portIndex,
693 OMX_VIDEO_CODINGTYPE compressionFormat,
694 OMX_COLOR_FORMATTYPE colorFormat) {
695 OMX_VIDEO_PARAM_PORTFORMATTYPE format;
Andreas Huber4c483422009-09-02 16:05:36 -0700696 InitOMXParams(&format);
Andreas Huberbe06d262009-08-14 14:37:10 -0700697 format.nPortIndex = portIndex;
698 format.nIndex = 0;
699 bool found = false;
700
701 OMX_U32 index = 0;
702 for (;;) {
703 format.nIndex = index;
Andreas Huber784202e2009-10-15 13:46:54 -0700704 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -0700705 mNode, OMX_IndexParamVideoPortFormat,
706 &format, sizeof(format));
707
708 if (err != OK) {
709 return err;
710 }
711
712 // The following assertion is violated by TI's video decoder.
Andreas Huber5c0a9132009-08-20 11:16:40 -0700713 // CHECK_EQ(format.nIndex, index);
Andreas Huberbe06d262009-08-14 14:37:10 -0700714
715#if 1
Andreas Huber53a76bd2009-10-06 16:20:44 -0700716 CODEC_LOGV("portIndex: %ld, index: %ld, eCompressionFormat=%d eColorFormat=%d",
Andreas Huberbe06d262009-08-14 14:37:10 -0700717 portIndex,
718 index, format.eCompressionFormat, format.eColorFormat);
719#endif
720
721 if (!strcmp("OMX.TI.Video.encoder", mComponentName)) {
722 if (portIndex == kPortIndexInput
723 && colorFormat == format.eColorFormat) {
724 // eCompressionFormat does not seem right.
725 found = true;
726 break;
727 }
728 if (portIndex == kPortIndexOutput
729 && compressionFormat == format.eCompressionFormat) {
730 // eColorFormat does not seem right.
731 found = true;
732 break;
733 }
734 }
735
736 if (format.eCompressionFormat == compressionFormat
737 && format.eColorFormat == colorFormat) {
738 found = true;
739 break;
740 }
741
742 ++index;
743 }
744
745 if (!found) {
746 return UNKNOWN_ERROR;
747 }
748
Andreas Huber53a76bd2009-10-06 16:20:44 -0700749 CODEC_LOGV("found a match.");
Andreas Huber784202e2009-10-15 13:46:54 -0700750 status_t err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -0700751 mNode, OMX_IndexParamVideoPortFormat,
752 &format, sizeof(format));
753
754 return err;
755}
756
Andreas Huberb482ce82009-10-29 12:02:48 -0700757static size_t getFrameSize(
758 OMX_COLOR_FORMATTYPE colorFormat, int32_t width, int32_t height) {
759 switch (colorFormat) {
760 case OMX_COLOR_FormatYCbYCr:
761 case OMX_COLOR_FormatCbYCrY:
762 return width * height * 2;
763
Andreas Huber71c27d92010-03-19 11:43:15 -0700764 case OMX_COLOR_FormatYUV420Planar:
Andreas Huberb482ce82009-10-29 12:02:48 -0700765 case OMX_COLOR_FormatYUV420SemiPlanar:
766 return (width * height * 3) / 2;
767
768 default:
769 CHECK(!"Should not be here. Unsupported color format.");
770 break;
771 }
772}
773
James Dongafd97e82010-08-03 17:19:23 -0700774status_t OMXCodec::findTargetColorFormat(
775 const sp<MetaData>& meta, OMX_COLOR_FORMATTYPE *colorFormat) {
776 LOGV("findTargetColorFormat");
777 CHECK(mIsEncoder);
778
779 *colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
780 int32_t targetColorFormat;
781 if (meta->findInt32(kKeyColorFormat, &targetColorFormat)) {
782 *colorFormat = (OMX_COLOR_FORMATTYPE) targetColorFormat;
783 } else {
784 if (!strcasecmp("OMX.TI.Video.encoder", mComponentName)) {
785 *colorFormat = OMX_COLOR_FormatYCbYCr;
786 }
787 }
788
789 // Check whether the target color format is supported.
790 return isColorFormatSupported(*colorFormat, kPortIndexInput);
791}
792
793status_t OMXCodec::isColorFormatSupported(
794 OMX_COLOR_FORMATTYPE colorFormat, int portIndex) {
795 LOGV("isColorFormatSupported: %d", static_cast<int>(colorFormat));
796
797 // Enumerate all the color formats supported by
798 // the omx component to see whether the given
799 // color format is supported.
800 OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
801 InitOMXParams(&portFormat);
802 portFormat.nPortIndex = portIndex;
803 OMX_U32 index = 0;
804 portFormat.nIndex = index;
805 while (true) {
806 if (OMX_ErrorNone != mOMX->getParameter(
807 mNode, OMX_IndexParamVideoPortFormat,
808 &portFormat, sizeof(portFormat))) {
809
810 return UNKNOWN_ERROR;
811 }
812 // Make sure that omx component does not overwrite
813 // the incremented index (bug 2897413).
814 CHECK_EQ(index, portFormat.nIndex);
815 if ((portFormat.eColorFormat == colorFormat)) {
816 LOGV("Found supported color format: %d", portFormat.eColorFormat);
817 return OK; // colorFormat is supported!
818 }
819 ++index;
820 portFormat.nIndex = index;
821
822 // OMX Spec defines less than 50 color formats
823 // 1000 is more than enough for us to tell whether the omx
824 // component in question is buggy or not.
825 if (index >= 1000) {
826 LOGE("More than %ld color formats are supported???", index);
827 break;
828 }
829 }
830 return UNKNOWN_ERROR;
831}
832
Andreas Huberbe06d262009-08-14 14:37:10 -0700833void OMXCodec::setVideoInputFormat(
James Dong1244eab2010-06-08 11:58:53 -0700834 const char *mime, const sp<MetaData>& meta) {
835
836 int32_t width, height, frameRate, bitRate, stride, sliceHeight;
837 bool success = meta->findInt32(kKeyWidth, &width);
838 success = success && meta->findInt32(kKeyHeight, &height);
839 success = success && meta->findInt32(kKeySampleRate, &frameRate);
840 success = success && meta->findInt32(kKeyBitRate, &bitRate);
841 success = success && meta->findInt32(kKeyStride, &stride);
842 success = success && meta->findInt32(kKeySliceHeight, &sliceHeight);
843 CHECK(success);
844 CHECK(stride != 0);
Andreas Huberbe06d262009-08-14 14:37:10 -0700845
846 OMX_VIDEO_CODINGTYPE compressionFormat = OMX_VIDEO_CodingUnused;
Andreas Hubere6c40962009-09-10 14:13:30 -0700847 if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700848 compressionFormat = OMX_VIDEO_CodingAVC;
Andreas Hubere6c40962009-09-10 14:13:30 -0700849 } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_MPEG4, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700850 compressionFormat = OMX_VIDEO_CodingMPEG4;
Andreas Hubere6c40962009-09-10 14:13:30 -0700851 } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_H263, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -0700852 compressionFormat = OMX_VIDEO_CodingH263;
853 } else {
854 LOGE("Not a supported video mime type: %s", mime);
855 CHECK(!"Should not be here. Not a supported video mime type.");
856 }
857
James Dongafd97e82010-08-03 17:19:23 -0700858 OMX_COLOR_FORMATTYPE colorFormat;
859 CHECK_EQ(OK, findTargetColorFormat(meta, &colorFormat));
Andreas Huberbe06d262009-08-14 14:37:10 -0700860
pgudadhe9c305322010-07-26 13:59:29 -0700861 if (!strcasecmp("OMX.Nvidia.h264.encoder", mComponentName)) {
862 colorFormat = OMX_COLOR_FormatYUV420Planar;
863 }
864
James Dongb00e2462010-04-26 17:48:26 -0700865 status_t err;
866 OMX_PARAM_PORTDEFINITIONTYPE def;
867 OMX_VIDEO_PORTDEFINITIONTYPE *video_def = &def.format.video;
868
869 //////////////////////// Input port /////////////////////////
Andreas Huberb482ce82009-10-29 12:02:48 -0700870 CHECK_EQ(setVideoPortFormatType(
Andreas Huberbe06d262009-08-14 14:37:10 -0700871 kPortIndexInput, OMX_VIDEO_CodingUnused,
Andreas Huberb482ce82009-10-29 12:02:48 -0700872 colorFormat), OK);
James Dong4f501f02010-06-07 14:41:41 -0700873
James Dongb00e2462010-04-26 17:48:26 -0700874 InitOMXParams(&def);
875 def.nPortIndex = kPortIndexInput;
Andreas Huberbe06d262009-08-14 14:37:10 -0700876
James Dongb00e2462010-04-26 17:48:26 -0700877 err = mOMX->getParameter(
878 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
879 CHECK_EQ(err, OK);
880
James Dong1244eab2010-06-08 11:58:53 -0700881 def.nBufferSize = getFrameSize(colorFormat,
882 stride > 0? stride: -stride, sliceHeight);
James Dongb00e2462010-04-26 17:48:26 -0700883
884 CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
885
886 video_def->nFrameWidth = width;
887 video_def->nFrameHeight = height;
James Dong1244eab2010-06-08 11:58:53 -0700888 video_def->nStride = stride;
889 video_def->nSliceHeight = sliceHeight;
James Dong4f501f02010-06-07 14:41:41 -0700890 video_def->xFramerate = (frameRate << 16); // Q16 format
James Dongb00e2462010-04-26 17:48:26 -0700891 video_def->eCompressionFormat = OMX_VIDEO_CodingUnused;
892 video_def->eColorFormat = colorFormat;
893
James Dongb00e2462010-04-26 17:48:26 -0700894 err = mOMX->setParameter(
895 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
896 CHECK_EQ(err, OK);
897
898 //////////////////////// Output port /////////////////////////
Andreas Huberb482ce82009-10-29 12:02:48 -0700899 CHECK_EQ(setVideoPortFormatType(
900 kPortIndexOutput, compressionFormat, OMX_COLOR_FormatUnused),
901 OK);
Andreas Huber4c483422009-09-02 16:05:36 -0700902 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -0700903 def.nPortIndex = kPortIndexOutput;
904
James Dongb00e2462010-04-26 17:48:26 -0700905 err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -0700906 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
907
908 CHECK_EQ(err, OK);
909 CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
910
911 video_def->nFrameWidth = width;
912 video_def->nFrameHeight = height;
James Dong81c929a2010-07-01 15:02:14 -0700913 video_def->xFramerate = 0; // No need for output port
James Dong4f501f02010-06-07 14:41:41 -0700914 video_def->nBitrate = bitRate; // Q16 format
Andreas Huberbe06d262009-08-14 14:37:10 -0700915 video_def->eCompressionFormat = compressionFormat;
916 video_def->eColorFormat = OMX_COLOR_FormatUnused;
917
Andreas Huber784202e2009-10-15 13:46:54 -0700918 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -0700919 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
920 CHECK_EQ(err, OK);
921
James Dongb00e2462010-04-26 17:48:26 -0700922 /////////////////// Codec-specific ////////////////////////
Andreas Huberb482ce82009-10-29 12:02:48 -0700923 switch (compressionFormat) {
924 case OMX_VIDEO_CodingMPEG4:
925 {
James Dong1244eab2010-06-08 11:58:53 -0700926 CHECK_EQ(setupMPEG4EncoderParameters(meta), OK);
Andreas Huberb482ce82009-10-29 12:02:48 -0700927 break;
928 }
929
930 case OMX_VIDEO_CodingH263:
James Dongc0ab2a62010-06-29 16:29:19 -0700931 CHECK_EQ(setupH263EncoderParameters(meta), OK);
Andreas Huberb482ce82009-10-29 12:02:48 -0700932 break;
933
Andreas Huberea6a38c2009-11-16 15:43:38 -0800934 case OMX_VIDEO_CodingAVC:
935 {
James Dong1244eab2010-06-08 11:58:53 -0700936 CHECK_EQ(setupAVCEncoderParameters(meta), OK);
Andreas Huberea6a38c2009-11-16 15:43:38 -0800937 break;
938 }
939
Andreas Huberb482ce82009-10-29 12:02:48 -0700940 default:
941 CHECK(!"Support for this compressionFormat to be implemented.");
942 break;
943 }
944}
945
James Dong1244eab2010-06-08 11:58:53 -0700946static OMX_U32 setPFramesSpacing(int32_t iFramesInterval, int32_t frameRate) {
947 if (iFramesInterval < 0) {
948 return 0xFFFFFFFF;
949 } else if (iFramesInterval == 0) {
950 return 0;
951 }
952 OMX_U32 ret = frameRate * iFramesInterval;
953 CHECK(ret > 1);
954 return ret;
955}
956
James Dongc0ab2a62010-06-29 16:29:19 -0700957status_t OMXCodec::setupErrorCorrectionParameters() {
958 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE errorCorrectionType;
959 InitOMXParams(&errorCorrectionType);
960 errorCorrectionType.nPortIndex = kPortIndexOutput;
961
962 status_t err = mOMX->getParameter(
963 mNode, OMX_IndexParamVideoErrorCorrection,
964 &errorCorrectionType, sizeof(errorCorrectionType));
965 CHECK_EQ(err, OK);
966
967 errorCorrectionType.bEnableHEC = OMX_FALSE;
968 errorCorrectionType.bEnableResync = OMX_TRUE;
969 errorCorrectionType.nResynchMarkerSpacing = 256;
970 errorCorrectionType.bEnableDataPartitioning = OMX_FALSE;
971 errorCorrectionType.bEnableRVLC = OMX_FALSE;
972
973 err = mOMX->setParameter(
974 mNode, OMX_IndexParamVideoErrorCorrection,
975 &errorCorrectionType, sizeof(errorCorrectionType));
976 CHECK_EQ(err, OK);
977 return OK;
978}
979
980status_t OMXCodec::setupBitRate(int32_t bitRate) {
981 OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
982 InitOMXParams(&bitrateType);
983 bitrateType.nPortIndex = kPortIndexOutput;
984
985 status_t err = mOMX->getParameter(
986 mNode, OMX_IndexParamVideoBitrate,
987 &bitrateType, sizeof(bitrateType));
988 CHECK_EQ(err, OK);
989
990 bitrateType.eControlRate = OMX_Video_ControlRateVariable;
991 bitrateType.nTargetBitrate = bitRate;
992
993 err = mOMX->setParameter(
994 mNode, OMX_IndexParamVideoBitrate,
995 &bitrateType, sizeof(bitrateType));
996 CHECK_EQ(err, OK);
997 return OK;
998}
999
James Dong81c929a2010-07-01 15:02:14 -07001000status_t OMXCodec::getVideoProfileLevel(
1001 const sp<MetaData>& meta,
1002 const CodecProfileLevel& defaultProfileLevel,
1003 CodecProfileLevel &profileLevel) {
1004 CODEC_LOGV("Default profile: %ld, level %ld",
1005 defaultProfileLevel.mProfile, defaultProfileLevel.mLevel);
1006
1007 // Are the default profile and level overwriten?
1008 int32_t profile, level;
1009 if (!meta->findInt32(kKeyVideoProfile, &profile)) {
1010 profile = defaultProfileLevel.mProfile;
1011 }
1012 if (!meta->findInt32(kKeyVideoLevel, &level)) {
1013 level = defaultProfileLevel.mLevel;
1014 }
1015 CODEC_LOGV("Target profile: %d, level: %d", profile, level);
1016
1017 // Are the target profile and level supported by the encoder?
1018 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
1019 InitOMXParams(&param);
1020 param.nPortIndex = kPortIndexOutput;
1021 for (param.nProfileIndex = 0;; ++param.nProfileIndex) {
1022 status_t err = mOMX->getParameter(
1023 mNode, OMX_IndexParamVideoProfileLevelQuerySupported,
1024 &param, sizeof(param));
1025
1026 if (err != OK) return err;
1027
1028 int32_t supportedProfile = static_cast<int32_t>(param.eProfile);
1029 int32_t supportedLevel = static_cast<int32_t>(param.eLevel);
James Dong929642e2010-07-08 11:16:11 -07001030 CODEC_LOGV("Supported profile: %d, level %d",
James Dong81c929a2010-07-01 15:02:14 -07001031 supportedProfile, supportedLevel);
1032
1033 if (profile == supportedProfile &&
1034 level == supportedLevel) {
1035 profileLevel.mProfile = profile;
1036 profileLevel.mLevel = level;
1037 return OK;
1038 }
1039 }
1040
1041 CODEC_LOGE("Target profile (%d) and level (%d) is not supported",
1042 profile, level);
1043 return BAD_VALUE;
1044}
1045
James Dongc0ab2a62010-06-29 16:29:19 -07001046status_t OMXCodec::setupH263EncoderParameters(const sp<MetaData>& meta) {
1047 int32_t iFramesInterval, frameRate, bitRate;
1048 bool success = meta->findInt32(kKeyBitRate, &bitRate);
1049 success = success && meta->findInt32(kKeySampleRate, &frameRate);
1050 success = success && meta->findInt32(kKeyIFramesInterval, &iFramesInterval);
1051 CHECK(success);
1052 OMX_VIDEO_PARAM_H263TYPE h263type;
1053 InitOMXParams(&h263type);
1054 h263type.nPortIndex = kPortIndexOutput;
1055
1056 status_t err = mOMX->getParameter(
1057 mNode, OMX_IndexParamVideoH263, &h263type, sizeof(h263type));
1058 CHECK_EQ(err, OK);
1059
1060 h263type.nAllowedPictureTypes =
1061 OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
1062
1063 h263type.nPFrames = setPFramesSpacing(iFramesInterval, frameRate);
1064 if (h263type.nPFrames == 0) {
1065 h263type.nAllowedPictureTypes = OMX_VIDEO_PictureTypeI;
1066 }
1067 h263type.nBFrames = 0;
1068
James Dong81c929a2010-07-01 15:02:14 -07001069 // Check profile and level parameters
1070 CodecProfileLevel defaultProfileLevel, profileLevel;
1071 defaultProfileLevel.mProfile = OMX_VIDEO_H263ProfileBaseline;
1072 defaultProfileLevel.mLevel = OMX_VIDEO_H263Level45;
1073 err = getVideoProfileLevel(meta, defaultProfileLevel, profileLevel);
1074 if (err != OK) return err;
1075 h263type.eProfile = static_cast<OMX_VIDEO_H263PROFILETYPE>(profileLevel.mProfile);
1076 h263type.eLevel = static_cast<OMX_VIDEO_H263LEVELTYPE>(profileLevel.mLevel);
James Dongc0ab2a62010-06-29 16:29:19 -07001077
1078 h263type.bPLUSPTYPEAllowed = OMX_FALSE;
1079 h263type.bForceRoundingTypeToZero = OMX_FALSE;
1080 h263type.nPictureHeaderRepetition = 0;
1081 h263type.nGOBHeaderInterval = 0;
1082
1083 err = mOMX->setParameter(
1084 mNode, OMX_IndexParamVideoH263, &h263type, sizeof(h263type));
1085 CHECK_EQ(err, OK);
1086
1087 CHECK_EQ(setupBitRate(bitRate), OK);
1088 CHECK_EQ(setupErrorCorrectionParameters(), OK);
1089
1090 return OK;
1091}
1092
James Dong1244eab2010-06-08 11:58:53 -07001093status_t OMXCodec::setupMPEG4EncoderParameters(const sp<MetaData>& meta) {
1094 int32_t iFramesInterval, frameRate, bitRate;
1095 bool success = meta->findInt32(kKeyBitRate, &bitRate);
1096 success = success && meta->findInt32(kKeySampleRate, &frameRate);
1097 success = success && meta->findInt32(kKeyIFramesInterval, &iFramesInterval);
1098 CHECK(success);
Andreas Huberb482ce82009-10-29 12:02:48 -07001099 OMX_VIDEO_PARAM_MPEG4TYPE mpeg4type;
1100 InitOMXParams(&mpeg4type);
1101 mpeg4type.nPortIndex = kPortIndexOutput;
1102
1103 status_t err = mOMX->getParameter(
1104 mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
1105 CHECK_EQ(err, OK);
1106
1107 mpeg4type.nSliceHeaderSpacing = 0;
1108 mpeg4type.bSVH = OMX_FALSE;
1109 mpeg4type.bGov = OMX_FALSE;
1110
1111 mpeg4type.nAllowedPictureTypes =
1112 OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
1113
James Dong1244eab2010-06-08 11:58:53 -07001114 mpeg4type.nPFrames = setPFramesSpacing(iFramesInterval, frameRate);
1115 if (mpeg4type.nPFrames == 0) {
1116 mpeg4type.nAllowedPictureTypes = OMX_VIDEO_PictureTypeI;
1117 }
Andreas Huberb482ce82009-10-29 12:02:48 -07001118 mpeg4type.nBFrames = 0;
Andreas Huberb482ce82009-10-29 12:02:48 -07001119 mpeg4type.nIDCVLCThreshold = 0;
1120 mpeg4type.bACPred = OMX_TRUE;
1121 mpeg4type.nMaxPacketSize = 256;
1122 mpeg4type.nTimeIncRes = 1000;
1123 mpeg4type.nHeaderExtension = 0;
1124 mpeg4type.bReversibleVLC = OMX_FALSE;
1125
James Dong81c929a2010-07-01 15:02:14 -07001126 // Check profile and level parameters
1127 CodecProfileLevel defaultProfileLevel, profileLevel;
1128 defaultProfileLevel.mProfile = OMX_VIDEO_MPEG4ProfileSimple;
1129 defaultProfileLevel.mLevel = OMX_VIDEO_MPEG4Level2;
1130 err = getVideoProfileLevel(meta, defaultProfileLevel, profileLevel);
1131 if (err != OK) return err;
1132 mpeg4type.eProfile = static_cast<OMX_VIDEO_MPEG4PROFILETYPE>(profileLevel.mProfile);
1133 mpeg4type.eLevel = static_cast<OMX_VIDEO_MPEG4LEVELTYPE>(profileLevel.mLevel);
Andreas Huberb482ce82009-10-29 12:02:48 -07001134
1135 err = mOMX->setParameter(
1136 mNode, OMX_IndexParamVideoMpeg4, &mpeg4type, sizeof(mpeg4type));
1137 CHECK_EQ(err, OK);
1138
James Dongc0ab2a62010-06-29 16:29:19 -07001139 CHECK_EQ(setupBitRate(bitRate), OK);
1140 CHECK_EQ(setupErrorCorrectionParameters(), OK);
Andreas Huberb482ce82009-10-29 12:02:48 -07001141
1142 return OK;
Andreas Huberbe06d262009-08-14 14:37:10 -07001143}
1144
James Dong1244eab2010-06-08 11:58:53 -07001145status_t OMXCodec::setupAVCEncoderParameters(const sp<MetaData>& meta) {
1146 int32_t iFramesInterval, frameRate, bitRate;
1147 bool success = meta->findInt32(kKeyBitRate, &bitRate);
1148 success = success && meta->findInt32(kKeySampleRate, &frameRate);
1149 success = success && meta->findInt32(kKeyIFramesInterval, &iFramesInterval);
1150 CHECK(success);
1151
Andreas Huberea6a38c2009-11-16 15:43:38 -08001152 OMX_VIDEO_PARAM_AVCTYPE h264type;
1153 InitOMXParams(&h264type);
1154 h264type.nPortIndex = kPortIndexOutput;
1155
1156 status_t err = mOMX->getParameter(
1157 mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
1158 CHECK_EQ(err, OK);
1159
1160 h264type.nAllowedPictureTypes =
1161 OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
1162
1163 h264type.nSliceHeaderSpacing = 0;
James Dong1244eab2010-06-08 11:58:53 -07001164 h264type.nBFrames = 0; // No B frames support yet
1165 h264type.nPFrames = setPFramesSpacing(iFramesInterval, frameRate);
1166 if (h264type.nPFrames == 0) {
1167 h264type.nAllowedPictureTypes = OMX_VIDEO_PictureTypeI;
1168 }
James Dong81c929a2010-07-01 15:02:14 -07001169
1170 // Check profile and level parameters
1171 CodecProfileLevel defaultProfileLevel, profileLevel;
1172 defaultProfileLevel.mProfile = h264type.eProfile;
1173 defaultProfileLevel.mLevel = h264type.eLevel;
1174 err = getVideoProfileLevel(meta, defaultProfileLevel, profileLevel);
1175 if (err != OK) return err;
1176 h264type.eProfile = static_cast<OMX_VIDEO_AVCPROFILETYPE>(profileLevel.mProfile);
1177 h264type.eLevel = static_cast<OMX_VIDEO_AVCLEVELTYPE>(profileLevel.mLevel);
1178
1179 if (h264type.eProfile == OMX_VIDEO_AVCProfileBaseline) {
1180 h264type.bUseHadamard = OMX_TRUE;
1181 h264type.nRefFrames = 1;
1182 h264type.nRefIdx10ActiveMinus1 = 0;
1183 h264type.nRefIdx11ActiveMinus1 = 0;
1184 h264type.bEntropyCodingCABAC = OMX_FALSE;
1185 h264type.bWeightedPPrediction = OMX_FALSE;
1186 h264type.bconstIpred = OMX_FALSE;
1187 h264type.bDirect8x8Inference = OMX_FALSE;
1188 h264type.bDirectSpatialTemporal = OMX_FALSE;
1189 h264type.nCabacInitIdc = 0;
1190 }
1191
1192 if (h264type.nBFrames != 0) {
1193 h264type.nAllowedPictureTypes |= OMX_VIDEO_PictureTypeB;
1194 }
1195
Andreas Huberea6a38c2009-11-16 15:43:38 -08001196 h264type.bEnableUEP = OMX_FALSE;
1197 h264type.bEnableFMO = OMX_FALSE;
1198 h264type.bEnableASO = OMX_FALSE;
1199 h264type.bEnableRS = OMX_FALSE;
Andreas Huberea6a38c2009-11-16 15:43:38 -08001200 h264type.bFrameMBsOnly = OMX_TRUE;
1201 h264type.bMBAFF = OMX_FALSE;
Andreas Huberea6a38c2009-11-16 15:43:38 -08001202 h264type.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
1203
pgudadhe9c305322010-07-26 13:59:29 -07001204 if (!strcasecmp("OMX.Nvidia.h264.encoder", mComponentName)) {
1205 h264type.eLevel = OMX_VIDEO_AVCLevelMax;
1206 }
1207
Andreas Huberea6a38c2009-11-16 15:43:38 -08001208 err = mOMX->setParameter(
1209 mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
1210 CHECK_EQ(err, OK);
1211
James Dongc0ab2a62010-06-29 16:29:19 -07001212 CHECK_EQ(setupBitRate(bitRate), OK);
Andreas Huberea6a38c2009-11-16 15:43:38 -08001213
1214 return OK;
1215}
1216
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001217status_t OMXCodec::setVideoOutputFormat(
Andreas Huberbe06d262009-08-14 14:37:10 -07001218 const char *mime, OMX_U32 width, OMX_U32 height) {
Andreas Huber53a76bd2009-10-06 16:20:44 -07001219 CODEC_LOGV("setVideoOutputFormat width=%ld, height=%ld", width, height);
Andreas Huberbe06d262009-08-14 14:37:10 -07001220
Andreas Huberbe06d262009-08-14 14:37:10 -07001221 OMX_VIDEO_CODINGTYPE compressionFormat = OMX_VIDEO_CodingUnused;
Andreas Hubere6c40962009-09-10 14:13:30 -07001222 if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -07001223 compressionFormat = OMX_VIDEO_CodingAVC;
Andreas Hubere6c40962009-09-10 14:13:30 -07001224 } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_MPEG4, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -07001225 compressionFormat = OMX_VIDEO_CodingMPEG4;
Andreas Hubere6c40962009-09-10 14:13:30 -07001226 } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_H263, mime)) {
Andreas Huberbe06d262009-08-14 14:37:10 -07001227 compressionFormat = OMX_VIDEO_CodingH263;
1228 } else {
1229 LOGE("Not a supported video mime type: %s", mime);
1230 CHECK(!"Should not be here. Not a supported video mime type.");
1231 }
1232
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001233 status_t err = setVideoPortFormatType(
Andreas Huberbe06d262009-08-14 14:37:10 -07001234 kPortIndexInput, compressionFormat, OMX_COLOR_FormatUnused);
1235
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001236 if (err != OK) {
1237 return err;
1238 }
1239
Andreas Huberbe06d262009-08-14 14:37:10 -07001240#if 1
1241 {
1242 OMX_VIDEO_PARAM_PORTFORMATTYPE format;
Andreas Huber4c483422009-09-02 16:05:36 -07001243 InitOMXParams(&format);
Andreas Huberbe06d262009-08-14 14:37:10 -07001244 format.nPortIndex = kPortIndexOutput;
1245 format.nIndex = 0;
1246
Andreas Huber784202e2009-10-15 13:46:54 -07001247 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001248 mNode, OMX_IndexParamVideoPortFormat,
1249 &format, sizeof(format));
1250 CHECK_EQ(err, OK);
1251 CHECK_EQ(format.eCompressionFormat, OMX_VIDEO_CodingUnused);
1252
1253 static const int OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00;
1254
1255 CHECK(format.eColorFormat == OMX_COLOR_FormatYUV420Planar
1256 || format.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar
1257 || format.eColorFormat == OMX_COLOR_FormatCbYCrY
1258 || format.eColorFormat == OMX_QCOM_COLOR_FormatYVU420SemiPlanar);
1259
Andreas Huber784202e2009-10-15 13:46:54 -07001260 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001261 mNode, OMX_IndexParamVideoPortFormat,
1262 &format, sizeof(format));
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001263
1264 if (err != OK) {
1265 return err;
1266 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001267 }
1268#endif
1269
1270 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07001271 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07001272 def.nPortIndex = kPortIndexInput;
1273
Andreas Huber4c483422009-09-02 16:05:36 -07001274 OMX_VIDEO_PORTDEFINITIONTYPE *video_def = &def.format.video;
1275
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001276 err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001277 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
1278
1279 CHECK_EQ(err, OK);
1280
1281#if 1
1282 // XXX Need a (much) better heuristic to compute input buffer sizes.
1283 const size_t X = 64 * 1024;
1284 if (def.nBufferSize < X) {
1285 def.nBufferSize = X;
1286 }
1287#endif
1288
1289 CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
1290
1291 video_def->nFrameWidth = width;
1292 video_def->nFrameHeight = height;
1293
Andreas Huberb482ce82009-10-29 12:02:48 -07001294 video_def->eCompressionFormat = compressionFormat;
Andreas Huberbe06d262009-08-14 14:37:10 -07001295 video_def->eColorFormat = OMX_COLOR_FormatUnused;
1296
Andreas Huber784202e2009-10-15 13:46:54 -07001297 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001298 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001299
1300 if (err != OK) {
1301 return err;
1302 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001303
1304 ////////////////////////////////////////////////////////////////////////////
1305
Andreas Huber4c483422009-09-02 16:05:36 -07001306 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07001307 def.nPortIndex = kPortIndexOutput;
1308
Andreas Huber784202e2009-10-15 13:46:54 -07001309 err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001310 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
1311 CHECK_EQ(err, OK);
1312 CHECK_EQ(def.eDomain, OMX_PortDomainVideo);
1313
1314#if 0
1315 def.nBufferSize =
1316 (((width + 15) & -16) * ((height + 15) & -16) * 3) / 2; // YUV420
1317#endif
1318
1319 video_def->nFrameWidth = width;
1320 video_def->nFrameHeight = height;
1321
Andreas Huber784202e2009-10-15 13:46:54 -07001322 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001323 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
Andreas Huber2a09c7e2010-03-16 11:44:07 -07001324
1325 return err;
Andreas Huberbe06d262009-08-14 14:37:10 -07001326}
1327
Andreas Huberbe06d262009-08-14 14:37:10 -07001328OMXCodec::OMXCodec(
1329 const sp<IOMX> &omx, IOMX::node_id node, uint32_t quirks,
Andreas Huberebf66ea2009-08-19 13:32:58 -07001330 bool isEncoder,
Andreas Huberbe06d262009-08-14 14:37:10 -07001331 const char *mime,
1332 const char *componentName,
1333 const sp<MediaSource> &source)
1334 : mOMX(omx),
Andreas Huberf1fe0642010-01-15 15:28:19 -08001335 mOMXLivesLocally(omx->livesLocally(getpid())),
Andreas Huberbe06d262009-08-14 14:37:10 -07001336 mNode(node),
1337 mQuirks(quirks),
1338 mIsEncoder(isEncoder),
1339 mMIME(strdup(mime)),
1340 mComponentName(strdup(componentName)),
1341 mSource(source),
1342 mCodecSpecificDataIndex(0),
Andreas Huberbe06d262009-08-14 14:37:10 -07001343 mState(LOADED),
Andreas Huber42978e52009-08-27 10:08:39 -07001344 mInitialBufferSubmit(true),
Andreas Huberbe06d262009-08-14 14:37:10 -07001345 mSignalledEOS(false),
1346 mNoMoreOutputData(false),
Andreas Hubercfd55572009-10-09 14:11:28 -07001347 mOutputPortSettingsHaveChanged(false),
Andreas Hubera4357ad2010-04-02 12:49:54 -07001348 mSeekTimeUs(-1),
Andreas Huber6624c9f2010-07-20 15:04:28 -07001349 mSeekMode(ReadOptions::SEEK_CLOSEST_SYNC),
1350 mTargetTimeUs(-1),
James Dong53d4e0d2010-07-21 14:51:35 -07001351 mSkipTimeUs(-1),
Andreas Huber1f24b302010-06-10 11:12:39 -07001352 mLeftOverBuffer(NULL),
1353 mPaused(false) {
Andreas Huberbe06d262009-08-14 14:37:10 -07001354 mPortStatus[kPortIndexInput] = ENABLED;
1355 mPortStatus[kPortIndexOutput] = ENABLED;
1356
Andreas Huber4c483422009-09-02 16:05:36 -07001357 setComponentRole();
1358}
1359
Andreas Hubere6c40962009-09-10 14:13:30 -07001360// static
1361void OMXCodec::setComponentRole(
1362 const sp<IOMX> &omx, IOMX::node_id node, bool isEncoder,
1363 const char *mime) {
Andreas Huber4c483422009-09-02 16:05:36 -07001364 struct MimeToRole {
1365 const char *mime;
1366 const char *decoderRole;
1367 const char *encoderRole;
1368 };
1369
1370 static const MimeToRole kMimeToRole[] = {
Andreas Hubere6c40962009-09-10 14:13:30 -07001371 { MEDIA_MIMETYPE_AUDIO_MPEG,
1372 "audio_decoder.mp3", "audio_encoder.mp3" },
1373 { MEDIA_MIMETYPE_AUDIO_AMR_NB,
1374 "audio_decoder.amrnb", "audio_encoder.amrnb" },
1375 { MEDIA_MIMETYPE_AUDIO_AMR_WB,
1376 "audio_decoder.amrwb", "audio_encoder.amrwb" },
1377 { MEDIA_MIMETYPE_AUDIO_AAC,
1378 "audio_decoder.aac", "audio_encoder.aac" },
1379 { MEDIA_MIMETYPE_VIDEO_AVC,
1380 "video_decoder.avc", "video_encoder.avc" },
1381 { MEDIA_MIMETYPE_VIDEO_MPEG4,
1382 "video_decoder.mpeg4", "video_encoder.mpeg4" },
1383 { MEDIA_MIMETYPE_VIDEO_H263,
1384 "video_decoder.h263", "video_encoder.h263" },
Andreas Huber4c483422009-09-02 16:05:36 -07001385 };
1386
1387 static const size_t kNumMimeToRole =
1388 sizeof(kMimeToRole) / sizeof(kMimeToRole[0]);
1389
1390 size_t i;
1391 for (i = 0; i < kNumMimeToRole; ++i) {
Andreas Hubere6c40962009-09-10 14:13:30 -07001392 if (!strcasecmp(mime, kMimeToRole[i].mime)) {
Andreas Huber4c483422009-09-02 16:05:36 -07001393 break;
1394 }
1395 }
1396
1397 if (i == kNumMimeToRole) {
1398 return;
1399 }
1400
1401 const char *role =
Andreas Hubere6c40962009-09-10 14:13:30 -07001402 isEncoder ? kMimeToRole[i].encoderRole
1403 : kMimeToRole[i].decoderRole;
Andreas Huber4c483422009-09-02 16:05:36 -07001404
1405 if (role != NULL) {
Andreas Huber4c483422009-09-02 16:05:36 -07001406 OMX_PARAM_COMPONENTROLETYPE roleParams;
1407 InitOMXParams(&roleParams);
1408
1409 strncpy((char *)roleParams.cRole,
1410 role, OMX_MAX_STRINGNAME_SIZE - 1);
1411
1412 roleParams.cRole[OMX_MAX_STRINGNAME_SIZE - 1] = '\0';
1413
Andreas Huber784202e2009-10-15 13:46:54 -07001414 status_t err = omx->setParameter(
Andreas Hubere6c40962009-09-10 14:13:30 -07001415 node, OMX_IndexParamStandardComponentRole,
Andreas Huber4c483422009-09-02 16:05:36 -07001416 &roleParams, sizeof(roleParams));
1417
1418 if (err != OK) {
1419 LOGW("Failed to set standard component role '%s'.", role);
1420 }
1421 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001422}
1423
Andreas Hubere6c40962009-09-10 14:13:30 -07001424void OMXCodec::setComponentRole() {
1425 setComponentRole(mOMX, mNode, mIsEncoder, mMIME);
1426}
1427
Andreas Huberbe06d262009-08-14 14:37:10 -07001428OMXCodec::~OMXCodec() {
Andreas Huber4f5e6022009-08-19 09:29:34 -07001429 CHECK(mState == LOADED || mState == ERROR);
Andreas Huberbe06d262009-08-14 14:37:10 -07001430
Andreas Huber784202e2009-10-15 13:46:54 -07001431 status_t err = mOMX->freeNode(mNode);
Andreas Huberbe06d262009-08-14 14:37:10 -07001432 CHECK_EQ(err, OK);
1433
1434 mNode = NULL;
1435 setState(DEAD);
1436
1437 clearCodecSpecificData();
1438
1439 free(mComponentName);
1440 mComponentName = NULL;
Andreas Huberebf66ea2009-08-19 13:32:58 -07001441
Andreas Huberbe06d262009-08-14 14:37:10 -07001442 free(mMIME);
1443 mMIME = NULL;
1444}
1445
1446status_t OMXCodec::init() {
Andreas Huber42978e52009-08-27 10:08:39 -07001447 // mLock is held.
Andreas Huberbe06d262009-08-14 14:37:10 -07001448
1449 CHECK_EQ(mState, LOADED);
1450
1451 status_t err;
1452 if (!(mQuirks & kRequiresLoadedToIdleAfterAllocation)) {
Andreas Huber784202e2009-10-15 13:46:54 -07001453 err = mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
Andreas Huberbe06d262009-08-14 14:37:10 -07001454 CHECK_EQ(err, OK);
Andreas Huberbe06d262009-08-14 14:37:10 -07001455 setState(LOADED_TO_IDLE);
1456 }
1457
1458 err = allocateBuffers();
1459 CHECK_EQ(err, OK);
1460
1461 if (mQuirks & kRequiresLoadedToIdleAfterAllocation) {
Andreas Huber784202e2009-10-15 13:46:54 -07001462 err = mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
Andreas Huberbe06d262009-08-14 14:37:10 -07001463 CHECK_EQ(err, OK);
1464
1465 setState(LOADED_TO_IDLE);
1466 }
1467
1468 while (mState != EXECUTING && mState != ERROR) {
1469 mAsyncCompletion.wait(mLock);
1470 }
1471
1472 return mState == ERROR ? UNKNOWN_ERROR : OK;
1473}
1474
1475// static
1476bool OMXCodec::isIntermediateState(State state) {
1477 return state == LOADED_TO_IDLE
1478 || state == IDLE_TO_EXECUTING
1479 || state == EXECUTING_TO_IDLE
1480 || state == IDLE_TO_LOADED
1481 || state == RECONFIGURING;
1482}
1483
1484status_t OMXCodec::allocateBuffers() {
1485 status_t err = allocateBuffersOnPort(kPortIndexInput);
1486
1487 if (err != OK) {
1488 return err;
1489 }
1490
1491 return allocateBuffersOnPort(kPortIndexOutput);
1492}
1493
1494status_t OMXCodec::allocateBuffersOnPort(OMX_U32 portIndex) {
1495 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07001496 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07001497 def.nPortIndex = portIndex;
1498
Andreas Huber784202e2009-10-15 13:46:54 -07001499 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07001500 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
1501
1502 if (err != OK) {
1503 return err;
1504 }
1505
Andreas Huber57648e42010-08-04 10:14:30 -07001506 CODEC_LOGI("allocating %lu buffers of size %lu on %s port",
1507 def.nBufferCountActual, def.nBufferSize,
1508 portIndex == kPortIndexInput ? "input" : "output");
1509
Andreas Huber5c0a9132009-08-20 11:16:40 -07001510 size_t totalSize = def.nBufferCountActual * def.nBufferSize;
Mathias Agopian6faf7892010-01-25 19:00:00 -08001511 mDealer[portIndex] = new MemoryDealer(totalSize, "OMXCodec");
Andreas Huber5c0a9132009-08-20 11:16:40 -07001512
Andreas Huberbe06d262009-08-14 14:37:10 -07001513 for (OMX_U32 i = 0; i < def.nBufferCountActual; ++i) {
Andreas Huber5c0a9132009-08-20 11:16:40 -07001514 sp<IMemory> mem = mDealer[portIndex]->allocate(def.nBufferSize);
Andreas Huberbe06d262009-08-14 14:37:10 -07001515 CHECK(mem.get() != NULL);
1516
Andreas Huberc712b9f2010-01-20 15:05:46 -08001517 BufferInfo info;
1518 info.mData = NULL;
1519 info.mSize = def.nBufferSize;
1520
Andreas Huberbe06d262009-08-14 14:37:10 -07001521 IOMX::buffer_id buffer;
1522 if (portIndex == kPortIndexInput
1523 && (mQuirks & kRequiresAllocateBufferOnInputPorts)) {
Andreas Huberf1fe0642010-01-15 15:28:19 -08001524 if (mOMXLivesLocally) {
Andreas Huberc712b9f2010-01-20 15:05:46 -08001525 mem.clear();
1526
Andreas Huberf1fe0642010-01-15 15:28:19 -08001527 err = mOMX->allocateBuffer(
Andreas Huberc712b9f2010-01-20 15:05:46 -08001528 mNode, portIndex, def.nBufferSize, &buffer,
1529 &info.mData);
Andreas Huberf1fe0642010-01-15 15:28:19 -08001530 } else {
1531 err = mOMX->allocateBufferWithBackup(
1532 mNode, portIndex, mem, &buffer);
1533 }
Andreas Huber446f44f2009-08-25 17:23:44 -07001534 } else if (portIndex == kPortIndexOutput
1535 && (mQuirks & kRequiresAllocateBufferOnOutputPorts)) {
Andreas Huberf1fe0642010-01-15 15:28:19 -08001536 if (mOMXLivesLocally) {
Andreas Huberc712b9f2010-01-20 15:05:46 -08001537 mem.clear();
1538
Andreas Huberf1fe0642010-01-15 15:28:19 -08001539 err = mOMX->allocateBuffer(
Andreas Huberc712b9f2010-01-20 15:05:46 -08001540 mNode, portIndex, def.nBufferSize, &buffer,
1541 &info.mData);
Andreas Huberf1fe0642010-01-15 15:28:19 -08001542 } else {
1543 err = mOMX->allocateBufferWithBackup(
1544 mNode, portIndex, mem, &buffer);
1545 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001546 } else {
Andreas Huber784202e2009-10-15 13:46:54 -07001547 err = mOMX->useBuffer(mNode, portIndex, mem, &buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001548 }
1549
1550 if (err != OK) {
1551 LOGE("allocate_buffer_with_backup failed");
1552 return err;
1553 }
1554
Andreas Huberc712b9f2010-01-20 15:05:46 -08001555 if (mem != NULL) {
1556 info.mData = mem->pointer();
1557 }
1558
Andreas Huberbe06d262009-08-14 14:37:10 -07001559 info.mBuffer = buffer;
1560 info.mOwnedByComponent = false;
1561 info.mMem = mem;
1562 info.mMediaBuffer = NULL;
1563
1564 if (portIndex == kPortIndexOutput) {
Andreas Huber52733b82010-01-25 10:41:35 -08001565 if (!(mOMXLivesLocally
1566 && (mQuirks & kRequiresAllocateBufferOnOutputPorts)
1567 && (mQuirks & kDefersOutputBufferAllocation))) {
1568 // If the node does not fill in the buffer ptr at this time,
1569 // we will defer creating the MediaBuffer until receiving
1570 // the first FILL_BUFFER_DONE notification instead.
1571 info.mMediaBuffer = new MediaBuffer(info.mData, info.mSize);
1572 info.mMediaBuffer->setObserver(this);
1573 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001574 }
1575
1576 mPortBuffers[portIndex].push(info);
1577
Andreas Huber4c483422009-09-02 16:05:36 -07001578 CODEC_LOGV("allocated buffer %p on %s port", buffer,
Andreas Huberbe06d262009-08-14 14:37:10 -07001579 portIndex == kPortIndexInput ? "input" : "output");
1580 }
1581
Andreas Huber2ea14e22009-12-16 09:30:55 -08001582 // dumpPortStatus(portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07001583
1584 return OK;
1585}
1586
1587void OMXCodec::on_message(const omx_message &msg) {
1588 Mutex::Autolock autoLock(mLock);
1589
1590 switch (msg.type) {
1591 case omx_message::EVENT:
1592 {
1593 onEvent(
1594 msg.u.event_data.event, msg.u.event_data.data1,
1595 msg.u.event_data.data2);
1596
1597 break;
1598 }
1599
1600 case omx_message::EMPTY_BUFFER_DONE:
1601 {
1602 IOMX::buffer_id buffer = msg.u.extended_buffer_data.buffer;
1603
Andreas Huber4c483422009-09-02 16:05:36 -07001604 CODEC_LOGV("EMPTY_BUFFER_DONE(buffer: %p)", buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001605
1606 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexInput];
1607 size_t i = 0;
1608 while (i < buffers->size() && (*buffers)[i].mBuffer != buffer) {
1609 ++i;
1610 }
1611
1612 CHECK(i < buffers->size());
1613 if (!(*buffers)[i].mOwnedByComponent) {
1614 LOGW("We already own input buffer %p, yet received "
1615 "an EMPTY_BUFFER_DONE.", buffer);
1616 }
1617
1618 buffers->editItemAt(i).mOwnedByComponent = false;
1619
1620 if (mPortStatus[kPortIndexInput] == DISABLING) {
Andreas Huber4c483422009-09-02 16:05:36 -07001621 CODEC_LOGV("Port is disabled, freeing buffer %p", buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001622
1623 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07001624 mOMX->freeBuffer(mNode, kPortIndexInput, buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001625 CHECK_EQ(err, OK);
1626
1627 buffers->removeAt(i);
Andreas Huber4a9375e2010-02-09 11:54:33 -08001628 } else if (mState != ERROR
1629 && mPortStatus[kPortIndexInput] != SHUTTING_DOWN) {
Andreas Huberbe06d262009-08-14 14:37:10 -07001630 CHECK_EQ(mPortStatus[kPortIndexInput], ENABLED);
1631 drainInputBuffer(&buffers->editItemAt(i));
1632 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001633 break;
1634 }
1635
1636 case omx_message::FILL_BUFFER_DONE:
1637 {
1638 IOMX::buffer_id buffer = msg.u.extended_buffer_data.buffer;
1639 OMX_U32 flags = msg.u.extended_buffer_data.flags;
1640
Andreas Huber2ea14e22009-12-16 09:30:55 -08001641 CODEC_LOGV("FILL_BUFFER_DONE(buffer: %p, size: %ld, flags: 0x%08lx, timestamp: %lld us (%.2f secs))",
Andreas Huberbe06d262009-08-14 14:37:10 -07001642 buffer,
1643 msg.u.extended_buffer_data.range_length,
Andreas Huber2ea14e22009-12-16 09:30:55 -08001644 flags,
Andreas Huberbe06d262009-08-14 14:37:10 -07001645 msg.u.extended_buffer_data.timestamp,
1646 msg.u.extended_buffer_data.timestamp / 1E6);
1647
1648 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexOutput];
1649 size_t i = 0;
1650 while (i < buffers->size() && (*buffers)[i].mBuffer != buffer) {
1651 ++i;
1652 }
1653
1654 CHECK(i < buffers->size());
1655 BufferInfo *info = &buffers->editItemAt(i);
1656
1657 if (!info->mOwnedByComponent) {
1658 LOGW("We already own output buffer %p, yet received "
1659 "a FILL_BUFFER_DONE.", buffer);
1660 }
1661
1662 info->mOwnedByComponent = false;
1663
1664 if (mPortStatus[kPortIndexOutput] == DISABLING) {
Andreas Huber4c483422009-09-02 16:05:36 -07001665 CODEC_LOGV("Port is disabled, freeing buffer %p", buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001666
1667 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07001668 mOMX->freeBuffer(mNode, kPortIndexOutput, buffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07001669 CHECK_EQ(err, OK);
1670
1671 buffers->removeAt(i);
Andreas Huber2ea14e22009-12-16 09:30:55 -08001672#if 0
Andreas Huberd7795892009-08-26 10:33:47 -07001673 } else if (mPortStatus[kPortIndexOutput] == ENABLED
1674 && (flags & OMX_BUFFERFLAG_EOS)) {
Andreas Huber4c483422009-09-02 16:05:36 -07001675 CODEC_LOGV("No more output data.");
Andreas Huberbe06d262009-08-14 14:37:10 -07001676 mNoMoreOutputData = true;
1677 mBufferFilled.signal();
Andreas Huber2ea14e22009-12-16 09:30:55 -08001678#endif
Andreas Huberbe06d262009-08-14 14:37:10 -07001679 } else if (mPortStatus[kPortIndexOutput] != SHUTTING_DOWN) {
1680 CHECK_EQ(mPortStatus[kPortIndexOutput], ENABLED);
Andreas Huberebf66ea2009-08-19 13:32:58 -07001681
Andreas Huber52733b82010-01-25 10:41:35 -08001682 if (info->mMediaBuffer == NULL) {
1683 CHECK(mOMXLivesLocally);
1684 CHECK(mQuirks & kRequiresAllocateBufferOnOutputPorts);
1685 CHECK(mQuirks & kDefersOutputBufferAllocation);
1686
1687 // The qcom video decoders on Nexus don't actually allocate
1688 // output buffer memory on a call to OMX_AllocateBuffer
1689 // the "pBuffer" member of the OMX_BUFFERHEADERTYPE
1690 // structure is only filled in later.
1691
1692 info->mMediaBuffer = new MediaBuffer(
1693 msg.u.extended_buffer_data.data_ptr,
1694 info->mSize);
1695 info->mMediaBuffer->setObserver(this);
1696 }
1697
Andreas Huberbe06d262009-08-14 14:37:10 -07001698 MediaBuffer *buffer = info->mMediaBuffer;
1699
Andreas Huberf88f8442010-08-10 11:18:36 -07001700 if (msg.u.extended_buffer_data.range_offset
1701 + msg.u.extended_buffer_data.range_length
1702 > buffer->size()) {
1703 CODEC_LOGE(
1704 "Codec lied about its buffer size requirements, "
1705 "sending a buffer larger than the originally "
1706 "advertised size in FILL_BUFFER_DONE!");
1707 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001708 buffer->set_range(
1709 msg.u.extended_buffer_data.range_offset,
1710 msg.u.extended_buffer_data.range_length);
1711
1712 buffer->meta_data()->clear();
1713
Andreas Huberfa8de752009-10-08 10:07:49 -07001714 buffer->meta_data()->setInt64(
1715 kKeyTime, msg.u.extended_buffer_data.timestamp);
Andreas Huberbe06d262009-08-14 14:37:10 -07001716
1717 if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_SYNCFRAME) {
1718 buffer->meta_data()->setInt32(kKeyIsSyncFrame, true);
1719 }
Andreas Huberea6a38c2009-11-16 15:43:38 -08001720 if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_CODECCONFIG) {
1721 buffer->meta_data()->setInt32(kKeyIsCodecConfig, true);
1722 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001723
1724 buffer->meta_data()->setPointer(
1725 kKeyPlatformPrivate,
1726 msg.u.extended_buffer_data.platform_private);
1727
1728 buffer->meta_data()->setPointer(
1729 kKeyBufferID,
1730 msg.u.extended_buffer_data.buffer);
1731
Andreas Huber2ea14e22009-12-16 09:30:55 -08001732 if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_EOS) {
1733 CODEC_LOGV("No more output data.");
1734 mNoMoreOutputData = true;
1735 }
Andreas Huber6624c9f2010-07-20 15:04:28 -07001736
1737 if (mTargetTimeUs >= 0) {
1738 CHECK(msg.u.extended_buffer_data.timestamp <= mTargetTimeUs);
1739
1740 if (msg.u.extended_buffer_data.timestamp < mTargetTimeUs) {
1741 CODEC_LOGV(
1742 "skipping output buffer at timestamp %lld us",
1743 msg.u.extended_buffer_data.timestamp);
1744
1745 fillOutputBuffer(info);
1746 break;
1747 }
1748
1749 CODEC_LOGV(
1750 "returning output buffer at target timestamp "
1751 "%lld us",
1752 msg.u.extended_buffer_data.timestamp);
1753
1754 mTargetTimeUs = -1;
1755 }
1756
1757 mFilledBuffers.push_back(i);
1758 mBufferFilled.signal();
Andreas Huberbe06d262009-08-14 14:37:10 -07001759 }
1760
1761 break;
1762 }
1763
1764 default:
1765 {
1766 CHECK(!"should not be here.");
1767 break;
1768 }
1769 }
1770}
1771
1772void OMXCodec::onEvent(OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) {
1773 switch (event) {
1774 case OMX_EventCmdComplete:
1775 {
1776 onCmdComplete((OMX_COMMANDTYPE)data1, data2);
1777 break;
1778 }
1779
1780 case OMX_EventError:
1781 {
Andreas Huber2ea14e22009-12-16 09:30:55 -08001782 LOGE("ERROR(0x%08lx, %ld)", data1, data2);
Andreas Huberbe06d262009-08-14 14:37:10 -07001783
1784 setState(ERROR);
1785 break;
1786 }
1787
1788 case OMX_EventPortSettingsChanged:
1789 {
1790 onPortSettingsChanged(data1);
1791 break;
1792 }
1793
Andreas Huber2ea14e22009-12-16 09:30:55 -08001794#if 0
Andreas Huberbe06d262009-08-14 14:37:10 -07001795 case OMX_EventBufferFlag:
1796 {
Andreas Huber4c483422009-09-02 16:05:36 -07001797 CODEC_LOGV("EVENT_BUFFER_FLAG(%ld)", data1);
Andreas Huberbe06d262009-08-14 14:37:10 -07001798
1799 if (data1 == kPortIndexOutput) {
1800 mNoMoreOutputData = true;
1801 }
1802 break;
1803 }
Andreas Huber2ea14e22009-12-16 09:30:55 -08001804#endif
Andreas Huberbe06d262009-08-14 14:37:10 -07001805
1806 default:
1807 {
Andreas Huber4c483422009-09-02 16:05:36 -07001808 CODEC_LOGV("EVENT(%d, %ld, %ld)", event, data1, data2);
Andreas Huberbe06d262009-08-14 14:37:10 -07001809 break;
1810 }
1811 }
1812}
1813
Andreas Huberb1678602009-10-19 13:06:40 -07001814// Has the format changed in any way that the client would have to be aware of?
1815static bool formatHasNotablyChanged(
1816 const sp<MetaData> &from, const sp<MetaData> &to) {
1817 if (from.get() == NULL && to.get() == NULL) {
1818 return false;
1819 }
1820
Andreas Huberf68c1682009-10-21 14:01:30 -07001821 if ((from.get() == NULL && to.get() != NULL)
1822 || (from.get() != NULL && to.get() == NULL)) {
Andreas Huberb1678602009-10-19 13:06:40 -07001823 return true;
1824 }
1825
1826 const char *mime_from, *mime_to;
1827 CHECK(from->findCString(kKeyMIMEType, &mime_from));
1828 CHECK(to->findCString(kKeyMIMEType, &mime_to));
1829
1830 if (strcasecmp(mime_from, mime_to)) {
1831 return true;
1832 }
1833
1834 if (!strcasecmp(mime_from, MEDIA_MIMETYPE_VIDEO_RAW)) {
1835 int32_t colorFormat_from, colorFormat_to;
1836 CHECK(from->findInt32(kKeyColorFormat, &colorFormat_from));
1837 CHECK(to->findInt32(kKeyColorFormat, &colorFormat_to));
1838
1839 if (colorFormat_from != colorFormat_to) {
1840 return true;
1841 }
1842
1843 int32_t width_from, width_to;
1844 CHECK(from->findInt32(kKeyWidth, &width_from));
1845 CHECK(to->findInt32(kKeyWidth, &width_to));
1846
1847 if (width_from != width_to) {
1848 return true;
1849 }
1850
1851 int32_t height_from, height_to;
1852 CHECK(from->findInt32(kKeyHeight, &height_from));
1853 CHECK(to->findInt32(kKeyHeight, &height_to));
1854
1855 if (height_from != height_to) {
1856 return true;
1857 }
1858 } else if (!strcasecmp(mime_from, MEDIA_MIMETYPE_AUDIO_RAW)) {
1859 int32_t numChannels_from, numChannels_to;
1860 CHECK(from->findInt32(kKeyChannelCount, &numChannels_from));
1861 CHECK(to->findInt32(kKeyChannelCount, &numChannels_to));
1862
1863 if (numChannels_from != numChannels_to) {
1864 return true;
1865 }
1866
1867 int32_t sampleRate_from, sampleRate_to;
1868 CHECK(from->findInt32(kKeySampleRate, &sampleRate_from));
1869 CHECK(to->findInt32(kKeySampleRate, &sampleRate_to));
1870
1871 if (sampleRate_from != sampleRate_to) {
1872 return true;
1873 }
1874 }
1875
1876 return false;
1877}
1878
Andreas Huberbe06d262009-08-14 14:37:10 -07001879void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
1880 switch (cmd) {
1881 case OMX_CommandStateSet:
1882 {
1883 onStateChange((OMX_STATETYPE)data);
1884 break;
1885 }
1886
1887 case OMX_CommandPortDisable:
1888 {
1889 OMX_U32 portIndex = data;
Andreas Huber4c483422009-09-02 16:05:36 -07001890 CODEC_LOGV("PORT_DISABLED(%ld)", portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07001891
1892 CHECK(mState == EXECUTING || mState == RECONFIGURING);
1893 CHECK_EQ(mPortStatus[portIndex], DISABLING);
1894 CHECK_EQ(mPortBuffers[portIndex].size(), 0);
1895
1896 mPortStatus[portIndex] = DISABLED;
1897
1898 if (mState == RECONFIGURING) {
1899 CHECK_EQ(portIndex, kPortIndexOutput);
1900
Andreas Huberb1678602009-10-19 13:06:40 -07001901 sp<MetaData> oldOutputFormat = mOutputFormat;
Andreas Hubercfd55572009-10-09 14:11:28 -07001902 initOutputFormat(mSource->getFormat());
Andreas Huberb1678602009-10-19 13:06:40 -07001903
1904 // Don't notify clients if the output port settings change
1905 // wasn't of importance to them, i.e. it may be that just the
1906 // number of buffers has changed and nothing else.
1907 mOutputPortSettingsHaveChanged =
1908 formatHasNotablyChanged(oldOutputFormat, mOutputFormat);
Andreas Hubercfd55572009-10-09 14:11:28 -07001909
Andreas Huberbe06d262009-08-14 14:37:10 -07001910 enablePortAsync(portIndex);
1911
1912 status_t err = allocateBuffersOnPort(portIndex);
1913 CHECK_EQ(err, OK);
1914 }
1915 break;
1916 }
1917
1918 case OMX_CommandPortEnable:
1919 {
1920 OMX_U32 portIndex = data;
Andreas Huber4c483422009-09-02 16:05:36 -07001921 CODEC_LOGV("PORT_ENABLED(%ld)", portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07001922
1923 CHECK(mState == EXECUTING || mState == RECONFIGURING);
1924 CHECK_EQ(mPortStatus[portIndex], ENABLING);
1925
1926 mPortStatus[portIndex] = ENABLED;
1927
1928 if (mState == RECONFIGURING) {
1929 CHECK_EQ(portIndex, kPortIndexOutput);
1930
1931 setState(EXECUTING);
1932
1933 fillOutputBuffers();
1934 }
1935 break;
1936 }
1937
1938 case OMX_CommandFlush:
1939 {
1940 OMX_U32 portIndex = data;
1941
Andreas Huber4c483422009-09-02 16:05:36 -07001942 CODEC_LOGV("FLUSH_DONE(%ld)", portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07001943
1944 CHECK_EQ(mPortStatus[portIndex], SHUTTING_DOWN);
1945 mPortStatus[portIndex] = ENABLED;
1946
1947 CHECK_EQ(countBuffersWeOwn(mPortBuffers[portIndex]),
1948 mPortBuffers[portIndex].size());
1949
1950 if (mState == RECONFIGURING) {
1951 CHECK_EQ(portIndex, kPortIndexOutput);
1952
1953 disablePortAsync(portIndex);
Andreas Huber127fcdc2009-08-26 16:27:02 -07001954 } else if (mState == EXECUTING_TO_IDLE) {
1955 if (mPortStatus[kPortIndexInput] == ENABLED
1956 && mPortStatus[kPortIndexOutput] == ENABLED) {
Andreas Huber4c483422009-09-02 16:05:36 -07001957 CODEC_LOGV("Finished flushing both ports, now completing "
Andreas Huber127fcdc2009-08-26 16:27:02 -07001958 "transition from EXECUTING to IDLE.");
1959
1960 mPortStatus[kPortIndexInput] = SHUTTING_DOWN;
1961 mPortStatus[kPortIndexOutput] = SHUTTING_DOWN;
1962
1963 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07001964 mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
Andreas Huber127fcdc2009-08-26 16:27:02 -07001965 CHECK_EQ(err, OK);
1966 }
Andreas Huberbe06d262009-08-14 14:37:10 -07001967 } else {
1968 // We're flushing both ports in preparation for seeking.
1969
1970 if (mPortStatus[kPortIndexInput] == ENABLED
1971 && mPortStatus[kPortIndexOutput] == ENABLED) {
Andreas Huber4c483422009-09-02 16:05:36 -07001972 CODEC_LOGV("Finished flushing both ports, now continuing from"
Andreas Huberbe06d262009-08-14 14:37:10 -07001973 " seek-time.");
1974
Andreas Huber1f24b302010-06-10 11:12:39 -07001975 // We implicitly resume pulling on our upstream source.
1976 mPaused = false;
1977
Andreas Huberbe06d262009-08-14 14:37:10 -07001978 drainInputBuffers();
1979 fillOutputBuffers();
1980 }
1981 }
1982
1983 break;
1984 }
1985
1986 default:
1987 {
Andreas Huber4c483422009-09-02 16:05:36 -07001988 CODEC_LOGV("CMD_COMPLETE(%d, %ld)", cmd, data);
Andreas Huberbe06d262009-08-14 14:37:10 -07001989 break;
1990 }
1991 }
1992}
1993
1994void OMXCodec::onStateChange(OMX_STATETYPE newState) {
Andreas Huberc712b9f2010-01-20 15:05:46 -08001995 CODEC_LOGV("onStateChange %d", newState);
1996
Andreas Huberbe06d262009-08-14 14:37:10 -07001997 switch (newState) {
1998 case OMX_StateIdle:
1999 {
Andreas Huber4c483422009-09-02 16:05:36 -07002000 CODEC_LOGV("Now Idle.");
Andreas Huberbe06d262009-08-14 14:37:10 -07002001 if (mState == LOADED_TO_IDLE) {
Andreas Huber784202e2009-10-15 13:46:54 -07002002 status_t err = mOMX->sendCommand(
Andreas Huberbe06d262009-08-14 14:37:10 -07002003 mNode, OMX_CommandStateSet, OMX_StateExecuting);
2004
2005 CHECK_EQ(err, OK);
2006
2007 setState(IDLE_TO_EXECUTING);
2008 } else {
2009 CHECK_EQ(mState, EXECUTING_TO_IDLE);
2010
2011 CHECK_EQ(
2012 countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
2013 mPortBuffers[kPortIndexInput].size());
2014
2015 CHECK_EQ(
2016 countBuffersWeOwn(mPortBuffers[kPortIndexOutput]),
2017 mPortBuffers[kPortIndexOutput].size());
2018
Andreas Huber784202e2009-10-15 13:46:54 -07002019 status_t err = mOMX->sendCommand(
Andreas Huberbe06d262009-08-14 14:37:10 -07002020 mNode, OMX_CommandStateSet, OMX_StateLoaded);
2021
2022 CHECK_EQ(err, OK);
2023
2024 err = freeBuffersOnPort(kPortIndexInput);
2025 CHECK_EQ(err, OK);
2026
2027 err = freeBuffersOnPort(kPortIndexOutput);
2028 CHECK_EQ(err, OK);
2029
2030 mPortStatus[kPortIndexInput] = ENABLED;
2031 mPortStatus[kPortIndexOutput] = ENABLED;
2032
2033 setState(IDLE_TO_LOADED);
2034 }
2035 break;
2036 }
2037
2038 case OMX_StateExecuting:
2039 {
2040 CHECK_EQ(mState, IDLE_TO_EXECUTING);
2041
Andreas Huber4c483422009-09-02 16:05:36 -07002042 CODEC_LOGV("Now Executing.");
Andreas Huberbe06d262009-08-14 14:37:10 -07002043
2044 setState(EXECUTING);
2045
Andreas Huber42978e52009-08-27 10:08:39 -07002046 // Buffers will be submitted to the component in the first
2047 // call to OMXCodec::read as mInitialBufferSubmit is true at
2048 // this point. This ensures that this on_message call returns,
2049 // releases the lock and ::init can notice the state change and
2050 // itself return.
Andreas Huberbe06d262009-08-14 14:37:10 -07002051 break;
2052 }
2053
2054 case OMX_StateLoaded:
2055 {
2056 CHECK_EQ(mState, IDLE_TO_LOADED);
2057
Andreas Huber4c483422009-09-02 16:05:36 -07002058 CODEC_LOGV("Now Loaded.");
Andreas Huberbe06d262009-08-14 14:37:10 -07002059
2060 setState(LOADED);
2061 break;
2062 }
2063
Andreas Huberc712b9f2010-01-20 15:05:46 -08002064 case OMX_StateInvalid:
2065 {
2066 setState(ERROR);
2067 break;
2068 }
2069
Andreas Huberbe06d262009-08-14 14:37:10 -07002070 default:
2071 {
2072 CHECK(!"should not be here.");
2073 break;
2074 }
2075 }
2076}
2077
2078// static
2079size_t OMXCodec::countBuffersWeOwn(const Vector<BufferInfo> &buffers) {
2080 size_t n = 0;
2081 for (size_t i = 0; i < buffers.size(); ++i) {
2082 if (!buffers[i].mOwnedByComponent) {
2083 ++n;
2084 }
2085 }
2086
2087 return n;
2088}
2089
2090status_t OMXCodec::freeBuffersOnPort(
2091 OMX_U32 portIndex, bool onlyThoseWeOwn) {
2092 Vector<BufferInfo> *buffers = &mPortBuffers[portIndex];
2093
2094 status_t stickyErr = OK;
2095
2096 for (size_t i = buffers->size(); i-- > 0;) {
2097 BufferInfo *info = &buffers->editItemAt(i);
2098
2099 if (onlyThoseWeOwn && info->mOwnedByComponent) {
2100 continue;
2101 }
2102
2103 CHECK_EQ(info->mOwnedByComponent, false);
2104
Andreas Huber92022852009-09-14 15:24:14 -07002105 CODEC_LOGV("freeing buffer %p on port %ld", info->mBuffer, portIndex);
2106
Andreas Huberbe06d262009-08-14 14:37:10 -07002107 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07002108 mOMX->freeBuffer(mNode, portIndex, info->mBuffer);
Andreas Huberbe06d262009-08-14 14:37:10 -07002109
2110 if (err != OK) {
2111 stickyErr = err;
2112 }
2113
2114 if (info->mMediaBuffer != NULL) {
2115 info->mMediaBuffer->setObserver(NULL);
2116
2117 // Make sure nobody but us owns this buffer at this point.
2118 CHECK_EQ(info->mMediaBuffer->refcount(), 0);
2119
2120 info->mMediaBuffer->release();
2121 }
2122
2123 buffers->removeAt(i);
2124 }
2125
2126 CHECK(onlyThoseWeOwn || buffers->isEmpty());
2127
2128 return stickyErr;
2129}
2130
2131void OMXCodec::onPortSettingsChanged(OMX_U32 portIndex) {
Andreas Huber4c483422009-09-02 16:05:36 -07002132 CODEC_LOGV("PORT_SETTINGS_CHANGED(%ld)", portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07002133
2134 CHECK_EQ(mState, EXECUTING);
2135 CHECK_EQ(portIndex, kPortIndexOutput);
2136 setState(RECONFIGURING);
2137
2138 if (mQuirks & kNeedsFlushBeforeDisable) {
Andreas Huber404cc412009-08-25 14:26:05 -07002139 if (!flushPortAsync(portIndex)) {
2140 onCmdComplete(OMX_CommandFlush, portIndex);
2141 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002142 } else {
2143 disablePortAsync(portIndex);
2144 }
2145}
2146
Andreas Huber404cc412009-08-25 14:26:05 -07002147bool OMXCodec::flushPortAsync(OMX_U32 portIndex) {
Andreas Huber127fcdc2009-08-26 16:27:02 -07002148 CHECK(mState == EXECUTING || mState == RECONFIGURING
2149 || mState == EXECUTING_TO_IDLE);
Andreas Huberbe06d262009-08-14 14:37:10 -07002150
Andreas Huber4c483422009-09-02 16:05:36 -07002151 CODEC_LOGV("flushPortAsync(%ld): we own %d out of %d buffers already.",
Andreas Huber404cc412009-08-25 14:26:05 -07002152 portIndex, countBuffersWeOwn(mPortBuffers[portIndex]),
2153 mPortBuffers[portIndex].size());
2154
Andreas Huberbe06d262009-08-14 14:37:10 -07002155 CHECK_EQ(mPortStatus[portIndex], ENABLED);
2156 mPortStatus[portIndex] = SHUTTING_DOWN;
2157
Andreas Huber404cc412009-08-25 14:26:05 -07002158 if ((mQuirks & kRequiresFlushCompleteEmulation)
2159 && countBuffersWeOwn(mPortBuffers[portIndex])
2160 == mPortBuffers[portIndex].size()) {
2161 // No flush is necessary and this component fails to send a
2162 // flush-complete event in this case.
2163
2164 return false;
2165 }
2166
Andreas Huberbe06d262009-08-14 14:37:10 -07002167 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07002168 mOMX->sendCommand(mNode, OMX_CommandFlush, portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07002169 CHECK_EQ(err, OK);
Andreas Huber404cc412009-08-25 14:26:05 -07002170
2171 return true;
Andreas Huberbe06d262009-08-14 14:37:10 -07002172}
2173
2174void OMXCodec::disablePortAsync(OMX_U32 portIndex) {
2175 CHECK(mState == EXECUTING || mState == RECONFIGURING);
2176
2177 CHECK_EQ(mPortStatus[portIndex], ENABLED);
2178 mPortStatus[portIndex] = DISABLING;
2179
2180 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07002181 mOMX->sendCommand(mNode, OMX_CommandPortDisable, portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07002182 CHECK_EQ(err, OK);
2183
2184 freeBuffersOnPort(portIndex, true);
2185}
2186
2187void OMXCodec::enablePortAsync(OMX_U32 portIndex) {
2188 CHECK(mState == EXECUTING || mState == RECONFIGURING);
2189
2190 CHECK_EQ(mPortStatus[portIndex], DISABLED);
2191 mPortStatus[portIndex] = ENABLING;
2192
2193 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07002194 mOMX->sendCommand(mNode, OMX_CommandPortEnable, portIndex);
Andreas Huberbe06d262009-08-14 14:37:10 -07002195 CHECK_EQ(err, OK);
2196}
2197
2198void OMXCodec::fillOutputBuffers() {
2199 CHECK_EQ(mState, EXECUTING);
2200
Andreas Huberdbcb2c62010-01-14 11:32:13 -08002201 // This is a workaround for some decoders not properly reporting
2202 // end-of-output-stream. If we own all input buffers and also own
2203 // all output buffers and we already signalled end-of-input-stream,
2204 // the end-of-output-stream is implied.
2205 if (mSignalledEOS
2206 && countBuffersWeOwn(mPortBuffers[kPortIndexInput])
2207 == mPortBuffers[kPortIndexInput].size()
2208 && countBuffersWeOwn(mPortBuffers[kPortIndexOutput])
2209 == mPortBuffers[kPortIndexOutput].size()) {
2210 mNoMoreOutputData = true;
2211 mBufferFilled.signal();
2212
2213 return;
2214 }
2215
Andreas Huberbe06d262009-08-14 14:37:10 -07002216 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexOutput];
2217 for (size_t i = 0; i < buffers->size(); ++i) {
2218 fillOutputBuffer(&buffers->editItemAt(i));
2219 }
2220}
2221
2222void OMXCodec::drainInputBuffers() {
Andreas Huberd06e5b82009-08-28 13:18:14 -07002223 CHECK(mState == EXECUTING || mState == RECONFIGURING);
Andreas Huberbe06d262009-08-14 14:37:10 -07002224
2225 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexInput];
2226 for (size_t i = 0; i < buffers->size(); ++i) {
2227 drainInputBuffer(&buffers->editItemAt(i));
2228 }
2229}
2230
2231void OMXCodec::drainInputBuffer(BufferInfo *info) {
2232 CHECK_EQ(info->mOwnedByComponent, false);
2233
2234 if (mSignalledEOS) {
2235 return;
2236 }
2237
2238 if (mCodecSpecificDataIndex < mCodecSpecificData.size()) {
2239 const CodecSpecificData *specific =
2240 mCodecSpecificData[mCodecSpecificDataIndex];
2241
2242 size_t size = specific->mSize;
2243
Andreas Hubere6c40962009-09-10 14:13:30 -07002244 if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mMIME)
Andreas Huber4f5e6022009-08-19 09:29:34 -07002245 && !(mQuirks & kWantsNALFragments)) {
Andreas Huberbe06d262009-08-14 14:37:10 -07002246 static const uint8_t kNALStartCode[4] =
2247 { 0x00, 0x00, 0x00, 0x01 };
2248
Andreas Huberc712b9f2010-01-20 15:05:46 -08002249 CHECK(info->mSize >= specific->mSize + 4);
Andreas Huberbe06d262009-08-14 14:37:10 -07002250
2251 size += 4;
2252
Andreas Huberc712b9f2010-01-20 15:05:46 -08002253 memcpy(info->mData, kNALStartCode, 4);
2254 memcpy((uint8_t *)info->mData + 4,
Andreas Huberbe06d262009-08-14 14:37:10 -07002255 specific->mData, specific->mSize);
2256 } else {
Andreas Huberc712b9f2010-01-20 15:05:46 -08002257 CHECK(info->mSize >= specific->mSize);
2258 memcpy(info->mData, specific->mData, specific->mSize);
Andreas Huberbe06d262009-08-14 14:37:10 -07002259 }
2260
Andreas Huber2ea14e22009-12-16 09:30:55 -08002261 mNoMoreOutputData = false;
2262
Andreas Huberdbcb2c62010-01-14 11:32:13 -08002263 CODEC_LOGV("calling emptyBuffer with codec specific data");
2264
Andreas Huber784202e2009-10-15 13:46:54 -07002265 status_t err = mOMX->emptyBuffer(
Andreas Huberbe06d262009-08-14 14:37:10 -07002266 mNode, info->mBuffer, 0, size,
2267 OMX_BUFFERFLAG_ENDOFFRAME | OMX_BUFFERFLAG_CODECCONFIG,
2268 0);
Andreas Huber3f427072009-10-08 11:02:27 -07002269 CHECK_EQ(err, OK);
Andreas Huberbe06d262009-08-14 14:37:10 -07002270
2271 info->mOwnedByComponent = true;
2272
2273 ++mCodecSpecificDataIndex;
2274 return;
2275 }
2276
Andreas Huber1f24b302010-06-10 11:12:39 -07002277 if (mPaused) {
2278 return;
2279 }
2280
Andreas Huberbe06d262009-08-14 14:37:10 -07002281 status_t err;
Andreas Huber2ea14e22009-12-16 09:30:55 -08002282
Andreas Hubera4357ad2010-04-02 12:49:54 -07002283 bool signalEOS = false;
2284 int64_t timestampUs = 0;
Andreas Huberbe06d262009-08-14 14:37:10 -07002285
Andreas Hubera4357ad2010-04-02 12:49:54 -07002286 size_t offset = 0;
2287 int32_t n = 0;
2288 for (;;) {
2289 MediaBuffer *srcBuffer;
James Dong53d4e0d2010-07-21 14:51:35 -07002290 MediaSource::ReadOptions options;
2291 if (mSkipTimeUs >= 0) {
2292 options.setSkipFrame(mSkipTimeUs);
2293 }
Andreas Hubera4357ad2010-04-02 12:49:54 -07002294 if (mSeekTimeUs >= 0) {
2295 if (mLeftOverBuffer) {
2296 mLeftOverBuffer->release();
2297 mLeftOverBuffer = NULL;
2298 }
Andreas Huber6624c9f2010-07-20 15:04:28 -07002299 options.setSeekTo(mSeekTimeUs, mSeekMode);
Andreas Hubera4357ad2010-04-02 12:49:54 -07002300
2301 mSeekTimeUs = -1;
Andreas Huber6624c9f2010-07-20 15:04:28 -07002302 mSeekMode = ReadOptions::SEEK_CLOSEST_SYNC;
Andreas Hubera4357ad2010-04-02 12:49:54 -07002303 mBufferFilled.signal();
2304
2305 err = mSource->read(&srcBuffer, &options);
Andreas Huber6624c9f2010-07-20 15:04:28 -07002306
2307 if (err == OK) {
2308 int64_t targetTimeUs;
2309 if (srcBuffer->meta_data()->findInt64(
2310 kKeyTargetTime, &targetTimeUs)
2311 && targetTimeUs >= 0) {
2312 mTargetTimeUs = targetTimeUs;
2313 } else {
2314 mTargetTimeUs = -1;
2315 }
2316 }
Andreas Hubera4357ad2010-04-02 12:49:54 -07002317 } else if (mLeftOverBuffer) {
2318 srcBuffer = mLeftOverBuffer;
2319 mLeftOverBuffer = NULL;
2320
2321 err = OK;
2322 } else {
James Dong53d4e0d2010-07-21 14:51:35 -07002323 err = mSource->read(&srcBuffer, &options);
Andreas Hubera4357ad2010-04-02 12:49:54 -07002324 }
2325
2326 if (err != OK) {
2327 signalEOS = true;
2328 mFinalStatus = err;
2329 mSignalledEOS = true;
2330 break;
2331 }
2332
2333 size_t remainingBytes = info->mSize - offset;
2334
2335 if (srcBuffer->range_length() > remainingBytes) {
2336 if (offset == 0) {
2337 CODEC_LOGE(
2338 "Codec's input buffers are too small to accomodate "
2339 "buffer read from source (info->mSize = %d, srcLength = %d)",
2340 info->mSize, srcBuffer->range_length());
2341
2342 srcBuffer->release();
2343 srcBuffer = NULL;
2344
2345 setState(ERROR);
2346 return;
2347 }
2348
2349 mLeftOverBuffer = srcBuffer;
2350 break;
2351 }
2352
James Dong4f501f02010-06-07 14:41:41 -07002353 if (mIsEncoder && (mQuirks & kAvoidMemcopyInputRecordingFrames)) {
2354 CHECK(mOMXLivesLocally && offset == 0);
2355 OMX_BUFFERHEADERTYPE *header = (OMX_BUFFERHEADERTYPE *) info->mBuffer;
2356 header->pBuffer = (OMX_U8 *) srcBuffer->data() + srcBuffer->range_offset();
2357 } else {
2358 memcpy((uint8_t *)info->mData + offset,
2359 (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(),
2360 srcBuffer->range_length());
2361 }
Andreas Hubera4357ad2010-04-02 12:49:54 -07002362
Andreas Huber2dd8ff82010-04-20 14:26:00 -07002363 int64_t lastBufferTimeUs;
2364 CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs));
Andreas Huber6624c9f2010-07-20 15:04:28 -07002365 CHECK(lastBufferTimeUs >= 0);
Andreas Huber2dd8ff82010-04-20 14:26:00 -07002366
Andreas Hubera4357ad2010-04-02 12:49:54 -07002367 if (offset == 0) {
Andreas Huber2dd8ff82010-04-20 14:26:00 -07002368 timestampUs = lastBufferTimeUs;
Andreas Hubera4357ad2010-04-02 12:49:54 -07002369 }
2370
2371 offset += srcBuffer->range_length();
2372
2373 srcBuffer->release();
2374 srcBuffer = NULL;
2375
2376 ++n;
2377
2378 if (!(mQuirks & kSupportsMultipleFramesPerInputBuffer)) {
2379 break;
2380 }
Andreas Huber2dd8ff82010-04-20 14:26:00 -07002381
2382 int64_t coalescedDurationUs = lastBufferTimeUs - timestampUs;
2383
2384 if (coalescedDurationUs > 250000ll) {
2385 // Don't coalesce more than 250ms worth of encoded data at once.
2386 break;
2387 }
Andreas Hubera4357ad2010-04-02 12:49:54 -07002388 }
2389
2390 if (n > 1) {
2391 LOGV("coalesced %d frames into one input buffer", n);
Andreas Huberbe06d262009-08-14 14:37:10 -07002392 }
2393
2394 OMX_U32 flags = OMX_BUFFERFLAG_ENDOFFRAME;
Andreas Huberbe06d262009-08-14 14:37:10 -07002395
Andreas Hubera4357ad2010-04-02 12:49:54 -07002396 if (signalEOS) {
Andreas Huberbe06d262009-08-14 14:37:10 -07002397 flags |= OMX_BUFFERFLAG_EOS;
Andreas Huberbe06d262009-08-14 14:37:10 -07002398 } else {
Andreas Huber2ea14e22009-12-16 09:30:55 -08002399 mNoMoreOutputData = false;
Andreas Huberbe06d262009-08-14 14:37:10 -07002400 }
2401
Andreas Hubera4357ad2010-04-02 12:49:54 -07002402 CODEC_LOGV("Calling emptyBuffer on buffer %p (length %d), "
2403 "timestamp %lld us (%.2f secs)",
2404 info->mBuffer, offset,
2405 timestampUs, timestampUs / 1E6);
Andreas Huber3f427072009-10-08 11:02:27 -07002406
Andreas Huber784202e2009-10-15 13:46:54 -07002407 err = mOMX->emptyBuffer(
Andreas Hubera4357ad2010-04-02 12:49:54 -07002408 mNode, info->mBuffer, 0, offset,
Andreas Huberfa8de752009-10-08 10:07:49 -07002409 flags, timestampUs);
Andreas Huber3f427072009-10-08 11:02:27 -07002410
2411 if (err != OK) {
2412 setState(ERROR);
2413 return;
2414 }
2415
2416 info->mOwnedByComponent = true;
Andreas Huberea6a38c2009-11-16 15:43:38 -08002417
2418 // This component does not ever signal the EOS flag on output buffers,
2419 // Thanks for nothing.
2420 if (mSignalledEOS && !strcmp(mComponentName, "OMX.TI.Video.encoder")) {
2421 mNoMoreOutputData = true;
2422 mBufferFilled.signal();
2423 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002424}
2425
2426void OMXCodec::fillOutputBuffer(BufferInfo *info) {
2427 CHECK_EQ(info->mOwnedByComponent, false);
2428
Andreas Huber404cc412009-08-25 14:26:05 -07002429 if (mNoMoreOutputData) {
Andreas Huber4c483422009-09-02 16:05:36 -07002430 CODEC_LOGV("There is no more output data available, not "
Andreas Huber404cc412009-08-25 14:26:05 -07002431 "calling fillOutputBuffer");
2432 return;
2433 }
2434
Andreas Huber4c483422009-09-02 16:05:36 -07002435 CODEC_LOGV("Calling fill_buffer on buffer %p", info->mBuffer);
Andreas Huber784202e2009-10-15 13:46:54 -07002436 status_t err = mOMX->fillBuffer(mNode, info->mBuffer);
Andreas Huber8f14c552010-04-12 10:20:12 -07002437
2438 if (err != OK) {
2439 CODEC_LOGE("fillBuffer failed w/ error 0x%08x", err);
2440
2441 setState(ERROR);
2442 return;
2443 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002444
2445 info->mOwnedByComponent = true;
2446}
2447
2448void OMXCodec::drainInputBuffer(IOMX::buffer_id buffer) {
2449 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexInput];
2450 for (size_t i = 0; i < buffers->size(); ++i) {
2451 if ((*buffers)[i].mBuffer == buffer) {
2452 drainInputBuffer(&buffers->editItemAt(i));
2453 return;
2454 }
2455 }
2456
2457 CHECK(!"should not be here.");
2458}
2459
2460void OMXCodec::fillOutputBuffer(IOMX::buffer_id buffer) {
2461 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexOutput];
2462 for (size_t i = 0; i < buffers->size(); ++i) {
2463 if ((*buffers)[i].mBuffer == buffer) {
2464 fillOutputBuffer(&buffers->editItemAt(i));
2465 return;
2466 }
2467 }
2468
2469 CHECK(!"should not be here.");
2470}
2471
2472void OMXCodec::setState(State newState) {
2473 mState = newState;
2474 mAsyncCompletion.signal();
2475
2476 // This may cause some spurious wakeups but is necessary to
2477 // unblock the reader if we enter ERROR state.
2478 mBufferFilled.signal();
2479}
2480
Andreas Huberda050cf22009-09-02 14:01:43 -07002481void OMXCodec::setRawAudioFormat(
2482 OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {
James Dongabed93a2010-04-22 17:27:04 -07002483
2484 // port definition
2485 OMX_PARAM_PORTDEFINITIONTYPE def;
2486 InitOMXParams(&def);
2487 def.nPortIndex = portIndex;
2488 status_t err = mOMX->getParameter(
2489 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
2490 CHECK_EQ(err, OK);
2491 def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
2492 CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamPortDefinition,
2493 &def, sizeof(def)), OK);
2494
2495 // pcm param
Andreas Huberda050cf22009-09-02 14:01:43 -07002496 OMX_AUDIO_PARAM_PCMMODETYPE pcmParams;
Andreas Huber4c483422009-09-02 16:05:36 -07002497 InitOMXParams(&pcmParams);
Andreas Huberda050cf22009-09-02 14:01:43 -07002498 pcmParams.nPortIndex = portIndex;
2499
James Dongabed93a2010-04-22 17:27:04 -07002500 err = mOMX->getParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -07002501 mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
2502
2503 CHECK_EQ(err, OK);
2504
2505 pcmParams.nChannels = numChannels;
2506 pcmParams.eNumData = OMX_NumericalDataSigned;
2507 pcmParams.bInterleaved = OMX_TRUE;
2508 pcmParams.nBitPerSample = 16;
2509 pcmParams.nSamplingRate = sampleRate;
2510 pcmParams.ePCMMode = OMX_AUDIO_PCMModeLinear;
2511
2512 if (numChannels == 1) {
2513 pcmParams.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
2514 } else {
2515 CHECK_EQ(numChannels, 2);
2516
2517 pcmParams.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
2518 pcmParams.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
2519 }
2520
Andreas Huber784202e2009-10-15 13:46:54 -07002521 err = mOMX->setParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -07002522 mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
2523
2524 CHECK_EQ(err, OK);
2525}
2526
James Dong17299ab2010-05-14 15:45:22 -07002527static OMX_AUDIO_AMRBANDMODETYPE pickModeFromBitRate(bool isAMRWB, int32_t bps) {
2528 if (isAMRWB) {
2529 if (bps <= 6600) {
2530 return OMX_AUDIO_AMRBandModeWB0;
2531 } else if (bps <= 8850) {
2532 return OMX_AUDIO_AMRBandModeWB1;
2533 } else if (bps <= 12650) {
2534 return OMX_AUDIO_AMRBandModeWB2;
2535 } else if (bps <= 14250) {
2536 return OMX_AUDIO_AMRBandModeWB3;
2537 } else if (bps <= 15850) {
2538 return OMX_AUDIO_AMRBandModeWB4;
2539 } else if (bps <= 18250) {
2540 return OMX_AUDIO_AMRBandModeWB5;
2541 } else if (bps <= 19850) {
2542 return OMX_AUDIO_AMRBandModeWB6;
2543 } else if (bps <= 23050) {
2544 return OMX_AUDIO_AMRBandModeWB7;
2545 }
2546
2547 // 23850 bps
2548 return OMX_AUDIO_AMRBandModeWB8;
2549 } else { // AMRNB
2550 if (bps <= 4750) {
2551 return OMX_AUDIO_AMRBandModeNB0;
2552 } else if (bps <= 5150) {
2553 return OMX_AUDIO_AMRBandModeNB1;
2554 } else if (bps <= 5900) {
2555 return OMX_AUDIO_AMRBandModeNB2;
2556 } else if (bps <= 6700) {
2557 return OMX_AUDIO_AMRBandModeNB3;
2558 } else if (bps <= 7400) {
2559 return OMX_AUDIO_AMRBandModeNB4;
2560 } else if (bps <= 7950) {
2561 return OMX_AUDIO_AMRBandModeNB5;
2562 } else if (bps <= 10200) {
2563 return OMX_AUDIO_AMRBandModeNB6;
2564 }
2565
2566 // 12200 bps
2567 return OMX_AUDIO_AMRBandModeNB7;
2568 }
2569}
2570
2571void OMXCodec::setAMRFormat(bool isWAMR, int32_t bitRate) {
Andreas Huber8768f2c2009-12-01 15:26:54 -08002572 OMX_U32 portIndex = mIsEncoder ? kPortIndexOutput : kPortIndexInput;
Andreas Huberbe06d262009-08-14 14:37:10 -07002573
Andreas Huber8768f2c2009-12-01 15:26:54 -08002574 OMX_AUDIO_PARAM_AMRTYPE def;
2575 InitOMXParams(&def);
2576 def.nPortIndex = portIndex;
Andreas Huberbe06d262009-08-14 14:37:10 -07002577
Andreas Huber8768f2c2009-12-01 15:26:54 -08002578 status_t err =
2579 mOMX->getParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
Andreas Huberbe06d262009-08-14 14:37:10 -07002580
Andreas Huber8768f2c2009-12-01 15:26:54 -08002581 CHECK_EQ(err, OK);
Andreas Huberbe06d262009-08-14 14:37:10 -07002582
Andreas Huber8768f2c2009-12-01 15:26:54 -08002583 def.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
James Dongabed93a2010-04-22 17:27:04 -07002584
James Dong17299ab2010-05-14 15:45:22 -07002585 def.eAMRBandMode = pickModeFromBitRate(isWAMR, bitRate);
Andreas Huber8768f2c2009-12-01 15:26:54 -08002586 err = mOMX->setParameter(mNode, OMX_IndexParamAudioAmr, &def, sizeof(def));
2587 CHECK_EQ(err, OK);
Andreas Huberee606e62009-09-08 10:19:21 -07002588
2589 ////////////////////////
2590
2591 if (mIsEncoder) {
2592 sp<MetaData> format = mSource->getFormat();
2593 int32_t sampleRate;
2594 int32_t numChannels;
2595 CHECK(format->findInt32(kKeySampleRate, &sampleRate));
2596 CHECK(format->findInt32(kKeyChannelCount, &numChannels));
2597
2598 setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
2599 }
2600}
2601
James Dong17299ab2010-05-14 15:45:22 -07002602void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bitRate) {
James Dongabed93a2010-04-22 17:27:04 -07002603 CHECK(numChannels == 1 || numChannels == 2);
Andreas Huberda050cf22009-09-02 14:01:43 -07002604 if (mIsEncoder) {
James Dongabed93a2010-04-22 17:27:04 -07002605 //////////////// input port ////////////////////
Andreas Huberda050cf22009-09-02 14:01:43 -07002606 setRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
James Dongabed93a2010-04-22 17:27:04 -07002607
2608 //////////////// output port ////////////////////
2609 // format
2610 OMX_AUDIO_PARAM_PORTFORMATTYPE format;
2611 format.nPortIndex = kPortIndexOutput;
2612 format.nIndex = 0;
2613 status_t err = OMX_ErrorNone;
2614 while (OMX_ErrorNone == err) {
2615 CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamAudioPortFormat,
2616 &format, sizeof(format)), OK);
2617 if (format.eEncoding == OMX_AUDIO_CodingAAC) {
2618 break;
2619 }
2620 format.nIndex++;
2621 }
2622 CHECK_EQ(OK, err);
2623 CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamAudioPortFormat,
2624 &format, sizeof(format)), OK);
2625
2626 // port definition
2627 OMX_PARAM_PORTDEFINITIONTYPE def;
2628 InitOMXParams(&def);
2629 def.nPortIndex = kPortIndexOutput;
2630 CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamPortDefinition,
2631 &def, sizeof(def)), OK);
2632 def.format.audio.bFlagErrorConcealment = OMX_TRUE;
2633 def.format.audio.eEncoding = OMX_AUDIO_CodingAAC;
2634 CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamPortDefinition,
2635 &def, sizeof(def)), OK);
2636
2637 // profile
2638 OMX_AUDIO_PARAM_AACPROFILETYPE profile;
2639 InitOMXParams(&profile);
2640 profile.nPortIndex = kPortIndexOutput;
2641 CHECK_EQ(mOMX->getParameter(mNode, OMX_IndexParamAudioAac,
2642 &profile, sizeof(profile)), OK);
2643 profile.nChannels = numChannels;
2644 profile.eChannelMode = (numChannels == 1?
2645 OMX_AUDIO_ChannelModeMono: OMX_AUDIO_ChannelModeStereo);
2646 profile.nSampleRate = sampleRate;
James Dong17299ab2010-05-14 15:45:22 -07002647 profile.nBitRate = bitRate;
James Dongabed93a2010-04-22 17:27:04 -07002648 profile.nAudioBandWidth = 0;
2649 profile.nFrameLength = 0;
2650 profile.nAACtools = OMX_AUDIO_AACToolAll;
2651 profile.nAACERtools = OMX_AUDIO_AACERNone;
2652 profile.eAACProfile = OMX_AUDIO_AACObjectLC;
2653 profile.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
2654 CHECK_EQ(mOMX->setParameter(mNode, OMX_IndexParamAudioAac,
2655 &profile, sizeof(profile)), OK);
2656
Andreas Huberda050cf22009-09-02 14:01:43 -07002657 } else {
2658 OMX_AUDIO_PARAM_AACPROFILETYPE profile;
Andreas Huber4c483422009-09-02 16:05:36 -07002659 InitOMXParams(&profile);
Andreas Huberda050cf22009-09-02 14:01:43 -07002660 profile.nPortIndex = kPortIndexInput;
Andreas Huberbe06d262009-08-14 14:37:10 -07002661
Andreas Huber784202e2009-10-15 13:46:54 -07002662 status_t err = mOMX->getParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -07002663 mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile));
2664 CHECK_EQ(err, OK);
Andreas Huberbe06d262009-08-14 14:37:10 -07002665
Andreas Huberda050cf22009-09-02 14:01:43 -07002666 profile.nChannels = numChannels;
2667 profile.nSampleRate = sampleRate;
2668 profile.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4ADTS;
Andreas Huberbe06d262009-08-14 14:37:10 -07002669
Andreas Huber784202e2009-10-15 13:46:54 -07002670 err = mOMX->setParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -07002671 mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile));
2672 CHECK_EQ(err, OK);
2673 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002674}
2675
2676void OMXCodec::setImageOutputFormat(
2677 OMX_COLOR_FORMATTYPE format, OMX_U32 width, OMX_U32 height) {
Andreas Huber4c483422009-09-02 16:05:36 -07002678 CODEC_LOGV("setImageOutputFormat(%ld, %ld)", width, height);
Andreas Huberbe06d262009-08-14 14:37:10 -07002679
2680#if 0
2681 OMX_INDEXTYPE index;
2682 status_t err = mOMX->get_extension_index(
2683 mNode, "OMX.TI.JPEG.decode.Config.OutputColorFormat", &index);
2684 CHECK_EQ(err, OK);
2685
2686 err = mOMX->set_config(mNode, index, &format, sizeof(format));
2687 CHECK_EQ(err, OK);
2688#endif
2689
2690 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07002691 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07002692 def.nPortIndex = kPortIndexOutput;
2693
Andreas Huber784202e2009-10-15 13:46:54 -07002694 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07002695 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
2696 CHECK_EQ(err, OK);
2697
2698 CHECK_EQ(def.eDomain, OMX_PortDomainImage);
2699
2700 OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
Andreas Huberebf66ea2009-08-19 13:32:58 -07002701
Andreas Huberbe06d262009-08-14 14:37:10 -07002702 CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingUnused);
2703 imageDef->eColorFormat = format;
2704 imageDef->nFrameWidth = width;
2705 imageDef->nFrameHeight = height;
2706
2707 switch (format) {
2708 case OMX_COLOR_FormatYUV420PackedPlanar:
2709 case OMX_COLOR_FormatYUV411Planar:
2710 {
2711 def.nBufferSize = (width * height * 3) / 2;
2712 break;
2713 }
2714
2715 case OMX_COLOR_FormatCbYCrY:
2716 {
2717 def.nBufferSize = width * height * 2;
2718 break;
2719 }
2720
2721 case OMX_COLOR_Format32bitARGB8888:
2722 {
2723 def.nBufferSize = width * height * 4;
2724 break;
2725 }
2726
Andreas Huber201511c2009-09-08 14:01:44 -07002727 case OMX_COLOR_Format16bitARGB4444:
2728 case OMX_COLOR_Format16bitARGB1555:
2729 case OMX_COLOR_Format16bitRGB565:
2730 case OMX_COLOR_Format16bitBGR565:
2731 {
2732 def.nBufferSize = width * height * 2;
2733 break;
2734 }
2735
Andreas Huberbe06d262009-08-14 14:37:10 -07002736 default:
2737 CHECK(!"Should not be here. Unknown color format.");
2738 break;
2739 }
2740
Andreas Huber5c0a9132009-08-20 11:16:40 -07002741 def.nBufferCountActual = def.nBufferCountMin;
2742
Andreas Huber784202e2009-10-15 13:46:54 -07002743 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07002744 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
2745 CHECK_EQ(err, OK);
Andreas Huber5c0a9132009-08-20 11:16:40 -07002746}
Andreas Huberbe06d262009-08-14 14:37:10 -07002747
Andreas Huber5c0a9132009-08-20 11:16:40 -07002748void OMXCodec::setJPEGInputFormat(
2749 OMX_U32 width, OMX_U32 height, OMX_U32 compressedSize) {
2750 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07002751 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07002752 def.nPortIndex = kPortIndexInput;
2753
Andreas Huber784202e2009-10-15 13:46:54 -07002754 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07002755 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
2756 CHECK_EQ(err, OK);
2757
Andreas Huber5c0a9132009-08-20 11:16:40 -07002758 CHECK_EQ(def.eDomain, OMX_PortDomainImage);
2759 OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
2760
Andreas Huberbe06d262009-08-14 14:37:10 -07002761 CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingJPEG);
2762 imageDef->nFrameWidth = width;
2763 imageDef->nFrameHeight = height;
2764
Andreas Huber5c0a9132009-08-20 11:16:40 -07002765 def.nBufferSize = compressedSize;
Andreas Huberbe06d262009-08-14 14:37:10 -07002766 def.nBufferCountActual = def.nBufferCountMin;
2767
Andreas Huber784202e2009-10-15 13:46:54 -07002768 err = mOMX->setParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07002769 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
2770 CHECK_EQ(err, OK);
2771}
2772
2773void OMXCodec::addCodecSpecificData(const void *data, size_t size) {
2774 CodecSpecificData *specific =
2775 (CodecSpecificData *)malloc(sizeof(CodecSpecificData) + size - 1);
2776
2777 specific->mSize = size;
2778 memcpy(specific->mData, data, size);
2779
2780 mCodecSpecificData.push(specific);
2781}
2782
2783void OMXCodec::clearCodecSpecificData() {
2784 for (size_t i = 0; i < mCodecSpecificData.size(); ++i) {
2785 free(mCodecSpecificData.editItemAt(i));
2786 }
2787 mCodecSpecificData.clear();
2788 mCodecSpecificDataIndex = 0;
2789}
2790
James Dong36e573b2010-06-19 09:04:18 -07002791status_t OMXCodec::start(MetaData *meta) {
Andreas Huber42978e52009-08-27 10:08:39 -07002792 Mutex::Autolock autoLock(mLock);
2793
Andreas Huberbe06d262009-08-14 14:37:10 -07002794 if (mState != LOADED) {
2795 return UNKNOWN_ERROR;
2796 }
Andreas Huberebf66ea2009-08-19 13:32:58 -07002797
Andreas Huberbe06d262009-08-14 14:37:10 -07002798 sp<MetaData> params = new MetaData;
Andreas Huber4f5e6022009-08-19 09:29:34 -07002799 if (mQuirks & kWantsNALFragments) {
2800 params->setInt32(kKeyWantsNALFragments, true);
Andreas Huberbe06d262009-08-14 14:37:10 -07002801 }
James Dong36e573b2010-06-19 09:04:18 -07002802 if (meta) {
2803 int64_t startTimeUs = 0;
2804 int64_t timeUs;
2805 if (meta->findInt64(kKeyTime, &timeUs)) {
2806 startTimeUs = timeUs;
2807 }
2808 params->setInt64(kKeyTime, startTimeUs);
2809 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002810 status_t err = mSource->start(params.get());
2811
2812 if (err != OK) {
2813 return err;
2814 }
2815
2816 mCodecSpecificDataIndex = 0;
Andreas Huber42978e52009-08-27 10:08:39 -07002817 mInitialBufferSubmit = true;
Andreas Huberbe06d262009-08-14 14:37:10 -07002818 mSignalledEOS = false;
2819 mNoMoreOutputData = false;
Andreas Hubercfd55572009-10-09 14:11:28 -07002820 mOutputPortSettingsHaveChanged = false;
Andreas Huberbe06d262009-08-14 14:37:10 -07002821 mSeekTimeUs = -1;
Andreas Huber6624c9f2010-07-20 15:04:28 -07002822 mSeekMode = ReadOptions::SEEK_CLOSEST_SYNC;
2823 mTargetTimeUs = -1;
Andreas Huberbe06d262009-08-14 14:37:10 -07002824 mFilledBuffers.clear();
Andreas Huber1f24b302010-06-10 11:12:39 -07002825 mPaused = false;
Andreas Huberbe06d262009-08-14 14:37:10 -07002826
2827 return init();
2828}
2829
2830status_t OMXCodec::stop() {
Andreas Huber4a9375e2010-02-09 11:54:33 -08002831 CODEC_LOGV("stop mState=%d", mState);
Andreas Huberbe06d262009-08-14 14:37:10 -07002832
2833 Mutex::Autolock autoLock(mLock);
2834
2835 while (isIntermediateState(mState)) {
2836 mAsyncCompletion.wait(mLock);
2837 }
2838
2839 switch (mState) {
2840 case LOADED:
2841 case ERROR:
2842 break;
2843
2844 case EXECUTING:
2845 {
2846 setState(EXECUTING_TO_IDLE);
2847
Andreas Huber127fcdc2009-08-26 16:27:02 -07002848 if (mQuirks & kRequiresFlushBeforeShutdown) {
Andreas Huber4c483422009-09-02 16:05:36 -07002849 CODEC_LOGV("This component requires a flush before transitioning "
Andreas Huber127fcdc2009-08-26 16:27:02 -07002850 "from EXECUTING to IDLE...");
Andreas Huberbe06d262009-08-14 14:37:10 -07002851
Andreas Huber127fcdc2009-08-26 16:27:02 -07002852 bool emulateInputFlushCompletion =
2853 !flushPortAsync(kPortIndexInput);
2854
2855 bool emulateOutputFlushCompletion =
2856 !flushPortAsync(kPortIndexOutput);
2857
2858 if (emulateInputFlushCompletion) {
2859 onCmdComplete(OMX_CommandFlush, kPortIndexInput);
2860 }
2861
2862 if (emulateOutputFlushCompletion) {
2863 onCmdComplete(OMX_CommandFlush, kPortIndexOutput);
2864 }
2865 } else {
2866 mPortStatus[kPortIndexInput] = SHUTTING_DOWN;
2867 mPortStatus[kPortIndexOutput] = SHUTTING_DOWN;
2868
2869 status_t err =
Andreas Huber784202e2009-10-15 13:46:54 -07002870 mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
Andreas Huber127fcdc2009-08-26 16:27:02 -07002871 CHECK_EQ(err, OK);
2872 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002873
2874 while (mState != LOADED && mState != ERROR) {
2875 mAsyncCompletion.wait(mLock);
2876 }
2877
2878 break;
2879 }
2880
2881 default:
2882 {
2883 CHECK(!"should not be here.");
2884 break;
2885 }
2886 }
2887
Andreas Hubera4357ad2010-04-02 12:49:54 -07002888 if (mLeftOverBuffer) {
2889 mLeftOverBuffer->release();
2890 mLeftOverBuffer = NULL;
2891 }
2892
Andreas Huberbe06d262009-08-14 14:37:10 -07002893 mSource->stop();
2894
Andreas Huber4a9375e2010-02-09 11:54:33 -08002895 CODEC_LOGV("stopped");
2896
Andreas Huberbe06d262009-08-14 14:37:10 -07002897 return OK;
2898}
2899
2900sp<MetaData> OMXCodec::getFormat() {
Andreas Hubercfd55572009-10-09 14:11:28 -07002901 Mutex::Autolock autoLock(mLock);
2902
Andreas Huberbe06d262009-08-14 14:37:10 -07002903 return mOutputFormat;
2904}
2905
2906status_t OMXCodec::read(
2907 MediaBuffer **buffer, const ReadOptions *options) {
2908 *buffer = NULL;
2909
2910 Mutex::Autolock autoLock(mLock);
2911
Andreas Huberd06e5b82009-08-28 13:18:14 -07002912 if (mState != EXECUTING && mState != RECONFIGURING) {
2913 return UNKNOWN_ERROR;
2914 }
2915
Andreas Hubere981c332009-10-22 13:49:30 -07002916 bool seeking = false;
2917 int64_t seekTimeUs;
Andreas Huber6624c9f2010-07-20 15:04:28 -07002918 ReadOptions::SeekMode seekMode;
2919 if (options && options->getSeekTo(&seekTimeUs, &seekMode)) {
Andreas Hubere981c332009-10-22 13:49:30 -07002920 seeking = true;
2921 }
James Dong53d4e0d2010-07-21 14:51:35 -07002922 int64_t skipTimeUs;
2923 if (options && options->getSkipFrame(&skipTimeUs)) {
2924 mSkipTimeUs = skipTimeUs;
2925 } else {
2926 mSkipTimeUs = -1;
2927 }
Andreas Hubere981c332009-10-22 13:49:30 -07002928
Andreas Huber42978e52009-08-27 10:08:39 -07002929 if (mInitialBufferSubmit) {
2930 mInitialBufferSubmit = false;
2931
Andreas Hubere981c332009-10-22 13:49:30 -07002932 if (seeking) {
2933 CHECK(seekTimeUs >= 0);
2934 mSeekTimeUs = seekTimeUs;
Andreas Huber6624c9f2010-07-20 15:04:28 -07002935 mSeekMode = seekMode;
Andreas Hubere981c332009-10-22 13:49:30 -07002936
2937 // There's no reason to trigger the code below, there's
2938 // nothing to flush yet.
2939 seeking = false;
Andreas Huber1f24b302010-06-10 11:12:39 -07002940 mPaused = false;
Andreas Hubere981c332009-10-22 13:49:30 -07002941 }
2942
Andreas Huber42978e52009-08-27 10:08:39 -07002943 drainInputBuffers();
Andreas Huber42978e52009-08-27 10:08:39 -07002944
Andreas Huberd06e5b82009-08-28 13:18:14 -07002945 if (mState == EXECUTING) {
2946 // Otherwise mState == RECONFIGURING and this code will trigger
2947 // after the output port is reenabled.
2948 fillOutputBuffers();
2949 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002950 }
2951
Andreas Hubere981c332009-10-22 13:49:30 -07002952 if (seeking) {
Andreas Huber4c483422009-09-02 16:05:36 -07002953 CODEC_LOGV("seeking to %lld us (%.2f secs)", seekTimeUs, seekTimeUs / 1E6);
Andreas Huberbe06d262009-08-14 14:37:10 -07002954
2955 mSignalledEOS = false;
Andreas Huberbe06d262009-08-14 14:37:10 -07002956
2957 CHECK(seekTimeUs >= 0);
2958 mSeekTimeUs = seekTimeUs;
Andreas Huber6624c9f2010-07-20 15:04:28 -07002959 mSeekMode = seekMode;
Andreas Huberbe06d262009-08-14 14:37:10 -07002960
2961 mFilledBuffers.clear();
2962
2963 CHECK_EQ(mState, EXECUTING);
2964
Andreas Huber404cc412009-08-25 14:26:05 -07002965 bool emulateInputFlushCompletion = !flushPortAsync(kPortIndexInput);
2966 bool emulateOutputFlushCompletion = !flushPortAsync(kPortIndexOutput);
2967
2968 if (emulateInputFlushCompletion) {
2969 onCmdComplete(OMX_CommandFlush, kPortIndexInput);
2970 }
2971
2972 if (emulateOutputFlushCompletion) {
2973 onCmdComplete(OMX_CommandFlush, kPortIndexOutput);
2974 }
Andreas Huber2ea14e22009-12-16 09:30:55 -08002975
2976 while (mSeekTimeUs >= 0) {
2977 mBufferFilled.wait(mLock);
2978 }
Andreas Huberbe06d262009-08-14 14:37:10 -07002979 }
2980
2981 while (mState != ERROR && !mNoMoreOutputData && mFilledBuffers.empty()) {
2982 mBufferFilled.wait(mLock);
2983 }
2984
2985 if (mState == ERROR) {
2986 return UNKNOWN_ERROR;
2987 }
2988
2989 if (mFilledBuffers.empty()) {
Andreas Huberd7d22eb2010-02-23 13:45:33 -08002990 return mSignalledEOS ? mFinalStatus : ERROR_END_OF_STREAM;
Andreas Huberbe06d262009-08-14 14:37:10 -07002991 }
2992
Andreas Hubercfd55572009-10-09 14:11:28 -07002993 if (mOutputPortSettingsHaveChanged) {
2994 mOutputPortSettingsHaveChanged = false;
2995
2996 return INFO_FORMAT_CHANGED;
2997 }
2998
Andreas Huberbe06d262009-08-14 14:37:10 -07002999 size_t index = *mFilledBuffers.begin();
3000 mFilledBuffers.erase(mFilledBuffers.begin());
3001
3002 BufferInfo *info = &mPortBuffers[kPortIndexOutput].editItemAt(index);
3003 info->mMediaBuffer->add_ref();
3004 *buffer = info->mMediaBuffer;
3005
3006 return OK;
3007}
3008
3009void OMXCodec::signalBufferReturned(MediaBuffer *buffer) {
3010 Mutex::Autolock autoLock(mLock);
3011
3012 Vector<BufferInfo> *buffers = &mPortBuffers[kPortIndexOutput];
3013 for (size_t i = 0; i < buffers->size(); ++i) {
3014 BufferInfo *info = &buffers->editItemAt(i);
3015
3016 if (info->mMediaBuffer == buffer) {
3017 CHECK_EQ(mPortStatus[kPortIndexOutput], ENABLED);
3018 fillOutputBuffer(info);
3019 return;
3020 }
3021 }
3022
3023 CHECK(!"should not be here.");
3024}
3025
3026static const char *imageCompressionFormatString(OMX_IMAGE_CODINGTYPE type) {
3027 static const char *kNames[] = {
3028 "OMX_IMAGE_CodingUnused",
3029 "OMX_IMAGE_CodingAutoDetect",
3030 "OMX_IMAGE_CodingJPEG",
3031 "OMX_IMAGE_CodingJPEG2K",
3032 "OMX_IMAGE_CodingEXIF",
3033 "OMX_IMAGE_CodingTIFF",
3034 "OMX_IMAGE_CodingGIF",
3035 "OMX_IMAGE_CodingPNG",
3036 "OMX_IMAGE_CodingLZW",
3037 "OMX_IMAGE_CodingBMP",
3038 };
3039
3040 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3041
3042 if (type < 0 || (size_t)type >= numNames) {
3043 return "UNKNOWN";
3044 } else {
3045 return kNames[type];
3046 }
3047}
3048
3049static const char *colorFormatString(OMX_COLOR_FORMATTYPE type) {
3050 static const char *kNames[] = {
3051 "OMX_COLOR_FormatUnused",
3052 "OMX_COLOR_FormatMonochrome",
3053 "OMX_COLOR_Format8bitRGB332",
3054 "OMX_COLOR_Format12bitRGB444",
3055 "OMX_COLOR_Format16bitARGB4444",
3056 "OMX_COLOR_Format16bitARGB1555",
3057 "OMX_COLOR_Format16bitRGB565",
3058 "OMX_COLOR_Format16bitBGR565",
3059 "OMX_COLOR_Format18bitRGB666",
3060 "OMX_COLOR_Format18bitARGB1665",
Andreas Huberebf66ea2009-08-19 13:32:58 -07003061 "OMX_COLOR_Format19bitARGB1666",
Andreas Huberbe06d262009-08-14 14:37:10 -07003062 "OMX_COLOR_Format24bitRGB888",
3063 "OMX_COLOR_Format24bitBGR888",
3064 "OMX_COLOR_Format24bitARGB1887",
3065 "OMX_COLOR_Format25bitARGB1888",
3066 "OMX_COLOR_Format32bitBGRA8888",
3067 "OMX_COLOR_Format32bitARGB8888",
3068 "OMX_COLOR_FormatYUV411Planar",
3069 "OMX_COLOR_FormatYUV411PackedPlanar",
3070 "OMX_COLOR_FormatYUV420Planar",
3071 "OMX_COLOR_FormatYUV420PackedPlanar",
3072 "OMX_COLOR_FormatYUV420SemiPlanar",
3073 "OMX_COLOR_FormatYUV422Planar",
3074 "OMX_COLOR_FormatYUV422PackedPlanar",
3075 "OMX_COLOR_FormatYUV422SemiPlanar",
3076 "OMX_COLOR_FormatYCbYCr",
3077 "OMX_COLOR_FormatYCrYCb",
3078 "OMX_COLOR_FormatCbYCrY",
3079 "OMX_COLOR_FormatCrYCbY",
3080 "OMX_COLOR_FormatYUV444Interleaved",
3081 "OMX_COLOR_FormatRawBayer8bit",
3082 "OMX_COLOR_FormatRawBayer10bit",
3083 "OMX_COLOR_FormatRawBayer8bitcompressed",
Andreas Huberebf66ea2009-08-19 13:32:58 -07003084 "OMX_COLOR_FormatL2",
3085 "OMX_COLOR_FormatL4",
3086 "OMX_COLOR_FormatL8",
3087 "OMX_COLOR_FormatL16",
3088 "OMX_COLOR_FormatL24",
Andreas Huberbe06d262009-08-14 14:37:10 -07003089 "OMX_COLOR_FormatL32",
3090 "OMX_COLOR_FormatYUV420PackedSemiPlanar",
3091 "OMX_COLOR_FormatYUV422PackedSemiPlanar",
3092 "OMX_COLOR_Format18BitBGR666",
3093 "OMX_COLOR_Format24BitARGB6666",
3094 "OMX_COLOR_Format24BitABGR6666",
3095 };
3096
3097 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3098
Andreas Huberbe06d262009-08-14 14:37:10 -07003099 if (type == OMX_QCOM_COLOR_FormatYVU420SemiPlanar) {
3100 return "OMX_QCOM_COLOR_FormatYVU420SemiPlanar";
3101 } else if (type < 0 || (size_t)type >= numNames) {
3102 return "UNKNOWN";
3103 } else {
3104 return kNames[type];
3105 }
3106}
3107
3108static const char *videoCompressionFormatString(OMX_VIDEO_CODINGTYPE type) {
3109 static const char *kNames[] = {
3110 "OMX_VIDEO_CodingUnused",
3111 "OMX_VIDEO_CodingAutoDetect",
3112 "OMX_VIDEO_CodingMPEG2",
3113 "OMX_VIDEO_CodingH263",
3114 "OMX_VIDEO_CodingMPEG4",
3115 "OMX_VIDEO_CodingWMV",
3116 "OMX_VIDEO_CodingRV",
3117 "OMX_VIDEO_CodingAVC",
3118 "OMX_VIDEO_CodingMJPEG",
3119 };
3120
3121 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3122
3123 if (type < 0 || (size_t)type >= numNames) {
3124 return "UNKNOWN";
3125 } else {
3126 return kNames[type];
3127 }
3128}
3129
3130static const char *audioCodingTypeString(OMX_AUDIO_CODINGTYPE type) {
3131 static const char *kNames[] = {
3132 "OMX_AUDIO_CodingUnused",
3133 "OMX_AUDIO_CodingAutoDetect",
3134 "OMX_AUDIO_CodingPCM",
3135 "OMX_AUDIO_CodingADPCM",
3136 "OMX_AUDIO_CodingAMR",
3137 "OMX_AUDIO_CodingGSMFR",
3138 "OMX_AUDIO_CodingGSMEFR",
3139 "OMX_AUDIO_CodingGSMHR",
3140 "OMX_AUDIO_CodingPDCFR",
3141 "OMX_AUDIO_CodingPDCEFR",
3142 "OMX_AUDIO_CodingPDCHR",
3143 "OMX_AUDIO_CodingTDMAFR",
3144 "OMX_AUDIO_CodingTDMAEFR",
3145 "OMX_AUDIO_CodingQCELP8",
3146 "OMX_AUDIO_CodingQCELP13",
3147 "OMX_AUDIO_CodingEVRC",
3148 "OMX_AUDIO_CodingSMV",
3149 "OMX_AUDIO_CodingG711",
3150 "OMX_AUDIO_CodingG723",
3151 "OMX_AUDIO_CodingG726",
3152 "OMX_AUDIO_CodingG729",
3153 "OMX_AUDIO_CodingAAC",
3154 "OMX_AUDIO_CodingMP3",
3155 "OMX_AUDIO_CodingSBC",
3156 "OMX_AUDIO_CodingVORBIS",
3157 "OMX_AUDIO_CodingWMA",
3158 "OMX_AUDIO_CodingRA",
3159 "OMX_AUDIO_CodingMIDI",
3160 };
3161
3162 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3163
3164 if (type < 0 || (size_t)type >= numNames) {
3165 return "UNKNOWN";
3166 } else {
3167 return kNames[type];
3168 }
3169}
3170
3171static const char *audioPCMModeString(OMX_AUDIO_PCMMODETYPE type) {
3172 static const char *kNames[] = {
3173 "OMX_AUDIO_PCMModeLinear",
3174 "OMX_AUDIO_PCMModeALaw",
3175 "OMX_AUDIO_PCMModeMULaw",
3176 };
3177
3178 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3179
3180 if (type < 0 || (size_t)type >= numNames) {
3181 return "UNKNOWN";
3182 } else {
3183 return kNames[type];
3184 }
3185}
3186
Andreas Huber7ae02c82009-09-09 16:29:47 -07003187static const char *amrBandModeString(OMX_AUDIO_AMRBANDMODETYPE type) {
3188 static const char *kNames[] = {
3189 "OMX_AUDIO_AMRBandModeUnused",
3190 "OMX_AUDIO_AMRBandModeNB0",
3191 "OMX_AUDIO_AMRBandModeNB1",
3192 "OMX_AUDIO_AMRBandModeNB2",
3193 "OMX_AUDIO_AMRBandModeNB3",
3194 "OMX_AUDIO_AMRBandModeNB4",
3195 "OMX_AUDIO_AMRBandModeNB5",
3196 "OMX_AUDIO_AMRBandModeNB6",
3197 "OMX_AUDIO_AMRBandModeNB7",
3198 "OMX_AUDIO_AMRBandModeWB0",
3199 "OMX_AUDIO_AMRBandModeWB1",
3200 "OMX_AUDIO_AMRBandModeWB2",
3201 "OMX_AUDIO_AMRBandModeWB3",
3202 "OMX_AUDIO_AMRBandModeWB4",
3203 "OMX_AUDIO_AMRBandModeWB5",
3204 "OMX_AUDIO_AMRBandModeWB6",
3205 "OMX_AUDIO_AMRBandModeWB7",
3206 "OMX_AUDIO_AMRBandModeWB8",
3207 };
3208
3209 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3210
3211 if (type < 0 || (size_t)type >= numNames) {
3212 return "UNKNOWN";
3213 } else {
3214 return kNames[type];
3215 }
3216}
3217
3218static const char *amrFrameFormatString(OMX_AUDIO_AMRFRAMEFORMATTYPE type) {
3219 static const char *kNames[] = {
3220 "OMX_AUDIO_AMRFrameFormatConformance",
3221 "OMX_AUDIO_AMRFrameFormatIF1",
3222 "OMX_AUDIO_AMRFrameFormatIF2",
3223 "OMX_AUDIO_AMRFrameFormatFSF",
3224 "OMX_AUDIO_AMRFrameFormatRTPPayload",
3225 "OMX_AUDIO_AMRFrameFormatITU",
3226 };
3227
3228 size_t numNames = sizeof(kNames) / sizeof(kNames[0]);
3229
3230 if (type < 0 || (size_t)type >= numNames) {
3231 return "UNKNOWN";
3232 } else {
3233 return kNames[type];
3234 }
3235}
Andreas Huberbe06d262009-08-14 14:37:10 -07003236
3237void OMXCodec::dumpPortStatus(OMX_U32 portIndex) {
3238 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07003239 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07003240 def.nPortIndex = portIndex;
3241
Andreas Huber784202e2009-10-15 13:46:54 -07003242 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07003243 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
3244 CHECK_EQ(err, OK);
3245
3246 printf("%s Port = {\n", portIndex == kPortIndexInput ? "Input" : "Output");
3247
3248 CHECK((portIndex == kPortIndexInput && def.eDir == OMX_DirInput)
3249 || (portIndex == kPortIndexOutput && def.eDir == OMX_DirOutput));
3250
3251 printf(" nBufferCountActual = %ld\n", def.nBufferCountActual);
3252 printf(" nBufferCountMin = %ld\n", def.nBufferCountMin);
3253 printf(" nBufferSize = %ld\n", def.nBufferSize);
3254
3255 switch (def.eDomain) {
3256 case OMX_PortDomainImage:
3257 {
3258 const OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
3259
3260 printf("\n");
3261 printf(" // Image\n");
3262 printf(" nFrameWidth = %ld\n", imageDef->nFrameWidth);
3263 printf(" nFrameHeight = %ld\n", imageDef->nFrameHeight);
3264 printf(" nStride = %ld\n", imageDef->nStride);
3265
3266 printf(" eCompressionFormat = %s\n",
3267 imageCompressionFormatString(imageDef->eCompressionFormat));
3268
3269 printf(" eColorFormat = %s\n",
3270 colorFormatString(imageDef->eColorFormat));
3271
3272 break;
3273 }
3274
3275 case OMX_PortDomainVideo:
3276 {
3277 OMX_VIDEO_PORTDEFINITIONTYPE *videoDef = &def.format.video;
3278
3279 printf("\n");
3280 printf(" // Video\n");
3281 printf(" nFrameWidth = %ld\n", videoDef->nFrameWidth);
3282 printf(" nFrameHeight = %ld\n", videoDef->nFrameHeight);
3283 printf(" nStride = %ld\n", videoDef->nStride);
3284
3285 printf(" eCompressionFormat = %s\n",
3286 videoCompressionFormatString(videoDef->eCompressionFormat));
3287
3288 printf(" eColorFormat = %s\n",
3289 colorFormatString(videoDef->eColorFormat));
3290
3291 break;
3292 }
3293
3294 case OMX_PortDomainAudio:
3295 {
3296 OMX_AUDIO_PORTDEFINITIONTYPE *audioDef = &def.format.audio;
3297
3298 printf("\n");
3299 printf(" // Audio\n");
3300 printf(" eEncoding = %s\n",
3301 audioCodingTypeString(audioDef->eEncoding));
3302
3303 if (audioDef->eEncoding == OMX_AUDIO_CodingPCM) {
3304 OMX_AUDIO_PARAM_PCMMODETYPE params;
Andreas Huber4c483422009-09-02 16:05:36 -07003305 InitOMXParams(&params);
Andreas Huberbe06d262009-08-14 14:37:10 -07003306 params.nPortIndex = portIndex;
3307
Andreas Huber784202e2009-10-15 13:46:54 -07003308 err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07003309 mNode, OMX_IndexParamAudioPcm, &params, sizeof(params));
3310 CHECK_EQ(err, OK);
3311
3312 printf(" nSamplingRate = %ld\n", params.nSamplingRate);
3313 printf(" nChannels = %ld\n", params.nChannels);
3314 printf(" bInterleaved = %d\n", params.bInterleaved);
3315 printf(" nBitPerSample = %ld\n", params.nBitPerSample);
3316
3317 printf(" eNumData = %s\n",
3318 params.eNumData == OMX_NumericalDataSigned
3319 ? "signed" : "unsigned");
3320
3321 printf(" ePCMMode = %s\n", audioPCMModeString(params.ePCMMode));
Andreas Huber7ae02c82009-09-09 16:29:47 -07003322 } else if (audioDef->eEncoding == OMX_AUDIO_CodingAMR) {
3323 OMX_AUDIO_PARAM_AMRTYPE amr;
3324 InitOMXParams(&amr);
3325 amr.nPortIndex = portIndex;
3326
Andreas Huber784202e2009-10-15 13:46:54 -07003327 err = mOMX->getParameter(
Andreas Huber7ae02c82009-09-09 16:29:47 -07003328 mNode, OMX_IndexParamAudioAmr, &amr, sizeof(amr));
3329 CHECK_EQ(err, OK);
3330
3331 printf(" nChannels = %ld\n", amr.nChannels);
3332 printf(" eAMRBandMode = %s\n",
3333 amrBandModeString(amr.eAMRBandMode));
3334 printf(" eAMRFrameFormat = %s\n",
3335 amrFrameFormatString(amr.eAMRFrameFormat));
Andreas Huberbe06d262009-08-14 14:37:10 -07003336 }
3337
3338 break;
3339 }
3340
3341 default:
3342 {
3343 printf(" // Unknown\n");
3344 break;
3345 }
3346 }
3347
3348 printf("}\n");
3349}
3350
3351void OMXCodec::initOutputFormat(const sp<MetaData> &inputFormat) {
3352 mOutputFormat = new MetaData;
3353 mOutputFormat->setCString(kKeyDecoderComponent, mComponentName);
James Dong52d13f02010-07-02 11:39:06 -07003354 if (mIsEncoder) {
3355 int32_t timeScale;
3356 if (inputFormat->findInt32(kKeyTimeScale, &timeScale)) {
3357 mOutputFormat->setInt32(kKeyTimeScale, timeScale);
3358 }
3359 }
Andreas Huberbe06d262009-08-14 14:37:10 -07003360
3361 OMX_PARAM_PORTDEFINITIONTYPE def;
Andreas Huber4c483422009-09-02 16:05:36 -07003362 InitOMXParams(&def);
Andreas Huberbe06d262009-08-14 14:37:10 -07003363 def.nPortIndex = kPortIndexOutput;
3364
Andreas Huber784202e2009-10-15 13:46:54 -07003365 status_t err = mOMX->getParameter(
Andreas Huberbe06d262009-08-14 14:37:10 -07003366 mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
3367 CHECK_EQ(err, OK);
3368
3369 switch (def.eDomain) {
3370 case OMX_PortDomainImage:
3371 {
3372 OMX_IMAGE_PORTDEFINITIONTYPE *imageDef = &def.format.image;
3373 CHECK_EQ(imageDef->eCompressionFormat, OMX_IMAGE_CodingUnused);
3374
Andreas Hubere6c40962009-09-10 14:13:30 -07003375 mOutputFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RAW);
Andreas Huberbe06d262009-08-14 14:37:10 -07003376 mOutputFormat->setInt32(kKeyColorFormat, imageDef->eColorFormat);
3377 mOutputFormat->setInt32(kKeyWidth, imageDef->nFrameWidth);
3378 mOutputFormat->setInt32(kKeyHeight, imageDef->nFrameHeight);
3379 break;
3380 }
3381
3382 case OMX_PortDomainAudio:
3383 {
3384 OMX_AUDIO_PORTDEFINITIONTYPE *audio_def = &def.format.audio;
3385
Andreas Huberda050cf22009-09-02 14:01:43 -07003386 if (audio_def->eEncoding == OMX_AUDIO_CodingPCM) {
3387 OMX_AUDIO_PARAM_PCMMODETYPE params;
Andreas Huber4c483422009-09-02 16:05:36 -07003388 InitOMXParams(&params);
Andreas Huberda050cf22009-09-02 14:01:43 -07003389 params.nPortIndex = kPortIndexOutput;
Andreas Huberbe06d262009-08-14 14:37:10 -07003390
Andreas Huber784202e2009-10-15 13:46:54 -07003391 err = mOMX->getParameter(
Andreas Huberda050cf22009-09-02 14:01:43 -07003392 mNode, OMX_IndexParamAudioPcm, &params, sizeof(params));
3393 CHECK_EQ(err, OK);
Andreas Huberbe06d262009-08-14 14:37:10 -07003394
Andreas Huberda050cf22009-09-02 14:01:43 -07003395 CHECK_EQ(params.eNumData, OMX_NumericalDataSigned);
3396 CHECK_EQ(params.nBitPerSample, 16);
3397 CHECK_EQ(params.ePCMMode, OMX_AUDIO_PCMModeLinear);
Andreas Huberbe06d262009-08-14 14:37:10 -07003398
Andreas Huberda050cf22009-09-02 14:01:43 -07003399 int32_t numChannels, sampleRate;
3400 inputFormat->findInt32(kKeyChannelCount, &numChannels);
3401 inputFormat->findInt32(kKeySampleRate, &sampleRate);
Andreas Huberbe06d262009-08-14 14:37:10 -07003402
Andreas Huberda050cf22009-09-02 14:01:43 -07003403 if ((OMX_U32)numChannels != params.nChannels) {
3404 LOGW("Codec outputs a different number of channels than "
Andreas Hubere331c7b2010-02-01 10:51:50 -08003405 "the input stream contains (contains %d channels, "
3406 "codec outputs %ld channels).",
3407 numChannels, params.nChannels);
Andreas Huberda050cf22009-09-02 14:01:43 -07003408 }
Andreas Huberbe06d262009-08-14 14:37:10 -07003409
Andreas Hubere6c40962009-09-10 14:13:30 -07003410 mOutputFormat->setCString(
3411 kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
Andreas Huberda050cf22009-09-02 14:01:43 -07003412
3413 // Use the codec-advertised number of channels, as some
3414 // codecs appear to output stereo even if the input data is
Andreas Hubere331c7b2010-02-01 10:51:50 -08003415 // mono. If we know the codec lies about this information,
3416 // use the actual number of channels instead.
3417 mOutputFormat->setInt32(
3418 kKeyChannelCount,
3419 (mQuirks & kDecoderLiesAboutNumberOfChannels)
3420 ? numChannels : params.nChannels);
Andreas Huberda050cf22009-09-02 14:01:43 -07003421
3422 // The codec-reported sampleRate is not reliable...
3423 mOutputFormat->setInt32(kKeySampleRate, sampleRate);
3424 } else if (audio_def->eEncoding == OMX_AUDIO_CodingAMR) {
Andreas Huber7ae02c82009-09-09 16:29:47 -07003425 OMX_AUDIO_PARAM_AMRTYPE amr;
3426 InitOMXParams(&amr);
3427 amr.nPortIndex = kPortIndexOutput;
3428
Andreas Huber784202e2009-10-15 13:46:54 -07003429 err = mOMX->getParameter(
Andreas Huber7ae02c82009-09-09 16:29:47 -07003430 mNode, OMX_IndexParamAudioAmr, &amr, sizeof(amr));
3431 CHECK_EQ(err, OK);
3432
3433 CHECK_EQ(amr.nChannels, 1);
3434 mOutputFormat->setInt32(kKeyChannelCount, 1);
3435
3436 if (amr.eAMRBandMode >= OMX_AUDIO_AMRBandModeNB0
3437 && amr.eAMRBandMode <= OMX_AUDIO_AMRBandModeNB7) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003438 mOutputFormat->setCString(
3439 kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AMR_NB);
Andreas Huber7ae02c82009-09-09 16:29:47 -07003440 mOutputFormat->setInt32(kKeySampleRate, 8000);
3441 } else if (amr.eAMRBandMode >= OMX_AUDIO_AMRBandModeWB0
3442 && amr.eAMRBandMode <= OMX_AUDIO_AMRBandModeWB8) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003443 mOutputFormat->setCString(
3444 kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AMR_WB);
Andreas Huber7ae02c82009-09-09 16:29:47 -07003445 mOutputFormat->setInt32(kKeySampleRate, 16000);
3446 } else {
3447 CHECK(!"Unknown AMR band mode.");
3448 }
Andreas Huberda050cf22009-09-02 14:01:43 -07003449 } else if (audio_def->eEncoding == OMX_AUDIO_CodingAAC) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003450 mOutputFormat->setCString(
3451 kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
James Dong17299ab2010-05-14 15:45:22 -07003452 int32_t numChannels, sampleRate, bitRate;
James Dongabed93a2010-04-22 17:27:04 -07003453 inputFormat->findInt32(kKeyChannelCount, &numChannels);
3454 inputFormat->findInt32(kKeySampleRate, &sampleRate);
James Dong17299ab2010-05-14 15:45:22 -07003455 inputFormat->findInt32(kKeyBitRate, &bitRate);
James Dongabed93a2010-04-22 17:27:04 -07003456 mOutputFormat->setInt32(kKeyChannelCount, numChannels);
3457 mOutputFormat->setInt32(kKeySampleRate, sampleRate);
James Dong17299ab2010-05-14 15:45:22 -07003458 mOutputFormat->setInt32(kKeyBitRate, bitRate);
Andreas Huberda050cf22009-09-02 14:01:43 -07003459 } else {
3460 CHECK(!"Should not be here. Unknown audio encoding.");
Andreas Huber43ad6eaf2009-09-01 16:02:43 -07003461 }
Andreas Huberbe06d262009-08-14 14:37:10 -07003462 break;
3463 }
3464
3465 case OMX_PortDomainVideo:
3466 {
3467 OMX_VIDEO_PORTDEFINITIONTYPE *video_def = &def.format.video;
3468
3469 if (video_def->eCompressionFormat == OMX_VIDEO_CodingUnused) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003470 mOutputFormat->setCString(
3471 kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RAW);
Andreas Huberbe06d262009-08-14 14:37:10 -07003472 } else if (video_def->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003473 mOutputFormat->setCString(
3474 kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
Andreas Huberbe06d262009-08-14 14:37:10 -07003475 } else if (video_def->eCompressionFormat == OMX_VIDEO_CodingH263) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003476 mOutputFormat->setCString(
3477 kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
Andreas Huberbe06d262009-08-14 14:37:10 -07003478 } else if (video_def->eCompressionFormat == OMX_VIDEO_CodingAVC) {
Andreas Hubere6c40962009-09-10 14:13:30 -07003479 mOutputFormat->setCString(
3480 kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
Andreas Huberbe06d262009-08-14 14:37:10 -07003481 } else {
3482 CHECK(!"Unknown compression format.");
3483 }
3484
3485 if (!strcmp(mComponentName, "OMX.PV.avcdec")) {
3486 // This component appears to be lying to me.
3487 mOutputFormat->setInt32(
3488 kKeyWidth, (video_def->nFrameWidth + 15) & -16);
3489 mOutputFormat->setInt32(
3490 kKeyHeight, (video_def->nFrameHeight + 15) & -16);
3491 } else {
3492 mOutputFormat->setInt32(kKeyWidth, video_def->nFrameWidth);
3493 mOutputFormat->setInt32(kKeyHeight, video_def->nFrameHeight);
3494 }
3495
3496 mOutputFormat->setInt32(kKeyColorFormat, video_def->eColorFormat);
3497 break;
3498 }
3499
3500 default:
3501 {
3502 CHECK(!"should not be here, neither audio nor video.");
3503 break;
3504 }
3505 }
3506}
3507
Andreas Huber1f24b302010-06-10 11:12:39 -07003508status_t OMXCodec::pause() {
3509 Mutex::Autolock autoLock(mLock);
3510
3511 mPaused = true;
3512
3513 return OK;
3514}
3515
Andreas Hubere6c40962009-09-10 14:13:30 -07003516////////////////////////////////////////////////////////////////////////////////
3517
3518status_t QueryCodecs(
3519 const sp<IOMX> &omx,
3520 const char *mime, bool queryDecoders,
3521 Vector<CodecCapabilities> *results) {
3522 results->clear();
3523
3524 for (int index = 0;; ++index) {
3525 const char *componentName;
3526
3527 if (!queryDecoders) {
3528 componentName = GetCodec(
3529 kEncoderInfo, sizeof(kEncoderInfo) / sizeof(kEncoderInfo[0]),
3530 mime, index);
3531 } else {
3532 componentName = GetCodec(
3533 kDecoderInfo, sizeof(kDecoderInfo) / sizeof(kDecoderInfo[0]),
3534 mime, index);
3535 }
3536
3537 if (!componentName) {
3538 return OK;
3539 }
3540
Andreas Huber1a189a82010-03-24 13:49:20 -07003541 if (strncmp(componentName, "OMX.", 4)) {
3542 // Not an OpenMax component but a software codec.
3543
3544 results->push();
3545 CodecCapabilities *caps = &results->editItemAt(results->size() - 1);
3546 caps->mComponentName = componentName;
3547
3548 continue;
3549 }
3550
Andreas Huber784202e2009-10-15 13:46:54 -07003551 sp<OMXCodecObserver> observer = new OMXCodecObserver;
Andreas Hubere6c40962009-09-10 14:13:30 -07003552 IOMX::node_id node;
Andreas Huber784202e2009-10-15 13:46:54 -07003553 status_t err = omx->allocateNode(componentName, observer, &node);
Andreas Hubere6c40962009-09-10 14:13:30 -07003554
3555 if (err != OK) {
3556 continue;
3557 }
3558
James Dong722d5912010-04-13 10:56:59 -07003559 OMXCodec::setComponentRole(omx, node, !queryDecoders, mime);
Andreas Hubere6c40962009-09-10 14:13:30 -07003560
3561 results->push();
3562 CodecCapabilities *caps = &results->editItemAt(results->size() - 1);
3563 caps->mComponentName = componentName;
3564
3565 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
3566 InitOMXParams(&param);
3567
3568 param.nPortIndex = queryDecoders ? 0 : 1;
3569
3570 for (param.nProfileIndex = 0;; ++param.nProfileIndex) {
Andreas Huber784202e2009-10-15 13:46:54 -07003571 err = omx->getParameter(
Andreas Hubere6c40962009-09-10 14:13:30 -07003572 node, OMX_IndexParamVideoProfileLevelQuerySupported,
3573 &param, sizeof(param));
3574
3575 if (err != OK) {
3576 break;
3577 }
3578
3579 CodecProfileLevel profileLevel;
3580 profileLevel.mProfile = param.eProfile;
3581 profileLevel.mLevel = param.eLevel;
3582
3583 caps->mProfileLevels.push(profileLevel);
3584 }
3585
Andreas Huber784202e2009-10-15 13:46:54 -07003586 CHECK_EQ(omx->freeNode(node), OK);
Andreas Hubere6c40962009-09-10 14:13:30 -07003587 }
3588}
3589
Andreas Huberbe06d262009-08-14 14:37:10 -07003590} // namespace android