xref: /aosp_15_r20/external/webrtc/pc/audio_track.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef PC_AUDIO_TRACK_H_
12 #define PC_AUDIO_TRACK_H_
13 
14 #include <string>
15 
16 #include "api/media_stream_interface.h"
17 #include "api/media_stream_track.h"
18 #include "api/scoped_refptr.h"
19 #include "api/sequence_checker.h"
20 #include "rtc_base/system/no_unique_address.h"
21 
22 namespace webrtc {
23 
24 // TODO(tommi): Instead of inheriting from `MediaStreamTrack<>`, implement the
25 // properties directly in this class. `MediaStreamTrack` doesn't guard against
26 // conflicting access, so we'd need to override those methods anyway in this
27 // class in order to make sure things are correctly checked.
28 class AudioTrack : public MediaStreamTrack<AudioTrackInterface>,
29                    public ObserverInterface {
30  protected:
31   // Protected ctor to force use of factory method.
32   AudioTrack(absl::string_view label,
33              const rtc::scoped_refptr<AudioSourceInterface>& source);
34 
35   AudioTrack() = delete;
36   AudioTrack(const AudioTrack&) = delete;
37   AudioTrack& operator=(const AudioTrack&) = delete;
38 
39   ~AudioTrack() override;
40 
41  public:
42   static rtc::scoped_refptr<AudioTrack> Create(
43       absl::string_view id,
44       const rtc::scoped_refptr<AudioSourceInterface>& source);
45 
46   // MediaStreamTrack implementation.
47   std::string kind() const override;
48 
49   // AudioTrackInterface implementation.
50   AudioSourceInterface* GetSource() const override;
51 
52   void AddSink(AudioTrackSinkInterface* sink) override;
53   void RemoveSink(AudioTrackSinkInterface* sink) override;
54 
55  private:
56   // ObserverInterface implementation.
57   void OnChanged() override;
58 
59  private:
60   const rtc::scoped_refptr<AudioSourceInterface> audio_source_;
61   RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker signaling_thread_checker_;
62 };
63 
64 }  // namespace webrtc
65 
66 #endif  // PC_AUDIO_TRACK_H_
67