mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 11:45:37 +00:00
Bug 1410456 - use jni methods in place of removed cubeb methods. r=padenot
MozReview-Commit-ID: 18fQVZeYAgk --HG-- extra : rebase_source : 67b9df3bdfb22d2baa05a15f6535af8d3d5c12d9
This commit is contained in:
parent
1561bd419e
commit
816b44e1a0
@ -25,6 +25,9 @@
|
||||
#include "prdtoa.h"
|
||||
#include <algorithm>
|
||||
#include <stdint.h>
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "GeneratedJNIWrappers.h"
|
||||
#endif
|
||||
|
||||
#define PREF_VOLUME_SCALE "media.volume_scale"
|
||||
#define PREF_CUBEB_BACKEND "media.cubeb.backend"
|
||||
@ -119,8 +122,8 @@ cubeb* sCubebContext;
|
||||
double sVolumeScale = 1.0;
|
||||
uint32_t sCubebPlaybackLatencyInMilliseconds = 100;
|
||||
uint32_t sCubebMSGLatencyInFrames = 512;
|
||||
bool sCubebPlaybackLatencyPrefSet;
|
||||
bool sCubebMSGLatencyPrefSet;
|
||||
bool sCubebPlaybackLatencyPrefSet = false;
|
||||
bool sCubebMSGLatencyPrefSet = false;
|
||||
bool sAudioStreamInitEverSucceeded = false;
|
||||
#ifdef MOZ_CUBEB_REMOTING
|
||||
bool sCubebSandbox;
|
||||
@ -305,11 +308,15 @@ bool InitPreferredSampleRate()
|
||||
if (!context) {
|
||||
return false;
|
||||
}
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
sPreferredSampleRate = AndroidGetAudioOutputSampleRate();
|
||||
#else
|
||||
if (cubeb_get_preferred_sample_rate(context,
|
||||
&sPreferredSampleRate) != CUBEB_OK) {
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
MOZ_ASSERT(sPreferredSampleRate);
|
||||
return true;
|
||||
}
|
||||
@ -527,14 +534,28 @@ bool CubebMSGLatencyPrefSet()
|
||||
return sCubebMSGLatencyPrefSet;
|
||||
}
|
||||
|
||||
Maybe<uint32_t> GetCubebMSGLatencyInFrames()
|
||||
uint32_t GetCubebMSGLatencyInFrames(cubeb_stream_params * params)
|
||||
{
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
if (!sCubebMSGLatencyPrefSet) {
|
||||
return Maybe<uint32_t>();
|
||||
if (sCubebMSGLatencyPrefSet) {
|
||||
MOZ_ASSERT(sCubebMSGLatencyInFrames > 0);
|
||||
return sCubebMSGLatencyInFrames;
|
||||
}
|
||||
MOZ_ASSERT(sCubebMSGLatencyInFrames > 0);
|
||||
return Some(sCubebMSGLatencyInFrames);
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
return AndroidGetAudioOutputFramesPerBuffer();
|
||||
#else
|
||||
cubeb* context = GetCubebContextUnlocked();
|
||||
if (!context) {
|
||||
return sCubebMSGLatencyInFrames; // default 512
|
||||
}
|
||||
uint32_t latency_frames = 0;
|
||||
if (cubeb_get_min_latency(context, params, &latency_frames) != CUBEB_OK) {
|
||||
NS_WARNING("Could not get minimal latency from cubeb.");
|
||||
return sCubebMSGLatencyInFrames; // default 512
|
||||
}
|
||||
return latency_frames;
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitLibrary()
|
||||
@ -741,5 +762,20 @@ void GetDeviceCollection(nsTArray<RefPtr<AudioDeviceInfo>>& aDeviceInfos,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
uint32_t AndroidGetAudioOutputSampleRate()
|
||||
{
|
||||
int32_t sample_rate = java::GeckoAppShell::GetAudioOutputSampleRate();
|
||||
MOZ_ASSERT(sample_rate > 0);
|
||||
return sample_rate;
|
||||
}
|
||||
uint32_t AndroidGetAudioOutputFramesPerBuffer()
|
||||
{
|
||||
int32_t frames = java::GeckoAppShell::GetAudioOutputFramesPerBuffer();
|
||||
MOZ_ASSERT(frames > 0);
|
||||
return frames;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace CubebUtils
|
||||
} // namespace mozilla
|
||||
|
@ -44,7 +44,7 @@ cubeb* GetCubebContext();
|
||||
void ReportCubebStreamInitFailure(bool aIsFirstStream);
|
||||
void ReportCubebBackendUsed();
|
||||
uint32_t GetCubebPlaybackLatencyInMilliseconds();
|
||||
Maybe<uint32_t> GetCubebMSGLatencyInFrames();
|
||||
uint32_t GetCubebMSGLatencyInFrames(cubeb_stream_params * params);
|
||||
bool CubebLatencyPrefSet();
|
||||
cubeb_channel_layout ConvertChannelMapToCubebLayout(uint32_t aChannelMap);
|
||||
void GetCurrentBackend(nsAString& aBackend);
|
||||
@ -52,6 +52,11 @@ void GetPreferredChannelLayout(nsAString& aLayout);
|
||||
void GetDeviceCollection(nsTArray<RefPtr<AudioDeviceInfo>>& aDeviceInfos,
|
||||
Side aSide);
|
||||
cubeb_channel_layout GetPreferredChannelLayoutOrSMPTE(cubeb* context, uint32_t aChannels);
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
uint32_t AndroidGetAudioOutputSampleRate();
|
||||
uint32_t AndroidGetAudioOutputFramesPerBuffer();
|
||||
#endif
|
||||
} // namespace CubebUtils
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -599,7 +599,6 @@ AudioCallbackDriver::Init()
|
||||
|
||||
cubeb_stream_params output;
|
||||
cubeb_stream_params input;
|
||||
uint32_t latency_frames;
|
||||
bool firstStream = CubebUtils::GetFirstStream();
|
||||
|
||||
MOZ_ASSERT(!NS_IsMainThread(),
|
||||
@ -629,14 +628,7 @@ AudioCallbackDriver::Init()
|
||||
output.layout = CubebUtils::GetPreferredChannelLayoutOrSMPTE(cubebContext, mOutputChannels);
|
||||
output.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
|
||||
Maybe<uint32_t> latencyPref = CubebUtils::GetCubebMSGLatencyInFrames();
|
||||
if (latencyPref) {
|
||||
latency_frames = latencyPref.value();
|
||||
} else {
|
||||
if (cubeb_get_min_latency(cubebContext, &output, &latency_frames) != CUBEB_OK) {
|
||||
NS_WARNING("Could not get minimal latency from cubeb.");
|
||||
}
|
||||
}
|
||||
uint32_t latency_frames = CubebUtils::GetCubebMSGLatencyInFrames(&output);
|
||||
|
||||
// Macbook and MacBook air don't have enough CPU to run very low latency
|
||||
// MediaStreamGraphs, cap the minimal latency to 512 frames int this case.
|
||||
|
Loading…
Reference in New Issue
Block a user