зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1651745 - Make channel count explicit for every audio MediaTrack. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D95932
This commit is contained in:
Родитель
7b6488e143
Коммит
3b3ae5f371
|
@ -101,6 +101,10 @@ void AudioCaptureTrack::ProcessInput(GraphTime aFrom, GraphTime aTo,
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t AudioCaptureTrack::NumberOfChannels() const {
|
||||
return GetData<AudioSegment>()->MaxChannelCount();
|
||||
}
|
||||
|
||||
void AudioCaptureTrack::MixerCallback(AudioDataValue* aMixedBuffer,
|
||||
AudioSampleFormat aFormat,
|
||||
uint32_t aChannels, uint32_t aFrames,
|
||||
|
|
|
@ -28,6 +28,8 @@ class AudioCaptureTrack : public ProcessedMediaTrack,
|
|||
|
||||
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override;
|
||||
|
||||
uint32_t NumberOfChannels() const override;
|
||||
|
||||
protected:
|
||||
void MixerCallback(AudioDataValue* aMixedBuffer, AudioSampleFormat aFormat,
|
||||
uint32_t aChannels, uint32_t aFrames,
|
||||
|
|
|
@ -162,6 +162,10 @@ CrossGraphReceiver::CrossGraphReceiver(TrackRate aSampleRate,
|
|||
static_cast<MediaSegment*>(new AudioSegment())),
|
||||
mDriftCorrection(aTransmitterRate, aSampleRate) {}
|
||||
|
||||
uint32_t CrossGraphReceiver::NumberOfChannels() const {
|
||||
return GetData<AudioSegment>()->MaxChannelCount();
|
||||
}
|
||||
|
||||
void CrossGraphReceiver::ProcessInput(GraphTime aFrom, GraphTime aTo,
|
||||
uint32_t aFlags) {
|
||||
LOG(LogLevel::Verbose,
|
||||
|
|
|
@ -31,6 +31,9 @@ class CrossGraphTransmitter : public ProcessedMediaTrack {
|
|||
RefPtr<CrossGraphReceiver> aReceiver);
|
||||
CrossGraphTransmitter* AsCrossGraphTransmitter() override { return this; }
|
||||
|
||||
uint32_t NumberOfChannels() const override {
|
||||
MOZ_CRASH("CrossGraphTransmitter has no segment. It cannot be played out.");
|
||||
}
|
||||
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override;
|
||||
|
||||
private:
|
||||
|
@ -45,6 +48,7 @@ class CrossGraphReceiver : public ProcessedMediaTrack {
|
|||
CrossGraphReceiver(TrackRate aSampleRate, TrackRate aTransmitterRate);
|
||||
CrossGraphReceiver* AsCrossGraphReceiver() override { return this; }
|
||||
|
||||
uint32_t NumberOfChannels() const override;
|
||||
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override;
|
||||
|
||||
int EnqueueAudio(AudioChunk& aChunk);
|
||||
|
|
|
@ -230,6 +230,14 @@ void ForwardedInputTrack::OnInputDisabledModeChanged(
|
|||
NotifyIfDisabledModeChangedFrom(oldMode);
|
||||
}
|
||||
|
||||
uint32_t ForwardedInputTrack::NumberOfChannels() const {
|
||||
MOZ_DIAGNOSTIC_ASSERT(mSegment->GetType() == MediaSegment::AUDIO);
|
||||
if (!mInputPort || !mInputPort->GetSource()) {
|
||||
return GetData<AudioSegment>()->MaxChannelCount();
|
||||
}
|
||||
return mInputPort->GetSource()->NumberOfChannels();
|
||||
}
|
||||
|
||||
void ForwardedInputTrack::AddDirectListenerImpl(
|
||||
already_AddRefed<DirectMediaTrackListener> aListener) {
|
||||
RefPtr<DirectMediaTrackListener> listener = aListener;
|
||||
|
|
|
@ -30,6 +30,8 @@ class ForwardedInputTrack : public ProcessedMediaTrack {
|
|||
void SetDisabledTrackModeImpl(DisabledTrackMode aMode) override;
|
||||
void OnInputDisabledModeChanged(DisabledTrackMode aInputMode) override;
|
||||
|
||||
uint32_t NumberOfChannels() const override;
|
||||
|
||||
friend class MediaTrackGraphImpl;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -2847,6 +2847,15 @@ void SourceMediaTrack::SetDisabledTrackModeImpl(DisabledTrackMode aMode) {
|
|||
MediaTrack::SetDisabledTrackModeImpl(aMode);
|
||||
}
|
||||
|
||||
uint32_t SourceMediaTrack::NumberOfChannels() const {
|
||||
AudioSegment* audio = GetData<AudioSegment>();
|
||||
MOZ_DIAGNOSTIC_ASSERT(audio);
|
||||
if (!audio) {
|
||||
return 0;
|
||||
}
|
||||
return audio->MaxChannelCount();
|
||||
}
|
||||
|
||||
void SourceMediaTrack::RemoveAllDirectListenersImpl() {
|
||||
GraphImpl()->AssertOnGraphThreadOrNotRunning();
|
||||
MutexAutoLock lock(mMutex);
|
||||
|
@ -3619,16 +3628,7 @@ uint32_t MediaTrackGraphImpl::AudioOutputChannelCount() const {
|
|||
// output channel count the machine can do, whichever is smaller.
|
||||
uint32_t channelCount = 0;
|
||||
for (auto& tkv : mAudioOutputs) {
|
||||
MediaTrack* t = tkv.mTrack;
|
||||
// This is an AudioDestinationNode
|
||||
if (t->AsAudioNodeTrack()) {
|
||||
channelCount = std::max<uint32_t>(
|
||||
channelCount, t->AsAudioNodeTrack()->NumberOfChannels());
|
||||
} else if (t->GetData<AudioSegment>()) {
|
||||
AudioSegment* segment = t->GetData<AudioSegment>();
|
||||
channelCount =
|
||||
std::max<uint32_t>(channelCount, segment->MaxChannelCount());
|
||||
}
|
||||
channelCount = std::max(channelCount, tkv.mTrack->NumberOfChannels());
|
||||
}
|
||||
channelCount = std::min(channelCount, mMaxOutputChannelCount);
|
||||
if (channelCount) {
|
||||
|
|
|
@ -419,6 +419,11 @@ class MediaTrack : public mozilla::LinkedListElement<MediaTrack> {
|
|||
GraphTime StartTime() const { return mStartTime; }
|
||||
bool Ended() const { return mEnded; }
|
||||
|
||||
// Returns the current number of channels this track contains if it's an audio
|
||||
// track. Calling this on a video track will trip assertions. Graph thread
|
||||
// only.
|
||||
virtual uint32_t NumberOfChannels() const = 0;
|
||||
|
||||
// The DisabledTrackMode after combining the explicit mode and that of the
|
||||
// input, if any.
|
||||
virtual DisabledTrackMode CombinedDisabledMode() const {
|
||||
|
@ -690,6 +695,8 @@ class SourceMediaTrack : public MediaTrack {
|
|||
MediaTrack::ApplyTrackDisabling(aSegment, aRawSegment);
|
||||
}
|
||||
|
||||
uint32_t NumberOfChannels() const override;
|
||||
|
||||
void RemoveAllDirectListenersImpl() override;
|
||||
|
||||
// The value set here is applied in MoveToSegment so we can avoid the
|
||||
|
|
|
@ -115,7 +115,7 @@ class AudioNodeTrack : public ProcessedMediaTrack {
|
|||
mAudioParamTrack = true;
|
||||
}
|
||||
// The value for channelCount on an AudioNode, but on the audio thread side.
|
||||
uint32_t NumberOfChannels() const;
|
||||
uint32_t NumberOfChannels() const override;
|
||||
|
||||
/*
|
||||
* Resume track after updating its concept of current time by aAdvance.
|
||||
|
|
|
@ -91,6 +91,8 @@ class FakeAudioTrack : public mozilla::ProcessedMediaTrack {
|
|||
|
||||
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override {}
|
||||
|
||||
uint32_t NumberOfChannels() const override { return NUM_CHANNELS; }
|
||||
|
||||
private:
|
||||
mozilla::Mutex mMutex;
|
||||
MediaTrackListener* mListener = nullptr;
|
||||
|
@ -98,11 +100,10 @@ class FakeAudioTrack : public mozilla::ProcessedMediaTrack {
|
|||
nsCOMPtr<nsITimer> mTimer;
|
||||
int mCount = 0;
|
||||
|
||||
static const int AUDIO_BUFFER_SIZE = 1600;
|
||||
static const int NUM_CHANNELS = 2;
|
||||
static void FakeAudioTrackGenerateData(nsITimer* timer, void* closure) {
|
||||
auto t = static_cast<FakeAudioTrack*>(closure);
|
||||
const int AUDIO_BUFFER_SIZE = 1600;
|
||||
const int NUM_CHANNELS = 2;
|
||||
|
||||
mozilla::MutexAutoLock lock(t->mMutex);
|
||||
if (t->mSuspended) {
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче