Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP3, Ogg/Vorbis and Flac playback #54

Merged
merged 5 commits into from Nov 8, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Flac playback support

  • Loading branch information...
philn committed Nov 7, 2017
commit 520c282e332e2a7dfdc39a096ddf8d78dca3946a
@@ -200,6 +200,8 @@ add_library(gecko_core OBJECT
gecko/src/dom/media/ogg/OggDemuxer.cpp
gecko/src/dom/media/ogg/OggCodecState.cpp
gecko/src/dom/media/ogg/OggCodecStore.cpp
gecko/src/dom/media/flac/FlacDecoder.cpp
gecko/src/dom/media/flac/FlacDemuxer.cpp
gecko/src/dom/media/flac/FlacFrameParser.cpp
gecko/src/dom/media/XiphExtradata.cpp
gecko/src/dom/media/platforms/agnostic/BlankDecoderModule.cpp
@@ -59,6 +59,8 @@
"OggCodecStore.h": "dom/media/ogg/OggCodecStore.h",
"OggDecoder.h": "dom/media/ogg/OggDecoder.h",
"OggDemuxer.h": "dom/media/ogg/OggDemuxer.h",
"FlacDecoder.h": "dom/media/flac/FlacDecoder.h",
"FlacDemuxer.h": "dom/media/flac/FlacDemuxer.h",
"FlacFrameParser.h": "dom/media/flac/FlacFrameParser.h",
"PDMFactory.h": "dom/media/platforms/PDMFactory.h",
"ReorderQueue.h": "dom/media/platforms/ReorderQueue.h",
@@ -28,6 +28,8 @@
"dom/media/ogg/OggDemuxer.cpp",
"dom/media/ogg/OggCodecState.cpp",
"dom/media/ogg/OggCodecStore.cpp",
"dom/media/flac/FlacDecoder.cpp",
"dom/media/flac/FlacDemuxer.cpp",
"dom/media/flac/FlacFrameParser.cpp",
"dom/media/XiphExtradata.cpp",
"dom/media/platforms/agnostic/BlankDecoderModule.cpp",
@@ -34,8 +34,8 @@
// #include "ADTSDecoder.h"
// #include "ADTSDemuxer.h"

// #include "FlacDecoder.h"
// #include "FlacDemuxer.h"
#include "FlacDecoder.h"
#include "FlacDemuxer.h"

#include "nsPluginHost.h"
#include "MediaPrefs.h"
@@ -121,9 +121,9 @@ CanHandleCodecsType(const MediaContainerType& aType,
// if (ADTSDecoder::IsSupportedType(aType)) {
// return CANPLAY_YES;
// }
// if (FlacDecoder::IsSupportedType(aType)) {
// return CANPLAY_YES;
// }
if (FlacDecoder::IsSupportedType(aType)) {
return CANPLAY_YES;
}

return CANPLAY_MAYBE;
}
@@ -177,9 +177,9 @@ CanHandleMediaType(const MediaContainerType& aType,
// if (ADTSDecoder::IsSupportedType(mimeType)) {
// return CANPLAY_MAYBE;
// }
// if (FlacDecoder::IsSupportedType(mimeType)) {
// return CANPLAY_MAYBE;
// }
if (FlacDecoder::IsSupportedType(mimeType)) {
return CANPLAY_MAYBE;
}
return CANPLAY_NO;
}

@@ -246,11 +246,10 @@ DecoderTraits::CreateReader(const MediaContainerType& aType,
// } else
if (WaveDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new WAVDemuxer(resource));
}
// } else
// if (FlacDecoder::IsSupportedType(aType)) {
// decoderReader = new MediaFormatReader(aInit, new FlacDemuxer(resource));
// } else
} else
if (FlacDecoder::IsSupportedType(aType)) {
decoderReader = new MediaFormatReader(aInit, new FlacDemuxer(resource));
} else
if (OggDecoder::IsSupportedType(aType)) {
RefPtr<OggDemuxer> demuxer = new OggDemuxer(resource);
decoderReader = new MediaFormatReader(aInit, demuxer);
@@ -272,7 +271,7 @@ DecoderTraits::IsSupportedType(const MediaContainerType& aType)
typedef bool (*IsSupportedFunction)(const MediaContainerType& aType);
static const IsSupportedFunction funcs[] = {
// &ADTSDecoder::IsSupportedType,
// &FlacDecoder::IsSupportedType,
&FlacDecoder::IsSupportedType,
&MP3Decoder::IsSupportedType,
#ifdef MOZ_FMP4
&MP4Decoder::IsSupportedTypeWithoutDiagnostics,
@@ -313,7 +312,7 @@ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
#endif
// MP3Decoder::IsSupportedType(*type) ||
// ADTSDecoder::IsSupportedType(*type) ||
// FlacDecoder::IsSupportedType(*type) ||
FlacDecoder::IsSupportedType(*type) ||
// #ifdef MOZ_ANDROID_HLS_SUPPORT
// HLSDecoder::IsSupportedType(*type) ||
// #endif
@@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef FLAC_DECODER_H_
#define FLAC_DECODER_H_

namespace mozilla {

class MediaContainerType;

class FlacDecoder
{
public:
// Returns true if the Flac backend is pref'ed on, and we're running on a
// platform that is likely to have decoders for the format.
static bool IsEnabled();
static bool IsSupportedType(const MediaContainerType& aContainerType);
};

} // namespace mozilla

#endif // !FLAC_DECODER_H_
@@ -0,0 +1,110 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef FLAC_DEMUXER_H_
#define FLAC_DEMUXER_H_

#include "mozilla/Attributes.h"
#include "MediaDataDemuxer.h"
#include "MediaResource.h"
namespace mozilla {

namespace flac {
class Frame;
class FrameParser;
}
class FlacTrackDemuxer;


class FlacDemuxer : public MediaDataDemuxer
{
public:
// MediaDataDemuxer interface.
explicit FlacDemuxer(MediaResource* aSource);
RefPtr<InitPromise> Init() override;
uint32_t GetNumberTracks(TrackInfo::TrackType aType) const override;
already_AddRefed<MediaTrackDemuxer> GetTrackDemuxer(
TrackInfo::TrackType aType, uint32_t aTrackNumber) override;
bool IsSeekable() const override;

// Return true if a valid flac frame header could be found.
static bool FlacSniffer(const uint8_t* aData, const uint32_t aLength);

private:
bool InitInternal();

RefPtr<MediaResource> mSource;
RefPtr<FlacTrackDemuxer> mTrackDemuxer;
};

class FlacTrackDemuxer : public MediaTrackDemuxer
{
public:
explicit FlacTrackDemuxer(MediaResource* aSource);

// Initializes the track demuxer by reading the first frame for meta data.
// Returns initialization success state.
bool Init();

// MediaTrackDemuxer interface.
UniquePtr<TrackInfo> GetInfo() const override;
RefPtr<SeekPromise> Seek(const media::TimeUnit& aTime) override;
RefPtr<SamplesPromise> GetSamples(int32_t aNumSamples = 1) override;
void Reset() override;
int64_t GetResourceOffset() const override;
media::TimeIntervals GetBuffered() override;
RefPtr<SkipAccessPointPromise> SkipToNextRandomAccessPoint(
const media::TimeUnit& aTimeThreshold) override;

bool IsSeekable() const;

private:
// Destructor.
~FlacTrackDemuxer();

// Returns the estimated stream duration, or a 0-duration if unknown.
media::TimeUnit Duration() const;
media::TimeUnit TimeAtEnd();

// Fast approximate seeking to given time.
media::TimeUnit FastSeek(const media::TimeUnit& aTime);

// Seeks by scanning the stream up to the given time for more accurate
// results.
media::TimeUnit ScanUntil(const media::TimeUnit& aTime);

// Finds the next valid frame and return it.
const flac::Frame& FindNextFrame();

// Returns the next ADTS frame, if available.
already_AddRefed<MediaRawData> GetNextFrame(const flac::Frame& aFrame);

// Reads aSize bytes into aBuffer from the source starting at aOffset.
// Returns the actual size read.
int32_t Read(uint8_t* aBuffer, int64_t aOffset, int32_t aSize);

// Returns the average frame length derived from the previously parsed frames.
double AverageFrameLength() const;

// The (hopefully) Flac resource.
MediaResourceIndex mSource;

// Flac frame parser used to detect frames and extract side info.
nsAutoPtr<flac::FrameParser> mParser;

// Total duration of parsed frames.
media::TimeUnit mParsedFramesDuration;

// Sum of parsed frames' lengths in bytes.
uint64_t mTotalFrameLen;

// Audio track config info.
UniquePtr<AudioInfo> mInfo;
};

} // mozilla

#endif // !FLAC_DEMUXER_H_
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "FlacDecoder.h"
#include "MediaContainerType.h"
#include "MediaPrefs.h"

namespace mozilla {

/* static */ bool
FlacDecoder::IsEnabled()
{
#ifdef MOZ_FFVPX
return MediaPrefs::FlacEnabled();
#else
// Until bug 1295886 is fixed.
return false;
#endif
}

/* static */ bool
FlacDecoder::IsSupportedType(const MediaContainerType& aContainerType)
{
return IsEnabled() &&
(aContainerType.Type() == MEDIAMIMETYPE("audio/flac") ||
aContainerType.Type() == MEDIAMIMETYPE("audio/x-flac") ||
aContainerType.Type() == MEDIAMIMETYPE("application/x-flac"));
}

} // namespace mozilla
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.