Bug 785536 - Add PluginHost->GetPref() so platform decoders can query about:config prefs. r=doublec

This commit is contained in:
Chris Peterson 2012-08-24 14:20:39 -07:00
parent d3986e96db
commit 7d31c29958
4 changed files with 61 additions and 5 deletions

View File

@ -100,6 +100,7 @@ struct PluginHost {
uint64_t (*GetLength)(Decoder *aDecoder);
void (*SetMetaDataReadMode)(Decoder *aDecoder);
void (*SetPlaybackReadMode)(Decoder *aDecoder);
bool (*GetIntPref)(const char *aPref, int32_t *aResult);
};
struct Decoder {

View File

@ -3,6 +3,7 @@
/* 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/. */
#include "mozilla/Preferences.h"
#include "mozilla/TimeStamp.h"
#include "nsTimeRanges.h"
#include "MediaResource.h"
@ -54,11 +55,34 @@ static void SetPlaybackReadMode(Decoder *aDecoder)
GetResource(aDecoder)->SetReadMode(nsMediaCacheStream::MODE_PLAYBACK);
}
class GetIntPrefEvent : public nsRunnable {
public:
GetIntPrefEvent(const char* aPref, int32_t* aResult)
: mPref(aPref), mResult(aResult) {}
NS_IMETHOD Run() {
return Preferences::GetInt(mPref, mResult);
}
private:
const char* mPref;
int32_t* mResult;
};
static bool GetIntPref(const char* aPref, int32_t* aResult)
{
// GetIntPref() is called on the decoder thread, but the Preferences API
// can only be called on the main thread. Post a runnable and wait.
NS_ENSURE_ARG_POINTER(aPref);
NS_ENSURE_ARG_POINTER(aResult);
nsCOMPtr<GetIntPrefEvent> event = new GetIntPrefEvent(aPref, aResult);
return NS_SUCCEEDED(NS_DispatchToMainThread(event, NS_DISPATCH_SYNC));
}
static PluginHost sPluginHost = {
Read,
GetLength,
SetMetaDataReadMode,
SetPlaybackReadMode
SetPlaybackReadMode,
GetIntPref
};
void nsMediaPluginHost::TryLoad(const char *name)

View File

@ -230,6 +230,33 @@ static sp<IOMX> GetOMX() {
}
#endif
static uint32_t GetVideoCreationFlags(PluginHost* pluginHost)
{
#ifdef MOZ_WIDGET_GONK
// Flag value of zero means return a hardware or software decoder
// depending on what the device supports.
return 0;
#else
// Check whether the user has set a pref to override our default OMXCodec
// CreationFlags flags. This is useful for A/B testing hardware and software
// decoders for performance and bugs. The interesting flag values are:
// 0 = Let Stagefright choose hardware or software decoding (default)
// 8 = Force software decoding
// 16 = Force hardware decoding
int32_t flags = 0;
pluginHost->GetIntPref("media.stagefright.omxcodec.flags", &flags);
if (flags != 0) {
LOG("media.stagefright.omxcodec.flags=%d", flags);
if ((flags & OMXCodec::kHardwareCodecsOnly) != 0) {
LOG("FORCE HARDWARE DECODING");
} else if ((flags & OMXCodec::kSoftwareCodecsOnly) != 0) {
LOG("FORCE SOFTWARE DECODING");
}
}
return static_cast<uint32_t>(flags);
#endif
}
bool OmxDecoder::Init() {
//register sniffers, if they are not registered in this process.
DataSource::RegisterDefaultSniffers();
@ -291,13 +318,11 @@ bool OmxDecoder::Init() {
}
sp<IOMX> omx = mClient.interface();
#endif
// Flag value of zero means return a hardware or software decoder
// depending on what the device supports.
uint32_t flags = 0;
sp<MediaSource> videoTrack;
sp<MediaSource> videoSource;
if (videoTrackIndex != -1 && (videoTrack = extractor->getTrack(videoTrackIndex)) != NULL) {
uint32_t flags = GetVideoCreationFlags(mPluginHost);
videoSource = OMXCodec::Create(omx,
videoTrack->getFormat(),
false, // decoder
@ -406,7 +431,7 @@ bool OmxDecoder::SetVideoFormat() {
LOG("rotation not available, assuming 0");
}
LOG("width: %d height: %d component: %s format: %d stride: %d sliceHeight: %d rotation: %d",
LOG("width: %d height: %d component: %s format: %#x stride: %d sliceHeight: %d rotation: %d",
mVideoWidth, mVideoHeight, componentName, mVideoColorFormat,
mVideoStride, mVideoSliceHeight, mVideoRotation);

View File

@ -658,6 +658,12 @@ pref("reader.has_used_toolbar", false);
// Media plugins for libstagefright playback on android
pref("media.plugins.enabled", true);
// Stagefright's OMXCodec::CreationFlags. The interesting flag values are:
// 0 = Let Stagefright choose hardware or software decoding (default)
// 8 = Force software decoding
// 16 = Force hardware decoding
pref("media.stagefright.omxcodec.flags", 0);
// Coalesce touch events to prevent them from flooding the event queue
pref("dom.event.touch.coalescing.enabled", true);