test: Add several esplusplayer API test suites 01/319101/8
authorGilbok Lee <gilbok.lee@samsung.com>
Tue, 15 Oct 2024 08:12:23 +0000 (17:12 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Mon, 28 Oct 2024 06:35:38 +0000 (15:35 +0900)
- esplusplayer_set_resource_conflicted_cb()
- esplusplayer_set_video_frame_buffer_type()
- esplusplayer_get_decoded_video_packet()
- esplusplayer_set_resource_allocate_policy()
- esplusplayer_set_media_packet_video_decoded_cb()

Change-Id: If607e10ddecb7dd66bedf454cb5492e57c831f25

packaging/esplusplayer.spec
test/CMakeLists.txt
test/esplusplayer_test.cpp

index a228b8a2cd5cc3fe0468202f91defe4b5603e291..3fe7fca1d74a3bb1335b34ebfb07b961c506a5a1 100644 (file)
@@ -12,7 +12,7 @@
 Name:       esplusplayer
 Summary:    new multimedia streaming player
 Version:    1.3.7
-Release:    5
+Release:    6
 Group:      Multimedia/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index e314d54d3bc35048b780574f61676d1d2195d937..79b245c1e3515550d920fed30df412b386e02e30 100644 (file)
@@ -11,7 +11,7 @@ SET(${fw_name}_CXXFLAGS "-Wall -Werror -std=c++17 -pthread -fPIE -Wl,-z,relro -f
 SET(${fw_name}_LDFLAGS)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0 appcore-efl elementary capi-mediademuxer capi-media-sound-manager)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 appcore-efl elementary capi-mediademuxer capi-media-sound-manager libtbm)
 
 FOREACH(flag ${${fw_test}_CFLAGS})
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 0ae5ccf5c30d60664b033c6cc531712b40dfb258..f1dc23b5108282b9ffe1a9712fee10863fe6c79c 100644 (file)
@@ -24,7 +24,9 @@
 #include <mediademuxer.h>
 #include <getopt.h>
 #include <sound_manager.h>
-
+#ifdef __DEBUG__
+#include <tbm_debug.h>
+#endif
 #include "esplusplayer_capi/esplusplayer_capi.h"
 #include "esplusplayer_capi/esplusplayer_internal.h"
 #ifdef PACKAGE
@@ -70,6 +72,8 @@ enum {
        CURRENT_STATUS_SET_LOW_LATENCY_MODE,
        CURRENT_STATUS_SET_SOUND_STREAM_INFO,
        CURRENT_STATUS_SET_TIME_UNIT,
+       CURRENT_STATUS_SET_VIDEO_BUFFER_TYPE,
+       CURRENT_STATUS_SET_RESOURCE_ALLOCATE_POLICY,
 };
 
 /* for video display */
@@ -114,6 +118,7 @@ typedef struct {
        int audio_track_id;
        sound_stream_info_h stream_info;
        bool is_seek_done;
+       bool is_ready_to_prepare_cb_called[STREAM_MAX];
        esplusplayer_time_unit_type time_unit;
 } test_h;
 
@@ -122,26 +127,31 @@ static test_h *g_test_h;
 static GRand *g_seek_rand = g_rand_new();
 static int g_max_range = 0;
 
-#define STREAM_LOCK(type) { \
+#define STREAM_LOCK(type) \
+do { \
        g_mutex_lock(&g_test_h->streams[type].mutex); \
-}
+} while(0)
 
-#define STREAM_UNLOCK(type) { \
+#define STREAM_UNLOCK(type) \
+do { \
        g_mutex_unlock(&g_test_h->streams[type].mutex); \
-}
+} while(0)
 
-#define STREAM_WAIT(type) { \
+#define STREAM_WAIT(type) \
+do { \
        g_cond_wait(&g_test_h->streams[type].cond, &g_test_h->streams[type].mutex); \
-}
+} while(0)
 
-#define STREAM_WAIT_UNTIL(type, time) { \
+#define STREAM_WAIT_UNTIL(type, time) \
+do { \
        g_cond_wait_until(&g_test_h->streams[type].cond, &g_test_h->streams[type].mutex, g_get_monotonic_time() + time); \
-}
+} while(0)
 
-#define STREAM_SIGNAL(type) { \
+#define STREAM_SIGNAL(type) \
+do { \
        g_test_h->streams[type].wait_thread = false; \
        g_cond_signal(&g_test_h->streams[type].cond); \
-}
+} while(0)
 
 static char *g_uri;
 static int g_menu_state = CURRENT_STATUS_MAINMENU;
