mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-28 18:32:38 +00:00
Fixed indexer callbacks and added some test code to exercise the C
service layer.
This commit is contained in:
parent
a38b797154
commit
10c27d3141
@ -101,7 +101,7 @@ void mcsdk_context_message_queue::Run() {
|
||||
* mcsdk_svc_indexer_callback_proxy
|
||||
*/
|
||||
|
||||
struct mcsdk_svc_indexer_callback_proxy {
|
||||
struct mcsdk_svc_indexer_callback_proxy: public sigslot::has_slots<> {
|
||||
mcsdk_svc_indexer_context_internal* context;
|
||||
|
||||
mcsdk_svc_indexer_callback_proxy(mcsdk_svc_indexer_context_internal* context) {
|
||||
@ -164,9 +164,13 @@ mcsdk_export void mcsdk_context_init(mcsdk_context** context) {
|
||||
c->preferences.opaque = internal->preferences.get();
|
||||
c->playback.opaque = internal->playback;
|
||||
|
||||
auto indexer = internal->library->Indexer();
|
||||
auto indexer_internal = new mcsdk_svc_indexer_context_internal();
|
||||
indexer_internal->indexer = internal->library->Indexer();
|
||||
indexer_internal->indexer = indexer;
|
||||
indexer_internal->callback_proxy = new mcsdk_svc_indexer_callback_proxy(indexer_internal);
|
||||
indexer->Started.connect(indexer_internal->callback_proxy, &mcsdk_svc_indexer_callback_proxy::on_started);
|
||||
indexer->Progress.connect(indexer_internal->callback_proxy, &mcsdk_svc_indexer_callback_proxy::on_progress);
|
||||
indexer->Finished.connect(indexer_internal->callback_proxy, &mcsdk_svc_indexer_callback_proxy::on_finished);
|
||||
c->indexer.opaque = indexer_internal;
|
||||
|
||||
if (!plugin_context) {
|
||||
|
@ -28,16 +28,56 @@ static void internal_sleep(int seconds) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void sleep_for(const char* tag, int seconds) {
|
||||
printf("[%s] sleeping for %d seconds...\n", tag, seconds);
|
||||
for (int i = 0; i < seconds; i++) {
|
||||
internal_sleep(1);
|
||||
printf("[%s] %d\n", tag, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int total_indexer_updated_count = 0;
|
||||
|
||||
static void indexer_started_callback(mcsdk_svc_indexer in) {
|
||||
total_indexer_updated_count = 0;
|
||||
printf("[indexer_started_callback]\n");
|
||||
}
|
||||
|
||||
static void indexer_progress_callback(mcsdk_svc_indexer in, int updated_count) {
|
||||
total_indexer_updated_count += updated_count;
|
||||
printf("[indexer_progress_callback] %d\n", total_indexer_updated_count);
|
||||
}
|
||||
|
||||
static void indexer_finished_callback(mcsdk_svc_indexer in, int updated_count) {
|
||||
printf("[indexer_finished_callback] %d\n", total_indexer_updated_count);
|
||||
}
|
||||
|
||||
static void test_indexer(mcsdk_context* context) {
|
||||
char buffer[4096];
|
||||
for (int i = 0; i < mcsdk_svc_indexer_get_paths_count(context->indexer); i++) {
|
||||
mcsdk_svc_indexer_get_paths_at(context->indexer, i, buffer, sizeof(buffer));
|
||||
printf("[test_indexer] path: %s\n", buffer);
|
||||
}
|
||||
mcsdk_svc_indexer_callbacks cb = { 0 };
|
||||
cb.on_started = indexer_started_callback;
|
||||
cb.on_progress = indexer_progress_callback;
|
||||
cb.on_finished = indexer_finished_callback;
|
||||
mcsdk_svc_indexer_add_callbacks(context->indexer, &cb);
|
||||
mcsdk_svc_indexer_schedule(context->indexer, mcsdk_svc_indexer_sync_type_local);
|
||||
sleep_for("test_indexer", 5);
|
||||
mcsdk_svc_indexer_remove_callbacks(context->indexer, &cb);
|
||||
}
|
||||
|
||||
static void test_decode_encode() {
|
||||
mcsdk_data_stream in = mcsdk_env_open_data_stream(INPUT_FILE, mcsdk_stream_open_flags_read);
|
||||
mcsdk_data_stream out = mcsdk_env_open_data_stream(OUTPUT_FILE, mcsdk_stream_open_flags_write);
|
||||
if (mcsdk_handle_ok(in) && mcsdk_handle_ok(out)) {
|
||||
printf("test_decode_encode: decoding from %s\n", INPUT_FILE);
|
||||
printf("test_decode_encode: encoding to %s\n", OUTPUT_FILE);
|
||||
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(ENCODER_TYPE);
|
||||
if (mcsdk_handle_ok(decoder) && mcsdk_handle_ok(encoder)) {
|
||||
printf("test_decode_encode: encoder and decoder opened successfully. running...\n");
|
||||
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);
|
||||
@ -73,7 +113,7 @@ static void test_decode_encode() {
|
||||
}
|
||||
mcsdk_data_stream_release(in);
|
||||
mcsdk_data_stream_release(out);
|
||||
printf("test_decode_encode: done.\n");
|
||||
printf("[test_decode_encode] done.\n");
|
||||
}
|
||||
|
||||
static void test_low_level_playback() {
|
||||
@ -83,18 +123,15 @@ static void test_low_level_playback() {
|
||||
mcsdk_audio_output_set_volume(output, 0.75);
|
||||
mcsdk_audio_output_resume(output);
|
||||
mcsdk_audio_player_play(player);
|
||||
printf("test_low_level_playback: playing for 5 seconds...\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
internal_sleep(1);
|
||||
printf(" %d\n", i + 1);
|
||||
}
|
||||
printf("[test_low_level_playback] playing for 5 seconds...\n");
|
||||
sleep_for("test_low_level_playback", 5);
|
||||
mcsdk_audio_player_release(player, mcsdk_audio_player_release_mode_no_drain);
|
||||
mcsdk_audio_output_release(output);
|
||||
printf("test_low_level_playback: done.\n");
|
||||
printf("[test_low_level_playback] done.\n");
|
||||
}
|
||||
|
||||
static void test_high_level_playback(mcsdk_context* context) {
|
||||
printf("test_playback: loading 'a day in the life' tracks\n");
|
||||
printf("[test_playback] loading 'a day in the life' tracks\n");
|
||||
mcsdk_track_list tl = mcsdk_svc_metadata_query_tracks(
|
||||
context->metadata, "a day in the life", mcsdk_no_limit, mcsdk_no_offset);
|
||||
// mcsdk_track_list tl = mcsdk_track_list_create(context);
|
||||
@ -103,17 +140,14 @@ static void test_high_level_playback(mcsdk_context* context) {
|
||||
// mcsdk_track_list_editor_release(tle);
|
||||
mcsdk_svc_playback_play(context->playback, tl, 0);
|
||||
mcsdk_track_list_release(tl);
|
||||
printf("test_high_level_playback: playing for 5 seconds...\n");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
internal_sleep(1);
|
||||
printf(" %d\n", i + 1);
|
||||
}
|
||||
printf("[test_high_level_playback] playing for 5 seconds...\n");
|
||||
sleep_for("test_high_level_playback", 5);
|
||||
mcsdk_svc_playback_stop(context->playback);
|
||||
printf("test_high_level_playback: done.\n");
|
||||
printf("[test_high_level_playback] done.\n");
|
||||
}
|
||||
|
||||
static void test_metadata(mcsdk_context* context) {
|
||||
printf("test_metadata: querying 'beatles' albums\n");
|
||||
printf("[test_metadata] querying 'beatles' albums\n");
|
||||
mcsdk_map_list ml = mcsdk_svc_metadata_query_albums(context->metadata, "beatles");
|
||||
int count = mcsdk_map_list_get_count(ml);
|
||||
for (int i = 0; i < count; i++) {
|
||||
@ -121,11 +155,11 @@ static void test_metadata(mcsdk_context* context) {
|
||||
size_t len = mcsdk_map_get_string(m, "album", NULL, 0);
|
||||
char* str = malloc(len * sizeof(char));
|
||||
mcsdk_map_get_string(m, "album", str, len);
|
||||
printf(" %s\n", str);
|
||||
printf("[test_metadata] album: %s\n", str);
|
||||
free(str);
|
||||
}
|
||||
mcsdk_map_list_release(ml);
|
||||
printf("test_metadata: done.\n");
|
||||
printf("[test_metadata] done.\n");
|
||||
}
|
||||
|
||||
static void configure_environment() {
|
||||
@ -136,7 +170,7 @@ static void configure_environment() {
|
||||
mcsdk_env_get_path(mcsdk_path_type_data, dest_path, length);
|
||||
strncat(dest_path, suffix, length);
|
||||
freopen(dest_path, "w", stderr);
|
||||
printf("stderr will be written to %s", dest_path);
|
||||
printf("[configure_environment] stderr will be written to %s\n", dest_path);
|
||||
free(dest_path);
|
||||
}
|
||||
|
||||
@ -145,13 +179,14 @@ int main(int argc, char** argv) {
|
||||
mcsdk_context* context = NULL;
|
||||
mcsdk_context_init(&context);
|
||||
if (context) {
|
||||
printf("main: context initialized\n");
|
||||
printf("[main] context initialized\n");
|
||||
test_indexer(context);
|
||||
test_metadata(context);
|
||||
test_low_level_playback();
|
||||
test_high_level_playback(context);
|
||||
test_decode_encode();
|
||||
mcsdk_context_release(&context);
|
||||
printf("main: context released\n");
|
||||
printf("[main] context released\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user