OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/pepper/pepper_media_stream_audio_track_host.h" | 5 #include "content/renderer/pepper/pepper_media_stream_audio_track_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/c/ppb_audio_frame.h" | 13 #include "ppapi/c/ppb_audio_buffer.h" |
14 #include "ppapi/shared_impl/media_stream_buffer.h" | 14 #include "ppapi/shared_impl/media_stream_buffer.h" |
15 | 15 |
16 using media::AudioParameters; | 16 using media::AudioParameters; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Max audio buffer duration in milliseconds. | 20 // Max audio buffer duration in milliseconds. |
21 const uint32_t kMaxDuration = 10; | 21 const uint32_t kMaxDuration = 10; |
22 | 22 |
23 // TODO(penghuang): make this configurable. | 23 // TODO(penghuang): make this configurable. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 if (index != -1) { | 89 if (index != -1) { |
90 // TODO(penghuang): support re-sampling, etc. | 90 // TODO(penghuang): support re-sampling, etc. |
91 ppapi::MediaStreamBuffer::Audio* buffer = | 91 ppapi::MediaStreamBuffer::Audio* buffer = |
92 &(host_->buffer_manager()->GetBufferPointer(index)->audio); | 92 &(host_->buffer_manager()->GetBufferPointer(index)->audio); |
93 buffer->header.size = host_->buffer_manager()->buffer_size(); | 93 buffer->header.size = host_->buffer_manager()->buffer_size(); |
94 buffer->header.type = ppapi::MediaStreamBuffer::TYPE_AUDIO; | 94 buffer->header.type = ppapi::MediaStreamBuffer::TYPE_AUDIO; |
95 buffer->timestamp = timestamp_.InMillisecondsF(); | 95 buffer->timestamp = timestamp_.InMillisecondsF(); |
96 buffer->sample_rate = static_cast<PP_AudioFrame_SampleRate>(sample_rate); | 96 buffer->sample_rate = static_cast<PP_AudioBuffer_SampleRate>(sample_rate); |
97 buffer->number_of_channels = number_of_channels; | 97 buffer->number_of_channels = number_of_channels; |
98 buffer->number_of_samples = number_of_channels * number_of_frames; | 98 buffer->number_of_samples = number_of_channels * number_of_frames; |
99 buffer->data_size = buffer_data_size_; | 99 buffer->data_size = buffer_data_size_; |
100 memcpy(buffer->data, audio_data, buffer_data_size_); | 100 memcpy(buffer->data, audio_data, buffer_data_size_); |
101 | 101 |
102 main_message_loop_proxy_->PostTask( | 102 main_message_loop_proxy_->PostTask( |
103 FROM_HERE, | 103 FROM_HERE, |
104 base::Bind(&AudioSink::SendEnqueueBufferMessageOnMainThread, | 104 base::Bind(&AudioSink::SendEnqueueBufferMessageOnMainThread, |
105 weak_factory_.GetWeakPtr(), index)); | 105 weak_factory_.GetWeakPtr(), index)); |
106 } | 106 } |
107 timestamp_ += buffer_duration_; | 107 timestamp_ += buffer_duration_; |
108 } | 108 } |
109 | 109 |
110 void PepperMediaStreamAudioTrackHost::AudioSink::OnSetFormat( | 110 void PepperMediaStreamAudioTrackHost::AudioSink::OnSetFormat( |
111 const AudioParameters& params) { | 111 const AudioParameters& params) { |
112 DCHECK(params.IsValid()); | 112 DCHECK(params.IsValid()); |
113 DCHECK_LE(params.GetBufferDuration().InMilliseconds(), kMaxDuration); | 113 DCHECK_LE(params.GetBufferDuration().InMilliseconds(), kMaxDuration); |
114 DCHECK_EQ(params.bits_per_sample(), 16); | 114 DCHECK_EQ(params.bits_per_sample(), 16); |
115 DCHECK((params.sample_rate() == AudioParameters::kTelephoneSampleRate) || | 115 DCHECK((params.sample_rate() == AudioParameters::kTelephoneSampleRate) || |
116 (params.sample_rate() == AudioParameters::kAudioCDSampleRate)); | 116 (params.sample_rate() == AudioParameters::kAudioCDSampleRate)); |
117 | 117 |
118 COMPILE_ASSERT(AudioParameters::kTelephoneSampleRate == | 118 COMPILE_ASSERT(AudioParameters::kTelephoneSampleRate == |
119 static_cast<int32_t>(PP_AUDIOFRAME_SAMPLERATE_8000), | 119 static_cast<int32_t>(PP_AUDIOBUFFER_SAMPLERATE_8000), |
120 audio_sample_rate_does_not_match); | 120 audio_sample_rate_does_not_match); |
121 COMPILE_ASSERT(AudioParameters::kAudioCDSampleRate == | 121 COMPILE_ASSERT(AudioParameters::kAudioCDSampleRate == |
122 static_cast<int32_t>(PP_AUDIOFRAME_SAMPLERATE_44100), | 122 static_cast<int32_t>(PP_AUDIOBUFFER_SAMPLERATE_44100), |
123 audio_sample_rate_does_not_match); | 123 audio_sample_rate_does_not_match); |
124 audio_params_ = params; | 124 audio_params_ = params; |
125 | 125 |
126 // TODO(penghuang): support setting format more than once. | 126 // TODO(penghuang): support setting format more than once. |
127 buffer_duration_ = params.GetBufferDuration(); | 127 buffer_duration_ = params.GetBufferDuration(); |
128 buffer_data_size_ = params.GetBytesPerBuffer(); | 128 buffer_data_size_ = params.GetBytesPerBuffer(); |
129 | 129 |
130 if (original_audio_params_.IsValid()) { | 130 if (original_audio_params_.IsValid()) { |
131 DCHECK_EQ(params.sample_rate(), original_audio_params_.sample_rate()); | 131 DCHECK_EQ(params.sample_rate(), original_audio_params_.sample_rate()); |
132 DCHECK_EQ(params.bits_per_sample(), | 132 DCHECK_EQ(params.bits_per_sample(), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 void PepperMediaStreamAudioTrackHost::DidConnectPendingHostToResource() { | 183 void PepperMediaStreamAudioTrackHost::DidConnectPendingHostToResource() { |
184 if (!connected_) { | 184 if (!connected_) { |
185 MediaStreamAudioSink::AddToAudioTrack(&audio_sink_, track_); | 185 MediaStreamAudioSink::AddToAudioTrack(&audio_sink_, track_); |
186 connected_ = true; | 186 connected_ = true; |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 } // namespace content | 190 } // namespace content |
OLD | NEW |