2013-12-11 21:42:44 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-03-27 10:56:23 +01:00
|
|
|
#include "webrtc/modules/audio_device/android/audio_manager.h"
|
2013-12-11 21:42:44 +00:00
|
|
|
#include "webrtc/modules/audio_device/android/audio_track_jni.h"
|
|
|
|
|
|
2015-12-17 03:04:15 -08:00
|
|
|
#include <utility>
|
|
|
|
|
|
2013-12-11 21:42:44 +00:00
|
|
|
#include <android/log.h>
|
|
|
|
|
|
2015-02-23 11:54:05 +00:00
|
|
|
#include "webrtc/base/arraysize.h"
|
|
|
|
|
#include "webrtc/base/checks.h"
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
#include "webrtc/base/format_macros.h"
|
2013-12-11 21:42:44 +00:00
|
|
|
|
2015-02-23 11:54:05 +00:00
|
|
|
#define TAG "AudioTrackJni"
|
|
|
|
|
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
|
|
|
|
|
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
|
|
|
|
|
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
|
|
|
|
|
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
|
|
|
|
|
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
2013-12-11 21:42:44 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
// AudioTrackJni::JavaAudioTrack implementation.
|
|
|
|
|
AudioTrackJni::JavaAudioTrack::JavaAudioTrack(
|
2015-12-17 03:04:15 -08:00
|
|
|
NativeRegistration* native_reg,
|
2016-02-24 05:00:36 -08:00
|
|
|
std::unique_ptr<GlobalRef> audio_track)
|
2015-12-17 03:04:15 -08:00
|
|
|
: audio_track_(std::move(audio_track)),
|
2016-04-05 07:20:27 -07:00
|
|
|
init_playout_(native_reg->GetMethodId("initPlayout", "(II)Z")),
|
2015-09-23 14:08:33 +02:00
|
|
|
start_playout_(native_reg->GetMethodId("startPlayout", "()Z")),
|
|
|
|
|
stop_playout_(native_reg->GetMethodId("stopPlayout", "()Z")),
|
|
|
|
|
set_stream_volume_(native_reg->GetMethodId("setStreamVolume", "(I)Z")),
|
2015-12-17 03:04:15 -08:00
|
|
|
get_stream_max_volume_(
|
|
|
|
|
native_reg->GetMethodId("getStreamMaxVolume", "()I")),
|
|
|
|
|
get_stream_volume_(native_reg->GetMethodId("getStreamVolume", "()I")) {}
|
2015-02-23 11:54:05 +00:00
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
AudioTrackJni::JavaAudioTrack::~JavaAudioTrack() {}
|
2015-02-23 11:54:05 +00:00
|
|
|
|
2016-04-05 07:20:27 -07:00
|
|
|
bool AudioTrackJni::JavaAudioTrack::InitPlayout(int sample_rate, int channels) {
|
|
|
|
|
return audio_track_->CallBooleanMethod(init_playout_, sample_rate, channels);
|
2015-05-25 10:11:27 +02:00
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
bool AudioTrackJni::JavaAudioTrack::StartPlayout() {
|
|
|
|
|
return audio_track_->CallBooleanMethod(start_playout_);
|
|
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
bool AudioTrackJni::JavaAudioTrack::StopPlayout() {
|
|
|
|
|
return audio_track_->CallBooleanMethod(stop_playout_);
|
|
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
bool AudioTrackJni::JavaAudioTrack::SetStreamVolume(int volume) {
|
|
|
|
|
return audio_track_->CallBooleanMethod(set_stream_volume_, volume);
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
int AudioTrackJni::JavaAudioTrack::GetStreamMaxVolume() {
|
|
|
|
|
return audio_track_->CallIntMethod(get_stream_max_volume_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::JavaAudioTrack::GetStreamVolume() {
|
|
|
|
|
return audio_track_->CallIntMethod(get_stream_volume_);
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-27 10:56:23 +01:00
|
|
|
// TODO(henrika): possible extend usage of AudioManager and add it as member.
|
|
|
|
|
AudioTrackJni::AudioTrackJni(AudioManager* audio_manager)
|
2016-04-26 08:18:04 -07:00
|
|
|
: j_environment_(JVM::GetInstance()->environment()),
|
2015-05-25 10:11:27 +02:00
|
|
|
audio_parameters_(audio_manager->GetPlayoutAudioParameters()),
|
|
|
|
|
direct_buffer_address_(nullptr),
|
2015-02-23 11:54:05 +00:00
|
|
|
direct_buffer_capacity_in_bytes_(0),
|
|
|
|
|
frames_per_buffer_(0),
|
|
|
|
|
initialized_(false),
|
|
|
|
|
playing_(false),
|
2015-05-25 10:11:27 +02:00
|
|
|
audio_device_buffer_(nullptr) {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGD("ctor%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(audio_parameters_.is_valid());
|
|
|
|
|
RTC_CHECK(j_environment_);
|
2015-05-25 10:11:27 +02:00
|
|
|
JNINativeMethod native_methods[] = {
|
|
|
|
|
{"nativeCacheDirectBufferAddress", "(Ljava/nio/ByteBuffer;J)V",
|
|
|
|
|
reinterpret_cast<void*>(
|
|
|
|
|
&webrtc::AudioTrackJni::CacheDirectBufferAddress)},
|
|
|
|
|
{"nativeGetPlayoutData", "(IJ)V",
|
|
|
|
|
reinterpret_cast<void*>(&webrtc::AudioTrackJni::GetPlayoutData)}};
|
2016-04-26 08:18:04 -07:00
|
|
|
j_native_registration_ = j_environment_->RegisterNatives(
|
|
|
|
|
"org/webrtc/voiceengine/WebRtcAudioTrack", native_methods,
|
|
|
|
|
arraysize(native_methods));
|
2015-05-25 10:11:27 +02:00
|
|
|
j_audio_track_.reset(new JavaAudioTrack(
|
|
|
|
|
j_native_registration_.get(),
|
2016-04-26 08:18:04 -07:00
|
|
|
j_native_registration_->NewObject(
|
2015-05-25 10:11:27 +02:00
|
|
|
"<init>", "(Landroid/content/Context;J)V",
|
2016-04-26 08:18:04 -07:00
|
|
|
JVM::GetInstance()->context(), PointerTojlong(this))));
|
2015-02-23 11:54:05 +00:00
|
|
|
// Detach from this thread since we want to use the checker to verify calls
|
|
|
|
|
// from the Java based audio thread.
|
|
|
|
|
thread_checker_java_.DetachFromThread();
|
2013-12-11 21:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioTrackJni::~AudioTrackJni() {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGD("~dtor%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2013-12-11 21:42:44 +00:00
|
|
|
Terminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t AudioTrackJni::Init() {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGD("Init%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2013-12-11 21:42:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t AudioTrackJni::Terminate() {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGD("Terminate%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2013-12-11 21:42:44 +00:00
|
|
|
StopPlayout();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t AudioTrackJni::InitPlayout() {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGD("InitPlayout%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
RTC_DCHECK(!initialized_);
|
|
|
|
|
RTC_DCHECK(!playing_);
|
2016-04-05 07:20:27 -07:00
|
|
|
if (!j_audio_track_->InitPlayout(
|
|
|
|
|
audio_parameters_.sample_rate(), audio_parameters_.channels())) {
|
|
|
|
|
ALOGE("InitPlayout failed!");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
initialized_ = true;
|
2013-12-11 21:42:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 11:54:05 +00:00
|
|
|
int32_t AudioTrackJni::StartPlayout() {
|
|
|
|
|
ALOGD("StartPlayout%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
RTC_DCHECK(initialized_);
|
|
|
|
|
RTC_DCHECK(!playing_);
|
2015-05-25 10:11:27 +02:00
|
|
|
if (!j_audio_track_->StartPlayout()) {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGE("StartPlayout failed!");
|
2013-12-11 21:42:44 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
playing_ = true;
|
2013-12-11 21:42:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 11:54:05 +00:00
|
|
|
int32_t AudioTrackJni::StopPlayout() {
|
|
|
|
|
ALOGD("StopPlayout%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-03-09 12:39:53 +00:00
|
|
|
if (!initialized_ || !playing_) {
|
2013-12-11 21:42:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-05-25 10:11:27 +02:00
|
|
|
if (!j_audio_track_->StopPlayout()) {
|
2015-02-23 11:54:05 +00:00
|
|
|
ALOGE("StopPlayout failed!");
|
2013-12-11 21:42:44 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-09-17 00:24:34 -07:00
|
|
|
// If we don't detach here, we will hit a RTC_DCHECK in OnDataIsRecorded()
|
|
|
|
|
// next time StartRecording() is called since it will create a new Java
|
|
|
|
|
// thread.
|
2015-02-23 11:54:05 +00:00
|
|
|
thread_checker_java_.DetachFromThread();
|
|
|
|
|
initialized_ = false;
|
|
|
|
|
playing_ = false;
|
2015-09-25 04:26:14 -07:00
|
|
|
direct_buffer_address_ = nullptr;
|
2013-12-11 21:42:44 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 10:56:23 +01:00
|
|
|
int AudioTrackJni::SpeakerVolumeIsAvailable(bool& available) {
|
|
|
|
|
available = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::SetSpeakerVolume(uint32_t volume) {
|
|
|
|
|
ALOGD("SetSpeakerVolume(%d)%s", volume, GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-05-25 10:11:27 +02:00
|
|
|
return j_audio_track_->SetStreamVolume(volume) ? 0 : -1;
|
2015-03-27 10:56:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::MaxSpeakerVolume(uint32_t& max_volume) const {
|
|
|
|
|
ALOGD("MaxSpeakerVolume%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-05-25 10:11:27 +02:00
|
|
|
max_volume = j_audio_track_->GetStreamMaxVolume();
|
2015-03-27 10:56:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::MinSpeakerVolume(uint32_t& min_volume) const {
|
|
|
|
|
ALOGD("MaxSpeakerVolume%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-03-27 10:56:23 +01:00
|
|
|
min_volume = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::SpeakerVolume(uint32_t& volume) const {
|
|
|
|
|
ALOGD("SpeakerVolume%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-05-25 10:11:27 +02:00
|
|
|
volume = j_audio_track_->GetStreamVolume();
|
2015-03-27 10:56:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 11:54:05 +00:00
|
|
|
// TODO(henrika): possibly add stereo support.
|
|
|
|
|
void AudioTrackJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
|
2015-03-27 10:56:23 +01:00
|
|
|
ALOGD("AttachAudioBuffer%s", GetThreadInfo().c_str());
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-02-23 11:54:05 +00:00
|
|
|
audio_device_buffer_ = audioBuffer;
|
2015-03-27 10:56:23 +01:00
|
|
|
const int sample_rate_hz = audio_parameters_.sample_rate();
|
|
|
|
|
ALOGD("SetPlayoutSampleRate(%d)", sample_rate_hz);
|
|
|
|
|
audio_device_buffer_->SetPlayoutSampleRate(sample_rate_hz);
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t channels = audio_parameters_.channels();
|
|
|
|
|
ALOGD("SetPlayoutChannels(%" PRIuS ")", channels);
|
2015-03-27 10:56:23 +01:00
|
|
|
audio_device_buffer_->SetPlayoutChannels(channels);
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JNICALL AudioTrackJni::CacheDirectBufferAddress(
|
|
|
|
|
JNIEnv* env, jobject obj, jobject byte_buffer, jlong nativeAudioTrack) {
|
|
|
|
|
webrtc::AudioTrackJni* this_object =
|
|
|
|
|
reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack);
|
|
|
|
|
this_object->OnCacheDirectBufferAddress(env, byte_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioTrackJni::OnCacheDirectBufferAddress(
|
|
|
|
|
JNIEnv* env, jobject byte_buffer) {
|
|
|
|
|
ALOGD("OnCacheDirectBufferAddress");
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-09-25 04:26:14 -07:00
|
|
|
RTC_DCHECK(!direct_buffer_address_);
|
2015-02-23 11:54:05 +00:00
|
|
|
direct_buffer_address_ =
|
|
|
|
|
env->GetDirectBufferAddress(byte_buffer);
|
|
|
|
|
jlong capacity = env->GetDirectBufferCapacity(byte_buffer);
|
|
|
|
|
ALOGD("direct buffer capacity: %lld", capacity);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
direct_buffer_capacity_in_bytes_ = static_cast<size_t>(capacity);
|
2015-02-23 11:54:05 +00:00
|
|
|
frames_per_buffer_ = direct_buffer_capacity_in_bytes_ / kBytesPerFrame;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
ALOGD("frames_per_buffer: %" PRIuS, frames_per_buffer_);
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JNICALL AudioTrackJni::GetPlayoutData(
|
|
|
|
|
JNIEnv* env, jobject obj, jint length, jlong nativeAudioTrack) {
|
|
|
|
|
webrtc::AudioTrackJni* this_object =
|
|
|
|
|
reinterpret_cast<webrtc::AudioTrackJni*> (nativeAudioTrack);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
this_object->OnGetPlayoutData(static_cast<size_t>(length));
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method is called on a high-priority thread from Java. The name of
|
|
|
|
|
// the thread is 'AudioRecordTrack'.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
void AudioTrackJni::OnGetPlayoutData(size_t length) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_java_.CalledOnValidThread());
|
|
|
|
|
RTC_DCHECK_EQ(frames_per_buffer_, length / kBytesPerFrame);
|
2015-03-09 12:39:53 +00:00
|
|
|
if (!audio_device_buffer_) {
|
|
|
|
|
ALOGE("AttachAudioBuffer has not been called!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-23 11:54:05 +00:00
|
|
|
// Pull decoded data (in 16-bit PCM format) from jitter buffer.
|
|
|
|
|
int samples = audio_device_buffer_->RequestPlayoutData(frames_per_buffer_);
|
2015-03-09 12:39:53 +00:00
|
|
|
if (samples <= 0) {
|
|
|
|
|
ALOGE("AudioDeviceBuffer::RequestPlayoutData failed!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_EQ(static_cast<size_t>(samples), frames_per_buffer_);
|
2015-02-23 11:54:05 +00:00
|
|
|
// Copy decoded data into common byte buffer to ensure that it can be
|
|
|
|
|
// written to the Java based audio track.
|
|
|
|
|
samples = audio_device_buffer_->GetPlayoutData(direct_buffer_address_);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_EQ(length, kBytesPerFrame * samples);
|
2015-02-23 11:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 21:42:44 +00:00
|
|
|
} // namespace webrtc
|