-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose audio sample buffers for Android (#89)
* Initial draft * Working impl * doc and cleanup * doc update
- Loading branch information
1 parent
28e2021
commit 98fe34e
Showing
8 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
|
||
package org.webrtc; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Java version of rtc::AudioTrackSinkInterface. | ||
*/ | ||
public interface AudioTrackSink { | ||
/** | ||
* Implementations should copy the audio data into a local copy if they wish | ||
* to use the data after this function returns. | ||
*/ | ||
@CalledByNative | ||
void onData(ByteBuffer audioData, int bitsPerSample, int sampleRate, | ||
int numberOfChannels, int numberOfFrames, | ||
long absoluteCaptureTimestampMs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
#include "sdk/android/src/jni/pc/audio_sink.h" | ||
|
||
#include "sdk/android/generated_peerconnection_jni/AudioTrackSink_jni.h" | ||
|
||
namespace webrtc { | ||
namespace jni { | ||
|
||
AudioTrackSinkWrapper::AudioTrackSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink) | ||
: j_sink_(jni, j_sink) {} | ||
|
||
AudioTrackSinkWrapper::~AudioTrackSinkWrapper() {} | ||
|
||
void AudioTrackSinkWrapper::OnData( | ||
const void* audio_data, | ||
int bits_per_sample, | ||
int sample_rate, | ||
size_t number_of_channels, | ||
size_t number_of_frames, | ||
absl::optional<int64_t> absolute_capture_timestamp_ms) { | ||
JNIEnv* jni = AttachCurrentThreadIfNeeded(); | ||
int length = (bits_per_sample / 8) * number_of_channels * number_of_frames; | ||
ScopedJavaLocalRef<jobject> audio_buffer = | ||
NewDirectByteBuffer(jni, (void *) audio_data, length); | ||
Java_AudioTrackSink_onData(jni, j_sink_, | ||
audio_buffer, bits_per_sample, sample_rate, (int) number_of_channels, (int) number_of_frames, (absolute_capture_timestamp_ms ? absolute_capture_timestamp_ms.value() : 0)); | ||
} | ||
|
||
} // namespace jni | ||
} // namespace webrtc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
#ifndef SDK_ANDROID_SRC_JNI_AUDIO_TRACK_SINK_H_ | ||
#define SDK_ANDROID_SRC_JNI_AUDIO_TRACK_SINK_H_ | ||
|
||
#include <jni.h> | ||
|
||
#include "api/media_stream_interface.h" | ||
#include "sdk/android/src/jni/jni_helpers.h" | ||
|
||
namespace webrtc { | ||
namespace jni { | ||
|
||
class AudioTrackSinkWrapper : public webrtc::AudioTrackSinkInterface { | ||
public: | ||
AudioTrackSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink); | ||
~AudioTrackSinkWrapper() override; | ||
|
||
private: | ||
void OnData(const void* audio_data, | ||
int bits_per_sample, | ||
int sample_rate, | ||
size_t number_of_channels, | ||
size_t number_of_frames, | ||
absl::optional<int64_t> absolute_capture_timestamp_ms) override; | ||
|
||
const ScopedJavaGlobalRef<jobject> j_sink_; | ||
}; | ||
|
||
} // namespace jni | ||
} // namespace webrtc | ||
|
||
#endif // SDK_ANDROID_SRC_JNI_AUDIO_TRACK_SINK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters