Bug 819609: Don't try to send too-large videos to hardware video decoders. r=doublec a=blocking-basecamp

This commit is contained in:
Chris Jones 2012-12-10 23:48:58 -08:00
Родитель 017e9c52ee
Коммит 74dfa6d566
2 изменённых файлов: 45 добавлений и 12 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include <fcntl.h>
#include "base/basictypes.h"
#include <cutils/properties.h>
#include <stagefright/DataSource.h>
#include <stagefright/MediaExtractor.h>
#include <stagefright/MetaData.h>
@ -232,21 +233,51 @@ bool OmxDecoder::Init() {
if (videoTrackIndex != -1 && (videoTrack = extractor->getTrack(videoTrackIndex)) != nullptr) {
int flags = 0; // prefer hw codecs
// XXX is this called off the main thread?
if (mozilla::Preferences::GetBool("media.omx.prefer_software_codecs", false)) {
flags |= kPreferSoftwareCodecs;
}
videoSource = OMXCodec::Create(GetOMX(),
videoTrack->getFormat(),
false, // decoder
videoTrack,
nullptr,
flags,
mNativeWindow);
if (videoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
return false;
}
do {
videoSource = OMXCodec::Create(GetOMX(),
videoTrack->getFormat(),
false, // decoder
videoTrack,
nullptr,
flags,
mNativeWindow);
if (videoSource == nullptr) {
NS_WARNING("Couldn't create OMX video source");
return false;
}
if (flags & kSoftwareCodecsOnly) {
break;
}
// Check if this video is sized such that we're comfortable
// possibly using a hardware decoder. If we can't get the size,
// fall back on SW to be safe.
int32_t maxWidth, maxHeight;
char propValue[PROPERTY_VALUE_MAX];
property_get("ro.moz.omx.hw.max_width", propValue, "-1");
maxWidth = atoi(propValue);
property_get("ro.moz.omx.hw.max_height", propValue, "-1");
maxHeight = atoi(propValue);
int32_t width = -1, height = -1;
if (maxWidth > 0 && maxHeight > 0 &&
!(videoSource->getFormat()->findInt32(kKeyWidth, &width) &&
videoSource->getFormat()->findInt32(kKeyHeight, &height) &&
width * height <= maxWidth * maxHeight)) {
printf_stderr("Failed to get video size, or it was too large for HW decoder (<w=%d, h=%d> but <maxW=%d, maxH=%d>)",
width, height, maxWidth, maxHeight);
videoSource.clear();
flags |= kSoftwareCodecsOnly;
continue;
}
break;
} while(true);
if (videoSource->start() != OK) {
NS_WARNING("Couldn't start OMX video source");

Просмотреть файл

@ -69,7 +69,9 @@ class OmxDecoder {
typedef mozilla::AbstractMediaDecoder AbstractMediaDecoder;
enum {
kPreferSoftwareCodecs = 1
kPreferSoftwareCodecs = 1,
kSoftwareCodecsOnly = 8,
kHardwareCodecsOnly = 16,
};
AbstractMediaDecoder *mDecoder;