diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/media/CrossGraphPort.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/CrossGraphPort.h')
-rw-r--r-- | dom/media/CrossGraphPort.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/dom/media/CrossGraphPort.h b/dom/media/CrossGraphPort.h new file mode 100644 index 0000000000..98d2a095d0 --- /dev/null +++ b/dom/media/CrossGraphPort.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZILLA_CROSS_GRAPH_TRACK_H_ +#define MOZILLA_CROSS_GRAPH_TRACK_H_ + +#include "AudioDriftCorrection.h" +#include "AudioSegment.h" +#include "ForwardedInputTrack.h" +#include "mozilla/SPSCQueue.h" +#include "mozilla/UniquePtr.h" + +namespace mozilla { +class CrossGraphReceiver; +} + +namespace mozilla::dom { +class AudioStreamTrack; +} + +namespace mozilla { + +/** + * See MediaTrackGraph::CreateCrossGraphTransmitter() + */ +class CrossGraphTransmitter : public ProcessedMediaTrack { + public: + CrossGraphTransmitter(TrackRate aSampleRate, + 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: + const RefPtr<CrossGraphReceiver> mReceiver; +}; + +/** + * See MediaTrackGraph::CreateCrossGraphReceiver() + */ +class CrossGraphReceiver : public ProcessedMediaTrack { + public: + 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); + + private: + SPSCQueue<AudioChunk> mCrossThreadFIFO{30}; + // Indicates that tre CrossGraphTransmitter has started sending frames. It + // is false untill the point, transmitter has sent the first valid frame. + // Accessed in GraphThread only. + bool mTransmitterHasStarted = false; + // Correct the drift between transmitter and receiver. Reciever (this class) + // is considered as the master clock. + // Accessed in GraphThread only. + AudioDriftCorrection mDriftCorrection; +}; + +class CrossGraphPort final { + public: + static UniquePtr<CrossGraphPort> Connect( + const RefPtr<dom::AudioStreamTrack>& aStreamTrack, + MediaTrackGraph* aPartnerGraph); + static UniquePtr<CrossGraphPort> Connect( + const RefPtr<dom::AudioStreamTrack>& aStreamTrack, AudioDeviceInfo* aSink, + nsPIDOMWindowInner* aWindow); + ~CrossGraphPort(); + + void AddAudioOutput(void* aKey); + void RemoveAudioOutput(void* aKey); + void SetAudioOutputVolume(void* aKey, float aVolume); + + RefPtr<GenericPromise> EnsureConnected(); + + const RefPtr<CrossGraphTransmitter> mTransmitter; + const RefPtr<CrossGraphReceiver> mReceiver; + + private: + explicit CrossGraphPort(RefPtr<MediaInputPort> aTransmitterPort, + RefPtr<CrossGraphTransmitter> aTransmitter, + RefPtr<CrossGraphReceiver> aReceiver) + : mTransmitter(std::move(aTransmitter)), + mReceiver(std::move(aReceiver)), + mTransmitterPort(std::move(aTransmitterPort)) { + MOZ_ASSERT(mTransmitter); + MOZ_ASSERT(mReceiver); + MOZ_ASSERT(mTransmitterPort); + } + + // The port that connects the input track to the transmitter. + const RefPtr<MediaInputPort> mTransmitterPort; +}; + +} // namespace mozilla + +#endif /* MOZILLA_CROSS_GRAPH_TRACK_H_ */ |