#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
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 */
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;
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;
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)
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)
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);
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:
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");
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
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);
}
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:
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;
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");
}
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");
}
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");
} 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();
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;
}