OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/protocol/webrtc_audio_stream.h" |
| 6 |
| 7 #include "base/location.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "remoting/base/constants.h" |
| 11 #include "remoting/protocol/audio_source.h" |
| 12 #include "remoting/protocol/webrtc_audio_source_adapter.h" |
| 13 #include "remoting/protocol/webrtc_transport.h" |
| 14 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 15 #include "third_party/webrtc/api/peerconnectioninterface.h" |
| 16 #include "third_party/webrtc/base/refcount.h" |
| 17 |
| 18 namespace remoting { |
| 19 namespace protocol { |
| 20 |
| 21 const char kAudioStreamLabel[] = "audio_stream"; |
| 22 const char kAudioTrackLabel[] = "system_audio"; |
| 23 |
| 24 WebrtcAudioStream::WebrtcAudioStream() {} |
| 25 |
| 26 WebrtcAudioStream::~WebrtcAudioStream() { |
| 27 if (stream_) { |
| 28 for (const auto& track : stream_->GetAudioTracks()) { |
| 29 stream_->RemoveTrack(track.get()); |
| 30 } |
| 31 peer_connection_->RemoveStream(stream_.get()); |
| 32 } |
| 33 } |
| 34 |
| 35 bool WebrtcAudioStream::Start( |
| 36 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 37 std::unique_ptr<AudioSource> audio_source, |
| 38 WebrtcTransport* webrtc_transport) { |
| 39 DCHECK(webrtc_transport); |
| 40 |
| 41 source_adapter_ = |
| 42 new rtc::RefCountedObject<WebrtcAudioSourceAdapter>(audio_task_runner); |
| 43 source_adapter_->Start(std::move(audio_source)); |
| 44 |
| 45 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( |
| 46 webrtc_transport->peer_connection_factory()); |
| 47 peer_connection_ = webrtc_transport->peer_connection(); |
| 48 |
| 49 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track = |
| 50 peer_connection_factory->CreateAudioTrack(kAudioTrackLabel, |
| 51 source_adapter_.get()); |
| 52 |
| 53 stream_ = peer_connection_factory->CreateLocalMediaStream(kAudioStreamLabel); |
| 54 |
| 55 if (!stream_->AddTrack(audio_track.get()) || |
| 56 !peer_connection_->AddStream(stream_.get())) { |
| 57 stream_ = nullptr; |
| 58 peer_connection_ = nullptr; |
| 59 return false; |
| 60 } |
| 61 |
| 62 return true; |
| 63 } |
| 64 |
| 65 void WebrtcAudioStream::Pause(bool pause) { |
| 66 source_adapter_->Pause(pause); |
| 67 } |
| 68 |
| 69 } // namespace protocol |
| 70 } // namespace remoting |
OLD | NEW |