@@ -283,6 +293,8 @@ static void __mediademuxer_err_cb(mediademuxer_error_e error, void *user_data)
 static void __mediademuxer_eos_cb(int track_index, void *user_data)
 {
        test_h *test_t = (test_h *)user_data;
+       if (!test_t)
+               return;
 
        g_print("Got EOS for track -- %d from Mediademuxer\n", track_index);
        if (track_index == test_t->streams[VIDEO_STREAM].track_index)
@@ -303,9 +315,13 @@ static void __espp_prepare_async_done_cb(bool ret, void* user_data)
 static void __espp_ready_to_prepare_cb(esplusplayer_stream_type type, void *user_data)
 {
        test_h *test_t = (test_h *)user_data;
+       if (!test_t)
+               return;
 
        g_print("__espp_ready_to_prepare_cb() is called, type[%u] espp[%p]\n", type, test_t->espp_h);
 
+       test_t->is_ready_to_prepare_cb_called[type] = true;
+
 }
 
 static void __espp_error_cb(esplusplayer_error_type type, void *user_data)
@@ -353,6 +369,50 @@ static void __espp_event_cb(esplusplayer_event_type type, esplusplayer_event_msg
        g_print("__espp_event_cb(type:%d, msg:%s) \n", type, msg.data);
 }
 
+static void __espp_resource_conflicted_cb(void *user_data)
+{
+       g_print("__espp_resource_conflicted_cb() is called\n");
+}
+
+#ifdef __DEBUG__
+void dump_video_frame(tbm_surface_h tbm_surf)
+{
+       static int cnt = 0;
+       char filename[128] = {0};
+       tbm_surface_info_s info;
+       if (tbm_surface_get_info(tbm_surf, &info))
+               return;
+
+       sprintf(filename, "video_frame_dump_%d", cnt);
+
+       tbm_surface_internal_dump_start((char *)"/tmp", info.width, info.height, 1);
+       tbm_surface_internal_dump_buffer(tbm_surf, filename);
+       tbm_surface_internal_dump_end();
+
+       g_print("[0]stride : %d, offset : %d\n", (int)info.planes[0].stride, (int)info.planes[0].offset);
+       g_print("[1]stride : %d, offset : %d\n", (int)info.planes[1].stride, (int)info.planes[1].offset);
+       g_print("[2]stride : %d, offset : %d\n", (int)info.planes[2].stride, (int)info.planes[2].offset);
+       g_print("DUMP_OUT_IMG_%d : buffer size(%d) surf(%p) %d*%d\n", cnt, (int)info.size, tbm_surf, info.width, info.height);
+       cnt++;
+}
+#endif
+
+static void __espp_media_packet_video_decoded_cb(const esplusplayer_decoded_video_packet* packet, void *user_data)
+{
+       test_h *test_t = (test_h *)user_data;
+
+       if (!test_t || !packet)
+               return;
+
+#ifdef __DEBUG__
+       dump_video_frame((tbm_surface_h)packet->surface_data);
+#endif
+
+       if (esplusplayer_decoded_buffer_destroy(test_t->espp_h, (esplusplayer_decoded_video_packet *)packet) != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_decoded_buffer_destroy\n");
+
+}
+
 static int __convert_media_format_mime_to_espp_mime(media_format_mimetype_e type)
 {
        g_print("media_format_mimetype(0x%x)\n", type);
@@ -362,6 +422,10 @@ static int __convert_media_format_mime_to_espp_mime(media_format_mimetype_e type
                return (int)ESPLUSPLAYER_AUDIO_MIME_TYPE_AAC;
        case MEDIA_FORMAT_OPUS:
                return (int)ESPLUSPLAYER_AUDIO_MIME_TYPE_OPUS;
+       case MEDIA_FORMAT_AC3:
+               return (int)ESPLUSPLAYER_AUDIO_MIME_TYPE_AC3;
+       case MEDIA_FORMAT_EAC3:
+               return (int)ESPLUSPLAYER_AUDIO_MIME_TYPE_EAC3;
        case MEDIA_FORMAT_VP8:
                return (int)ESPLUSPLAYER_VIDEO_MIME_TYPE_VP8;
        case MEDIA_FORMAT_VP9:
@@ -484,6 +548,12 @@ static void __init_espp()
        else
                g_print("                       => esplusplayer_set_event_cb() success\n");
 
+       ret = esplusplayer_set_resource_conflicted_cb(g_test_h->espp_h, __espp_resource_conflicted_cb, g_test_h);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_set_resource_conflicted_cb()\n");
+       else
+               g_print("                       => esplusplayer_set_resource_conflicted_cb() success\n");
+
        ret = esplusplayer_open(g_test_h->espp_h);
        if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
                g_print("                       => failed to esplusplayer_open()\n");
@@ -1006,11 +1076,11 @@ void *_fetch_audio_data(void *ptr)
                                break;
 
                        test_t->streams[AUDIO_STREAM].is_full_waiting = true;
-                       if (test_t->is_seek_done) {
+                       if (test_t->is_seek_done)
                                STREAM_WAIT(AUDIO_STREAM);
-                       } else {
+                       else
                                STREAM_WAIT_UNTIL(AUDIO_STREAM, SEEK_WAIT_TIME);
-                       }
+
                        test_t->streams[AUDIO_STREAM].is_full_waiting = false;
                }
 #ifdef DEBUG_LOG
@@ -1134,13 +1204,19 @@ static void __test_submit_packet()
 
        if (g_test_h->streams[AUDIO_STREAM].activate) {
                g_print("In main: creating thread  for audio\n");
-               pthread_create(&g_test_h->streams[AUDIO_STREAM].thread,
-                               &attr, _fetch_audio_data, g_test_h);
+               if (g_test_h->is_ready_to_prepare_cb_called[AUDIO_STREAM])
+                       pthread_create(&g_test_h->streams[AUDIO_STREAM].thread,
+                                       &attr, _fetch_audio_data, g_test_h);
+               else
+                       g_print("Audio ready to prepare callback not called yet\n");
        }
        if (g_test_h->streams[VIDEO_STREAM].activate) {
                g_print("In main: creating thread  for video\n");
-               pthread_create(&g_test_h->streams[VIDEO_STREAM].thread,
-                               &attr, _fetch_video_data, g_test_h);
+               if (g_test_h->is_ready_to_prepare_cb_called[VIDEO_STREAM])
+                       pthread_create(&g_test_h->streams[VIDEO_STREAM].thread,
+                                       &attr, _fetch_video_data, g_test_h);
+               else
+                       g_print("Video ready to prepare callback not called yet\n");
        }
        pthread_attr_destroy(&attr);
 }
@@ -1452,6 +1528,9 @@ static void __test_set_low_latency_mode(int value)
                mode = ESPLUSPLAYER_LOW_LATENCY_MODE_NONE;
                break;
        case 1:
+               mode = ESPLUSPLAYER_LOW_LATENCY_MODE_VIDEO;
+               break;
+       case 2:
                mode = ESPLUSPLAYER_LOW_LATENCY_MODE_DISABLE_PREROLL;
                break;
        default:
@@ -1574,6 +1653,84 @@ static void __test_set_time_unit(int time_unit)
                g_print("                       => esplusplayer_set_timeunit_type(%d) success\n", g_test_h->time_unit);
 }
 
+static void __test_set_video_frame_buffer_type(int buffer_type)
+{
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       if (buffer_type < ESPLUSPLAYER_DECODED_VIDEO_FRAME_BUFFER_TYPE_NONE
+               || buffer_type > ESPLUSPLAYER_DECODED_VIDEO_FRAME_BUFFER_TYPE_MANUAL_COPY) {
+               g_print("!!! Not support video frame buffer type (%d)\n", buffer_type);
+               return;
+       }
+
+       int ret = esplusplayer_set_video_frame_buffer_type(g_test_h->espp_h, (esplusplayer_decoded_video_frame_buffer_type)buffer_type);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_set_video_frame_buffer_type(%d)\n", buffer_type);
+       else
+               g_print("                       => esplusplayer_set_video_frame_buffer_type(%d) success\n", buffer_type);
+}
+
+static void __test_set_decoded_video_packet_decoded()
+{
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       int ret = esplusplayer_set_media_packet_video_decoded_cb(g_test_h->espp_h, __espp_media_packet_video_decoded_cb, g_test_h);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_set_media_packet_video_decoded_cb\n");
+       else
+               g_print("                       => esplusplayer_set_media_packet_video_decoded_cb success\n");
+}
+
+static void __test_get_decoded_video_packet()
+{
+       esplusplayer_decoded_video_packet pkt;
+       esplusplayer_get_decoded_video_frame_status_type status;
+       g_print("!!! must set ESPP_LOW_LATENCY_MODE_VIDEO, ESPP_DECODED_VIDEO_FRAME_BUFFER_TYPE_MANUAL_COPY\n");
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       int ret = esplusplayer_get_decoded_video_packet(g_test_h->espp_h, &pkt, &status);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_get_decoded_video_packet\n");
+       else
+               g_print("                       => esplusplayer_get_decoded_video_packet success\n");
+
+       if (status != ESPLUSPLAYER_GET_DECVIDEOFRAME_STATUS_SUCCESS)
+               g_print("                       => esplusplayer_get_decoded_video_packet didn't succeed (%d)\n", status);
+
+       if (esplusplayer_decoded_buffer_destroy(g_test_h->espp_h, &pkt) != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_decoded_buffer_destroy\n");
+
+}
+
+static void __test_set_resource_allocate_policy(int policy)
+{
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       if (policy < ESPLUSPLAYER_RSC_ALLOC_EXCLUSIVE
+               || policy > ESPLUSPLAYER_RSC_ALLOC_EXCLUSIVE_MFC_FORCED) {
+               g_print("!!! Not support rsc alloc policy (%d)\n", policy);
+               return;
+       }
+
+       int ret = esplusplayer_set_resource_allocate_policy(g_test_h->espp_h, (esplusplayer_rsc_alloc_policy)policy);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_set_resource_allocate_policy(%d)\n", policy);
+       else
+               g_print("                       => esplusplayer_set_resource_allocate_policy(%d) success\n", policy);
+}
+
 static void __test_get_playing_time()
 {
        uint64_t time = 0;
@@ -1768,6 +1925,8 @@ static void __interpret_main_menu(char *cmd)
                        g_menu_state = CURRENT_STATUS_SET_TIME_UNIT;
                } else if (strncmp(cmd, "gp", 2) == 0) {
                        __test_get_playing_time();
+               } else if (strncmp(cmd, "ra", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_SET_RESOURCE_ALLOCATE_POLICY;
                } else {
                        g_print("unknown menu \n");
                }
@@ -1784,6 +1943,12 @@ static void __interpret_main_menu(char *cmd)
                        g_menu_state = CURRENT_STATUS_SET_SOUND_STREAM_INFO;
                } else if (strncmp(cmd, "ssr", 3) == 0) {
                        g_menu_state = CURRENT_STATUS_SET_SEEK_RANGE;
+               } else if (strncmp(cmd, "svb", 3) == 0) {
+                       g_menu_state = CURRENT_STATUS_SET_VIDEO_BUFFER_TYPE;
+               } else if (strncmp(cmd, "svp", 3) == 0) {
+                       __test_set_decoded_video_packet_decoded();
+               } else if (strncmp(cmd, "gvp", 3) == 0) {
+                       __test_get_decoded_video_packet();
                } else {
                        g_print("unknown menu \n");
                }
@@ -1827,6 +1992,10 @@ static void __display_sub_basic()
        g_print("[volume] f.Set Volume\t");
        g_print("g.Get Volume\t");
        g_print("h.Set Mute\n");
+       g_print("[resource] ra.Set Resource allocate policy\n");
+       g_print("[Video Decoded] svb.Set Video frame buffer type\n");
+       g_print("                svp.Set decoded video packet callback\n");
+       g_print("                gvp.Get decoded video packet\n");
        g_print("[etc] ");
        g_print("sr.Set render time offset\t\t");
        g_print("ll.Set low latency mode\n");
@@ -1886,11 +2055,15 @@ static void __displaymenu()
        } else if (g_menu_state == CURRENT_STATUS_SET_RENDER_TIME_OFFSET) {
                g_print("*** Input stream type and time offset\n");
        } else if (g_menu_state == CURRENT_STATUS_SET_LOW_LATENCY_MODE) {
-               g_print("*** Input low latency mode (0: none, 1: disable preroll)\n");
+               g_print("*** Input low latency mode (0: none, 1: video, 2: disable preroll)\n");
        } else if (g_menu_state == CURRENT_STATUS_SET_SOUND_STREAM_INFO) {
                g_print("*** input sound stream type.(0:MEDIA 1:SYSTEM 2:ALARM 3:NOTIFICATION 4:EMERGENCY 5:VOICE_INFORMATION 9:MEDIA_EXT_ONLY)\n");
        } else if (g_menu_state == CURRENT_STATUS_SET_TIME_UNIT) {
                g_print("*** input time unit.(0:ms 1:us)\n");
+       } else if (g_menu_state == CURRENT_STATUS_SET_VIDEO_BUFFER_TYPE) {
+               g_print("*** input video frame buffer type.(0:none, 1:copy, 2:reference, 3:scale, 4:manual copy)\n");
+       } else if (g_menu_state == CURRENT_STATUS_SET_RESOURCE_ALLOCATE_POLICY) {
+               g_print("*** input resource allocate policy. (0:exclusive, 1:exclusive_conditional)\n");
        } else {
                g_print("*** Unknown status.\n");
                quit_program();
@@ -2198,6 +2371,20 @@ static void interpret(char *cmd)
                reset_menu_state();
                break;
        }
+       case CURRENT_STATUS_SET_VIDEO_BUFFER_TYPE:
+       {
+               value = atoi(cmd);
+               __test_set_video_frame_buffer_type(value);
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_SET_RESOURCE_ALLOCATE_POLICY:
+       {
+               value = atoi(cmd);
+               __test_set_resource_allocate_policy(value);
+               reset_menu_state();
+               break;
+       }
        default:
                break;
        }