Closed Bug 1195723 Opened 10 years ago Closed 8 years ago

FLAC support / Create FLAC MediaDataDemuxer

Categories

(Core :: Audio/Video: Playback, enhancement, P5)

enhancement

Tracking

()

VERIFIED FIXED
mozilla51
Tracking Status
relnote-firefox --- 51+
firefox51 --- verified

People

(Reporter: sir.suriv, Assigned: jya)

References

Details

(Keywords: dev-doc-complete, feature)

Attachments

(16 files)

58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
u480271
: review+
Details
58 bytes, text/x-review-board-request
mozbugz
: review+
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 Expected results: It would be great if FLAC was supported in audio elements. This is similar to https://bugzilla.mozilla.org/show_bug.cgi?id=586568 but cajbir suggested opening a new bug just for FLAC. It looks like Chromium may land this soon, see https://code.google.com/p/chromium/issues/detail?id=93887
Technically a duplicate of bug 514365, but if another browser will add FLAC support, the issue may be worth revisiting.
Severity: normal → enhancement
Component: Untriaged → Audio/Video: Playback
OS: Unspecified → All
Product: Firefox → Core
Hardware: Unspecified → All
The intent of the js decoders is to cover this kind of thing.
Priority: -- → P5
FWIW, Tidal is serving FLAC to Chrome using a PNaCl FLAC decoder for "HiFi" streams (some details about why they do this rather than use a pure JS decoder in https://github.com/audiocogs/flac.js/issues/8). Firefox isn't offered this quality level, only "Normal" and "High", which are using lossy codecs via Flash plugin (not sure why they don't use native playback, presumably it's just MP3 or AAC).
(In reply to Gingerbread Man from comment #1) > Technically a duplicate of bug 514365, but if another browser will add FLAC > support, the issue may be worth revisiting. Duping 514365 forward to this one.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: feature
Depends on: 1270016
I confirm FLAC doesn't work I comment in order to share with you an easy test case: http://hpr.dogphilosophy.net/test/
Depends on: 1286097
Assignee: nobody → jyavenard
Summary: FLAC support → FLAC support / Create FLAC MediaDataDemuxer
the file in testing/web-platform/tests/media/A4.ogv is a theora/flac file ; though not particularly useful. I used the flac sample file there http://www.eclassical.com/pages/24-bit-faq.html and converted them to ogg with: ffmpeg -i BIS1447-002-flac_16.flac -acodec copy BIS1447-002-flac_16.ogg tested with flac 16 bits and 24 bits, 44.1kHz and 88.2kHz.
Comment on attachment 8780310 [details] Bug 1195723: [ogg/flac] P3. Add flac support in ogg. https://reviewboard.mozilla.org/r/71022/#review68634 ::: dom/media/ogg/OggCodecState.h:623 (Diff revision 1) > + nsresult PageIn(ogg_page* aPage) override; > + > + // Return a hash table with tag metadata. > + MetadataTags* GetTags() override; > + > + AudioInfo& GetInfo(); can this be const AudioInfo& GetInfo()? ::: dom/media/ogg/OggCodecState.cpp:1245 (Diff revision 1) > +bool > +FlacState::DecodeHeader(ogg_packet* aPacket) > +{ > + nsAutoRef<ogg_packet> autoRelease(aPacket); > + > + if (!mParser.DecodeHeaderBlock(aPacket->packet, aPacket->bytes)) { From my understanding of https://xiph.org/flac/ogg_mapping.html and looking at example flac-in-ogg, when this is called, aPacket begins with: `0x7f + FLAC + MAJOR + MINOR + HEADER_COUNT + fLaC + METADATABLOCK + ...` Why not strip off the 9 bytes header here and pass: `flac + METADATA_BLOCK + ...` into mParser.DecoderHeaderBlock()? ::: dom/media/ogg/OggCodecState.cpp:1260 (Diff revision 1) > +FlacState::Time(int64_t granulepos) > +{ > + if (!mParser.mInfo.IsValid()) { > + return -1; > + } > + CheckedInt64 t = nit: Too long for one line? ::: dom/media/ogg/OggCodecState.cpp:1311 (Diff revision 1) > + } > + return NS_OK; > +} > + > +// Return a hash table with tag metadata. > +MetadataTags* const MetadataTags*? or is it intended that caller might modify the hash table? (I see it's an override from base class) ::: dom/media/ogg/OggCodecState.cpp:1327 (Diff revision 1) > + > +bool > +FlacState::ReconstructFlacGranulepos(void) > +{ > + NS_ASSERTION(mUnstamped.Length() > 0, "Must have unstamped packets"); > + ogg_packet* last = mUnstamped[mUnstamped.Length()-1]; `ogg_packet* last = mUnstamped.LastElement();` ::: dom/media/ogg/OggDemuxer.h:267 (Diff revision 1) > VorbisState* mVorbisState; > > // Decode state of the Opus bitstream we're decoding, if we have one. > OpusState* mOpusState; > > // Get the bitstream decode state for the given track type Should this comment go with GetTrackCodecState?
Attachment #8780310 - Flags: review?(dglastonbury) → review-
Comment on attachment 8780309 [details] Bug 1195723: [ogg] P2. Refactor mimetype parsing for ogg. https://reviewboard.mozilla.org/r/71020/#review68640
Attachment #8780309 - Flags: review?(dglastonbury) → review+
Comment on attachment 8780310 [details] Bug 1195723: [ogg/flac] P3. Add flac support in ogg. https://reviewboard.mozilla.org/r/71022/#review68634 > From my understanding of https://xiph.org/flac/ogg_mapping.html and looking at example flac-in-ogg, when this is called, aPacket begins with: > > `0x7f + FLAC + MAJOR + MINOR + HEADER_COUNT + fLaC + METADATABLOCK + ...` > > Why not strip off the 9 bytes header here and pass: > > `flac + METADATA_BLOCK + ...` > > into mParser.DecoderHeaderBlock()? but I do want to verify that those 9 bytes are correct! if I were to simply strip them, how would I verify the validity of the content ? > const MetadataTags*? or is it intended that caller might modify the hash table? (I see it's an override from base class) i'm extending an existing code, i did not write the API.... > `ogg_packet* last = mUnstamped.LastElement();` this is the exact same code as found in all other CodecState implementation. > Should this comment go with GetTrackCodecState? oops
Comment on attachment 8780308 [details] Bug 1195723: [flac] P1. Primitive flac frame parser. https://reviewboard.mozilla.org/r/71018/#review68592 With bug fixed. ::: dom/media/FlacFrameParser.h:20 (Diff revision 1) > +namespace mozilla > +{ > + > +class OpusParser; > + > +class FlacFrameParser Maybe you could add a comment that this parses FLAC contained in Ogg and reference the spec https://xiph.org/flac/ogg_mapping.html? ::: dom/media/FlacFrameParser.h:40 (Diff revision 1) > + AudioInfo mInfo; > + > +private: > + bool ReconstructFlacGranulepos(void); > + Maybe<uint32_t> mNumHeaders; > + uint32_t mMinBlockSize; These *could* be uint16_t. ::: dom/media/FlacFrameParser.cpp:71 (Diff revision 1) > + , mPacketCount(0) > +{ > +} > + > +bool > +FlacFrameParser::DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength) Maybe DecodeStreamHeader is a better name? ::: dom/media/FlacFrameParser.cpp:81 (Diff revision 1) > + } > + AutoByteReader br(aPacket, aLength); > + > + mPacketCount++; > + > + uint32_t blockType = br.ReadU8() & 0x7f; I think this is a bug. r- ::: dom/media/FlacFrameParser.cpp:83 (Diff revision 1) > + > + mPacketCount++; > + > + uint32_t blockType = br.ReadU8() & 0x7f; > + > + if (blockType == OGG_FLAC_METADATA_TYPE_STREAMINFO) { if your current flac-in-ogg header is passed to this function, how is it valid to access blockType before stripping off `0x7F + FLAC`? I think this code should check for `0x&F + FLAC` or `fLaC` and assert it.
Attachment #8780308 - Flags: review?(dglastonbury) → review+
Comment on attachment 8780310 [details] Bug 1195723: [ogg/flac] P3. Add flac support in ogg. https://reviewboard.mozilla.org/r/71022/#review68654 After discussion on irc, that issues as suggestions.
Attachment #8780310 - Flags: review- → review+
(In reply to Jean-Yves Avenard [:jya] from comment #13) > Comment on attachment 8780310 [details] > Bug 1195723: [ogg/flac] P3. Add flac support in ogg. > > https://reviewboard.mozilla.org/r/71022/#review68634 > > > From my understanding of https://xiph.org/flac/ogg_mapping.html and looking at example flac-in-ogg, when this is called, aPacket begins with: > > > > `0x7f + FLAC + MAJOR + MINOR + HEADER_COUNT + fLaC + METADATABLOCK + ...` > > > > Why not strip off the 9 bytes header here and pass: > > > > `flac + METADATA_BLOCK + ...` > > > > into mParser.DecoderHeaderBlock()? > > but I do want to verify that those 9 bytes are correct! > if I were to simply strip them, how would I verify the validity of the > content ? My fault. My unspoken assumption was that you're check the 9 bytes, and then 'strip' them from the packet before handing them on to DecoderHeaderBlock(). I'll be explicit next time.
Comment on attachment 8780308 [details] Bug 1195723: [flac] P1. Primitive flac frame parser. https://reviewboard.mozilla.org/r/71018/#review68592 > I think this is a bug. r- why that? the first bit is a flag to indicate if it's the last metadata or not, and then you have the type > if your current flac-in-ogg header is passed to this function, how is it valid to access blockType before stripping off `0x7F + FLAC`? > > I think this code should check for `0x&F + FLAC` or `fLaC` and assert it. That's what the first code block above does. if (blockType == OGG_FLAC_METADATA_TYPE_STREAMINFO) { ... check that the ogg header is valid, and advance the pointer so that it points straight to the start of the STREAMINFO. So we check that it starts by FLAC, that this ogg prefix is correct and will error if not. it will also check that it's the first block seen and that it must contain a STREAMINFO.
(In reply to Gingerbread Man from comment #1) > Technically a duplicate of bug 514365, but if another browser will add FLAC > support, the issue may be worth revisiting. this bug is primarily about adding support for flac, the raw container... the bug you pointed it so for flac in ogg.
Comment on attachment 8780308 [details] Bug 1195723: [flac] P1. Primitive flac frame parser. https://reviewboard.mozilla.org/r/71018/#review68592 > That's what the first code block above does. > > if (blockType == OGG_FLAC_METADATA_TYPE_STREAMINFO) { > ... check that the ogg header is valid, and advance the pointer so that it points straight to the start of the STREAMINFO. > > So we check that it starts by FLAC, that this ogg prefix is correct and will error if not. > it will also check that it's the first block seen and that it must contain a STREAMINFO. Sorry, I didn't refer back to the definition of OGG_FLAC_METADATA_TYPE_STREAMINFO. I confused it with METADATA_BLOCK_HEADER BLOCK_TYPE STREAMINFO from the Flac spec.
Comment on attachment 8780308 [details] Bug 1195723: [flac] P1. Primitive flac frame parser. https://reviewboard.mozilla.org/r/71018/#review68592 > why that? the first bit is a flag to indicate if it's the last metadata or not, and then you have the type Because blockType sounds like https://xiph.org/flac/format.html#metadata_block_header
Blocks: 1295886
Attachment #8782196 - Flags: review?(dglastonbury) → review+
Attachment #8782197 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782198 [details] Bug 1195723: [flac] P6. Add support for raw flac metadata decoding. https://reviewboard.mozilla.org/r/72404/#review70064
Attachment #8782198 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782199 [details] Bug 1195723: [flac] P7. Add flac demuxer. https://reviewboard.mozilla.org/r/72406/#review70070 ::: dom/media/flac/FlacDemuxer.cpp:360 (Diff revision 1) > + void SetRate(uint32_t aRate) { mHeader.mInfo.mRate = aRate; }; > + > + void SetBitDepth(uint32_t aBitDepth) { mHeader.mInfo.mBitDepth = aBitDepth; } > + > + void SetInvalid() { mHeader.mValid = false; } > + Stray white space.
Attachment #8782199 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782200 [details] Bug 1195723: [flac] P8. Add flac MediaDecoder. https://reviewboard.mozilla.org/r/72408/#review70072 ::: dom/media/flac/FlacDecoder.cpp:46 (Diff revision 1) > +{ > + return IsEnabled() && > + (aType.EqualsASCII("audio/flac") || aType.EqualsASCII("audio/x-flac") || > + aType.EqualsASCII("application/x-flac")); > + > + return false; You can do with out this return false;
Attachment #8782200 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782201 [details] Bug 1195723: [flac] P9. Hook up flac decoder and demuxer. https://reviewboard.mozilla.org/r/72410/#review70074
Attachment #8782201 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782202 [details] Bug 1195723: [flac] P10. Add media sniffer for flac file. https://reviewboard.mozilla.org/r/72412/#review70078
Attachment #8782202 - Flags: review?(dglastonbury) → review+
Attachment #8782203 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782200 [details] Bug 1195723: [flac] P8. Add flac MediaDecoder. https://reviewboard.mozilla.org/r/72408/#review70072 > You can do with out this return false; also disabled flac on android for now. we don't compile ffvpx on this platform.
Attachment #8782308 - Flags: review?(dglastonbury) → review+
Attachment #8782309 - Flags: review?(dglastonbury) → review+
Comment on attachment 8782310 [details] Bug 1195723: [flac] P14. Add support for metadata. https://reviewboard.mozilla.org/r/72522/#review70132 ::: dom/media/flac/FlacDemuxer.cpp:617 (Diff revision 1) > UniquePtr<TrackInfo> > FlacTrackDemuxer::GetInfo() const > { > if (mParser->Info().IsValid()) { > // We have a proper metadata header. > - return mParser->Info().Clone(); > + auto info = mParser->Info().Clone(); I don't think that's a great use of auto, since it's not clear what type it should be from the function call.
Attachment #8782310 - Flags: review?(dglastonbury) → review+
Attachment #8782311 - Flags: review?(dglastonbury) → review+
Blocks: 1296529
Pushed by jyavenard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/04eceefa54c7 [flac] P1. Primitive flac frame parser. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/efb6bcf743e7 [ogg] P2. Refactor mimetype parsing for ogg. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/7f86beff4263 [ogg/flac] P3. Add flac support in ogg. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/a4f7a73c04fa [adts] P4. Add extra mimetype for adts/aac. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/7bdb9540b60f P5. Add BitReader class. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/c938ad9dd11c [flac] P6. Add support for raw flac metadata decoding. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/867d6507a381 [flac] P7. Add flac demuxer. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/3fcb5682049a [flac] P8. Add flac MediaDecoder. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/39908ea4c390 [flac] P9. Hook up flac decoder and demuxer. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/c2664064fa55 [flac] P10. Add media sniffer for flac file. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/4637f8be98bb [flac] P11. Enable FLAC in Ogg by default. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/894061e6037e [flac] P12. Add sniffer for streaming flac. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/ba0aeb71c672 [flac] P13. Add mochitest files. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/c3775a6225d8 [flac] P14. Add support for metadata. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/2a3b10281c9c [flac] P15. Add metadata mochitest. r=kamidphish
Status: RESOLVED → REOPENED
Flags: needinfo?(jyavenard)
Resolution: FIXED → ---
Target Milestone: mozilla51 → ---
Attachment #8783735 - Flags: review?(gsquelart) → review+
Pushed by jyavenard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d12c7bc5be51 [flac] P1. Primitive flac frame parser. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/1a6c05bb21f0 [ogg] P2. Refactor mimetype parsing for ogg. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/a95820f09bdd [ogg/flac] P3. Add flac support in ogg. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/a2d5451f56bc [adts] P4. Add extra mimetype for adts/aac. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/6feb50a80c50 P5. Add BitReader class. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/d8a7f672b3f4 [flac] P6. Add support for raw flac metadata decoding. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/6f02e9165d09 [flac] P7. Add flac demuxer. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/2a136bde12bd [flac] P8. Add flac MediaDecoder. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/a25add7d4afc [flac] P9. Hook up flac decoder and demuxer. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/1ce419e3955f [flac] P10. Add media sniffer for flac file. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/01ff85a264b9 [flac] P11. Enable FLAC in Ogg by default. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/e42414eeeabe [flac] P12. Add sniffer for streaming flac. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/53c739399220 [flac] P13. Add mochitest files. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/612d774f82ee [flac] P14. Add support for metadata. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/2ae43363f27a [flac] P15. Add metadata mochitest. r=kamidphish https://hg.mozilla.org/integration/autoland/rev/8d448381edbb P16. Adjust expected results. r=gerald
jya, should we mention FLAC support in our Firefox 51 release notes? Or is there more work that must be completed before FLAC is usable by web content?
Support is complete as far as playing plain flac goes. Obviously being so new and written from scratch I'm expecting issues. Feature wise, supporting chaining of flac similar to how we do it with Ogg could be interesting. But seeing that no one support flac streaming (they always do so in Ogg) it may not matter. So yes, it can be mentioned in the release notes.
Flags: needinfo?(jyavenard)
Release Note Request (optional, but appreciated) [Why is this notable]: Firefox is adding support for another audio codec. [Suggested wording]: Added support for FLAC (Free Lossless Audio Codec) playback. [Links (documentation, blog post, etc)]: https://xiph.org/flac/ We should probably add a note about FLAC support on MDN, so I'm adding the dev-doc-needed keyword to this bug.
relnote-firefox: --- → ?
Keywords: dev-doc-needed
This looks like something manual QA could help test. jya, what do you think? Should we treat this as a full blown feature or just add a few tests to our audio compatibility test suites?
Flags: qe-verify?
Flags: needinfo?(jyavenard)
Feel free to add any tests you see fit. Area of testing is seeking and if it plays to the end. At this stage, everything should work. I'm not aware of anything not working or supported.
Flags: needinfo?(jyavenard)
Flags: qe-verify? → qe-verify+
QA Contact: ciprian.georgiu
(In reply to mattia.b89 from comment #6) > I confirm FLAC doesn't work > > I comment in order to share with you an easy test case: > http://hpr.dogphilosophy.net/test/ You may want to try that with current Nightly. You'll find that it will work just fine.
Flags: needinfo?(mattia.b89)
It works! Great work! PS: with nightly version (51) I noticed new high-res icon, mandatory for my monitor
Flags: needinfo?(mattia.b89)
Added to Fx51 (Aurora) release notes.
Docs are up-to-date already; someone beat me to it. Nice job. :)
I quickly filled up the MDN docs. Not sure if that's the docs you referred to
This issue is verified fixed on 51.0b2-build1 (2016-11-21) across platforms: - Windows 10 x64 - Mac OS X 10.11 - Ubuntu 16.04 x64 LTS
Status: RESOLVED → VERIFIED
Flags: qe-verify+
> also disabled flac on android for now. we don't compile ffvpx on this platform. While any start to flac support is welcome, I hope you will reconsider omitting this support from Android. We are rapidly approaching the point where, to a first approximation, if you don't support mobile web, you don't support the web.
In the release notes of 51 with "Added support for FLAC (Free Lossless Audio Codec) playback" as wording.
Blocks: 1424555
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: