tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AudioStreamTrack.h (2494B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef AUDIOSTREAMTRACK_H_
      7 #define AUDIOSTREAMTRACK_H_
      8 
      9 #include "CrossGraphPort.h"
     10 #include "DOMMediaStream.h"
     11 #include "MediaStreamTrack.h"
     12 #include "nsClassHashtable.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 class AudioStreamTrack : public MediaStreamTrack {
     17 public:
     18  AudioStreamTrack(
     19      nsPIDOMWindowInner* aWindow, mozilla::MediaTrack* aInputTrack,
     20      MediaStreamTrackSource* aSource,
     21      MediaStreamTrackState aReadyState = MediaStreamTrackState::Live,
     22      bool aMuted = false,
     23      const MediaTrackConstraints& aConstraints = MediaTrackConstraints())
     24      : MediaStreamTrack(aWindow, aInputTrack, aSource, aReadyState, aMuted,
     25                         aConstraints) {}
     26 
     27  already_AddRefed<MediaStreamTrack> Clone() override;
     28 
     29  AudioStreamTrack* AsAudioStreamTrack() override { return this; }
     30  const AudioStreamTrack* AsAudioStreamTrack() const override { return this; }
     31 
     32  // Direct output to aSink, or the default output device if aSink is null.
     33  // No more than one output may exist for a single aKey at any one time.
     34  // Returns a promise that resolves when the device is processing audio.
     35  RefPtr<GenericPromise> AddAudioOutput(void* aKey, AudioDeviceInfo* aSink);
     36  void RemoveAudioOutput(void* aKey);
     37  void SetAudioOutputVolume(void* aKey, float aVolume);
     38 
     39  // Use AddConsumerPort instead of ForwardTrackContentsTo when possible, since
     40  // it handles CrossGraphPort creation automatically. Must be balanced with a
     41  // corresponding RemoveConsumerPort call.
     42  already_AddRefed<MediaInputPort> AddConsumerPort(ProcessedMediaTrack* aTrack);
     43  void RemoveConsumerPort(MediaInputPort* aPort);
     44 
     45  // WebIDL
     46  void GetKind(nsAString& aKind) override { aKind.AssignLiteral("audio"); }
     47 
     48  void GetLabel(nsAString& aLabel, CallerType aCallerType) override;
     49 
     50 protected:
     51  void SetReadyState(MediaStreamTrackState aState) override;
     52 
     53 private:
     54  // Main thread only
     55  struct CrossGraphConnection {
     56    UniquePtr<CrossGraphPort> mPort;
     57    size_t mRefCount;
     58 
     59    explicit CrossGraphConnection(UniquePtr<CrossGraphPort> aPort)
     60        : mPort(std::move(aPort)), mRefCount(1) {}
     61  };
     62  nsTArray<CrossGraphConnection> mCrossGraphs;
     63 };
     64 
     65 }  // namespace mozilla::dom
     66 
     67 #endif /* AUDIOSTREAMTRACK_H_ */