Bug 953394 - Force OMXCodec to output a sane colour format on Android 4.4 and above r=doublec

This commit is contained in:
Edwin Flores 2014-01-09 14:54:57 +13:00
parent 0cfe5a3801
commit ed3d2608a0
5 changed files with 157 additions and 8 deletions

View File

@ -152,7 +152,13 @@ static const char* GetOmxLibraryName()
return nullptr;
#if defined(ANDROID) && !defined(MOZ_WIDGET_GONK)
if (version == 13 || version == 12 || version == 11) {
/*
if (version >= 19) {
*/
if (version >= 16) {
return "libomxpluginkk.so";
}
else if (version == 13 || version == 12 || version == 11) {
return "libomxpluginhc.so";
}
else if (version == 10 && release_version >= NS_LITERAL_STRING("2.3.6")) {
@ -180,7 +186,7 @@ static const char* GetOmxLibraryName()
return nullptr;
}
// Default libomxplugin for non-gingerbread devices
// Ice Cream Sandwich and Jellybean
return "libomxplugin.so";
#elif defined(ANDROID) && defined(MOZ_WIDGET_GONK)

View File

@ -23,6 +23,9 @@
#include "android/log.h"
#define MAX_DECODER_NAME_LEN 256
#define AVC_MIME_TYPE "video/avc"
#if !defined(MOZ_ANDROID_FROYO)
#define DEFAULT_STAGEFRIGHT_FLAGS OMXCodec::kClientNeedsFramebuffer
#else
@ -239,7 +242,13 @@ static uint32_t GetVideoCreationFlags(PluginHost* aPluginHost)
#endif
}
static bool
enum ColorFormatSupport {
ColorFormatNotSupported = 0,
ColorFormatSupportOK,
ColorFormatSupportPreferred,
};
static ColorFormatSupport
IsColorFormatSupported(OMX_COLOR_FORMATTYPE aColorFormat)
{
switch (aColorFormat) {
@ -250,15 +259,19 @@ IsColorFormatSupported(OMX_COLOR_FORMATTYPE aColorFormat)
case OMX_QCOM_COLOR_FormatYVU420SemiPlanar:
case OMX_TI_COLOR_FormatYUV420PackedSemiPlanar:
LOG("Colour format %#x supported natively.", aColorFormat);
return true;
// Prefer natively supported colour formats over formats that need another
// slow software conversion.
return ColorFormatSupportPreferred;
default:
break;
}
// These formats are okay if we can't find a better one; Android provides a
// software conversion to a sane colour format.
#if !defined(MOZ_ANDROID_HC)
if (ColorConverter(aColorFormat, OMX_COLOR_Format16bitRGB565).isValid()) {
LOG("Colour format %#x supported by Android ColorConverter.", aColorFormat);
return true;
return ColorFormatSupportOK;
}
#endif
@ -268,12 +281,64 @@ IsColorFormatSupported(OMX_COLOR_FORMATTYPE aColorFormat)
if (yuvConverter.isLoaded() &&
yuvConverter.getDecoderOutputFormat() == aColorFormat) {
LOG("Colour format %#x supported by Android I420ColorConverter.", aColorFormat);
return true;
return ColorFormatSupportOK;
}
#endif
return ColorFormatNotSupported;
}
#if defined(MOZ_ANDROID_KK)
/**
* Look for a decoder that supports a colour format that we support.
*/
static bool
FindPreferredDecoderAndColorFormat(const sp<IOMX>& aOmx,
char *aDecoderName,
size_t aDecoderLen,
OMX_COLOR_FORMATTYPE *aColorFormat)
{
Vector<CodecCapabilities> codecs;
// Get all AVC decoder/colour format pairs that this device supports.
QueryCodecs(aOmx, AVC_MIME_TYPE, true /* queryDecoders */, &codecs);
// We assume that faster (hardware accelerated) decoders come first in the
// list, so we choose the first decoder with a colour format we can use.
for (uint32_t i = 0; i < codecs.size(); i++) {
const CodecCapabilities &caps = codecs[i];
const Vector<OMX_U32> &colors = caps.mColorFormats;
bool found = false;
for (uint32_t j = 0; j < colors.size(); j++) {
OMX_COLOR_FORMATTYPE color = (OMX_COLOR_FORMATTYPE)colors[j];
LOG("Decoder %s can output colour format %#x.\n",
caps.mComponentName.string(), color);
ColorFormatSupport supported = IsColorFormatSupported(color);
if (supported) {
strncpy(aDecoderName, caps.mComponentName.string(), aDecoderLen);
*aColorFormat = (OMX_COLOR_FORMATTYPE)color;
found = true;
}
if (supported == ColorFormatSupportPreferred) {
// The colour format is natively supported -- that's as good as we're
// going to get.
break;
}
}
if (found) {
return true;
}
}
return false;
}
#endif
static sp<MediaSource> CreateVideoSource(PluginHost* aPluginHost,
const sp<IOMX>& aOmx,
@ -281,10 +346,29 @@ static sp<MediaSource> CreateVideoSource(PluginHost* aPluginHost,
{
uint32_t flags = GetVideoCreationFlags(aPluginHost);
char decoderName[MAX_DECODER_NAME_LEN] = "";
sp<MetaData> videoFormat = aVideoTrack->getFormat();
#if defined(MOZ_ANDROID_KK)
OMX_COLOR_FORMATTYPE colorFormat = (OMX_COLOR_FORMATTYPE)0;
if (FindPreferredDecoderAndColorFormat(aOmx,
decoderName, sizeof(decoderName),
&colorFormat)) {
// We found a colour format that we can handle. Tell OMXCodec to use it in
// case it isn't the default.
videoFormat->setInt32(kKeyColorFormat, colorFormat);
LOG("Found compatible decoder %s with colour format %#x.\n",
decoderName, colorFormat);
}
#endif
if (flags == DEFAULT_STAGEFRIGHT_FLAGS) {
// Let Stagefright choose hardware or software decoder.
sp<MediaSource> videoSource = OMXCodec::Create(aOmx, aVideoTrack->getFormat(),
false, aVideoTrack, nullptr, flags);
sp<MediaSource> videoSource = OMXCodec::Create(aOmx, videoFormat,
false, aVideoTrack,
decoderName[0] ? decoderName : nullptr,
flags);
if (videoSource == nullptr)
return nullptr;

View File

@ -0,0 +1,31 @@
# Copyright 2012 Mozilla Foundation and Mozilla contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Don't use STL wrappers; this isn't Gecko code
STL_FLAGS =
# must link statically with the CRT; this isn't Gecko code
USE_STATIC_LIBS = 1
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += \
-L$(DEPTH)/media/omx-plugin/lib/ics/libutils \
-lutils \
-L$(DEPTH)/media/omx-plugin/lib/ics/libstagefright \
-lstagefright \
-L$(DEPTH)/media/omx-plugin/lib/ics/libvideoeditorplayer \
-lvideoeditorplayer \
$(NULL)

View File

@ -0,0 +1,8 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#define MOZ_STAGEFRIGHT_OFF_T off64_t
#define MOZ_ANDROID_KK
#include "../OmxPlugin.cpp"

View File

@ -0,0 +1,20 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
SOURCES += [
'OmxPluginKitKat.cpp',
]
LIBRARY_NAME = 'omxpluginkk'
FORCE_SHARED_LIB = True
LOCAL_INCLUDES += [
'../../../content/media/plugins',
'../include/ics',
'../include/ics/media/stagefright/openmax',
]