Source code

Revision control

Copy as Markdown

Other Tools

/* -*- 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 */
#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 {
* CrossGraphTransmitter and CrossGraphPort are currently unused, but intended
* for connecting MediaTracks of different MediaTrackGraphs with different
* sample rates or clock sources for bug 1674892.
* Create with MediaTrackGraph::CreateCrossGraphTransmitter()
class CrossGraphTransmitter : public ProcessedMediaTrack {
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;
const RefPtr<CrossGraphReceiver> mReceiver;
* Create with MediaTrackGraph::CreateCrossGraphReceiver()
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);
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 {
static UniquePtr<CrossGraphPort> Connect(
const RefPtr<dom::AudioStreamTrack>& aStreamTrack,
MediaTrackGraph* aPartnerGraph);
const RefPtr<CrossGraphTransmitter> mTransmitter;
const RefPtr<CrossGraphReceiver> mReceiver;
explicit CrossGraphPort(RefPtr<MediaInputPort> aTransmitterPort,
RefPtr<CrossGraphTransmitter> aTransmitter,
RefPtr<CrossGraphReceiver> aReceiver)
: mTransmitter(std::move(aTransmitter)),
mTransmitterPort(std::move(aTransmitterPort)) {
// The port that connects the input track to the transmitter.
const RefPtr<MediaInputPort> mTransmitterPort;
} // namespace mozilla