Bug 834172 - Implement CreateDecoder in DecoderTraits. r=cpearce

The class DecoderTraits knows about all supported decoders. Adding
an interface to create decoder instances simplifies all users of this
functionality. nsHtmlMediaElement has been updated to use the new
function.
This commit is contained in:
Thomas Zimmermann 2013-03-05 09:56:34 -05:00
Родитель 3a831e50dd
Коммит 3f3ba124ad
4 изменённых файлов: 97 добавлений и 119 удалений

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

@ -379,12 +379,6 @@ protected:
*/
already_AddRefed<DOMMediaStream> CaptureStreamInternal(bool aFinishWhenEnded);
/**
* Create a decoder for the given aMIMEType. Returns null if we
* were unable to create the decoder.
*/
already_AddRefed<MediaDecoder> CreateDecoder(const nsACString& aMIMEType);
/**
* Initialize a decoder as a clone of an existing decoder in another
* element.

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

@ -75,35 +75,6 @@
#include "nsIPowerManagerService.h"
#include <algorithm>
#ifdef MOZ_OGG
#include "OggDecoder.h"
#endif
#ifdef MOZ_WAVE
#include "WaveDecoder.h"
#endif
#ifdef MOZ_WEBM
#include "WebMDecoder.h"
#endif
#ifdef MOZ_RAW
#include "RawDecoder.h"
#endif
#ifdef MOZ_GSTREAMER
#include "GStreamerDecoder.h"
#endif
#ifdef MOZ_MEDIA_PLUGINS
#include "MediaPluginHost.h"
#include "MediaPluginDecoder.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "MediaOmxDecoder.h"
#endif
#ifdef MOZ_DASH
#include "DASHDecoder.h"
#endif
#ifdef MOZ_WMF
#include "WMFDecoder.h"
#endif
#ifdef PR_LOGGING
static PRLogModuleInfo* gMediaElementLog;
static PRLogModuleInfo* gMediaElementEventsLog;
@ -2194,89 +2165,6 @@ nsHTMLMediaElement::CanPlayType(const nsAString& aType, nsAString& aResult)
return NS_OK;
}
already_AddRefed<MediaDecoder>
nsHTMLMediaElement::CreateDecoder(const nsACString& aType)
{
// If you change this list to add support for new decoders for codecs that
// can be used by <audio>, please consider updating MediaDecodeTask::CreateDecoder
// as well.
#ifdef MOZ_GSTREAMER
if (DecoderTraits::IsGStreamerSupportedType(aType)) {
nsRefPtr<GStreamerDecoder> decoder = new GStreamerDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_RAW
if (DecoderTraits::IsRawType(aType)) {
nsRefPtr<RawDecoder> decoder = new RawDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_OGG
if (DecoderTraits::IsOggType(aType)) {
nsRefPtr<OggDecoder> decoder = new OggDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_WAVE
if (DecoderTraits::IsWaveType(aType)) {
nsRefPtr<WaveDecoder> decoder = new WaveDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_WIDGET_GONK
if (DecoderTraits::IsOmxSupportedType(aType)) {
nsRefPtr<MediaOmxDecoder> decoder = new MediaOmxDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_MEDIA_PLUGINS
if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) {
nsRefPtr<MediaPluginDecoder> decoder = new MediaPluginDecoder(aType);
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_WEBM
if (DecoderTraits::IsWebMType(aType)) {
nsRefPtr<WebMDecoder> decoder = new WebMDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_DASH
if (DecoderTraits::IsDASHMPDType(aType)) {
nsRefPtr<DASHDecoder> decoder = new DASHDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
#ifdef MOZ_WMF
if (DecoderTraits::IsWMFSupportedType(aType)) {
nsRefPtr<WMFDecoder> decoder = new WMFDecoder();
if (decoder->Init(this)) {
return decoder.forget();
}
}
#endif
return nullptr;
}
nsresult nsHTMLMediaElement::InitializeDecoderAsClone(MediaDecoder* aOriginal)
{
NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
@ -2323,7 +2211,7 @@ nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
aChannel->GetContentType(mimeType);
NS_ASSERTION(!mimeType.IsEmpty(), "We should have the Content-Type.");
nsRefPtr<MediaDecoder> decoder = CreateDecoder(mimeType);
nsRefPtr<MediaDecoder> decoder = DecoderTraits::CreateDecoder(mimeType, this);
if (!decoder) {
nsAutoString src;
GetCurrentSrc(src);

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

@ -17,6 +17,35 @@
#include "WMFDecoder.h"
#endif
#ifdef MOZ_OGG
#include "OggDecoder.h"
#endif
#ifdef MOZ_WAVE
#include "WaveDecoder.h"
#endif
#ifdef MOZ_WEBM
#include "WebMDecoder.h"
#endif
#ifdef MOZ_RAW
#include "RawDecoder.h"
#endif
#ifdef MOZ_GSTREAMER
#include "GStreamerDecoder.h"
#endif
#ifdef MOZ_MEDIA_PLUGINS
#include "MediaPluginHost.h"
#include "MediaPluginDecoder.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "MediaOmxDecoder.h"
#endif
#ifdef MOZ_DASH
#include "DASHDecoder.h"
#endif
#ifdef MOZ_WMF
#include "WMFDecoder.h"
#endif
namespace mozilla
{
@ -353,5 +382,63 @@ DecoderTraits::CanHandleMediaType(const char* aMIMEType,
return CANPLAY_YES;
}
/* static */
already_AddRefed<MediaDecoder>
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
nsRefPtr<MediaDecoder> decoder;
#ifdef MOZ_GSTREAMER
if (IsGStreamerSupportedType(aType)) {
decoder = new GStreamerDecoder();
}
#endif
#ifdef MOZ_RAW
if (IsRawType(aType)) {
decoder = new RawDecoder();
}
#endif
#ifdef MOZ_OGG
if (IsOggType(aType)) {
decoder = new OggDecoder();
}
#endif
#ifdef MOZ_WAVE
if (IsWaveType(aType)) {
decoder = new WaveDecoder();
}
#endif
#ifdef MOZ_WIDGET_GONK
if (IsOmxSupportedType(aType)) {
decoder = new MediaOmxDecoder();
}
#endif
#ifdef MOZ_MEDIA_PLUGINS
if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) {
decoder = new MediaPluginDecoder(aType);
}
#endif
#ifdef MOZ_WEBM
if (IsWebMType(aType)) {
decoder = new WebMDecoder();
}
#endif
#ifdef MOZ_DASH
if (IsDASHMPDType(aType)) {
decoder = new DASHDecoder();
}
#endif
#ifdef MOZ_WMF
if (IsWMFSupportedType(aType)) {
decoder = new WMFDecoder();
}
#endif
NS_ENSURE_TRUE(decoder != nullptr, nullptr);
NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
return decoder.forget();
}
}

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

@ -7,11 +7,15 @@
#ifndef DecoderTraits_h_
#define DecoderTraits_h_
#include "nsCOMPtr.h"
#include "nsAString.h"
namespace mozilla
{
class MediaDecoder;
class MediaDecoderOwner;
enum CanPlayStatus {
CANPLAY_NO,
CANPLAY_MAYBE,
@ -74,6 +78,11 @@ public:
#ifdef MOZ_WMF
static bool IsWMFSupportedType(const nsACString& aType);
#endif
// Create a decoder for the given aType. Returns null if we
// were unable to create the decoder.
static already_AddRefed<MediaDecoder> CreateDecoder(const nsACString& aType,
MediaDecoderOwner* aOwner);
};
}