Bug 834172 - Implement CreateReader in DecoderTraits. r=cpearce

MediaDecoderReaders are now created from within DecoderTraits. The
codec-specific code has been removed from class MediaDecodeTask.
This commit is contained in:
Thomas Zimmermann 2013-03-04 10:24:45 -05:00
parent c2d0a094e1
commit d496d84db9
3 changed files with 74 additions and 81 deletions

View File

@ -7,43 +7,48 @@
#include "DecoderTraits.h"
#include "MediaDecoder.h"
#include "nsCharSeparatedTokenizer.h"
#ifdef MOZ_MEDIA_PLUGINS
#include "MediaPluginHost.h"
#endif
#ifdef MOZ_GSTREAMER
#include "mozilla/Preferences.h"
#endif
#ifdef MOZ_WMF
#include "WMFDecoder.h"
#endif
#ifdef MOZ_OGG
#include "OggDecoder.h"
#include "OggReader.h"
#endif
#ifdef MOZ_WAVE
#include "WaveDecoder.h"
#include "WaveReader.h"
#endif
#ifdef MOZ_WEBM
#include "WebMDecoder.h"
#include "WebMReader.h"
#endif
#ifdef MOZ_RAW
#include "RawDecoder.h"
#include "RawReader.h"
#endif
#ifdef MOZ_GSTREAMER
#include "mozilla/Preferences.h"
#include "GStreamerDecoder.h"
#include "GStreamerReader.h"
#endif
#ifdef MOZ_MEDIA_PLUGINS
#include "MediaPluginHost.h"
#include "MediaPluginDecoder.h"
#include "MediaPluginReader.h"
#include "MediaPluginHost.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "MediaOmxDecoder.h"
#include "MediaOmxReader.h"
#endif
#ifdef MOZ_DASH
#include "DASHDecoder.h"
#endif
#ifdef MOZ_WMF
#include "WMFDecoder.h"
#include "WMFReader.h"
#endif
namespace mozilla
@ -440,6 +445,60 @@ DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
return decoder.forget();
}
/* static */
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
{
MediaDecoderReader* decoderReader = nullptr;
#ifdef MOZ_GSTREAMER
if (IsGStreamerSupportedType(aType)) {
decoderReader = new GStreamerReader(aDecoder);
} else
#endif
#ifdef MOZ_RAW
if (IsRawType(aType)) {
decoderReader = new RawReader(aDecoder);
} else
#endif
#ifdef MOZ_OGG
if (IsOggType(aType)) {
decoderReader = new OggReader(aDecoder);
} else
#endif
#ifdef MOZ_WAVE
if (IsWaveType(aType)) {
decoderReader = new WaveReader(aDecoder);
} else
#endif
#ifdef MOZ_WIDGET_GONK
if (IsOmxSupportedType(aType)) {
decoderReader = new MediaOmxReader(aDecoder);
} else
#endif
#ifdef MOZ_MEDIA_PLUGINS
if (MediaDecoder::IsMediaPluginsEnabled() &&
GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
decoderReader = new MediaPluginReader(aDecoder, aType);
} else
#endif
#ifdef MOZ_WEBM
if (IsWebMType(aType)) {
decoderReader = new WebMReader(aDecoder);
} else
#endif
#ifdef MOZ_WMF
if (IsWMFSupportedType(aType)) {
decoderReader = new WMFReader(aDecoder);
} else
#endif
#ifdef MOZ_DASH
// The DASH decoder is not supported.
#endif
if (false) {} // dummy if to take care of the dangling else
return decoderReader;
}
/* static */
bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
{

View File

@ -10,11 +10,12 @@
#include "nsCOMPtr.h"
#include "nsAString.h"
namespace mozilla
{
namespace mozilla {
class AbstractMediaDecoder;
class MediaDecoder;
class MediaDecoderOwner;
class MediaDecoderReader;
enum CanPlayStatus {
CANPLAY_NO,
@ -84,6 +85,11 @@ public:
static already_AddRefed<MediaDecoder> CreateDecoder(const nsACString& aType,
MediaDecoderOwner* aOwner);
// Create a reader for thew given MIME type aType. Returns null
// if we were unable to create the reader.
static MediaDecoderReader* CreateReader(const nsACString& aType,
AbstractMediaDecoder* aDecoder);
// Returns true if MIME type aType is supported in video documents,
// or false otherwise. Not all platforms support all MIME types, and
// vice versa.

View File

@ -22,34 +22,6 @@
#include "nsIScriptError.h"
#include "nsMimeTypes.h"
#ifdef MOZ_GSTREAMER
#include "GStreamerReader.h"
#endif
#ifdef MOZ_RAW
#include "RawReader.h"
#endif
#ifdef MOZ_OGG
#include "OggReader.h"
#endif
#ifdef MOZ_WAVE
#include "WaveReader.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "MediaOmxReader.h"
#endif
#ifdef MOZ_MEDIA_PLUGINS
#include "MediaDecoder.h"
#include "MediaPluginDecoder.h"
#include "MediaPluginReader.h"
#include "MediaPluginHost.h"
#endif
#ifdef MOZ_WEBM
#include "WebMReader.h"
#endif
#ifdef MOZ_WMF
#include "WMFReader.h"
#endif
namespace mozilla {
using namespace dom;
@ -427,51 +399,7 @@ MediaDecodeTask::CreateReader()
// If you change this list to add support for new decoders, please consider
// updating nsHTMLMediaElement::CreateDecoder as well.
#ifdef MOZ_GSTREAMER
if (DecoderTraits::IsGStreamerSupportedType(mContentType)) {
mDecoderReader = new GStreamerReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_RAW
if (DecoderTraits::IsRawType(mContentType)) {
mDecoderReader = new RawReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_OGG
if (DecoderTraits::IsOggType(mContentType)) {
mDecoderReader = new OggReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_WAVE
if (DecoderTraits::IsWaveType(mContentType)) {
mDecoderReader = new WaveReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_WIDGET_GONK
if (DecoderTraits::IsOmxSupportedType(mContentType)) {
mDecoderReader = new MediaOmxReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_MEDIA_PLUGINS
if (MediaDecoder::IsMediaPluginsEnabled() &&
GetMediaPluginHost()->FindDecoder(mContentType, nullptr)) {
mDecoderReader = new MediaPluginReader(mBufferDecoder, mContentType);
} else
#endif
#ifdef MOZ_WEBM
if (DecoderTraits::IsWebMType(mContentType)) {
mDecoderReader = new WebMReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_WMF
if (DecoderTraits::IsWMFSupportedType(mContentType)) {
mDecoderReader = new WMFReader(mBufferDecoder);
} else
#endif
#ifdef MOZ_DASH
// The DASH decoder is not supported.
#endif
if (false) {} // dummy if to take care of the dangling else
mDecoderReader = DecoderTraits::CreateReader(mContentType, mBufferDecoder);
if (!mDecoderReader) {
return false;