blob: 5d0ccd2039eba56ab2af7328d0c4c84d640a2196 [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) {
453 for (C2Value::Primitive profile : profileQuery[0].values.values) {
454 pl.profile = (C2Config::profile_t)profile.ref<uint32_t>();
455 std::vector<std::unique_ptr<C2SettingResult>> failures;
456 err = intf->config({&pl}, C2_DONT_BLOCK, &failures);
457 ALOGV("set profile to %u -> %s", pl.profile, asString(err));
458 std::vector<C2FieldSupportedValuesQuery> levelQuery = {
459 C2FieldSupportedValuesQuery::Current(C2ParamField(&pl, &pl.level))
460 };
461 err = intf->querySupportedValues(levelQuery, C2_DONT_BLOCK);
462 ALOGV("query supported levels -> %s | %s",
463 asString(err), asString(levelQuery[0].status));
464 if (err == C2_OK && levelQuery[0].status == C2_OK) {
465 if (levelQuery[0].values.type == C2FieldSupportedValues::VALUES
466 && levelQuery[0].values.values.size() > 0) {
467 C2Value::Primitive level = levelQuery[0].values.values.back();
468 pl.level = (C2Config::level_t)level.ref<uint32_t>();
469 ALOGV("supporting level: %u", pl.level);
470 int32_t sdkProfile, sdkLevel;
471 if (mapper && mapper->mapProfile(pl.profile, &sdkProfile)
472 && mapper->mapLevel(pl.level, &sdkLevel)) {
473 caps->addProfileLevel(
474 (uint32_t)sdkProfile, (uint32_t)sdkLevel);
475 gotProfileLevels = true;
476 } else if (!mapper) {
477 caps->addProfileLevel(pl.profile, pl.level);
478 gotProfileLevels = true;
479 }
480
481 // for H.263 also advertise the second highest level if the
482 // codec supports level 45, as level 45 only covers level 10
483 // TODO: move this to some form of a setting so it does not
484 // have to be here
485 if (mediaType == MIMETYPE_VIDEO_H263) {
486 C2Config::level_t nextLevel = C2Config::LEVEL_UNUSED;
487 for (C2Value::Primitive v : levelQuery[0].values.values) {
488 C2Config::level_t level =
489 (C2Config::level_t)v.ref<uint32_t>();
490 if (level < C2Config::LEVEL_H263_45
491 && level > nextLevel) {
492 nextLevel = level;
493 }
494 }
495 if (nextLevel != C2Config::LEVEL_UNUSED
496 && nextLevel != pl.level
497 && mapper
498 && mapper->mapProfile(pl.profile, &sdkProfile)
499 && mapper->mapLevel(nextLevel, &sdkLevel)) {
500 caps->addProfileLevel(
501 (uint32_t)sdkProfile, (uint32_t)sdkLevel);
502 }
503 }
504 }
505 }
506 }
507 }
508 }
509 }
510
511 if (!gotProfileLevels) {
512 if (mediaType == MIMETYPE_VIDEO_VP9) {
513 if (encoder) {
514 caps->addProfileLevel(VP9Profile0, VP9Level41);
515 } else {
516 caps->addProfileLevel(VP9Profile0, VP9Level5);
517 caps->addProfileLevel(VP9Profile2, VP9Level5);
518 caps->addProfileLevel(VP9Profile2HDR, VP9Level5);
519 }
Ray Essick707c1462018-12-05 15:21:35 -0800520 } else if (mediaType == MIMETYPE_VIDEO_AV1 && !encoder) {
521 caps->addProfileLevel(AV1Profile0, AV1Level2);
522 caps->addProfileLevel(AV1Profile0, AV1Level21);
523 caps->addProfileLevel(AV1Profile1, AV1Level22);
524 caps->addProfileLevel(AV1Profile1, AV1Level3);
525 caps->addProfileLevel(AV1Profile2, AV1Level31);
526 caps->addProfileLevel(AV1Profile2, AV1Level32);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800527 } else if (mediaType == MIMETYPE_VIDEO_HEVC && !encoder) {
528 caps->addProfileLevel(HEVCProfileMain, HEVCMainTierLevel51);
529 caps->addProfileLevel(HEVCProfileMainStill, HEVCMainTierLevel51);
530 } else if (mediaType == MIMETYPE_VIDEO_VP8) {
531 if (encoder) {
532 caps->addProfileLevel(VP8ProfileMain, VP8Level_Version0);
533 } else {
534 caps->addProfileLevel(VP8ProfileMain, VP8Level_Version0);
535 }
536 } else if (mediaType == MIMETYPE_VIDEO_AVC) {
537 if (encoder) {
538 caps->addProfileLevel(AVCProfileBaseline, AVCLevel41);
539// caps->addProfileLevel(AVCProfileConstrainedBaseline, AVCLevel41);
540 caps->addProfileLevel(AVCProfileMain, AVCLevel41);
541 } else {
542 caps->addProfileLevel(AVCProfileBaseline, AVCLevel52);
543 caps->addProfileLevel(AVCProfileConstrainedBaseline, AVCLevel52);
544 caps->addProfileLevel(AVCProfileMain, AVCLevel52);
545 caps->addProfileLevel(AVCProfileConstrainedHigh, AVCLevel52);
546 caps->addProfileLevel(AVCProfileHigh, AVCLevel52);
547 }
548 } else if (mediaType == MIMETYPE_VIDEO_MPEG4) {
549 if (encoder) {
550 caps->addProfileLevel(MPEG4ProfileSimple, MPEG4Level2);
551 } else {
552 caps->addProfileLevel(MPEG4ProfileSimple, MPEG4Level3);
553 }
554 } else if (mediaType == MIMETYPE_VIDEO_H263) {
555 if (encoder) {
556 caps->addProfileLevel(H263ProfileBaseline, H263Level45);
557 } else {
558 caps->addProfileLevel(H263ProfileBaseline, H263Level30);
559 caps->addProfileLevel(H263ProfileBaseline, H263Level45);
560 caps->addProfileLevel(H263ProfileISWV2, H263Level30);
561 caps->addProfileLevel(H263ProfileISWV2, H263Level45);
562 }
563 } else if (mediaType == MIMETYPE_VIDEO_MPEG2 && !encoder) {
564 caps->addProfileLevel(MPEG2ProfileSimple, MPEG2LevelHL);
565 caps->addProfileLevel(MPEG2ProfileMain, MPEG2LevelHL);
566 }
567 }
568
569 // TODO: get this from intf() as well, but how do we map them to
570 // MediaCodec color formats?
571 if (mediaType.find("video") != std::string::npos) {
572 // vendor video codecs prefer opaque format
573 if (trait.name.find("android") == std::string::npos) {
574 caps->addColorFormat(COLOR_FormatSurface);
575 }
576 caps->addColorFormat(COLOR_FormatYUV420Flexible);
577 caps->addColorFormat(COLOR_FormatYUV420Planar);
578 caps->addColorFormat(COLOR_FormatYUV420SemiPlanar);
579 caps->addColorFormat(COLOR_FormatYUV420PackedPlanar);
580 caps->addColorFormat(COLOR_FormatYUV420PackedSemiPlanar);
581 // framework video encoders must support surface format, though it is unclear
582 // that they will be able to map it if it is opaque
583 if (encoder && trait.name.find("android") != std::string::npos) {
584 caps->addColorFormat(COLOR_FormatSurface);
585 }
586 }
587 }
588 }
589 return OK;
590}
591
592} // namespace android
593
594extern "C" android::MediaCodecListBuilderBase *CreateBuilder() {
595 return new android::Codec2InfoBuilder;
596}
597