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

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

Issue 2653563004: Revert 25680c62320767f590d037d301edfe15e9c55650 (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « remoting/protocol/webrtc_audio_sink_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/protocol/webrtc_audio_sink_adapter.h" 5 #include "remoting/protocol/webrtc_audio_sink_adapter.h"
6 6
7 #include "base/bind.h"
8 #include "base/callback.h" 7 #include "base/callback.h"
9 #include "remoting/proto/audio.pb.h" 8 #include "remoting/proto/audio.pb.h"
10 #include "remoting/protocol/audio_stub.h" 9 #include "remoting/protocol/audio_stub.h"
11 10
12 namespace remoting { 11 namespace remoting {
13 namespace protocol { 12 namespace protocol {
14 13
15 WebrtcAudioSinkAdapter::WebrtcAudioSinkAdapter( 14 WebrtcAudioSinkAdapter::WebrtcAudioSinkAdapter(
16 scoped_refptr<webrtc::MediaStreamInterface> stream, 15 scoped_refptr<webrtc::MediaStreamInterface> stream,
17 base::WeakPtr<AudioStub> audio_stub) 16 base::WeakPtr<AudioStub> audio_stub) {
18 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 17 audio_stub_ = audio_stub;
19 audio_stub_(audio_stub), 18
20 media_stream_(std::move(stream)) { 19 media_stream_ = std::move(stream);
20
21 webrtc::AudioTrackVector audio_tracks = media_stream_->GetAudioTracks(); 21 webrtc::AudioTrackVector audio_tracks = media_stream_->GetAudioTracks();
22 22
23 // Caller must verify that the media stream contains audio tracks. 23 // Caller must verify that the media stream contains audio tracks.
24 DCHECK(!audio_tracks.empty()); 24 DCHECK(!audio_tracks.empty());
25
25 if (audio_tracks.size() > 1U) { 26 if (audio_tracks.size() > 1U) {
26 LOG(WARNING) << "Received media stream with multiple audio tracks."; 27 LOG(WARNING) << "Received media stream with multiple audio tracks.";
27 } 28 }
29
28 audio_track_ = audio_tracks[0]; 30 audio_track_ = audio_tracks[0];
29 audio_track_->GetSource()->AddSink(this); 31 audio_track_->GetSource()->AddSink(this);
30 } 32 }
31 33
32 WebrtcAudioSinkAdapter::~WebrtcAudioSinkAdapter() { 34 WebrtcAudioSinkAdapter::~WebrtcAudioSinkAdapter() {
33 audio_track_->GetSource()->RemoveSink(this); 35 audio_track_->GetSource()->RemoveSink(this);
34 } 36 }
35 37
36 void WebrtcAudioSinkAdapter::OnData(const void* audio_data, 38 void WebrtcAudioSinkAdapter::OnData(const void* audio_data,
37 int bits_per_sample, 39 int bits_per_sample,
38 int sample_rate, 40 int sample_rate,
39 size_t number_of_channels, 41 size_t number_of_channels,
40 size_t number_of_frames) { 42 size_t number_of_frames) {
43 if (!audio_stub_)
44 return;
45
41 std::unique_ptr<AudioPacket> audio_packet(new AudioPacket()); 46 std::unique_ptr<AudioPacket> audio_packet(new AudioPacket());
42 audio_packet->set_encoding(AudioPacket::ENCODING_RAW); 47 audio_packet->set_encoding(AudioPacket::ENCODING_RAW);
43 48
44 switch (sample_rate) { 49 switch (sample_rate) {
45 case 44100: 50 case 44100:
46 audio_packet->set_sampling_rate(AudioPacket::SAMPLING_RATE_44100); 51 audio_packet->set_sampling_rate(AudioPacket::SAMPLING_RATE_44100);
47 break; 52 break;
48 case 48000: 53 case 48000:
49 audio_packet->set_sampling_rate(AudioPacket::SAMPLING_RATE_48000); 54 audio_packet->set_sampling_rate(AudioPacket::SAMPLING_RATE_48000);
50 break; 55 break;
(...skipping 10 matching lines...) Expand all
61 66
62 if (number_of_channels != 2) { 67 if (number_of_channels != 2) {
63 LOG(WARNING) << "Unsupported number of channels: " << number_of_channels; 68 LOG(WARNING) << "Unsupported number of channels: " << number_of_channels;
64 return; 69 return;
65 } 70 }
66 audio_packet->set_channels(AudioPacket::CHANNELS_STEREO); 71 audio_packet->set_channels(AudioPacket::CHANNELS_STEREO);
67 72
68 size_t data_size = 73 size_t data_size =
69 number_of_frames * number_of_channels * (bits_per_sample / 8); 74 number_of_frames * number_of_channels * (bits_per_sample / 8);
70 audio_packet->add_data(reinterpret_cast<const char*>(audio_data), data_size); 75 audio_packet->add_data(reinterpret_cast<const char*>(audio_data), data_size);
71 76 audio_stub_->ProcessAudioPacket(std::move(audio_packet), base::Closure());
72 task_runner_->PostTask(
73 FROM_HERE, base::Bind(&AudioStub::ProcessAudioPacket, audio_stub_,
74 base::Passed(&audio_packet), base::Closure()));
75 } 77 }
76 78
77 } // namespace protocol 79 } // namespace protocol
78 } // namespace remoting 80 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/webrtc_audio_sink_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698