Closed
Bug 918861
Opened 11 years ago
Closed 11 years ago
Allow the MediaStreamGraph to run at different samplerates
Categories
(Core :: Audio/Video, defect)
Core
Audio/Video
Tracking
()
Tracking | Status | |
---|---|---|
firefox28 | --- | fixed |
People
(Reporter: padenot, Assigned: padenot)
References
Details
Attachments
(4 files, 2 obsolete files)
5.52 KB,
patch
|
kinetik
:
review+
|
Details | Diff | Splinter Review |
3.12 KB,
patch
|
roc
:
review+
|
Details | Diff | Splinter Review |
769.54 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
24.43 KB,
patch
|
kinetik
:
review+
|
Details | Diff | Splinter Review |
It can be important to allow the MSG to use something different than the fixed 48000Hz we use right now:
- It can save a resampling pass: if the MSG runs at the same sampling rate as the system mixer/hardware/etc. This means lower latency and load.
- It can trigger a fastpath on Android, when using OpenSL (an exact samplerate and the exact buffer size has to be provided on stream opening to get allocated a FastTrack in the mixer). I can go as low as 12.5ms (instead of the 100+ms/ Number are theoretical, based on samplerate and buffer sizes) this way, on my Galaxy Nexus.
- It can reduce resampling in AudioBufferSourceNodes: most of the media that go through decodeAudioData are at 44100Hz (which is not really surprising for audio-only files), not 48000Hz (which is usually for videos).
First, we need to be able to query the hardware/mixer/etc. to get the right samplerate, then pass this value to the MSG. I have most of the platforms done for the former, and I haven't tried the latter.
Assignee | ||
Comment 1•11 years ago
|
||
Breakdown by platform as well:
- WASAPI, easy, we just query the mixer format.
- alsa, it will not work if we are dealing with pulse with an Alsa
API. Asked around, people didn't know how to do it, so I picked 44100.
- WinMM, the mixer can decide to change the sampling rate, based on what it is
playing and the hardware, so I picked some reasonable value.
- Audiounit, we just query the hardware samplerate.
- pulse, we use the samplerate of the sink, to avoid resampling in the sink.
- OpenSL, same technique as for the latency, we get the value from the .so
- AudioTrack, we use an API
- sndio, no idea
Attachment #810656 -
Flags: review?(kinetik)
Assignee | ||
Comment 2•11 years ago
|
||
Since this can do IO (dlopen on a terrible flash memory), I put in a little
cache.
Attachment #810657 -
Flags: review?(kinetik)
Assignee | ||
Comment 3•11 years ago
|
||
roc, this _seems_ to not bust WebAudio, anything in particular I should be
afraid of?
Attachment #810659 -
Flags: review?(roc)
Assignee | ||
Comment 4•11 years ago
|
||
This is what I had to update to have a variable samplerate MSG. I'll have to
adjust the fuzzing values again for test_mediaDecode.html, though.
Attachment #810662 -
Flags: review?(ehsan)
Comment 5•11 years ago
|
||
Comment on attachment 810662 [details] [diff] [review]
Update tests that were relying on a 48000Hz samplerate. r=
Review of attachment 810662 [details] [diff] [review]:
-----------------------------------------------------------------
::: content/media/webaudio/test/test_mediaDecoding.html
@@ +213,5 @@
> var result = true;
> var difference = 0;
> is(buf1.length, buf2.length, "same length");
> for (var i = 0; i < buf1.length; ++i) {
> + if (Math.abs(buf1[i] - buf2[i]) > 90) {
Why 90?
@@ +243,5 @@
> + dump("SR: " + test.sampleRate + "\n");
> + var SRCRate = test.sampleRate / cx.sampleRate;
> + dump("SRCRate: " + SRCRate + "\n");
> + dump("buffer.length " + buffer.length + "\n");
> + dump("test.frames " + test.frames + "\n");
Please remove the dumps.
@@ +249,5 @@
>
> var wave = createWaveFileData(buffer);
> +// var blob = new Blob([wave], {type: "application/octet-binary"});
> +// var url = URL.createObjectURL(blob);
> +// location.href = url;
And the commented code.
Attachment #810659 -
Flags: review?(roc) → review+
Comment 6•11 years ago
|
||
Comment on attachment 810657 [details] [diff] [review]
Expose a better samplerate though the AudioStream interface. r=
Review of attachment 810657 [details] [diff] [review]:
-----------------------------------------------------------------
::: content/media/AudioStream.cpp
@@ +42,5 @@
> static double gVolumeScale;
> static uint32_t gCubebLatency;
>
> +StaticMutex AudioStream::mMutex;
> +uint32_t AudioStream::mPreferredSamplerate = 0;
SampleRate
@@ +443,5 @@
> + // often, and the complexity of the function call below depends on the
> + // backend used platform.
> + const int fallbackSamplerate = 44100;
> + if (mPreferredSamplerate == 0) {
> + if(cubeb_get_preferred_samplerate(GetCubebContext(), &mPreferredSamplerate) != CUBEB_OK) {
Space between if and (
::: media/libcubeb/src/cubeb_opensl.c
@@ +513,5 @@
> .init = opensl_init,
> .get_backend_id = opensl_get_backend_id,
> .get_max_channel_count = opensl_get_max_channel_count,
> .get_minimal_latency = opensl_get_minimal_latency,
> + .get_preferred_samplerate = opensl_get_preferred_samplerate,
This should be in the cubeb patch.
Attachment #810657 -
Flags: review?(kinetik) → review+
Comment 7•11 years ago
|
||
Comment on attachment 810656 [details] [diff] [review]
Add an API to get the native samplerate for a given audio backend. r=
Review of attachment 810656 [details] [diff] [review]:
-----------------------------------------------------------------
r- due to the compile errors
::: media/libcubeb/include/cubeb.h
@@ +198,5 @@
> @retval CUBEB_ERROR_INVALID_PARAMETER
> @retval CUBEB_OK */
> int cubeb_get_minimal_latency(cubeb * context, cubeb_stream_params * params, uint32_t * latency_ms);
>
> +/** Get the preferred samplerate for this backed: this is hardware and platform
sample rate, backend
@@ +204,5 @@
> + @param context
> + @param samplerate The samplerate (in Hz) the current configuration prefers.
> + @return CUBEB_ERROR_INVALID_PARAMETER
> + @return CUBEB_OK */
> +int cubeb_get_preferred_samplerate(cubeb * context, uint32_t * samplerate);
sample_rate in the function name, rate for the parameter
::: media/libcubeb/src/cubeb_alsa.c
@@ +933,5 @@
> +alsa_get_preferred_samplerate(cubeb * ctx, uint32_t * samplerate)
> +{
> + int rv, dir;
> + snd_pcm_t *pcm;
> + snd_pcm_hw_params_t* hw_params;
Spaces around *.
@@ +966,5 @@
> + snd_pcm_close(pcm);
> + return CUBEB_ERROR;
> + }
> +
> + rv = snd_pcm_close(pcm);
Either check rv, or don't store the return value if you're going to ignore it.
::: media/libcubeb/src/cubeb_audiounit.c
@@ +236,5 @@
> AudioValueRange latency_range;
> audiounit_get_acceptable_latency_range(&latency_range);
>
> *latency_ms = latency_range.mMinimum * 1000 / params->rate;
> +static int
Looks like this was inserted in the middle of get_minimal_latency?
::: media/libcubeb/src/cubeb_opensl.c
@@ +513,5 @@
> .init = opensl_init,
> .get_backend_id = opensl_get_backend_id,
> .get_max_channel_count = opensl_get_max_channel_count,
> .get_minimal_latency = opensl_get_minimal_latency,
> + .get_preferred_sampelrate = opensl_get_preferred_samplerate,
sample
::: media/libcubeb/src/cubeb_sndio.c
@@ +269,5 @@
>
> +static int
> +sndio_get_preferred_samplerate(cubeb * ctx, uint32_t * samplerate)
> +{
> + // XXX
"Not yet implemented", just to be clearer
::: media/libcubeb/src/cubeb_winmm.c
@@ +532,5 @@
>
> static int
> +winmm_get_preferred_samplerate(cubeb * ctx, uint32_t * samplerate)
> +{
> + *samplerate = 44100;
It should be possible to query this via waveOutGetDevCaps?
Attachment #810656 -
Flags: review?(kinetik) → review-
Comment 8•11 years ago
|
||
Comment on attachment 810662 [details] [diff] [review]
Update tests that were relying on a 48000Hz samplerate. r=
Review of attachment 810662 [details] [diff] [review]:
-----------------------------------------------------------------
Clearing the request pending an answer to the question about 90.
Attachment #810662 -
Flags: review?(ehsan)
Assignee | ||
Comment 9•11 years ago
|
||
The "> 90" bit was just some debugging code, the test passes without.
I also addressed the other two comments.
Attachment #811162 -
Flags: review?(ehsan)
Assignee | ||
Updated•11 years ago
|
Attachment #810662 -
Attachment is obsolete: true
Updated•11 years ago
|
Attachment #811162 -
Flags: review?(ehsan) → review+
Updated•11 years ago
|
Target Milestone: --- → mozilla27
Assignee | ||
Comment 10•11 years ago
|
||
This is green on try, now. Sorry about the other patch.
Attachment #815418 -
Flags: review?(kinetik)
Assignee | ||
Updated•11 years ago
|
Attachment #810656 -
Attachment is obsolete: true
Comment 11•11 years ago
|
||
Comment on attachment 815418 [details] [diff] [review]
Add an API to get the native samplerate for a given audio backend. r=
Review of attachment 815418 [details] [diff] [review]:
-----------------------------------------------------------------
Thanks!
Sorry about the delay reviewing this, the r? email got lost in my mail.
Attachment #815418 -
Flags: review?(kinetik) → review+
Assignee | ||
Comment 12•11 years ago
|
||
Comment 13•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/7049d17385d9
https://hg.mozilla.org/mozilla-central/rev/ac461ea5f961
https://hg.mozilla.org/mozilla-central/rev/8c159c637fdb
https://hg.mozilla.org/mozilla-central/rev/c988007d5cd1
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Updated•11 years ago
|
blocking-b2g: --- → 1.3+
Updated•11 years ago
|
status-firefox28:
--- → fixed
Updated•11 years ago
|
Blocks: b2g-webrtc
Comment 14•11 years ago
|
||
This fix seem to be covered by the tests here:
https://hg.mozilla.org/mozilla-central/rev/c988007d5cd1
Anything else needing testing here?
Flags: in-testsuite?
You need to log in
before you can comment on or make changes to this bug.
Description
•