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

Side by Side Diff: remoting/client/audio_player.cc

Issue 2052723002: Adding an interface to allow extention of the audio player for CRD and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/client/audio_player.h" 5 #include "remoting/client/audio_player.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 12
12 // If queue grows bigger than 150ms we start dropping packets. 13 // If queue grows bigger than 150ms we start dropping packets.
13 const int kMaxQueueLatencyMs = 150; 14 const int kMaxQueueLatencyMs = 150;
14 15
15 namespace remoting { 16 namespace remoting {
16 17
17 AudioPlayer::AudioPlayer() 18 AudioPlayer::AudioPlayer()
18 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), 19 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID),
19 start_failed_(false), 20 start_failed_(false),
20 queued_bytes_(0), 21 queued_bytes_(0),
21 bytes_consumed_(0) { 22 bytes_consumed_(0) {
22 } 23 }
23 24
24 AudioPlayer::~AudioPlayer() { 25 AudioPlayer::~AudioPlayer() {
25 base::AutoLock auto_lock(lock_); 26 base::AutoLock auto_lock(lock_);
26 ResetQueue(); 27 ResetQueue();
27 } 28 }
28 29
29 void AudioPlayer::ProcessAudioPacket(std::unique_ptr<AudioPacket> packet) { 30 void AudioPlayer::AddAudioPacket(std::unique_ptr<AudioPacket> packet) {
nicholss 2016/06/09 17:26:39 Add vs Process is to align with how consumers norm
30 CHECK_EQ(1, packet->data_size()); 31 CHECK_EQ(1, packet->data_size());
31 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); 32 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding());
32 DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate()); 33 DCHECK_NE(AudioPacket::SAMPLING_RATE_INVALID, packet->sampling_rate());
33 DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample())); 34 DCHECK_EQ(kSampleSizeBytes, static_cast<int>(packet->bytes_per_sample()));
34 DCHECK_EQ(kChannels, static_cast<int>(packet->channels())); 35 DCHECK_EQ(kChannels, static_cast<int>(packet->channels()));
35 DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u); 36 DCHECK_EQ(packet->data(0).size() % (kChannels * kSampleSizeBytes), 0u);
36 37
37 // No-op if the Pepper player won't start. 38 // No-op if the Pepper player won't start.
38 if (start_failed_) { 39 if (start_failed_) {
39 return; 40 return;
(...skipping 26 matching lines...) Expand all
66 base::Time::kMillisecondsPerSecond; 67 base::Time::kMillisecondsPerSecond;
67 while (queued_bytes_ > max_buffer_size_) { 68 while (queued_bytes_ > max_buffer_size_) {
68 queued_bytes_ -= queued_packets_.front()->data(0).size() - bytes_consumed_; 69 queued_bytes_ -= queued_packets_.front()->data(0).size() - bytes_consumed_;
69 DCHECK_GE(queued_bytes_, 0); 70 DCHECK_GE(queued_bytes_, 0);
70 delete queued_packets_.front(); 71 delete queued_packets_.front();
71 queued_packets_.pop_front(); 72 queued_packets_.pop_front();
72 bytes_consumed_ = 0; 73 bytes_consumed_ = 0;
73 } 74 }
74 } 75 }
75 76
77 void AudioPlayer::ProcessAudioPacket(std::unique_ptr<AudioPacket> packet) {
78 AddAudioPacket(std::move(packet));
79 }
80
76 // static 81 // static
77 void AudioPlayer::AudioPlayerCallback(void* samples, 82 void AudioPlayer::AudioPlayerCallback(void* samples,
78 uint32_t buffer_size, 83 uint32_t buffer_size,
79 void* data) { 84 void* data) {
80 AudioPlayer* audio_player = static_cast<AudioPlayer*>(data); 85 AudioPlayer* audio_player = static_cast<AudioPlayer*>(data);
81 audio_player->FillWithSamples(samples, buffer_size); 86 audio_player->FillWithSamples(samples, buffer_size);
82 } 87 }
83 88
84 void AudioPlayer::ResetQueue() { 89 void AudioPlayer::ResetQueue() {
85 lock_.AssertAcquired(); 90 lock_.AssertAcquired();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 128
124 next_sample += bytes_to_copy; 129 next_sample += bytes_to_copy;
125 bytes_consumed_ += bytes_to_copy; 130 bytes_consumed_ += bytes_to_copy;
126 bytes_extracted += bytes_to_copy; 131 bytes_extracted += bytes_to_copy;
127 queued_bytes_ -= bytes_to_copy; 132 queued_bytes_ -= bytes_to_copy;
128 DCHECK_GE(queued_bytes_, 0); 133 DCHECK_GE(queued_bytes_, 0);
129 } 134 }
130 } 135 }
131 136
132 } // namespace remoting 137 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698