Android-cuttlefish cvd tool
audio_track_source_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <mutex>
20#include <set>
21
22#include "api/media_stream_interface.h"
23
25
26namespace cuttlefish {
27namespace webrtc_streaming {
28
29class AudioTrackSourceImpl : public webrtc::AudioSourceInterface {
30 public:
32
33 // Sets the volume of the source. |volume| is in the range of [0, 10].
34 void SetVolume(double volume) override;
35
36 void RegisterAudioObserver(AudioObserver* observer) override;
37 void UnregisterAudioObserver(AudioObserver* observer) override;
38
39 void AddSink(webrtc::AudioTrackSinkInterface* sink) override;
40 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override;
41
42 // Returns options for the AudioSource.
43 // (for some of the settings this approach is broken, e.g. setting
44 // audio network adaptation on the source is the wrong layer of abstraction).
45 virtual const cricket::AudioOptions options() const override;
46
47 void OnFrame(const AudioFrameBuffer& frame, int64_t timestamp_ms);
48
49 // MediaSourceInterface implementation
50 SourceState state() const override;
51 bool remote() const override;
52
53 // NotifierInterface implementation
54 void RegisterObserver(webrtc::ObserverInterface* observer) override;
55 void UnregisterObserver(webrtc::ObserverInterface* observer) override;
56
57 private:
58 std::set<AudioObserver*> audio_observers_;
59 std::mutex observers_mutex_;
60 std::set<webrtc::AudioTrackSinkInterface*> sinks_;
61 std::mutex sinks_mutex_;
62};
63
64// Wraps an AudioTrackSourceImpl as an implementation of the AudioSink
65// interface. This is needed as the AudioTrackSourceImpl is a reference counted
66// object that should only be referenced by rtc::scoped_refptr pointers, but the
67// AudioSink interface is not a reference counted object and therefore not
68// compatible with that kind of pointers. This class can be referenced by a
69// shared pointer and it in turn holds a scoped_refptr to the wrapped object.
71 public:
73
74 AudioTrackSourceImplSinkWrapper(rtc::scoped_refptr<AudioTrackSourceImpl> obj)
75 : track_source_impl_(obj) {}
76
77 void OnFrame(const AudioFrameBuffer& frame, int64_t timestamp_ms) override {
78 track_source_impl_->OnFrame(frame, timestamp_ms);
79 }
80
81 private:
82 rtc::scoped_refptr<AudioTrackSourceImpl> track_source_impl_;
83};
84
85} // namespace webrtc_streaming
86} // namespace cuttlefish
Definition: audio_frame_buffer.h:24
Definition: audio_sink.h:26
void OnFrame(const AudioFrameBuffer &frame, int64_t timestamp_ms) override
Definition: audio_track_source_impl.h:77
rtc::scoped_refptr< AudioTrackSourceImpl > track_source_impl_
Definition: audio_track_source_impl.h:82
AudioTrackSourceImplSinkWrapper(rtc::scoped_refptr< AudioTrackSourceImpl > obj)
Definition: audio_track_source_impl.h:74
Definition: audio_track_source_impl.h:29
void RegisterAudioObserver(AudioObserver *observer) override
Definition: audio_track_source_impl.cpp:29
void RemoveSink(webrtc::AudioTrackSinkInterface *sink) override
Definition: audio_track_source_impl.cpp:43
bool remote() const override
Definition: audio_track_source_impl.cpp:65
SourceState state() const override
Definition: audio_track_source_impl.cpp:61
virtual const cricket::AudioOptions options() const override
Definition: audio_track_source_impl.cpp:48
std::mutex observers_mutex_
Definition: audio_track_source_impl.h:59
void AddSink(webrtc::AudioTrackSinkInterface *sink) override
Definition: audio_track_source_impl.cpp:38
void OnFrame(const AudioFrameBuffer &frame, int64_t timestamp_ms)
Definition: audio_track_source_impl.cpp:52
std::mutex sinks_mutex_
Definition: audio_track_source_impl.h:61
std::set< AudioObserver * > audio_observers_
Definition: audio_track_source_impl.h:58
void UnregisterObserver(webrtc::ObserverInterface *observer) override
Definition: audio_track_source_impl.cpp:70
std::set< webrtc::AudioTrackSinkInterface * > sinks_
Definition: audio_track_source_impl.h:60
void UnregisterAudioObserver(AudioObserver *observer) override
Definition: audio_track_source_impl.cpp:33
void SetVolume(double volume) override
Definition: audio_track_source_impl.cpp:22
void RegisterObserver(webrtc::ObserverInterface *observer) override
Definition: audio_track_source_impl.cpp:67
Definition: alloc_driver.h:20