Bug 1568058 - pt 1 - Add DecoderTraits::CreateDemuxer and use it in CreateReader. r=jya

CreateDemuxer will be used in MediaBufferDecoder as we remove MediaFormatReader.

Differential Revision: https://phabricator.services.mozilla.com/D45094

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Michael Froman 2019-11-14 16:06:29 +00:00
Родитель 93489fe04d
Коммит 19bb343143
2 изменённых файлов: 38 добавлений и 14 удалений

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

@ -228,33 +228,50 @@ bool DecoderTraits::ShouldHandleMediaType(
} }
/* static */ /* static */
MediaFormatReader* DecoderTraits::CreateReader(const MediaContainerType& aType, already_AddRefed<MediaDataDemuxer> DecoderTraits::CreateDemuxer(
MediaFormatReaderInit& aInit) { const MediaContainerType& aType, MediaResource* aResource) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MediaFormatReader* decoderReader = nullptr; RefPtr<MediaDataDemuxer> demuxer;
MediaResource* resource = aInit.mResource;
#ifdef MOZ_FMP4 #ifdef MOZ_FMP4
if (MP4Decoder::IsSupportedType(aType, if (MP4Decoder::IsSupportedType(aType,
/* DecoderDoctorDiagnostics* */ nullptr)) { /* DecoderDoctorDiagnostics* */ nullptr)) {
decoderReader = new MediaFormatReader(aInit, new MP4Demuxer(resource)); demuxer = new MP4Demuxer(aResource);
} else } else
#endif #endif
if (MP3Decoder::IsSupportedType(aType)) { if (MP3Decoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new MP3Demuxer(resource)); demuxer = new MP3Demuxer(aResource);
} else if (ADTSDecoder::IsSupportedType(aType)) { } else if (ADTSDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new ADTSDemuxer(resource)); demuxer = new ADTSDemuxer(aResource);
} else if (WaveDecoder::IsSupportedType(aType)) { } else if (WaveDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new WAVDemuxer(resource)); demuxer = new WAVDemuxer(aResource);
} else if (FlacDecoder::IsSupportedType(aType)) { } else if (FlacDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new FlacDemuxer(resource)); demuxer = new FlacDemuxer(aResource);
} else if (OggDecoder::IsSupportedType(aType)) { } else if (OggDecoder::IsSupportedType(aType)) {
RefPtr<OggDemuxer> demuxer = new OggDemuxer(resource); demuxer = new OggDemuxer(aResource);
decoderReader = new MediaFormatReader(aInit, demuxer);
demuxer->SetChainingEvents(&decoderReader->TimedMetadataProducer(),
&decoderReader->MediaNotSeekableProducer());
} else if (WebMDecoder::IsSupportedType(aType)) { } else if (WebMDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new WebMDemuxer(resource)); demuxer = new WebMDemuxer(aResource);
}
return demuxer.forget();
}
/* static */
MediaFormatReader* DecoderTraits::CreateReader(const MediaContainerType& aType,
MediaFormatReaderInit& aInit) {
MOZ_ASSERT(NS_IsMainThread());
RefPtr<MediaDataDemuxer> demuxer = CreateDemuxer(aType, aInit.mResource);
if (!demuxer) {
return nullptr;
}
MediaFormatReader* decoderReader = new MediaFormatReader(aInit, demuxer);
if (OggDecoder::IsSupportedType(aType)) {
static_cast<OggDemuxer*>(demuxer.get())
->SetChainingEvents(&decoderReader->TimedMetadataProducer(),
&decoderReader->MediaNotSeekableProducer());
} }
return decoderReader; return decoderReader;

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

@ -15,8 +15,10 @@ namespace mozilla {
class DecoderDoctorDiagnostics; class DecoderDoctorDiagnostics;
class MediaContainerType; class MediaContainerType;
class MediaDataDemuxer;
struct MediaFormatReaderInit; struct MediaFormatReaderInit;
class MediaFormatReader; class MediaFormatReader;
class MediaResource;
class TrackInfo; class TrackInfo;
enum CanPlayStatus { CANPLAY_NO, CANPLAY_MAYBE, CANPLAY_YES }; enum CanPlayStatus { CANPLAY_NO, CANPLAY_MAYBE, CANPLAY_YES };
@ -35,6 +37,11 @@ class DecoderTraits {
static bool ShouldHandleMediaType(const char* aMIMEType, static bool ShouldHandleMediaType(const char* aMIMEType,
DecoderDoctorDiagnostics* aDiagnostics); DecoderDoctorDiagnostics* aDiagnostics);
// Create a demuxer for the given MIME type aType. Returns null if we
// were unable to create the demuxer.
static already_AddRefed<MediaDataDemuxer> CreateDemuxer(
const MediaContainerType& aType, MediaResource* aResource);
// Create a reader for thew given MIME type aType. Returns null // Create a reader for thew given MIME type aType. Returns null
// if we were unable to create the reader. // if we were unable to create the reader.
static MediaFormatReader* CreateReader(const MediaContainerType& aType, static MediaFormatReader* CreateReader(const MediaContainerType& aType,