mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-28 18:32:38 +00:00
A couple minor bug fixes and also implemented sample code for streaming
encoders.
This commit is contained in:
parent
68853eb5a8
commit
e75592dfd9
@ -752,7 +752,10 @@ mcsdk_export mcsdk_encoder_type mcsdk_encoder_get_type(mcsdk_encoder e) {
|
||||
if (dynamic_cast<IBlockingEncoder*>(encoder) != nullptr) {
|
||||
return mcsdk_encoder_type_blocking;
|
||||
}
|
||||
return mcsdk_encoder_type_streaming;
|
||||
if (dynamic_cast<IStreamingEncoder*>(encoder) != nullptr) {
|
||||
return mcsdk_encoder_type_streaming;
|
||||
}
|
||||
return mcsdk_encoder_type_none;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -795,7 +798,7 @@ mcsdk_export void mcsdk_streaming_encoder_finalize(mcsdk_streaming_encoder se, c
|
||||
STREAMINGENCODER(se)->Finalize(uri);
|
||||
}
|
||||
|
||||
mcsdk_export void mcsdk_streaming_encoder_release(mcsdk_streaming_encoder se, mcsdk_encoder e) {
|
||||
mcsdk_export void mcsdk_streaming_encoder_release(mcsdk_streaming_encoder se) {
|
||||
RELEASE(se, STREAMINGENCODER);
|
||||
}
|
||||
|
||||
|
@ -140,8 +140,9 @@ typedef enum mcsdk_resource_class {
|
||||
} mcsdk_resource_class;
|
||||
|
||||
typedef enum mcsdk_encoder_type {
|
||||
mcsdk_encoder_type_blocking = 0,
|
||||
mcsdk_encoder_type_streaming = 1
|
||||
mcsdk_encoder_type_none = 0,
|
||||
mcsdk_encoder_type_blocking = 1,
|
||||
mcsdk_encoder_type_streaming = 2
|
||||
} mcsdk_encoder_type;
|
||||
|
||||
typedef enum mcsdk_audio_player_release_mode {
|
||||
@ -517,7 +518,7 @@ mcsdk_export bool mcsdk_streaming_encoder_initialize(mcsdk_streaming_encoder se,
|
||||
mcsdk_export int mcsdk_streaming_encoder_encode(mcsdk_streaming_encoder se, mcsdk_audio_buffer ab, char** data);
|
||||
mcsdk_export int mcsdk_streaming_encoder_flush(mcsdk_streaming_encoder se, char** data);
|
||||
mcsdk_export void mcsdk_streaming_encoder_finalize(mcsdk_streaming_encoder se, const char* uri);
|
||||
mcsdk_export void mcsdk_streaming_encoder_release(mcsdk_streaming_encoder se, mcsdk_encoder e);
|
||||
mcsdk_export void mcsdk_streaming_encoder_release(mcsdk_streaming_encoder se);
|
||||
|
||||
/*
|
||||
* IDebug
|
||||
|
@ -33,20 +33,38 @@ static void test_decode_encode() {
|
||||
printf("test_decode_encode: decoding from %s\n", INPUT_FILE);
|
||||
printf("test_decode_encode: encoding to %s\n", OUTPUT_FILE);
|
||||
mcsdk_decoder decoder = mcsdk_env_open_decoder(in);
|
||||
mcsdk_encoder encoder = mcsdk_env_open_encoder(".opus");
|
||||
mcsdk_encoder encoder = mcsdk_env_open_encoder(".mp3");
|
||||
if (mcsdk_handle_ok(decoder) && mcsdk_handle_ok(encoder)) {
|
||||
printf("test_decode_encode: encoder and decoder opened successfully. running...\n");
|
||||
mcsdk_audio_buffer buffer = mcsdk_env_create_audio_buffer(4096, 44100, 2);
|
||||
if (mcsdk_encoder_get_type(encoder) == mcsdk_encoder_type_blocking) {
|
||||
mcsdk_blocking_encoder be = mcsdk_cast_handle(encoder);
|
||||
mcsdk_audio_buffer buffer = mcsdk_env_create_audio_buffer(4096, 44100, 2);
|
||||
if (mcsdk_blocking_encoder_initialize(be, out, 44100, 2, 192)) {
|
||||
while (mcsdk_decoder_fill_buffer(decoder, buffer)) {
|
||||
mcsdk_blocking_encoder_encode(be, buffer);
|
||||
}
|
||||
mcsdk_blocking_encoder_finalize(be);
|
||||
}
|
||||
mcsdk_audio_buffer_release(buffer);
|
||||
} else if (mcsdk_encoder_get_type(encoder) == mcsdk_encoder_type_streaming) {
|
||||
mcsdk_streaming_encoder se = mcsdk_cast_handle(encoder);
|
||||
if (mcsdk_streaming_encoder_initialize(se, 44100, 2, 192)) {
|
||||
char* bytes = NULL;
|
||||
int length = 0;
|
||||
while (mcsdk_decoder_fill_buffer(decoder, buffer)) {
|
||||
length = mcsdk_streaming_encoder_encode(se, buffer, &bytes);
|
||||
if (bytes && length) {
|
||||
mcsdk_data_stream_write(out, bytes, length);
|
||||
}
|
||||
}
|
||||
length = mcsdk_streaming_encoder_flush(se, &bytes);
|
||||
if (bytes && length) {
|
||||
mcsdk_data_stream_write(out, bytes, length);
|
||||
}
|
||||
mcsdk_data_stream_close(out);
|
||||
mcsdk_streaming_encoder_finalize(se, OUTPUT_FILE);
|
||||
}
|
||||
}
|
||||
mcsdk_audio_buffer_release(buffer);
|
||||
}
|
||||
mcsdk_decoder_release(decoder);
|
||||
mcsdk_encoder_release(encoder);
|
||||
|
Loading…
x
Reference in New Issue
Block a user