blob: 184f215fcab180264af3c13af4c8cab11ae0cab9 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright (C) 2018 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 "Codec2InfoBuilder"
19#include <log/log.h>
20
21#include <strings.h>
22
23#include <C2Component.h>
24#include <C2Config.h>
25#include <C2Debug.h>
26#include <C2PlatformSupport.h>
27#include <Codec2Mapper.h>
28
29#include <OMX_Audio.h>
30#include <OMX_AudioExt.h>
31#include <OMX_IndexExt.h>
32#include <OMX_Types.h>
33#include <OMX_Video.h>
34#include <OMX_VideoExt.h>
35#include <OMX_AsString.h>
36
37#include <android/hardware/media/omx/1.0/IOmx.h>
38#include <android/hardware/media/omx/1.0/IOmxObserver.h>
39#include <android/hardware/media/omx/1.0/IOmxNode.h>
40#include <android/hardware/media/omx/1.0/types.h>
41
42#include <android-base/properties.h>
43#include <codec2/hidl/client.h>
44#include <cutils/native_handle.h>
45#include <media/omx/1.0/WOmxNode.h>
46#include <media/stagefright/MediaCodecConstants.h>
47#include <media/stagefright/foundation/MediaDefs.h>
48#include <media/stagefright/omx/OMXUtils.h>
49#include <media/stagefright/xmlparser/MediaCodecsXmlParser.h>
50
51#include "Codec2InfoBuilder.h"
52
53namespace android {
54
55using Traits = C2Component::Traits;
56
57namespace /* unnamed */ {
58
59bool hasPrefix(const std::string& s, const char* prefix) {
60 size_t prefixLen = strlen(prefix);
61 return s.compare(0, prefixLen, prefix) == 0;
62}
63
64bool hasSuffix(const std::string& s, const char* suffix) {
65 size_t suffixLen = strlen(suffix);
66 return suffixLen > s.size() ? false :
67 s.compare(s.size() - suffixLen, suffixLen, suffix) == 0;
68}
69
70// Constants from ACodec
71constexpr OMX_U32 kPortIndexInput = 0;
72constexpr OMX_U32 kPortIndexOutput = 1;
73constexpr OMX_U32 kMaxIndicesToCheck = 32;
74
75status_t queryOmxCapabilities(
76 const char* name, const char* mime, bool isEncoder,
77 MediaCodecInfo::CapabilitiesWriter* caps) {
78
79 const char *role = GetComponentRole(isEncoder, mime);
80 if (role == nullptr) {
81 return BAD_VALUE;
82 }
83
84 using namespace ::android::hardware::media::omx::V1_0;
85 using ::android::hardware::Return;
86 using ::android::hardware::Void;
87 using ::android::hardware::hidl_vec;
88 using ::android::hardware::media::omx::V1_0::utils::LWOmxNode;
89
90 sp<IOmx> omx = IOmx::getService();
91 if (!omx) {
92 ALOGW("Could not obtain IOmx service.");
93 return NO_INIT;
94 }
95
96 struct Observer : IOmxObserver {
97 virtual Return<void> onMessages(const hidl_vec<Message>&) override {
98 return Void();
99 }
100 };
101
102 sp<Observer> observer = new Observer();
103 Status status;
104 sp<IOmxNode> tOmxNode;
105 Return<void> transStatus = omx->allocateNode(
106 name, observer,
107 [&status, &tOmxNode](Status s, const sp<IOmxNode>& n) {
108 status = s;
109 tOmxNode = n;
110 });
111 if (!transStatus.isOk()) {
112 ALOGW("IOmx::allocateNode -- transaction failed.");
113 return NO_INIT;
114 }
115 if (status != Status::OK) {
116 ALOGW("IOmx::allocateNode -- error returned: %d.",
117 static_cast<int>(status));
118 return NO_INIT;
119 }
120
121 sp<LWOmxNode> omxNode = new LWOmxNode(tOmxNode);
122
123 status_t err = SetComponentRole(omxNode, role);
124 if (err != OK) {
125 omxNode->freeNode();
126 ALOGW("Failed to SetComponentRole: component = %s, role = %s.",
127 name, role);
128 return err;
129 }
130
131 bool isVideo = hasPrefix(mime, "video/") == 0;
132 bool isImage = hasPrefix(mime, "image/") == 0;
133
134 if (isVideo || isImage) {
135 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
136 InitOMXParams(&param);
137 param.nPortIndex = isEncoder ? kPortIndexOutput : kPortIndexInput;
138
139 for (OMX_U32 index = 0; index <= kMaxIndicesToCheck; ++index) {
140 param.nProfileIndex = index;
141 status_t err = omxNode->getParameter(
142 OMX_IndexParamVideoProfileLevelQuerySupported,
143 &param, sizeof(param));
144 if (err != OK) {
145 break;
146 }
147 caps->addProfileLevel(param.eProfile, param.eLevel);
148
149 // AVC components may not list the constrained profiles explicitly, but
150 // decoders that support a profile also support its constrained version.
151 // Encoders must explicitly support constrained profiles.
152 if (!isEncoder && strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC) == 0) {
153 if (param.eProfile == OMX_VIDEO_AVCProfileHigh) {
154 caps->addProfileLevel(OMX_VIDEO_AVCProfileConstrainedHigh, param.eLevel);
155 } else if (param.eProfile == OMX_VIDEO_AVCProfileBaseline) {
156 caps->addProfileLevel(OMX_VIDEO_AVCProfileConstrainedBaseline, param.eLevel);
157 }
158 }
159
160 if (index == kMaxIndicesToCheck) {
161 ALOGW("[%s] stopping checking profiles after %u: %x/%x",
162 name, index,
163 param.eProfile, param.eLevel);
164 }
165 }
166
167 // Color format query
168 // return colors in the order reported by the OMX component
169 // prefix "flexible" standard ones with the flexible equivalent
170 OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
171 InitOMXParams(&portFormat);
172 portFormat.nPortIndex = isEncoder ? kPortIndexInput : kPortIndexOutput;
173 for (OMX_U32 index = 0; index <= kMaxIndicesToCheck; ++index) {
174 portFormat.nIndex = index;
175 status_t err = omxNode->getParameter(
176 OMX_IndexParamVideoPortFormat,
177 &portFormat, sizeof(portFormat));
178 if (err != OK) {
179 break;
180 }
181
182 OMX_U32 flexibleEquivalent;
183 if (IsFlexibleColorFormat(
184 omxNode, portFormat.eColorFormat, false /* usingNativeWindow */,
185 &flexibleEquivalent)) {
186 caps->addColorFormat(flexibleEquivalent);
187 }
188 caps->addColorFormat(portFormat.eColorFormat);
189
190 if (index == kMaxIndicesToCheck) {
191 ALOGW("[%s] stopping checking formats after %u: %s(%x)",
192 name, index,
193 asString(portFormat.eColorFormat), portFormat.eColorFormat);
194 }
195 }
196 } else if (strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC) == 0) {
197 // More audio codecs if they have profiles.
198 OMX_AUDIO_PARAM_ANDROID_PROFILETYPE param;
199 InitOMXParams(&param);
200 param.nPortIndex = isEncoder ? kPortIndexOutput : kPortIndexInput;
201 for (OMX_U32 index = 0; index <= kMaxIndicesToCheck; ++index) {
202 param.nProfileIndex = index;
203 status_t err = omxNode->getParameter(
204 (OMX_INDEXTYPE)OMX_IndexParamAudioProfileQuerySupported,
205 &param, sizeof(param));
206 if (err != OK) {
207 break;
208 }
209 // For audio, level is ignored.
210 caps->addProfileLevel(param.eProfile, 0 /* level */);
211
212 if (index == kMaxIndicesToCheck) {
213 ALOGW("[%s] stopping checking profiles after %u: %x",
214 name, index,
215 param.eProfile);
216 }
217 }
218
219 // NOTE: Without Android extensions, OMX does not provide a way to query
220 // AAC profile support
221 if (param.nProfileIndex == 0) {
222 ALOGW("component %s doesn't support profile query.", name);
223 }
224 }
225
226 if (isVideo && !isEncoder) {
227 native_handle_t *sidebandHandle = nullptr;
228 if (omxNode->configureVideoTunnelMode(
229 kPortIndexOutput, OMX_TRUE, 0, &sidebandHandle) == OK) {
230 // tunneled playback includes adaptive playback
231 caps->addFlags(MediaCodecInfo::Capabilities::kFlagSupportsAdaptivePlayback
232 | MediaCodecInfo::Capabilities::kFlagSupportsTunneledPlayback);
233 } else if (omxNode->setPortMode(
234 kPortIndexOutput, IOMX::kPortModeDynamicANWBuffer) == OK ||
235 omxNode->prepareForAdaptivePlayback(
236 kPortIndexOutput, OMX_TRUE,
237 1280 /* width */, 720 /* height */) == OK) {
238 caps->addFlags(MediaCodecInfo::Capabilities::kFlagSupportsAdaptivePlayback);
239 }
240 }
241
242 if (isVideo && isEncoder) {
243 OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE params;
244 InitOMXParams(&params);
245 params.nPortIndex = kPortIndexOutput;
246 // TODO: should we verify if fallback is supported?
247 if (omxNode->getConfig(
248 (OMX_INDEXTYPE)OMX_IndexConfigAndroidIntraRefresh,
249 &params, sizeof(params)) == OK) {
250 caps->addFlags(MediaCodecInfo::Capabilities::kFlagSupportsIntraRefresh);
251 }
252 }
253
254 omxNode->freeNode();
255 return OK;
256}
257
258void buildOmxInfo(const MediaCodecsXmlParser& parser,
259 MediaCodecListWriter* writer) {
260 uint32_t omxRank = ::android::base::GetUintProperty(
261 "debug.stagefright.omx_default_rank", uint32_t(0x100));
262 for (const MediaCodecsXmlParser::Codec& codec : parser.getCodecMap()) {
263 const std::string &name = codec.first;
264 if (!hasPrefix(codec.first, "OMX.")) {
265 continue;
266 }
267 const MediaCodecsXmlParser::CodecProperties &properties = codec.second;
268 bool encoder = properties.isEncoder;
269 std::unique_ptr<MediaCodecInfoWriter> info =
270 writer->addMediaCodecInfo();
271 info->setName(name.c_str());
272 info->setOwner("default");
273 info->setEncoder(encoder);
274 info->setRank(omxRank);
275 for (const MediaCodecsXmlParser::Type& type : properties.typeMap) {
276 const std::string &mime = type.first;
277 std::unique_ptr<MediaCodecInfo::CapabilitiesWriter> caps =
278 info->addMime(mime.c_str());
279 const MediaCodecsXmlParser::AttributeMap &attrMap = type.second;
280 for (const MediaCodecsXmlParser::Attribute& attr : attrMap) {
281 const std::string &key = attr.first;
282 const std::string &value = attr.second;
283 if (hasPrefix(key, "feature-") &&
284 !hasPrefix(key, "feature-bitrate-modes")) {
285 caps->addDetail(key.c_str(), hasPrefix(value, "1") ? 1 : 0);
286 } else {
287 caps->addDetail(key.c_str(), value.c_str());
288 }
289 }
290 status_t err = queryOmxCapabilities(
291 name.c_str(),
292 mime.c_str(),
293 encoder,
294 caps.get());
295 if (err != OK) {
296 ALOGE("Failed to query capabilities for %s (mime: %s). Error: %d",
297 name.c_str(),
298 mime.c_str(),
299 static_cast<int>(err));
300 }
301 }
302 }
303}
304
305} // unnamed namespace
306
307status_t Codec2InfoBuilder::buildMediaCodecList(MediaCodecListWriter* writer) {
308 // TODO: Remove run-time configurations once all codecs are working
309 // properly. (Assume "full" behavior eventually.)
310 //
311 // debug.stagefright.ccodec supports 5 values.
312 // 0 - Only OMX components are available.
313 // 1 - Audio decoders and encoders with prefix "c2.android." are available
314 // and ranked first.
315 // All other components with prefix "c2.android." are available with
316 // their normal ranks.
317 // Components with prefix "c2.vda." are available with their normal
318 // ranks.
319 // All other components with suffix ".avc.decoder" or ".avc.encoder"
320 // are available but ranked last.
321 // 2 - Components with prefix "c2.android." are available and ranked
322 // first.
323 // Components with prefix "c2.vda." are available with their normal
324 // ranks.
325 // All other components with suffix ".avc.decoder" or ".avc.encoder"
326 // are available but ranked last.
327 // 3 - Components with prefix "c2.android." are available and ranked
328 // first.
329 // All other components are available with their normal ranks.
330 // 4 - All components are available with their normal ranks.
331 //
332 // The default value (boot time) is 1.
333 //
334 // Note: Currently, OMX components have default rank 0x100, while all
335 // Codec2.0 software components have default rank 0x200.
336 int option = ::android::base::GetIntProperty("debug.stagefright.ccodec", 1);
337
338 // Obtain Codec2Client
339 std::vector<Traits> traits = Codec2Client::ListComponents();
340
341 MediaCodecsXmlParser parser(
342 MediaCodecsXmlParser::defaultSearchDirs,
343 option == 0 ? "media_codecs.xml" :
344 "media_codecs_c2.xml",
345 option == 0 ? "media_codecs_performance.xml" :
346 "media_codecs_performance_c2.xml");
347 if (parser.getParsingStatus() != OK) {
348 ALOGD("XML parser no good");
349 return OK;
350 }
351
352 bool surfaceTest(Codec2Client::CreateInputSurface());
353 if (option == 0 || !surfaceTest) {
354 buildOmxInfo(parser, writer);
355 }
356
357 for (const Traits& trait : traits) {
358 C2Component::rank_t rank = trait.rank;
359
360 std::shared_ptr<Codec2Client::Interface> intf =
361 Codec2Client::CreateInterfaceByName(trait.name.c_str());
362 if (!intf || parser.getCodecMap().count(intf->getName()) == 0) {
363 ALOGD("%s not found in xml", trait.name.c_str());
364 continue;
365 }
366 std::string canonName = intf->getName();
367
368 // TODO: Remove this block once all codecs are enabled by default.
369 switch (option) {
370 case 0:
371 continue;
372 case 1:
373 if (hasPrefix(canonName, "c2.vda.")) {
374 break;
375 }
376 if (hasPrefix(canonName, "c2.android.")) {
377 if (trait.domain == C2Component::DOMAIN_AUDIO) {
378 rank = 1;
379 break;
380 }
381 break;
382 }
383 if (hasSuffix(canonName, ".avc.decoder") ||
384 hasSuffix(canonName, ".avc.encoder")) {
385 rank = std::numeric_limits<decltype(rank)>::max();
386 break;
387 }
388 continue;
389 case 2:
390 if (hasPrefix(canonName, "c2.vda.")) {
391 break;
392 }
393 if (hasPrefix(canonName, "c2.android.")) {
394 rank = 1;
395 break;
396 }
397 if (hasSuffix(canonName, ".avc.decoder") ||
398 hasSuffix(canonName, ".avc.encoder")) {
399 rank = std::numeric_limits<decltype(rank)>::max();
400 break;
401 }
402 continue;
403 case 3:
404 if (hasPrefix(canonName, "c2.android.")) {
405 rank = 1;
406 }
407 break;
408 }
409
410 std::unique_ptr<MediaCodecInfoWriter> codecInfo = writer->addMediaCodecInfo();
411 codecInfo->setName(trait.name.c_str());
412 codecInfo->setOwner("codec2");
413 bool encoder = trait.kind == C2Component::KIND_ENCODER;
414 codecInfo->setEncoder(encoder);
415 codecInfo->setRank(rank);
416 const MediaCodecsXmlParser::CodecProperties &codec =
417 parser.getCodecMap().at(canonName);
418
419 for (auto typeIt = codec.typeMap.begin(); typeIt != codec.typeMap.end(); ++typeIt) {
420 const std::string &mediaType = typeIt->first;
421 const MediaCodecsXmlParser::AttributeMap &attrMap = typeIt->second;
422 std::unique_ptr<MediaCodecInfo::CapabilitiesWriter> caps =
423 codecInfo->addMime(mediaType.c_str());
424 for (auto attrIt = attrMap.begin(); attrIt != attrMap.end(); ++attrIt) {
425 std::string key, value;
426 std::tie(key, value) = *attrIt;
427 if (key.find("feature-") == 0 && key.find("feature-bitrate-modes") != 0) {
428 caps->addDetail(key.c_str(), std::stoi(value));
429 } else {
430 caps->addDetail(key.c_str(), value.c_str());
431 }
432 }
433
434 bool gotProfileLevels = false;
435 if (intf) {
436 std::shared_ptr<C2Mapper::ProfileLevelMapper> mapper =
437 C2Mapper::GetProfileLevelMapper(trait.mediaType);
438 // if we don't know the media type, pass through all values unmapped
439
440 // TODO: we cannot find levels that are local 'maxima' without knowing the coding
441 // e.g. H.263 level 45 and level 30 could be two values for highest level as
442 // they don't include one another. For now we use the last supported value.
443 C2StreamProfileLevelInfo pl(encoder /* output */, 0u);
444 std::vector<C2FieldSupportedValuesQuery> profileQuery = {
445 C2FieldSupportedValuesQuery::Possible(C2ParamField(&pl, &pl.profile))
446 };
447
448 c2_status_t err = intf->querySupportedValues(profileQuery, C2_DONT_BLOCK);
449 ALOGV("query supported profiles -> %s | %s",
450 asString(err), asString(profileQuery[0].status));
451 if (err == C2_OK && profileQuery[0].status == C2_OK) {
452 if (profileQuery[0].values.type == C2FieldSupportedValues::VALUES) {
Chong Zhanga8d5b4f2018-12-04 17:05:29 -0800453 std::vector<std::shared_ptr<C2ParamDescriptor>> paramDescs;
454 c2_status_t err1 = intf->querySupportedParams(&paramDescs);
455 bool isHdr = false, isHdr10Plus = false;
456 if (err1 == C2_OK) {
457 for (const std::shared_ptr<C2ParamDescriptor> &desc : paramDescs) {
458 if ((uint32_t)desc->index() ==
459 C2StreamHdr10PlusInfo::output::PARAM_TYPE) {
460 isHdr10Plus = true;
461 } else if ((uint32_t)desc->index() ==
462 C2StreamHdrStaticInfo::output::PARAM_TYPE) {
463 isHdr = true;
464 }
465 }
466 }
467 // For VP9, the static info is always propagated by framework.
468 isHdr |= (mediaType == MIMETYPE_VIDEO_VP9);
469
Pawin Vongmasa36653902018-11-15 00:10:25 -0800470 for (C2Value::Primitive profile : profileQuery[0].values.values) {
471 pl.profile = (C2Config::profile_t)profile.ref<uint32_t>();
472 std::vector<std::unique_ptr<C2SettingResult>> failures;
473 err = intf->config({&pl}, C2_DONT_BLOCK, &failures);
474 ALOGV("set profile to %u -> %s", pl.profile, asString(err));
475 std::vector<C2FieldSupportedValuesQuery> levelQuery = {
476 C2FieldSupportedValuesQuery::Current(C2ParamField(&pl, &pl.level))
477 };
478 err = intf->querySupportedValues(levelQuery, C2_DONT_BLOCK);
479 ALOGV("query supported levels -> %s | %s",
480 asString(err), asString(levelQuery[0].status));
481 if (err == C2_OK && levelQuery[0].status == C2_OK) {
482 if (levelQuery[0].values.type == C2FieldSupportedValues::VALUES
483 && levelQuery[0].values.values.size() > 0) {
484 C2Value::Primitive level = levelQuery[0].values.values.back();
485 pl.level = (C2Config::level_t)level.ref<uint32_t>();
486 ALOGV("supporting level: %u", pl.level);
487 int32_t sdkProfile, sdkLevel;
488 if (mapper && mapper->mapProfile(pl.profile, &sdkProfile)
489 && mapper->mapLevel(pl.level, &sdkLevel)) {
490 caps->addProfileLevel(
491 (uint32_t)sdkProfile, (uint32_t)sdkLevel);
492 gotProfileLevels = true;
Chong Zhanga8d5b4f2018-12-04 17:05:29 -0800493 if (isHdr) {
494 auto hdrMapper = C2Mapper::GetHdrProfileLevelMapper(
495 trait.mediaType);
496 if (hdrMapper && hdrMapper->mapProfile(
497 pl.profile, &sdkProfile)) {
498 caps->addProfileLevel(
499 (uint32_t)sdkProfile,
500 (uint32_t)sdkLevel);
501 }
502 if (isHdr10Plus) {
503 hdrMapper = C2Mapper::GetHdrProfileLevelMapper(
504 trait.mediaType, true /*isHdr10Plus*/);
505 if (hdrMapper && hdrMapper->mapProfile(
506 pl.profile, &sdkProfile)) {
507 caps->addProfileLevel(
508 (uint32_t)sdkProfile,
509 (uint32_t)sdkLevel);
510 }
511 }
512 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800513 } else if (!mapper) {
514 caps->addProfileLevel(pl.profile, pl.level);
515 gotProfileLevels = true;
516 }
517
518 // for H.263 also advertise the second highest level if the
519 // codec supports level 45, as level 45 only covers level 10
520 // TODO: move this to some form of a setting so it does not
521 // have to be here
522 if (mediaType == MIMETYPE_VIDEO_H263) {
523 C2Config::level_t nextLevel = C2Config::LEVEL_UNUSED;
524 for (C2Value::Primitive v : levelQuery[0].values.values) {
525 C2Config::level_t level =
526 (C2Config::level_t)v.ref<uint32_t>();
527 if (level < C2Config::LEVEL_H263_45
528 && level > nextLevel) {
529 nextLevel = level;
530 }
531 }
532 if (nextLevel != C2Config::LEVEL_UNUSED
533 && nextLevel != pl.level
534 && mapper
535 && mapper->mapProfile(pl.profile, &sdkProfile)
536 && mapper->mapLevel(nextLevel, &sdkLevel)) {
537 caps->addProfileLevel(
538 (uint32_t)sdkProfile, (uint32_t)sdkLevel);
539 }
540 }
541 }
542 }
543 }
544 }
545 }
546 }
547
548 if (!gotProfileLevels) {
549 if (mediaType == MIMETYPE_VIDEO_VP9) {
550 if (encoder) {
551 caps->addProfileLevel(VP9Profile0, VP9Level41);
552 } else {
553 caps->addProfileLevel(VP9Profile0, VP9Level5);
554 caps->addProfileLevel(VP9Profile2, VP9Level5);
555 caps->addProfileLevel(VP9Profile2HDR, VP9Level5);
556 }
Ray Essick707c1462018-12-05 15:21:35 -0800557 } else if (mediaType == MIMETYPE_VIDEO_AV1 && !encoder) {
558 caps->addProfileLevel(AV1Profile0, AV1Level2);
559 caps->addProfileLevel(AV1Profile0, AV1Level21);
560 caps->addProfileLevel(AV1Profile1, AV1Level22);
561 caps->addProfileLevel(AV1Profile1, AV1Level3);
562 caps->addProfileLevel(AV1Profile2, AV1Level31);
563 caps->addProfileLevel(AV1Profile2, AV1Level32);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800564 } else if (mediaType == MIMETYPE_VIDEO_HEVC && !encoder) {
565 caps->addProfileLevel(HEVCProfileMain, HEVCMainTierLevel51);
566 caps->addProfileLevel(HEVCProfileMainStill, HEVCMainTierLevel51);
567 } else if (mediaType == MIMETYPE_VIDEO_VP8) {
568 if (encoder) {
569 caps->addProfileLevel(VP8ProfileMain, VP8Level_Version0);
570 } else {
571 caps->addProfileLevel(VP8ProfileMain, VP8Level_Version0);
572 }
573 } else if (mediaType == MIMETYPE_VIDEO_AVC) {
574 if (encoder) {
575 caps->addProfileLevel(AVCProfileBaseline, AVCLevel41);
576// caps->addProfileLevel(AVCProfileConstrainedBaseline, AVCLevel41);
577 caps->addProfileLevel(AVCProfileMain, AVCLevel41);
578 } else {
579 caps->addProfileLevel(AVCProfileBaseline, AVCLevel52);
580 caps->addProfileLevel(AVCProfileConstrainedBaseline, AVCLevel52);
581 caps->addProfileLevel(AVCProfileMain, AVCLevel52);
582 caps->addProfileLevel(AVCProfileConstrainedHigh, AVCLevel52);
583 caps->addProfileLevel(AVCProfileHigh, AVCLevel52);
584 }
585 } else if (mediaType == MIMETYPE_VIDEO_MPEG4) {
586 if (encoder) {
587 caps->addProfileLevel(MPEG4ProfileSimple, MPEG4Level2);
588 } else {
589 caps->addProfileLevel(MPEG4ProfileSimple, MPEG4Level3);
590 }
591 } else if (mediaType == MIMETYPE_VIDEO_H263) {
592 if (encoder) {
593 caps->addProfileLevel(H263ProfileBaseline, H263Level45);
594 } else {
595 caps->addProfileLevel(H263ProfileBaseline, H263Level30);
596 caps->addProfileLevel(H263ProfileBaseline, H263Level45);
597 caps->addProfileLevel(H263ProfileISWV2, H263Level30);
598 caps->addProfileLevel(H263ProfileISWV2, H263Level45);
599 }
600 } else if (mediaType == MIMETYPE_VIDEO_MPEG2 && !encoder) {
601 caps->addProfileLevel(MPEG2ProfileSimple, MPEG2LevelHL);
602 caps->addProfileLevel(MPEG2ProfileMain, MPEG2LevelHL);
603 }
604 }
605
606 // TODO: get this from intf() as well, but how do we map them to
607 // MediaCodec color formats?
608 if (mediaType.find("video") != std::string::npos) {
609 // vendor video codecs prefer opaque format
610 if (trait.name.find("android") == std::string::npos) {
611 caps->addColorFormat(COLOR_FormatSurface);
612 }
613 caps->addColorFormat(COLOR_FormatYUV420Flexible);
614 caps->addColorFormat(COLOR_FormatYUV420Planar);
615 caps->addColorFormat(COLOR_FormatYUV420SemiPlanar);
616 caps->addColorFormat(COLOR_FormatYUV420PackedPlanar);
617 caps->addColorFormat(COLOR_FormatYUV420PackedSemiPlanar);
618 // framework video encoders must support surface format, though it is unclear
619 // that they will be able to map it if it is opaque
620 if (encoder && trait.name.find("android") != std::string::npos) {
621 caps->addColorFormat(COLOR_FormatSurface);
622 }
623 }
624 }
625 }
626 return OK;
627}
628
629} // namespace android
630
631extern "C" android::MediaCodecListBuilderBase *CreateBuilder() {
632 return new android::Codec2InfoBuilder;
633}
634