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"
|
|
|
|
|
|
|
|
|
|
#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(
|
|
|
|
|
NativeRegistration* native_reg, rtc::scoped_ptr<GlobalRef> audio_track)
|
|
|
|
|
: audio_track_(audio_track.Pass()),
|
|
|
|
|
init_playout_(native_reg->GetMethodId("InitPlayout", "(II)V")),
|
|
|
|
|
start_playout_(native_reg->GetMethodId("StartPlayout", "()Z")),
|
|
|
|
|
stop_playout_(native_reg->GetMethodId("StopPlayout", "()Z")),
|
|
|
|
|
set_stream_volume_(native_reg->GetMethodId("SetStreamVolume", "(I)Z")),
|
|
|
|
|
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
|
|
|
|
2015-05-25 10:11:27 +02:00
|
|
|
void AudioTrackJni::JavaAudioTrack::InitPlayout(int sample_rate, int channels) {
|
|
|
|
|
audio_track_->CallVoidMethod(init_playout_, sample_rate, channels);
|
|
|
|
|
}
|
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)
|
2015-05-25 10:11:27 +02:00
|
|
|
: j_environment_(JVM::GetInstance()->environment()),
|
|
|
|
|
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-03-27 10:56:23 +01:00
|
|
|
DCHECK(audio_parameters_.is_valid());
|
2015-05-25 10:11:27 +02:00
|
|
|
CHECK(j_environment_);
|
|
|
|
|
JNINativeMethod native_methods[] = {
|
|
|
|
|
{"nativeCacheDirectBufferAddress", "(Ljava/nio/ByteBuffer;J)V",
|
|
|
|
|
reinterpret_cast<void*>(
|
|
|
|
|
&webrtc::AudioTrackJni::CacheDirectBufferAddress)},
|
|
|
|
|
{"nativeGetPlayoutData", "(IJ)V",
|
|
|
|
|
reinterpret_cast<void*>(&webrtc::AudioTrackJni::GetPlayoutData)}};
|
|
|
|
|
j_native_registration_ = j_environment_->RegisterNatives(
|
|
|
|
|
"org/webrtc/voiceengine/WebRtcAudioTrack",
|
|
|
|
|
native_methods, arraysize(native_methods));
|
|
|
|
|
j_audio_track_.reset(new JavaAudioTrack(
|
|
|
|
|
j_native_registration_.get(),
|
|
|
|
|
j_native_registration_->NewObject(
|
|
|
|
|
"<init>", "(Landroid/content/Context;J)V",
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
DCHECK(!initialized_);
|
|
|
|
|
DCHECK(!playing_);
|
2015-05-25 10:11:27 +02:00
|
|
|
j_audio_track_->InitPlayout(
|
Adding support for OpenSL ES output in native WebRTC
BUG=4573,2982,2175,3590
TEST=modules_unittests --gtest_filter=AudioDevice*, AppRTCDemo and WebRTCDemo
Summary:
- Removes dependency of the 'enable_android_opensl' compiler flag.
Instead, OpenSL ES is always supported, and will enabled for devices that
supports low-latency output.
- WebRTC no longer supports OpenSL ES for the input/recording side.
- Removes old code and demos using OpenSL ES for audio input.
- Improves accuracy of total delay estimates (better AEC performance).
- Reduces roundtrip audio latency; especially when OpenSL can be used.
Performance verified on: Nexus 5, 6, 7 and 9. Samsung Galaxy S4 and S6.
Android One device.
R=magjed@webrtc.org, phoglund@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/51759004
Cr-Commit-Position: refs/heads/master@{#9208}
2015-05-18 16:49:16 +02:00
|
|
|
audio_parameters_.sample_rate(), audio_parameters_.channels());
|
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());
|
|
|
|
|
DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
DCHECK(initialized_);
|
|
|
|
|
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());
|
|
|
|
|
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-02-23 11:54:05 +00:00
|
|
|
// If we don't detach here, we will hit a DCHECK in OnDataIsRecorded() next
|
|
|
|
|
// time StartRecording() is called since it will create a new Java thread.
|
|
|
|
|
thread_checker_java_.DetachFromThread();
|
|
|
|
|
initialized_ = false;
|
|
|
|
|
playing_ = false;
|
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());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
min_volume = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AudioTrackJni::SpeakerVolume(uint32_t& volume) const {
|
|
|
|
|
ALOGD("SpeakerVolume%s", GetThreadInfo().c_str());
|
|
|
|
|
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-02-23 11:54:05 +00:00
|
|
|
DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
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);
|
|
|
|
|
const int channels = audio_parameters_.channels();
|
|
|
|
|
ALOGD("SetPlayoutChannels(%d)", channels);
|
|
|
|
|
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");
|
|
|
|
|
DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
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-02-23 11:54:05 +00:00
|
|
|
DCHECK(thread_checker_java_.CalledOnValidThread());
|
|
|
|
|
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;
|
|
|
|
|
}
|
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
|
|
|
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_);
|
|
|
|
|
DCHECK_EQ(length, kBytesPerFrame * samples);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 21:42:44 +00:00
|
|
|
} // namespace webrtc
|