Add some doc comments
This commit is contained in:
parent
b993bd9aef
commit
155842f8bc
@ -20,9 +20,13 @@
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
int CodecOggOpus::encoderInit(char* filePath, int sampleRate) {
|
int CodecOggOpus::encoderInit(char* filePath, int sampleRate) {
|
||||||
|
// Create default, empty comment header
|
||||||
comments = ope_comments_create();
|
comments = ope_comments_create();
|
||||||
int numChannels = 1; // Mono audio
|
// Mono audio
|
||||||
int family = 0; // Channel Mapping Family 0, used for mono/stereo streams
|
int numChannels = 1;
|
||||||
|
// Channel Mapping Family 0, used for mono/stereo streams
|
||||||
|
int family = 0;
|
||||||
|
// Create encoder to encode PCM chunks and write the result to a file with the OggOpus framing
|
||||||
encoder = ope_encoder_create_file(filePath, comments, sampleRate, numChannels, family, &ret);
|
encoder = ope_encoder_create_file(filePath, comments, sampleRate, numChannels, family, &ret);
|
||||||
if (ret != OPE_OK) {
|
if (ret != OPE_OK) {
|
||||||
LOGE(TAG, "Creation of OggOpusEnc failed.");
|
LOGE(TAG, "Creation of OggOpusEnc failed.");
|
||||||
@ -41,12 +45,16 @@ int CodecOggOpus::setBitrate(int bitrate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CodecOggOpus::writeFrame(short* frame, int samplesPerChannel) {
|
int CodecOggOpus::writeFrame(short* frame, int samplesPerChannel) {
|
||||||
|
// Encode the raw PCM-16 buffer to Opus and write it to the ogg file
|
||||||
return ope_encoder_write(encoder, frame, samplesPerChannel);
|
return ope_encoder_write(encoder, frame, samplesPerChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodecOggOpus::encoderRelease() {
|
void CodecOggOpus::encoderRelease() {
|
||||||
|
// Finish any pending encode/write operations
|
||||||
ope_encoder_drain(encoder);
|
ope_encoder_drain(encoder);
|
||||||
|
// De-init the encoder instance
|
||||||
ope_encoder_destroy(encoder);
|
ope_encoder_destroy(encoder);
|
||||||
|
// De-init the comment header struct
|
||||||
ope_comments_destroy(comments);
|
ope_comments_destroy(comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,16 @@
|
|||||||
#define ELEMENT_ANDROID_CODECOGGOPUS_H
|
#define ELEMENT_ANDROID_CODECOGGOPUS_H
|
||||||
|
|
||||||
#include <opusenc.h>
|
#include <opusenc.h>
|
||||||
|
/**
|
||||||
|
* This class is a wrapper around libopusenc, used to encode and write Opus frames into an Ogg file.
|
||||||
|
*
|
||||||
|
* The usual flow would be:
|
||||||
|
*
|
||||||
|
* 1. Use encoderInit to initialize the internal encoder with the sample rate and the path to write the encoded frames to.
|
||||||
|
* 2. (Optional) set the bitrate to use.
|
||||||
|
* 3. While recording, read PCM-16 chunks from the recorder, feed them to the encoder using writeFrame.
|
||||||
|
* 4. When finished, call encoderRelease to free some resources.
|
||||||
|
*/
|
||||||
class CodecOggOpus {
|
class CodecOggOpus {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -20,6 +20,9 @@ import android.util.Log
|
|||||||
import androidx.annotation.IntRange
|
import androidx.annotation.IntRange
|
||||||
import im.vector.opusencoder.configuration.SampleRate
|
import im.vector.opusencoder.configuration.SampleRate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JNI bridge to CodecOggOpus in the native opuscodec library.
|
||||||
|
*/
|
||||||
class OggOpusEncoder {
|
class OggOpusEncoder {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
Reference in New Issue
Block a user