| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void AudioTrackJni::OnCacheDirectBufferAddress( | 220 void AudioTrackJni::OnCacheDirectBufferAddress( |
| 221 JNIEnv* env, jobject byte_buffer) { | 221 JNIEnv* env, jobject byte_buffer) { |
| 222 ALOGD("OnCacheDirectBufferAddress"); | 222 ALOGD("OnCacheDirectBufferAddress"); |
| 223 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 223 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 RTC_DCHECK(!direct_buffer_address_); | 224 RTC_DCHECK(!direct_buffer_address_); |
| 225 direct_buffer_address_ = | 225 direct_buffer_address_ = |
| 226 env->GetDirectBufferAddress(byte_buffer); | 226 env->GetDirectBufferAddress(byte_buffer); |
| 227 jlong capacity = env->GetDirectBufferCapacity(byte_buffer); | 227 jlong capacity = env->GetDirectBufferCapacity(byte_buffer); |
| 228 ALOGD("direct buffer capacity: %lld", capacity); | 228 ALOGD("direct buffer capacity: %lld", capacity); |
| 229 direct_buffer_capacity_in_bytes_ = static_cast<size_t>(capacity); | 229 direct_buffer_capacity_in_bytes_ = static_cast<size_t>(capacity); |
| 230 frames_per_buffer_ = direct_buffer_capacity_in_bytes_ / kBytesPerFrame; | 230 const size_t bytes_per_frame = audio_parameters_.channels() * sizeof(int16_t); |
| 231 frames_per_buffer_ = direct_buffer_capacity_in_bytes_ / bytes_per_frame; |
| 231 ALOGD("frames_per_buffer: %" PRIuS, frames_per_buffer_); | 232 ALOGD("frames_per_buffer: %" PRIuS, frames_per_buffer_); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void JNICALL AudioTrackJni::GetPlayoutData( | 235 void JNICALL AudioTrackJni::GetPlayoutData( |
| 235 JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack) { | 236 JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack) { |
| 236 webrtc::AudioTrackJni* this_object = | 237 webrtc::AudioTrackJni* this_object = |
| 237 reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack); | 238 reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack); |
| 238 this_object->OnGetPlayoutData(static_cast<size_t>(length)); | 239 this_object->OnGetPlayoutData(static_cast<size_t>(length)); |
| 239 } | 240 } |
| 240 | 241 |
| 241 // This method is called on a high-priority thread from Java. The name of | 242 // This method is called on a high-priority thread from Java. The name of |
| 242 // the thread is 'AudioRecordTrack'. | 243 // the thread is 'AudioRecordTrack'. |
| 243 void AudioTrackJni::OnGetPlayoutData(size_t length) { | 244 void AudioTrackJni::OnGetPlayoutData(size_t length) { |
| 244 RTC_DCHECK(thread_checker_java_.CalledOnValidThread()); | 245 RTC_DCHECK(thread_checker_java_.CalledOnValidThread()); |
| 245 RTC_DCHECK_EQ(frames_per_buffer_, length / kBytesPerFrame); | 246 const size_t bytes_per_frame = audio_parameters_.channels() * sizeof(int16_t); |
| 247 RTC_DCHECK_EQ(frames_per_buffer_, length / bytes_per_frame); |
| 246 if (!audio_device_buffer_) { | 248 if (!audio_device_buffer_) { |
| 247 ALOGE("AttachAudioBuffer has not been called!"); | 249 ALOGE("AttachAudioBuffer has not been called!"); |
| 248 return; | 250 return; |
| 249 } | 251 } |
| 250 // Pull decoded data (in 16-bit PCM format) from jitter buffer. | 252 // Pull decoded data (in 16-bit PCM format) from jitter buffer. |
| 251 int samples = audio_device_buffer_->RequestPlayoutData(frames_per_buffer_); | 253 int samples = audio_device_buffer_->RequestPlayoutData(frames_per_buffer_); |
| 252 if (samples <= 0) { | 254 if (samples <= 0) { |
| 253 ALOGE("AudioDeviceBuffer::RequestPlayoutData failed!"); | 255 ALOGE("AudioDeviceBuffer::RequestPlayoutData failed!"); |
| 254 return; | 256 return; |
| 255 } | 257 } |
| 256 RTC_DCHECK_EQ(static_cast<size_t>(samples), frames_per_buffer_); | 258 RTC_DCHECK_EQ(static_cast<size_t>(samples), frames_per_buffer_); |
| 257 // Copy decoded data into common byte buffer to ensure that it can be | 259 // Copy decoded data into common byte buffer to ensure that it can be |
| 258 // written to the Java based audio track. | 260 // written to the Java based audio track. |
| 259 samples = audio_device_buffer_->GetPlayoutData(direct_buffer_address_); | 261 samples = audio_device_buffer_->GetPlayoutData(direct_buffer_address_); |
| 260 RTC_DCHECK_EQ(length, kBytesPerFrame * samples); | 262 RTC_DCHECK_EQ(length, bytes_per_frame * samples); |
| 261 } | 263 } |
| 262 | 264 |
| 263 } // namespace webrtc | 265 } // namespace webrtc |
| OLD | NEW |