Add some testsuite case 46/301946/9 accepted/tizen/unified/20231205.171419
authorGilbok Lee <gilbok.lee@samsung.com>
Tue, 28 Nov 2023 06:15:10 +0000 (15:15 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Mon, 4 Dec 2023 08:08:35 +0000 (17:08 +0900)
- esplusplayer_set_timeunit_type()
- esplusplayer_get_playing_time()

Change-Id: If05e7abe631261e0a9711e6de092415139cb6421

test/esplusplayer_test.cpp

index 3fa200f..d20132a 100644 (file)
 
 #define MAX_STRING_LEN 2048
 #define MAX_TRACK_COUNT        10
+
+#define TIME_SECOND  ((gint64)(G_USEC_PER_SEC * G_GINT64_CONSTANT (1000)))
+#define TIME_USECOND ((gint64)(TIME_SECOND / G_GINT64_CONSTANT (1000000)))
+#define TIME_MSECOND ((gint64)(TIME_SECOND / G_GINT64_CONSTANT (1000)))
+#define TIME_USEC_TO_MSEC(time) ((time) / G_GINT64_CONSTANT (1000))
+
 constexpr uint64_t SEEK_WAIT_TIME = 100 * G_TIME_SPAN_MILLISECOND;
 // #define DEBUG_LOG
 
@@ -63,6 +69,7 @@ enum {
        CURRENT_STATUS_SET_RENDER_TIME_OFFSET,
        CURRENT_STATUS_SET_LOW_LATENCY_MODE,
        CURRENT_STATUS_SET_SOUND_STREAM_INFO,
+       CURRENT_STATUS_SET_TIME_UNIT,
 };
 
 /* for video display */
@@ -107,6 +114,7 @@ typedef struct {
        int audio_track_id;
        sound_stream_info_h stream_info;
        bool is_seek_done;
+       esplusplayer_time_unit_type time_unit;
 } test_h;
 
 static appdata g_ad;
@@ -504,6 +512,7 @@ static void __init_test()
        g_test_h->audio_track_id = -1;
        g_test_h->video_track_id = -1;
        g_test_h->is_seek_done = true;
+       g_test_h->time_unit = ESPLUSPLAYER_TIME_UNIT_MS;
 
        __init_espp();
        __init_demux();
@@ -910,6 +919,7 @@ static void __convert_espp_packet(media_packet_h packet, esplusplayer_es_packet*
        bool is_audio;
        uint64_t gst_pts;
        uint64_t gst_duration;
+       int64_t time_scale = TIME_MSECOND;
 
        if (!packet) {
                g_print("media packet is NULL\n");
@@ -923,10 +933,13 @@ static void __convert_espp_packet(media_packet_h packet, esplusplayer_es_packet*
        media_packet_get_buffer_size(packet, (uint64_t *)&espp_packet->buffer_size);
        media_packet_get_pts(packet, &gst_pts);
        media_packet_get_duration(packet, &gst_duration);
+       if (g_test_h->time_unit == ESPLUSPLAYER_TIME_UNIT_US)
+               time_scale = TIME_USECOND;
+
        if (gst_pts != (uint64_t) -1)
-               espp_packet->pts = gst_pts / G_GINT64_CONSTANT(1000000);
+               espp_packet->pts = gst_pts / time_scale;
        if (gst_duration != (uint64_t) -1)
-               espp_packet->duration = gst_duration / G_GINT64_CONSTANT(1000000);
+               espp_packet->duration = gst_duration / time_scale;
 
        espp_packet->matroska_color_info = NULL;
        espp_packet->hdr10p_metadata = NULL;
@@ -1192,7 +1205,7 @@ static void __test_pause()
                g_print("                       => esplusplayer_pause() success\n");
 }
 
-static void __test_seek(uint64_t time_ms)
+static void __test_seek(uint64_t time)
 {
        int i = 0;
        int ret = 0;
@@ -1220,23 +1233,27 @@ static void __test_seek(uint64_t time_ms)
                STREAM_UNLOCK(i);
        }
 
+       int64_t time_ms = (int64_t)time;
+       if (g_test_h->time_unit == ESPLUSPLAYER_TIME_UNIT_US)
+               time_ms = TIME_USEC_TO_MSEC(time);
+
        ret = mediademuxer_seek(g_test_h->audio_demux_h, time_ms);
        if (ret != MEDIADEMUXER_ERROR_NONE)
-               g_print("                       => failed to mediademuxer_seek(audio, %" PRIu64 ")\n", time_ms);
+               g_print("                       => failed to mediademuxer_seek(audio, %" PRId64 " ms)\n", time_ms);
        else
-               g_print("                       => mediademuxer_seek(audio, %" PRIu64 ") success\n", time_ms);
+               g_print("                       => mediademuxer_seek(audio, %" PRId64 " ms) success\n", time_ms);
 
        ret = mediademuxer_seek(g_test_h->video_demux_h, time_ms);
        if (ret != MEDIADEMUXER_ERROR_NONE)
-               g_print("                       => failed to mediademuxer_seek(video, %" PRIu64 ")\n", time_ms);
+               g_print("                       => failed to mediademuxer_seek(video, %" PRId64 " ms)\n", time_ms);
        else
-               g_print("                       => mediademuxer_seek(video, %" PRIu64 ") success\n", time_ms);
+               g_print("                       => mediademuxer_seek(video, %" PRId64 " ms) success\n", time_ms);
 
-       ret = esplusplayer_seek(g_test_h->espp_h, time_ms);
+       ret = esplusplayer_seek(g_test_h->espp_h, time);
        if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
-               g_print("                       => failed to esplusplayer_seek(%" PRIu64 ")\n", time_ms);
+               g_print("                       => failed to esplusplayer_seek(%" PRIu64 " (ms/us))\n", time);
        else
-               g_print("                       => esplusplayer_seek(%" PRIu64 ") success\n", time_ms);
+               g_print("                       => esplusplayer_seek(%" PRIu64 " (ms/us)) success\n", time);
 }
 
 static void __test_set_playback_rate(double playback_rate, bool audio_mute)
@@ -1541,6 +1558,41 @@ END:
                sound_manager_free_device_list(device_list);
 }
 
+static void __test_set_time_unit(int time_unit)
+{
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       if (time_unit < 0 || time_unit > 1) {
+               g_print("!!! Not support time unit (%d)\n", time_unit);
+               return;
+       }
+
+       g_test_h->time_unit = (esplusplayer_time_unit_type)time_unit;
+       int ret = esplusplayer_set_timeunit_type(g_test_h->espp_h, g_test_h->time_unit);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_set_timeunit_type(%d)\n", g_test_h->time_unit);
+       else
+               g_print("                       => esplusplayer_set_timeunit_type(%d) success\n", g_test_h->time_unit);
+}
+
+static void __test_get_playing_time()
+{
+       uint64_t time = 0;
+       if (!g_test_h) {
+               g_print("test handle is NULL\n");
+               return;
+       }
+
+       int ret = esplusplayer_get_playing_time(g_test_h->espp_h, &time);
+       if (ret != ESPLUSPLAYER_ERROR_TYPE_NONE)
+               g_print("                       => failed to esplusplayer_get_playing_time(%" PRIu64 ")(ms/ns) success\n", time);
+       else
+               g_print("                       => esplusplayer_get_playing_time(%" PRIu64 ")(ms/ns) success\n", time);
+}
+
 static void __test_quick_prepare()
 {
        int ret = 0;
@@ -1671,8 +1723,12 @@ static void __interpret_main_menu(char *cmd)
                } else if (strncmp(cmd, "q", 1) == 0) {
                        quit_program();
                } else if (strncmp(cmd, "3", 1) == 0) {
-                       if (g_max_range > 0)
-                               __test_seek(g_rand_int_range(g_seek_rand, 0, g_max_range));
+                       if (g_max_range > 0) {
+                               uint64_t seek_time = (uint64_t)g_rand_int_range(g_seek_rand, 0, g_max_range);
+                               if (g_test_h->time_unit == ESPLUSPLAYER_TIME_UNIT_US)
+                                       seek_time = seek_time * G_GINT64_CONSTANT(1000);
+                               __test_seek(seek_time);
+                       }
                        g_menu_state = CURRENT_STATUS_MAINMENU;
                } else {
                        g_print("unknown menu \n");
@@ -1712,6 +1768,10 @@ static void __interpret_main_menu(char *cmd)
                        __test_quick_prepare();
                } else if (strncmp(cmd, "ll", 2) == 0) {
                        g_menu_state = CURRENT_STATUS_SET_LOW_LATENCY_MODE;
+               } else if (strncmp(cmd, "st", 2) == 0) {
+                       g_menu_state = CURRENT_STATUS_SET_TIME_UNIT;
+               } else if (strncmp(cmd, "gp", 2) == 0) {
+                       __test_get_playing_time();
                } else {
                        g_print("unknown menu \n");
                }
@@ -1761,6 +1821,7 @@ static void __display_sub_basic()
        g_print("d.Resume\t");
        g_print("e.Pause\t\t");
        g_print("dt.Destroy\n");
+       g_print("           gp.Get playing time\n");
        g_print("[quick] qp.quick prepare\n");
        g_print("[seek] j.Seek\t");
        g_print("3.Random seek\t");
@@ -1771,15 +1832,16 @@ static void __display_sub_basic()
        g_print("g.Get Volume\t");
        g_print("h.Set Mute\n");
        g_print("[etc] ");
-       g_print("sr.Set render time offset\t");
+       g_print("sr.Set render time offset\t\t");
        g_print("ll.Set low latency mode\n");
-       g_print("      ssi.Set sound stream info\n\n");
+       g_print("      ssi.Set sound stream info\t\t");
+       g_print("st.Set Time Unit\n\n");
 
        g_print("-- << mediademuxer cmd >> ---------------------------------------------------------------\n");
        g_print("prd.prepare demuxer\n\n");
 
        g_print("-- << display >> ------------------------------------------------------------------------\n");
-       g_print("ev.enable videohole\t\t");
+       g_print("ev.enable videohole\t");
        g_print("ds.set display\t\t");
        g_print("dm.set display mode\n");
        g_print("dr.set display roi\t");
@@ -1800,7 +1862,7 @@ static void __displaymenu()
        } else if (g_menu_state == CURRENT_STATUS_DEACTIVATE) {
                g_print("*** Input deactivate stream.(0:audio, 1:video)\n");
        } else if (g_menu_state == CURRENT_STATUS_SEEK) {
-               g_print("*** Input seek position.(ms)\n");
+               g_print("*** Input seek position.(ms/us))\n");
        } else if (g_menu_state == CURRENT_STATUS_SET_SEEK_RANGE) {
                g_print("*** Input random seek range.(ms)\n");
        } else if (g_menu_state == CURRENT_STATUS_SET_RATE) {
@@ -1831,6 +1893,8 @@ static void __displaymenu()
                g_print("*** Input low latency mode (0: none, 1: 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 {
                g_print("*** Unknown status.\n");
                quit_program();
@@ -2131,6 +2195,13 @@ static void interpret(char *cmd)
                reset_menu_state();
                break;
        }
+       case CURRENT_STATUS_SET_TIME_UNIT:
+       {
+               value = atoi(cmd);
+               __test_set_time_unit(value);
+               reset_menu_state();
+               break;
+       }
        default:
                break;
        }