From 41b64a19edbd7ad8492740934d3b5750c453682f Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Tue, 21 Jan 2020 17:49:19 +0900 Subject: [PATCH] Adds testsuite for looback mode Change-Id: I31b286182467798d286ed3ae813141d3e029e369 Signed-off-by: Hyunsoo Park --- packaging/capi-media-streamrecorder.spec | 2 +- test/streamrecorder_loopback_test.c | 144 +++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 test/streamrecorder_loopback_test.c diff --git a/packaging/capi-media-streamrecorder.spec b/packaging/capi-media-streamrecorder.spec index 59ec669..340ef66 100644 --- a/packaging/capi-media-streamrecorder.spec +++ b/packaging/capi-media-streamrecorder.spec @@ -1,6 +1,6 @@ Name: capi-media-streamrecorder Summary: A Streamrecorder library in Tizen Native API -Version: 0.0.26 +Version: 0.0.27 Release: 0 Group: Multimedia/Other License: Apache-2.0 diff --git a/test/streamrecorder_loopback_test.c b/test/streamrecorder_loopback_test.c new file mode 100644 index 0000000..a9138fd --- /dev/null +++ b/test/streamrecorder_loopback_test.c @@ -0,0 +1,144 @@ +#include +#include +#include +#include + +#define DEST_FILE "/tmp/test_with_suite.mp4" +#define WIDTH 1280 +#define HEIGHT 720 +#define FRAME_RATE 30 + +#define LOGD(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) +#define LOGE(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) +#define LOGW(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0) + +streamrecorder_h streamrecorder; + +static void +streamrecorder_cb_notify(streamrecorder_state_e previous, + streamrecorder_state_e current, + streamrecorder_notify_e notification, + void *data) +{ + LOGD("streamrecorder_notify (prev: %d, curr: %d)", previous, current); +} + +static gboolean +_cb_finish(gpointer user_data) +{ + GMainLoop *loop = user_data; + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; +} + +static void _recording_status_cb(unsigned long long elapsed_time, unsigned long long file_size, void *user_data) +{ + g_print("elapsed time :%lld, file_size :%lld \r", elapsed_time, file_size); +} + +int +main(int argc, char *argv[]) +{ + streamrecorder_state_e state; + int err = 0; + int ret = 0; + streamrecorder_mode_e mode = STREAMRECORDER_MODE_DEVICE_LOOPBACK; + streamrecorder = NULL; + + err = streamrecorder_create(&streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_create()': %d", err); + return -1; + } + + err = streamrecorder_get_state(streamrecorder, &state); + if (err == STREAMRECORDER_ERROR_NONE) { + if (state == STREAMRECORDER_STATE_CREATED) { + LOGD("A state of StreamRecorder is 'Created'"); + } + else + LOGD("A state of StreamRecorder is '%d'", state); + } + + err = streamrecorder_set_notify_cb(streamrecorder, + streamrecorder_cb_notify, + &streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_notify_cb()': %d", err); + ret = -1; + goto end; + } + + // err = streamrecorder_enable_source_buffer(streamrecorder, STREAMRECORDER_SOURCE_VIDEO_AUDIO); + // if (err != STREAMRECORDER_ERROR_NONE) { + // LOGE("failed 'streamrecorder_enable_source_buffer'"); + // return 0; + // } + + err = streamrecorder_set_mode(streamrecorder, STREAMRECORDER_MODE_DEVICE_LOOPBACK); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_mode'"); + goto end; + } + + err = streamrecorder_get_mode(streamrecorder, &mode); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_get_mode'"); + goto end; + } + + err = streamrecorder_set_video_resolution(streamrecorder, WIDTH, HEIGHT); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_video_resolution()'"); + goto end; + } + + err = streamrecorder_set_video_framerate(streamrecorder, FRAME_RATE); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_video_framerate()'"); + goto end; + } + + + err = streamrecorder_set_recording_status_cb(streamrecorder, + _recording_status_cb, + NULL); + if (err != STREAMRECORDER_ERROR_NONE) + { + LOGE("failed to set callback for recording status"); + goto end; + } + err = streamrecorder_set_filename(streamrecorder, DEST_FILE); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_set_filename(): %d'", err); + goto end; + } + + err = streamrecorder_prepare(streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_prepare()': %d", err); + ret = -1; + goto end; + } + + err = streamrecorder_start(streamrecorder); + if (err != STREAMRECORDER_ERROR_NONE) { + LOGE("failed 'streamrecorder_start()': %d", err); + ret = -1; + goto end; + } + + GMainLoop *loop = g_main_loop_new(NULL, FALSE); + g_timeout_add_seconds(5, _cb_finish, loop); + g_main_loop_run(loop); + + streamrecorder_commit(streamrecorder); + + g_main_loop_unref(loop); + +end: + streamrecorder_destroy(streamrecorder); + streamrecorder = NULL; + + return ret; +} -- 2.7.4