Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: remoting/protocol/webrtc_audio_stream.cc

Issue 2392963003: Add Audio support in Chromoting host when using WebRTC. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 void 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 // AddTrack() may fail only if there is another track with the same name,
56 // which is impossible because it's a brand new stream.
57 bool result = stream_->AddTrack(audio_track.get());
58 DCHECK(result);
59
60 // AddStream() may fail if there is another stream with the same name or when
61 // the PeerConnection is closed, neither is expected.
62 result = peer_connection_->AddStream(stream_.get());
63 DCHECK(result);
64 }
65
66 void WebrtcAudioStream::Pause(bool pause) {
67 source_adapter_->Pause(pause);
68 }
69
70 } // namespace protocol
71 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/webrtc_audio_stream.h ('k') | remoting/protocol/webrtc_connection_to_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698