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 #include "host/frontend/webrtc/libdevice/audio_track_source_impl.h"
18 
19 #include <android-base/logging.h>
20 
21 namespace cuttlefish {
22 namespace webrtc_streaming {
23 
SetVolume(double volume)24 void AudioTrackSourceImpl::SetVolume(double volume) {
25   std::lock_guard<std::mutex> lock(observers_mutex_);
26   for (auto observer : audio_observers_) {
27     observer->OnSetVolume(volume);
28   }
29 }
30 
RegisterAudioObserver(AudioObserver * observer)31 void AudioTrackSourceImpl::RegisterAudioObserver(AudioObserver* observer) {
32   std::lock_guard<std::mutex> lock(observers_mutex_);
33   audio_observers_.insert(observer);
34 }
UnregisterAudioObserver(AudioObserver * observer)35 void AudioTrackSourceImpl::UnregisterAudioObserver(AudioObserver* observer) {
36   std::lock_guard<std::mutex> lock(observers_mutex_);
37   audio_observers_.erase(observer);
38 }
39 
AddSink(webrtc::AudioTrackSinkInterface * sink)40 void AudioTrackSourceImpl::AddSink(webrtc::AudioTrackSinkInterface* sink) {
41   std::lock_guard<std::mutex> lock(sinks_mutex_);
42   sinks_.insert(sink);
43 }
44 
RemoveSink(webrtc::AudioTrackSinkInterface * sink)45 void AudioTrackSourceImpl::RemoveSink(webrtc::AudioTrackSinkInterface* sink) {
46   std::lock_guard<std::mutex> lock(sinks_mutex_);
47   sinks_.erase(sink);
48 }
49 
options() const50 const cricket::AudioOptions AudioTrackSourceImpl::options() const {
51   return cricket::AudioOptions();
52 }
53 
OnFrame(const AudioFrameBuffer & frame,int64_t timestamp_ms)54 void AudioTrackSourceImpl::OnFrame(const AudioFrameBuffer& frame,
55                                    int64_t timestamp_ms) {
56     std::lock_guard<std::mutex> lock(sinks_mutex_);
57     for (auto sink : sinks_) {
58       sink->OnData(frame.data(), frame.bits_per_sample(),
59                    frame.sample_rate(), frame.channels(), frame.frames(),
60                    timestamp_ms);
61     }
62 }
63 
state() const64 AudioTrackSourceImpl::SourceState AudioTrackSourceImpl::state() const {
65   return SourceState::kLive;
66 }
67 
remote() const68 bool AudioTrackSourceImpl::remote() const { return false; }
69 
RegisterObserver(webrtc::ObserverInterface *)70 void AudioTrackSourceImpl::RegisterObserver(
71     webrtc::ObserverInterface* /*observer*/) {}
72 
UnregisterObserver(webrtc::ObserverInterface *)73 void AudioTrackSourceImpl::UnregisterObserver(
74     webrtc::ObserverInterface* /*observer*/) {}
75 
76 }  // namespace webrtc_streaming
77 }  // namespace cuttlefish
78