Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix wrong selection of VP8 video decoder on some Samsung devices.
Browse files Browse the repository at this point in the history
- Create HW decoder using first codec in MediaCoedcList instead of
using createDecoderByType function. Later may result in opening
OMX.SEC.vp8.dec decoder, which can not be used for surface decoding.
- Revert r279297 and mark all OMX.SEC.* codecs as non HW accelerated.

BUG=408353, 396578
TBR=qinmin@chromium.org

Review URL: https://codereview.chromium.org/605883002

Cr-Commit-Position: refs/heads/master@{#297667}
(cherry picked from commit 6e86e4f)

Review URL: https://codereview.chromium.org/666953003

Cr-Commit-Position: refs/branch-heads/2171@{#190}
Cr-Branched-From: 267aeeb-refs/heads/master@{#297060}
  • Loading branch information
Victoria Kirst committed Oct 20, 2014
1 parent 274aa5b commit c1bc792
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ private static CodecInfo[] getCodecsInfo() {
return codecInfos.toArray(new CodecInfo[codecInfos.size()]);
}

/**
* Get a name of default android codec.
*/
@SuppressWarnings("deprecation")
@CalledByNative
private static String getDefaultCodecName(String mime, int direction) {
String codecName = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
MediaCodec mediaCodec = null;
if (direction == MEDIA_CODEC_ENCODER) {
mediaCodec = MediaCodec.createEncoderByType(mime);
} else {
mediaCodec = MediaCodec.createDecoderByType(mime);
}
codecName = mediaCodec.getName();
mediaCodec.release();
} catch (Exception e) {
Log.w(TAG, "getDefaultCodecName: Failed to create MediaCodec: " +
mime + ", direction: " + direction, e);
}
}
return codecName;
}

@SuppressWarnings("deprecation")
private static String getDecoderNameForMime(String mime) {
int count = MediaCodecList.getCodecCount();
Expand Down
55 changes: 44 additions & 11 deletions media/base/android/media_codec_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ bool MediaCodecBridge::SupportsSetParameters() {
return base::android::BuildInfo::GetInstance()->sdk_int() >= 19;
}

// static
bool MediaCodecBridge::SupportsGetName() {
// MediaCodec.getName() is only available on JB MR2 and greater.
return base::android::BuildInfo::GetInstance()->sdk_int() >= 18;
}

// static
std::vector<MediaCodecBridge::CodecsInfo> MediaCodecBridge::GetCodecsInfo() {
std::vector<CodecsInfo> codecs_info;
Expand Down Expand Up @@ -150,6 +156,20 @@ std::vector<MediaCodecBridge::CodecsInfo> MediaCodecBridge::GetCodecsInfo() {
return codecs_info;
}

// static
std::string MediaCodecBridge::GetDefaultCodecName(
const std::string& mime_type,
MediaCodecDirection direction) {
if (!IsAvailable())
return std::string();

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime_type);
ScopedJavaLocalRef<jstring> j_codec_name =
Java_MediaCodecBridge_getDefaultCodecName(env, j_mime.obj(), direction);
return ConvertJavaStringToUTF8(env, j_codec_name.obj());
}

// static
bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) {
if (!IsAvailable())
Expand All @@ -175,19 +195,32 @@ bool MediaCodecBridge::IsKnownUnaccelerated(const std::string& mime_type,
if (!IsAvailable())
return true;

std::string codec_type = AndroidMimeTypeToCodecType(mime_type);
std::vector<media::MediaCodecBridge::CodecsInfo> codecs_info =
MediaCodecBridge::GetCodecsInfo();
for (size_t i = 0; i < codecs_info.size(); ++i) {
if (codecs_info[i].codecs == codec_type &&
codecs_info[i].direction == direction) {
// It would be nice if MediaCodecInfo externalized some notion of
// HW-acceleration but it doesn't. Android Media guidance is that the
// prefix below is always used for SW decoders, so that's what we use.
if (!StartsWithASCII(codecs_info[i].name, "OMX.google.", true))
return false;
std::string codec_name;
if (SupportsGetName()) {
codec_name = GetDefaultCodecName(mime_type, direction);
} else {
std::string codec_type = AndroidMimeTypeToCodecType(mime_type);
std::vector<media::MediaCodecBridge::CodecsInfo> codecs_info =
MediaCodecBridge::GetCodecsInfo();
for (size_t i = 0; i < codecs_info.size(); ++i) {
if (codecs_info[i].codecs == codec_type &&
codecs_info[i].direction == direction) {
codec_name = codecs_info[i].name;
break;
}
}
}
DVLOG(1) << __PRETTY_FUNCTION__ << "Default codec for " << mime_type <<
" : " << codec_name;
// It would be nice if MediaCodecInfo externalized some notion of
// HW-acceleration but it doesn't. Android Media guidance is that the
// "OMX.google" prefix is always used for SW decoders, so that's what we
// use. "OMX.SEC.*" codec is Samsung software implementation - report it
// as unaccelerated as well.
if (codec_name.length() > 0) {
return (StartsWithASCII(codec_name, "OMX.google.", true) ||
StartsWithASCII(codec_name, "OMX.SEC.", true));
}
return true;
}

Expand Down
7 changes: 7 additions & 0 deletions media/base/android/media_codec_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class MEDIA_EXPORT MediaCodecBridge {
// Returns true if MediaCodec.setParameters() is available on the device.
static bool SupportsSetParameters();

// Returns true if MediaCodec.getName() is available on the device.
static bool SupportsGetName();

// Returns whether MediaCodecBridge has a decoder that |is_secure| and can
// decode |codec| type.
static bool CanDecode(const std::string& codec, bool is_secure);
Expand All @@ -74,6 +77,10 @@ class MEDIA_EXPORT MediaCodecBridge {
// Get a list of supported codecs.
static std::vector<CodecsInfo> GetCodecsInfo();

// Get default codec name for |mime_type|.
static std::string GetDefaultCodecName(const std::string& mime_type,
MediaCodecDirection direction);

virtual ~MediaCodecBridge();

// Resets both input and output, all indices previously returned in calls to
Expand Down

0 comments on commit c1bc792

Please sign in to comment.