Closed Bug 1039639 Opened 10 years ago Closed 9 years ago

Add support for Flac on Firefox OS

Categories

(Firefox OS Graveyard :: Gaia::Music, defect)

defect
Not set
normal

Tracking

(firefox39 fixed, b2g-v1.4 wontfix, b2g-v2.0 wontfix, b2g-v2.0M wontfix, b2g-v2.1 wontfix, b2g-v2.2 wontfix, b2g-master affected)

RESOLVED FIXED
Tracking Status
firefox39 --- fixed
b2g-v1.4 --- wontfix
b2g-v2.0 --- wontfix
b2g-v2.0M --- wontfix
b2g-v2.1 --- wontfix
b2g-v2.2 --- wontfix
b2g-master --- affected

People

(Reporter: zefling, Assigned: squib)

References

Details

(Whiteboard: [ft:media] [2.2 target][mozfr-community])

Attachments

(2 files, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140611125853

Steps to reproduce:

I passed my Micro SD card of my android phone on Flame. All my music on my android phone is in Flac and unplayable.


Actual results:

Currently, the Flac audio format isn't support on Firefox OS. 


Expected results:

Add the Flac audio format support on Firefox OS.
I can confirm that FLAC is also unsupported on my HEAD build of Firefox OS on flame.
Apple lossless (ALAC) is also not supported.
I can confirm as well on Flame (Firefox OS 2.1)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Storage API needs to be updated for FLAC. See bug 1059903.
Depends on: 1059903
Part of this, we'd need to add support for FLAC metadata (mostly like VorbisComment).
+1 let me know what I can do to help test this. I have some flac on my SD card now that's not showing up and I update my phone pretty regularly (rebuilding after a `./repo sync`); I'd be happy to work with someone on squashing this one.
So I tried renaming my .flac files to .flac.mp3 (per the comment here: https://github.com/nazar-pc/CleverStyle-Music/issues/3#issuecomment-53760443, I could've also just renamed them to .mp3). The result in the built in player was that they work (as in I can play them), but there's no metadata (so all flac shows up under 'Unknown artist'). I'm not sure if that means more work, or if the built-in music app will "just work" after https://bugzilla.mozilla.org/show_bug.cgi?id=1059903 is fixed.
As someone with a large library of music in FLAC format, I would welcome not having to transcode to a lossy format in order to use a Firefox phone as a music player with metadata. There are a couple of additional benefits which were not mentioned above...

1. Decoding FLAC is likely to use less CPU/battery than decoding any lossy format (see the graphs at the end of the page http://www.hydrogenaud.io/forums/index.php?showtopic=92235)

2. Many hi-fi companies are supporting FLAC as an open standard format (https://en.wikipedia.org/wiki/List_of_hardware_and_software_that_supports_FLAC#Others), so having FLAC metadata support on the phone would enable them to create Firefox OS apps which integrate with their systems.
(In reply to randomenduser from comment #6)
> So I tried renaming my .flac files to .flac.mp3 ... The result in the built in
> player was that they work (as in I can play them)...

This works for me too. What the hell is going on here? I guess we can just take advantage of that, although I really want to know why this works (notably, it doesn't work at all on Firefox desktop, which is where I was testing this).

(In reply to daniel.james from comment #7)
> 1. Decoding FLAC is likely to use less CPU/battery than decoding any lossy
> format (see the graphs at the end of the page
> http://www.hydrogenaud.io/forums/index.php?showtopic=92235)

That's just not true. The main difference is that MP3s use a hardware decoder which consumes quite a bit less battery.

Anyway, give me a couple of days to land bug 1089718 and then it should be a simple matter to fully-support FLAC (or at least, as much as we support Vorbis, anyway).
Attached file Parse FLAC metadata
I still need to write tests, and we need to make deviceStorage recognize FLAC (bug 1059903), but if you're ok with farting around with file extensions, this pull request should parse FLAC metadata (but no album art yet).
Assignee: nobody → squibblyflabbetydoo
Status: NEW → ASSIGNED
> > So I tried renaming my .flac files to .flac.mp3 ... The result in the built in
> > player was that they work (as in I can play them)...
> 
> This works for me too. What the hell is going on here?

Some players will reject a file as unplayable based on the extension alone, without looking at the mimetype, before attempting to decode them. It saves throwing an error later. I'll take a wild guess that this is the cause here.

> > 1. Decoding FLAC is likely to use less CPU/battery than decoding any lossy
> > format (see the graphs at the end of the page
> > http://www.hydrogenaud.io/forums/index.php?showtopic=92235)
> 
> That's just not true. The main difference is that MP3s use a hardware
> decoder which consumes quite a bit less battery.

I was not aware that the Flame phone contained an MP3 hardware decoder. Thanks for your work on the pull request.
Thanks for the quick turnaround! I'll try to build and flash your branch this weekend and let you know how it goes.
(In reply to daniel.james from comment #10)
> > > So I tried renaming my .flac files to .flac.mp3 ... The result in the built in
> > > player was that they work (as in I can play them)...
> > 
> > This works for me too. What the hell is going on here?
> 
> Some players will reject a file as unplayable based on the extension alone,
> without looking at the mimetype, before attempting to decode them. It saves
> throwing an error later. I'll take a wild guess that this is the cause here.

The "what the hell" was because Gecko doesn't actually have any FLAC code at all, but after talking to some people, apparently there's a FLAC decoder in the Gonk layer.
 (In reply to Jim Porter (:squib) from comment #12)
> (In reply to daniel.james from comment #10)
> > > > So I tried renaming my .flac files to .flac.mp3 ... The result in the built in
> > > > player was that they work (as in I can play them)...
> > > 
> > > This works for me too. What the hell is going on here?
> > 
> > Some players will reject a file as unplayable based on the extension alone,
> > without looking at the mimetype, before attempting to decode them. It saves
> > throwing an error later. I'll take a wild guess that this is the cause here.
> 
> The "what the hell" was because Gecko doesn't actually have any FLAC code at
> all, but after talking to some people, apparently there's a FLAC decoder in
> the Gonk layer.
Bug 992756 may be helpful to you. 
Yes. Currently FFOS leverages libstagefright's decoder via MediaOmxReader.
Whiteboard: [ft:media] [2.2 target]
Target Milestone: --- → 2.2 S1 (5dec)
Comment on attachment 8518458 [details] [review]
Parse FLAC metadata

Here's the Gaia side to FLAC support. David, I think you'll find this much simpler to review than my last metadata patch. :)
Attachment #8518458 - Flags: review?(dflanagan)
Attached patch Support FLAC in Gecko (obsolete) — Splinter Review
This is currently untested, but it's really simple. I'll try to test this out myself later today, or possibly Monday.
Attachment #8527017 - Flags: review?(dhylands)
Comment on attachment 8527017 [details] [diff] [review]
Support FLAC in Gecko

Review of attachment 8527017 [details] [diff] [review]:
-----------------------------------------------------------------

::: netwerk/mime/nsMimeTypes.h
@@ +79,4 @@
>  #define AUDIO_MP3                           "audio/mpeg"
>  #define AUDIO_MP4                           "audio/mp4"
>  #define AUDIO_AMR                           "audio/amr"
> +#define AUDIO_FLAC                          "audio/flac"

This isn't official yet according to http://www.iana.org/assignments/media-types/media-types.xhtml#audio

Does it matter?  (Also, I note that amr is audio/AMR in uppercase)

Should audio/amr and audio/flac be ifdeffed like they are in the cpp file?
Comment on attachment 8518458 [details] [review]
Parse FLAC metadata

A few nits on github, but otherwise it looks good.

Too bad that you couldn't reuse the existing vorbis comment parsing code. But given how short it is, it doesn't seem worth the time to refactor it into a form where it could be shared.
Attachment #8518458 - Flags: review?(dflanagan) → review+
Comment on attachment 8527017 [details] [diff] [review]
Support FLAC in Gecko

Review of attachment 8527017 [details] [diff] [review]:
-----------------------------------------------------------------

Where does the flac codec live?

If it requires OMX to do the decoding then I think we'll need more changes.

See bug 986331

DecoderTraits.cpp is now in dom/media.

You should get cajbir to review
Attachment #8527017 - Flags: review?(dhylands)
(In reply to David Flanagan [:djf] from comment #16)
> Comment on attachment 8527017 [details] [diff] [review]
> Support FLAC in Gecko
> 
> Review of attachment 8527017 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: netwerk/mime/nsMimeTypes.h
> @@ +79,4 @@
> >  #define AUDIO_MP3                           "audio/mpeg"
> >  #define AUDIO_MP4                           "audio/mp4"
> >  #define AUDIO_AMR                           "audio/amr"
> > +#define AUDIO_FLAC                          "audio/flac"
> 
> This isn't official yet according to
> http://www.iana.org/assignments/media-types/media-types.xhtml#audio
> 
> Does it matter?

It doesn't matter. One is supposed to use audio/x-flac until audio/flac is registered, but that just means one has to support _two_ mime types. Flac has been deployed for 13 years. No other codec is going to appear with a better claim for the official registration.
Blocks: 907929
Ok, I think this is right. I'm not entirely sure I got the tests right; they pass, but I'm not 100% what's getting tested...
Attachment #8527017 - Attachment is obsolete: true
Attachment #8531373 - Flags: review?(cajbir.bugzilla)
Attachment #8531373 - Flags: review?(cajbir.bugzilla) → review+
I'm out right now, but this can probably land; I just don't have time to watch the tree after landing myself...
Keywords: checkin-needed
Release Note Request (optional, but appreciated)
[Why is this notable]:
[Suggested wording]:
[Links (documentation, blog post, etc)]:
Keywords: checkin-needed
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
We still need the Gecko patch.
Status: RESOLVED → REOPENED
Keywords: checkin-needed
Resolution: FIXED → ---
Status: REOPENED → ASSIGNED
Looks like other tests were hitting similar issues. Make sure this gets a full green B2G mochitest run (opt and debug) before re-landing.
:cajbir, any ideas why this might crash? I know next to nothing about how Gecko talks to libstagefright.
Flags: needinfo?(cajbir.bugzilla)
They were timeouts that were force-crashed to get a stack, in case that helps.
Buggy flac decoder in Stagefright maybe? The crash looks to be inside the actual stagefright flac decoder code.
Flags: needinfo?(cajbir.bugzilla)
What's the way forward then? Disable the tests?
Flags: needinfo?(cajbir.bugzilla)
The way forward is for someone to debug exactly what's causing the crash, and what devices it occurs on. Then a decision would need to be made if we need to disable it on crashy devices and enable it on working ones. It may be something we are doing wrong in calling stagefright that triggers it too.
Flags: needinfo?(cajbir.bugzilla)
Sotaro may be able to help with identification of the reason for the crash.
Flags: needinfo?(sotaro.ikeda.g)
(In reply to cajbir (:cajbir) from comment #33)
> Sotaro may be able to help with identification of the reason for the crash.

I can help it, but it becomes tomorrow(17th). Is it OK?
(In reply to Sotaro Ikeda [:sotaro PTO Dec/24-Jan/6] from comment #35)
> re-check tryserver result.
> https://treeherder.mozilla.org/#/jobs?repo=try&revision=28191f14e618
> https://tbpl.mozilla.org/?tree=Try&rev=28191f14e618

test failure happens only on debug build and there seems no problem on flame and hamachi devices. Therefore, FLACParser's algorithm seems not have a problem.
The following is disassemble of copyStereo16()

------------------------------------------------
Dump of assembler code for function copyStereo16:
406	{
   0x432f6aec <+0>:	push	{r4, lr}

407	    for (unsigned i = 0; i < nSamples; ++i) {
=> 0x432f6aee <+2>:	movs	r3, #0
   0x432f6af0 <+4>:	b.n	0x432f6b08 <copyStereo16+28>
   0x432f6b02 <+22>:	adds	r3, #1
   0x432f6b08 <+28>:	adds	r0, #4
   0x432f6b0a <+30>:	cmp	r3, r2
   0x432f6b0c <+32>:	bne.n	0x432f6af2 <copyStereo16+6>

408	        *dst++ = src[0][i];
   0x432f6af2 <+6>:	ldr	r4, [r1, #0]
   0x432f6af4 <+8>:	ldrh.w	r12, [r4, r3, lsl #2]
   0x432f6af8 <+12>:	strh.w	r12, [r0, #-4]

409	        *dst++ = src[1][i];
   0x432f6afc <+16>:	ldr	r4, [r1, #4]
   0x432f6afe <+18>:	ldrh.w	r4, [r4, r3, lsl #2]
   0x432f6b04 <+24>:	strh.w	r4, [r0, #-2]

410	    }
411	}
   0x432f6b0e <+34>:	pop	{r4, pc}

End of assembler dump.
Crash address seems always 0x50. It is r4's value. From the following code, r4 is source address.

----------------------------------------------

12:53:04     INFO -  Crash reason:  SIGSEGV
12:53:04     INFO -  Crash address: 0x50
12:53:04     INFO -  Thread 26 (crashed)
12:53:04     INFO -   0  libstagefright.so!android::copyStereo16 [FLACExtractor.cpp : 409 + 0x2]
12:53:04     INFO -       r4 = 0x00000050    r5 = 0x00000001    r6 = 0x00000000    r7 = 0x467f8000
12:53:04     INFO -       r8 = 0x00000004    r9 = 0x42643157   r10 = 0x42643170    fp = 0x002e2761
12:53:04     INFO -       sp = 0x46ea8b50    lr = 0x4313d621    pc = 0x4313d176
(In reply to Sotaro Ikeda [:sotaro PTO Dec/24-Jan/6] from comment #38)
> Crash address seems always 0x50. It is r4's value. From the following code,
> r4 is source address.

Source buffer is come from FLAC library.
I could re-generate the crash by using long flac music file and do seek in Music app.
Implementation of FLACParser seems to have a problem. It seems better to handle it in a new bug. I am going to create a bug for it.
Depends on: 1113271
blocking-b2g: --- → 2.2?
AFAIK, FLAC support is not a blocking feature for 2.2. Removing from blocking nom
blocking-b2g: 2.2? → ---
i want FLAC support aswell for next version if you could do it, as most of my music is in FLAC, any list of supported audio or video formats

//Martin "bittin" Jernberg
+1 Please add FLAC support, since most torrents are encoded using FLAC nowadays (*irony*)
There's no need to add "me too" comments to this bug. It already has patches and is just waiting for some platform fixes to land before I check in the final bit that fully-enables FLAC. Please be patient.
Since bug 1113271 is fixed, I think we can try landing this again.
Keywords: checkin-needed
Can we get a Try run to confirm that first? :)
Flags: needinfo?(squibblyflabbetydoo)
Keywords: checkin-needed
Target Milestone: 2.2 S1 (5dec) → ---
Finally got around to pushing to try:

https://treeherder.mozilla.org/#/jobs?repo=try&revision=76959dd0683c
Flags: needinfo?(squibblyflabbetydoo)
I think the tests look ok. There are a couple of failures, but they seem to be unrelated. (The closest seems to be a couple of failures for video playback on Windows, but I don't think that's related to this.)
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/f19216bba031
Status: ASSIGNED → RESOLVED
Closed: 10 years ago9 years ago
Resolution: --- → FIXED
Whiteboard: [ft:media] [2.2 target] → [ft:media] [2.2 target][mozfr-community]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: