| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return audio_track_->CallIntMethod(get_stream_volume_); | 67 return audio_track_->CallIntMethod(get_stream_volume_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // TODO(henrika): possible extend usage of AudioManager and add it as member. | 70 // TODO(henrika): possible extend usage of AudioManager and add it as member. |
| 71 AudioTrackJni::AudioTrackJni(AudioManager* audio_manager) | 71 AudioTrackJni::AudioTrackJni(AudioManager* audio_manager) |
| 72 : j_environment_(JVM::GetInstance()->environment()), | 72 : j_environment_(JVM::GetInstance()->environment()), |
| 73 audio_parameters_(audio_manager->GetPlayoutAudioParameters()), | 73 audio_parameters_(audio_manager->GetPlayoutAudioParameters()), |
| 74 direct_buffer_address_(nullptr), | 74 direct_buffer_address_(nullptr), |
| 75 direct_buffer_capacity_in_bytes_(0), | 75 direct_buffer_capacity_in_bytes_(0), |
| 76 frames_per_buffer_(0), | 76 frames_per_buffer_(0), |
| 77 bytes_per_frame_(0), |
| 77 initialized_(false), | 78 initialized_(false), |
| 78 playing_(false), | 79 playing_(false), |
| 79 audio_device_buffer_(nullptr) { | 80 audio_device_buffer_(nullptr) { |
| 80 ALOGD("ctor%s", GetThreadInfo().c_str()); | 81 ALOGD("ctor%s", GetThreadInfo().c_str()); |
| 81 RTC_DCHECK(audio_parameters_.is_valid()); | 82 RTC_DCHECK(audio_parameters_.is_valid()); |
| 82 RTC_CHECK(j_environment_); | 83 RTC_CHECK(j_environment_); |
| 83 JNINativeMethod native_methods[] = { | 84 JNINativeMethod native_methods[] = { |
| 84 {"nativeCacheDirectBufferAddress", "(Ljava/nio/ByteBuffer;J)V", | 85 {"nativeCacheDirectBufferAddress", "(Ljava/nio/ByteBuffer;J)V", |
| 85 reinterpret_cast<void*>( | 86 reinterpret_cast<void*>( |
| 86 &webrtc::AudioTrackJni::CacheDirectBufferAddress)}, | 87 &webrtc::AudioTrackJni::CacheDirectBufferAddress)}, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void AudioTrackJni::OnCacheDirectBufferAddress( | 221 void AudioTrackJni::OnCacheDirectBufferAddress( |
| 221 JNIEnv* env, jobject byte_buffer) { | 222 JNIEnv* env, jobject byte_buffer) { |
| 222 ALOGD("OnCacheDirectBufferAddress"); | 223 ALOGD("OnCacheDirectBufferAddress"); |
| 223 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 224 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 RTC_DCHECK(!direct_buffer_address_); | 225 RTC_DCHECK(!direct_buffer_address_); |
| 225 direct_buffer_address_ = | 226 direct_buffer_address_ = |
| 226 env->GetDirectBufferAddress(byte_buffer); | 227 env->GetDirectBufferAddress(byte_buffer); |
| 227 jlong capacity = env->GetDirectBufferCapacity(byte_buffer); | 228 jlong capacity = env->GetDirectBufferCapacity(byte_buffer); |
| 228 ALOGD("direct buffer capacity: %lld", capacity); | 229 ALOGD("direct buffer capacity: %lld", capacity); |
| 229 direct_buffer_capacity_in_bytes_ = static_cast<size_t>(capacity); | 230 direct_buffer_capacity_in_bytes_ = static_cast<size_t>(capacity); |
| 230 frames_per_buffer_ = direct_buffer_capacity_in_bytes_ / kBytesPerFrame; | 231 bytes_per_frame_ = audio_parameters_.channels() * sizeof(int16_t); |
| 232 frames_per_buffer_ = direct_buffer_capacity_in_bytes_ / bytes_per_frame_; |
| 231 ALOGD("frames_per_buffer: %" PRIuS, frames_per_buffer_); | 233 ALOGD("frames_per_buffer: %" PRIuS, frames_per_buffer_); |
| 232 } | 234 } |
| 233 | 235 |
| 234 void JNICALL AudioTrackJni::GetPlayoutData( | 236 void JNICALL AudioTrackJni::GetPlayoutData( |
| 235 JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack) { | 237 JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack) { |
| 236 webrtc::AudioTrackJni* this_object = | 238 webrtc::AudioTrackJni* this_object = |
| 237 reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack); | 239 reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack); |
| 238 this_object->OnGetPlayoutData(static_cast<size_t>(length)); | 240 this_object->OnGetPlayoutData(static_cast<size_t>(length)); |
| 239 } | 241 } |
| 240 | 242 |
| 241 // This method is called on a high-priority thread from Java. The name of | 243 // This method is called on a high-priority thread from Java. The name of |
| 242 // the thread is 'AudioRecordTrack'. | 244 // the thread is 'AudioRecordTrack'. |
| 243 void AudioTrackJni::OnGetPlayoutData(size_t length) { | 245 void AudioTrackJni::OnGetPlayoutData(size_t length) { |
| 244 RTC_DCHECK(thread_checker_java_.CalledOnValidThread()); | 246 RTC_DCHECK(thread_checker_java_.CalledOnValidThread()); |
| 245 RTC_DCHECK_EQ(frames_per_buffer_, length / kBytesPerFrame); | 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 |