From 9af4fd0a171b75ec5e9f94c7c9121afb294943d7 Mon Sep 17 00:00:00 2001 From: Eunhae Choi Date: Thu, 8 Oct 2015 11:20:33 +0900 Subject: [PATCH] add media packet flag and null buff handling Change-Id: Iddd3291833f8da1510e2d488f42173a2177b3786 --- client/src/player2.c | 1 + client/test/player_es_push_test.c | 80 ++++++++++++++++++++++++++++----------- include/player_msg_private.h | 1 + src/player_msg_dispatcher.c | 28 ++++++++++---- 4 files changed, 81 insertions(+), 29 deletions(-) diff --git a/client/src/player2.c b/client/src/player2.c index 1dd8c19..9c8f2f7 100644 --- a/client/src/player2.c +++ b/client/src/player2.c @@ -2930,6 +2930,7 @@ int player_push_media_stream(player_h player, media_packet_h packet) media_packet_get_buffer_size(packet, &push_media.size); media_packet_get_pts(packet, &push_media.pts); media_packet_get_format(packet, &format); + media_packet_get_flags(packet, &push_media.flags); push_media.buf_type = PUSH_MEDIA_BUF_TYPE_RAW; diff --git a/client/test/player_es_push_test.c b/client/test/player_es_push_test.c index d1d8905..4d0bf48 100644 --- a/client/test/player_es_push_test.c +++ b/client/test/player_es_push_test.c @@ -26,8 +26,6 @@ #endif #define KEY_END "XF86Stop" -#define ES_FEEDING_PATH "es_buff://push_mode" -//#define ES_FEEDING_PATH "es_buff://pull_mode" #define ES_DEFAULT_DIR_PATH "/home/owner/content/" #define ES_DEFAULT_H264_VIDEO_PATH ES_DEFAULT_DIR_PATH"Simpsons.h264" @@ -270,7 +268,7 @@ static void _player_prepared_cb(void *user_data) LOGD("done"); } -unsigned int bytestream2nalunit(FILE *fd, unsigned char* nal) +int bytestream2nalunit(FILE *fd, unsigned char* nal) { int nal_length = 0; size_t result; @@ -316,11 +314,13 @@ unsigned int bytestream2nalunit(FILE *fd, unsigned char* nal) while(1) { if (feof(fd)) - return nal_length; + return -1; result = fread(buffer, 1, read_size, fd); if(result != read_size) { + if (init == 1) + return -1; break; } val = buffer[0]; @@ -377,8 +377,31 @@ unsigned int bytestream2nalunit(FILE *fd, unsigned char* nal) return nal_length; } -static void feed_video_data(appdata_s *appdata) +static void feed_eos_data(appdata_s *appdata) { + appdata_s *ad = appdata; + + LOGD("push EOS"); + + if (media_packet_create(ad->video_fmt, NULL, NULL, &ad->video_pkt) != MEDIA_PACKET_ERROR_NONE) { + LOGE("media_packet_create_alloc failed\n"); + return; + } + + media_packet_set_flags(ad->video_pkt, MEDIA_PACKET_END_OF_STREAM); + if (player_push_media_stream(ad->player_handle, ad->video_pkt) != PLAYER_ERROR_NONE) { + LOGE("fail to push media packet\n"); + } + + media_packet_destroy(ad->video_pkt); + ad->video_pkt = NULL; + + return; +} + +static bool feed_video_data(appdata_s *appdata) +{ + bool ret = FALSE; int read = 0; static guint64 pts = 0L; void *buf_data_ptr = NULL; @@ -386,17 +409,17 @@ static void feed_video_data(appdata_s *appdata) if (media_packet_create_alloc(ad->video_fmt, NULL, NULL, &ad->video_pkt) != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_create_alloc failed\n"); - return; + return FALSE; } if (media_packet_get_buffer_data_ptr(ad->video_pkt, &buf_data_ptr) != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_get_buffer_data_ptr failed\n"); - return; + goto ERROR; } if (media_packet_set_pts(ad->video_pkt, (uint64_t)(pts/1000000)) != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_set_pts failed\n"); - return; + goto ERROR; } /* NOTE: In case of H.264 video, stream format for feeding is NAL unit. @@ -405,39 +428,58 @@ static void feed_video_data(appdata_s *appdata) read = bytestream2nalunit(ad->file_src, buf_data_ptr); LOGD("real length = %d\n", read); if (read == 0) { - LOGD("input file read failed\n"); - return; + LOGE("input file read failed\n"); + ret = TRUE; + goto ERROR; + } + else if (read < 0) { + LOGD("push EOS"); + media_packet_destroy(ad->video_pkt); + ad->video_pkt = NULL; + + if (media_packet_create(ad->video_fmt, NULL, NULL, &ad->video_pkt) != MEDIA_PACKET_ERROR_NONE) { + LOGE("media_packet_create failed\n"); + goto ERROR; + } + media_packet_set_flags (ad->video_pkt, MEDIA_PACKET_END_OF_STREAM); + if (player_push_media_stream(ad->player_handle, ad->video_pkt) != PLAYER_ERROR_NONE) { + LOGE("fail to push media packet\n"); + } + goto ERROR; } if (media_packet_set_buffer_size(ad->video_pkt, (uint64_t)read) != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_set_buffer_size failed\n"); - return; + goto ERROR; } /* push media packet */ player_push_media_stream(ad->player_handle, ad->video_pkt); pts += ES_DEFAULT_VIDEO_PTS_OFFSET; + ret = TRUE; +ERROR: /* destroy media packet after use*/ media_packet_destroy(ad->video_pkt); ad->video_pkt = NULL; - return; + return ret; } static void feed_video_data_thread_func(void *data) { - gboolean exit = FALSE; appdata_s *ad = (appdata_s *)data; - while (!exit) + while (TRUE) { static int frame_count = 0; if (frame_count < ES_DEFAULT_NUMBER_OF_FEED) { - feed_video_data(ad); + if (!feed_video_data(ad)) + break; frame_count++; } else { - exit = TRUE; + feed_eos_data(ad); + break; } } } @@ -497,12 +539,6 @@ static int app_reset(bundle *b, void *data) goto FAILED; } - ret = player_set_uri(ad->player_handle, ES_FEEDING_PATH); - if (ret != PLAYER_ERROR_NONE) { - LOGE("player_set_uri failed : 0x%x", ret); - goto FAILED; - } - /* get media format format */ ret = media_format_create(&ad->video_fmt); if (ret != MEDIA_FORMAT_ERROR_NONE) { diff --git a/include/player_msg_private.h b/include/player_msg_private.h index 661c2cd..3e94fc7 100644 --- a/include/player_msg_private.h +++ b/include/player_msg_private.h @@ -45,6 +45,7 @@ typedef struct _player_push_media_msg_type{ uint64_t size; uint64_t pts; media_format_mimetype_e mimetype; + media_buffer_flags_e flags; tbm_key key; }player_push_media_msg_type; diff --git a/src/player_msg_dispatcher.c b/src/player_msg_dispatcher.c index 787ef0d..5100ecd 100644 --- a/src/player_msg_dispatcher.c +++ b/src/player_msg_dispatcher.c @@ -58,6 +58,7 @@ typedef struct { uint64_t pts; uint64_t size; media_format_mimetype_e mimetype; + media_buffer_flags_e flags; }push_data_q_t; typedef struct { @@ -1763,11 +1764,11 @@ static gpointer _player_push_media_stream_handler(gpointer param) push_media.mimetype = qData->mimetype; push_media.pts = qData->pts; push_media.size = qData->size; + push_media.flags = qData->flags; buf = muse_core_ipc_get_data(module); - if(buf) { - _push_media_stream(qData->handle, &push_media, buf); + _push_media_stream(qData->handle, &push_media, buf); + if(buf) muse_core_ipc_delete_data(buf); - } g_free(qData); } else { g_mutex_lock(&thread_i->mutex); @@ -1833,13 +1834,24 @@ static int _push_media_stream(intptr_t handle, player_push_media_msg_type *push_ return PLAYER_ERROR_INVALID_PARAMETER; } - ret = media_packet_create_from_external_memory(format, buf, - push_media->size, NULL, NULL, &packet); - if(ret != MEDIA_PACKET_ERROR_NONE) { - return PLAYER_ERROR_INVALID_PARAMETER; + if (buf) { + ret = media_packet_create_from_external_memory(format, buf, + push_media->size, NULL, NULL, &packet); + if(ret != MEDIA_PACKET_ERROR_NONE) { + LOGE("fail to create media packet with external mem"); + return PLAYER_ERROR_INVALID_PARAMETER; + } + } + else { + ret = media_packet_create(format, NULL, NULL, &packet); + if(ret != MEDIA_PACKET_ERROR_NONE) { + LOGE("fail to create media packet"); + return PLAYER_ERROR_INVALID_PARAMETER; + } } media_packet_set_pts(packet, push_media->pts); + media_packet_set_flags(packet, push_media->flags); ret = player_push_media_stream((player_h)handle, packet); if(ret != PLAYER_ERROR_NONE) @@ -1901,6 +1913,8 @@ static int player_disp_push_media_stream(muse_module_h module) qData->mimetype = push_media.mimetype; qData->pts = push_media.pts; qData->size = push_media.size; + qData->flags = push_media.flags; + g_queue_push_tail(thread_i->queue ,qData); g_cond_signal(&thread_i->cond); } -- 2.7.4