From 6f91f7d18df1e885b9bfcce531b2627e9faba005 Mon Sep 17 00:00:00 2001 From: Zhao Cancan Date: Mon, 26 Dec 2016 04:59:57 -0500 Subject: [PATCH] Fix FPS error issue when encoding MPEG4 video remove null caractor in log Change-Id: I4d742d0d9ffb6f15500276fd764006e8b4330d9d --- include/mediamuxer_private.h | 2 +- include/mediamuxer_util.h | 8 +- include/port_gst/mediamuxer_port_gst.h | 4 +- packaging/capi-mediamuxer.spec | 2 +- src/mediamuxer.c | 72 +++---- src/mediamuxer_ini.c | 28 +-- src/mediamuxer_port.c | 6 +- src/port_custom/mediamuxer_port_custom.c | 4 +- src/port_ffmpeg/mediamuxer_port_ffmpeg.c | 4 +- src/port_gst/mediamuxer_port_gst.c | 331 +++++++++++++++++-------------- 10 files changed, 248 insertions(+), 213 deletions(-) diff --git a/include/mediamuxer_private.h b/include/mediamuxer_private.h index 9761db0..06779cc 100755 --- a/include/mediamuxer_private.h +++ b/include/mediamuxer_private.h @@ -33,7 +33,7 @@ extern "C" { do { \ if (condition) { \ } else { \ - MX_E("[%s] %s(0x%08x)\n", __FUNCTION__, msg, error); \ + MX_E("[%s] %s(0x%08x)", __FUNCTION__, msg, error); \ return error; \ } \ } while (0) diff --git a/include/mediamuxer_util.h b/include/mediamuxer_util.h index 7ea22aa..71fcd4e 100755 --- a/include/mediamuxer_util.h +++ b/include/mediamuxer_util.h @@ -43,8 +43,8 @@ extern "C" { #else #include #include -#define MX_FENTER(); LOGI("function:[%s] ENTER\n", __func__); -#define MX_FLEAVE(); LOGI("function [%s] LEAVE\n", __func__); +#define MX_FENTER(); LOGI("function:[%s] ENTER", __func__); +#define MX_FLEAVE(); LOGI("function [%s] LEAVE", __func__); #define MX_C LOGE /* MMF_DEBUG_LEVEL_0 */ #define MX_E LOGE /* MMF_DEBUG_LEVEL_1 */ #define MX_W LOGW /* MMF_DEBUG_LEVEL_2 */ @@ -73,7 +73,7 @@ extern "C" { #define MEDIAMUXER_CHECK_NULL(x_var) \ do { \ if (!x_var) { \ - MX_E("[%s] is NULL, Line_No:%x\n", #x_var, __LINE__); \ + MX_E("[%s] is NULL, Line_No:%x", #x_var, __LINE__); \ return MX_INVALID_ARGUMENT; \ } \ } while (0) @@ -81,7 +81,7 @@ extern "C" { do { \ if (x_var != x_cond) { \ ret = ret_val; \ - MX_E("%s\n", #err_text); \ + MX_E("%s", #err_text); \ MEDIAMUXER_FLEAVE(); \ return ret; \ } \ diff --git a/include/port_gst/mediamuxer_port_gst.h b/include/port_gst/mediamuxer_port_gst.h index ea1da7e..c1a2646 100755 --- a/include/port_gst/mediamuxer_port_gst.h +++ b/include/port_gst/mediamuxer_port_gst.h @@ -28,9 +28,9 @@ #define ADTS_HEADER_SIZE 7 #define MEDIAMUXER_ELEMENT_SET_STATE(x_element, x_state) \ - MX_I("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \ + MX_I("setting state [%s:%d] to [%s]", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \ if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) { \ - MX_E("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \ + MX_E("failed to set state %s to %s", #x_state, GST_ELEMENT_NAME(x_element)); \ goto STATE_CHANGE_FAILED; \ } diff --git a/packaging/capi-mediamuxer.spec b/packaging/capi-mediamuxer.spec index 972965b..8e4c655 100755 --- a/packaging/capi-mediamuxer.spec +++ b/packaging/capi-mediamuxer.spec @@ -1,6 +1,6 @@ Name: capi-mediamuxer Summary: A Media Muxer library in Tizen Native API -Version: 0.1.8 +Version: 0.1.9 Release: 1 Group: Multimedia/API License: Apache-2.0 diff --git a/src/mediamuxer.c b/src/mediamuxer.c index 31690bd..50344c1 100644 --- a/src/mediamuxer.c +++ b/src/mediamuxer.c @@ -34,7 +34,7 @@ static gboolean _mediamuxer_error_cb(mediamuxer_error_e error, void *user_data); int mediamuxer_create(mediamuxer_h *muxer) { - MX_I("mediamuxer_create\n"); + MX_I("mediamuxer_create"); mediamuxer_error_e ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); @@ -44,14 +44,14 @@ int mediamuxer_create(mediamuxer_h *muxer) memset(handle, 0, sizeof(mediamuxer_s)); handle->muxer_state = MEDIAMUXER_STATE_NONE; } else { - MX_E("[CoreAPI][%s] MUXER_ERROR_OUT_OF_MEMORY(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_OUT_OF_MEMORY); return MEDIAMUXER_ERROR_OUT_OF_MEMORY; } ret = mx_create(&handle->mx_handle); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); g_free(handle); handle = NULL; @@ -71,7 +71,7 @@ int mediamuxer_create(mediamuxer_h *muxer) int mediamuxer_set_data_sink(mediamuxer_h muxer, char *path, mediamuxer_output_format_e format) { - MX_I("mediamuxer_set_data_sink\n"); + MX_I("mediamuxer_set_data_sink"); int ret = MEDIAMUXER_ERROR_NONE; mediamuxer_s *handle; MUXER_INSTANCE_CHECK(muxer); @@ -89,7 +89,7 @@ int mediamuxer_set_data_sink(mediamuxer_h muxer, char *path, mediamuxer_output_f && format != MEDIAMUXER_CONTAINER_FORMAT_AMR_NB && format != MEDIAMUXER_CONTAINER_FORMAT_AMR_WB && format != MEDIAMUXER_CONTAINER_FORMAT_AAC_ADTS) { - MX_E("Unsupported Container format: %d \n", format); + MX_E("Unsupported Container format: %d", format); handle->muxer_state = MEDIAMUXER_STATE_NONE; return MEDIAMUXER_ERROR_INVALID_PARAMETER; } @@ -105,7 +105,7 @@ int mediamuxer_set_data_sink(mediamuxer_h muxer, char *path, mediamuxer_output_f __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); handle->muxer_state = MEDIAMUXER_STATE_NONE; ret = MEDIAMUXER_ERROR_INVALID_STATE; @@ -115,7 +115,7 @@ int mediamuxer_set_data_sink(mediamuxer_h muxer, char *path, mediamuxer_output_f int mediamuxer_add_track(mediamuxer_h muxer, media_format_h media_format, int *track_index) { - MX_I("mediamuxer_add_track\n"); + MX_I("mediamuxer_add_track"); mediamuxer_error_e ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle; @@ -123,7 +123,7 @@ int mediamuxer_add_track(mediamuxer_h muxer, media_format_h media_format, int *t if (handle->muxer_state == MEDIAMUXER_STATE_IDLE) { ret = mx_add_track(handle->mx_handle, media_format, track_index); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } else { @@ -131,7 +131,7 @@ int mediamuxer_add_track(mediamuxer_h muxer, media_format_h media_format, int *t handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); ret = MEDIAMUXER_ERROR_INVALID_STATE; } @@ -140,14 +140,14 @@ int mediamuxer_add_track(mediamuxer_h muxer, media_format_h media_format, int *t int mediamuxer_prepare(mediamuxer_h muxer) { - MX_I("mediamuxer_prepare\n"); + MX_I("mediamuxer_prepare"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); if (handle->muxer_state == MEDIAMUXER_STATE_IDLE) { ret = mx_prepare(handle->mx_handle); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } else { @@ -155,7 +155,7 @@ int mediamuxer_prepare(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -166,14 +166,14 @@ int mediamuxer_prepare(mediamuxer_h muxer) int mediamuxer_start(mediamuxer_h muxer) { - MX_I("mediamuxer_start\n"); + MX_I("mediamuxer_start"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); if (handle->muxer_state == MEDIAMUXER_STATE_READY) { ret = mx_start(handle->mx_handle); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } else { @@ -181,7 +181,7 @@ int mediamuxer_start(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -192,7 +192,7 @@ int mediamuxer_start(mediamuxer_h muxer) int mediamuxer_write_sample(mediamuxer_h muxer, int track_index, media_packet_h inbuf) { - MX_I("mediamuxer_write_sample\n"); + MX_I("mediamuxer_write_sample"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -211,7 +211,7 @@ int mediamuxer_write_sample(mediamuxer_h muxer, int track_index, media_packet_h __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -222,7 +222,7 @@ int mediamuxer_write_sample(mediamuxer_h muxer, int track_index, media_packet_h int mediamuxer_close_track(mediamuxer_h muxer, int track_index) { - MX_I("mediamuxer_close_track\n"); + MX_I("mediamuxer_close_track"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -242,7 +242,7 @@ int mediamuxer_close_track(mediamuxer_h muxer, int track_index) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); ret = MEDIAMUXER_ERROR_INVALID_STATE; } @@ -251,7 +251,7 @@ int mediamuxer_close_track(mediamuxer_h muxer, int track_index) int mediamuxer_pause(mediamuxer_h muxer) { - MX_I("mediamuxer_pause\n"); + MX_I("mediamuxer_pause"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -268,7 +268,7 @@ int mediamuxer_pause(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -279,7 +279,7 @@ int mediamuxer_pause(mediamuxer_h muxer) int mediamuxer_resume(mediamuxer_h muxer) { - MX_I("mediamuxer_resume\n"); + MX_I("mediamuxer_resume"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -295,7 +295,7 @@ int mediamuxer_resume(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -306,7 +306,7 @@ int mediamuxer_resume(mediamuxer_h muxer) int mediamuxer_stop(mediamuxer_h muxer) { - MX_I("mediamuxer_stop\n"); + MX_I("mediamuxer_stop"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -314,7 +314,7 @@ int mediamuxer_stop(mediamuxer_h muxer) || handle->muxer_state == MEDIAMUXER_STATE_PAUSED) { ret = mx_stop(handle->mx_handle); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } else { @@ -322,7 +322,7 @@ int mediamuxer_stop(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -333,7 +333,7 @@ int mediamuxer_stop(mediamuxer_h muxer) int mediamuxer_unprepare(mediamuxer_h muxer) { - MX_I("mediamuxer_unprepare\n"); + MX_I("mediamuxer_unprepare"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); @@ -351,7 +351,7 @@ int mediamuxer_unprepare(mediamuxer_h muxer) __FUNCTION__, handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -362,7 +362,7 @@ int mediamuxer_unprepare(mediamuxer_h muxer) int mediamuxer_destroy(mediamuxer_h muxer) { - MX_I("mediamuxer_destroy\n"); + MX_I("mediamuxer_destroy"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle; @@ -370,7 +370,7 @@ int mediamuxer_destroy(mediamuxer_h muxer) if (handle->muxer_state == MEDIAMUXER_STATE_IDLE) { ret = mx_destroy(handle->mx_handle); if (ret != MEDIAMUXER_ERROR_NONE) { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } else { @@ -378,7 +378,7 @@ int mediamuxer_destroy(mediamuxer_h muxer) handle); } } else { - MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)\n", + MX_E("[CoreAPI][%s] MEDIAMUXER_ERROR_INVALID_STATE(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_STATE); return MEDIAMUXER_ERROR_INVALID_STATE; } @@ -389,14 +389,14 @@ int mediamuxer_destroy(mediamuxer_h muxer) int mediamuxer_get_state(mediamuxer_h muxer, mediamuxer_state_e *state) { - MX_I("mediamuxer_get_state\n"); + MX_I("mediamuxer_get_state"); int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); if (state != NULL) { *state = handle->muxer_state; } else { - MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)\n", + MX_E("[CoreAPI][%s] MUXER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, MEDIAMUXER_ERROR_INVALID_OPERATION); ret = MEDIAMUXER_ERROR_INVALID_OPERATION; } @@ -423,14 +423,14 @@ int mediamuxer_unset_error_cb(mediamuxer_h muxer) handle->error_cb = NULL; handle->error_cb_userdata = NULL; - MX_I("mediamuxer_unset_error_cb\n"); + MX_I("mediamuxer_unset_error_cb"); return MEDIAMUXER_ERROR_NONE; } static gboolean _mediamuxer_error_cb(mediamuxer_error_e error, void *user_data) { if (user_data == NULL) { - MX_I("_mediamuxer_error_cb: ERROR %d to report. But call back is not set\n", error); + MX_I("_mediamuxer_error_cb: ERROR %d to report. But call back is not set", error); return 0; } mediamuxer_s * handle = (mediamuxer_s *) user_data; @@ -438,7 +438,7 @@ static gboolean _mediamuxer_error_cb(mediamuxer_error_e error, void *user_data) if (handle->error_cb) ((mediamuxer_error_cb)handle->error_cb)(error, handle->error_cb_userdata); else - MX_I("_mediamuxer_error_cb: ERROR %d to report. But call back is not set\n", error); + MX_I("_mediamuxer_error_cb: ERROR %d to report. But call back is not set", error); return 0; } diff --git a/src/mediamuxer_ini.c b/src/mediamuxer_ini.c index 20857a5..ec3665c 100644 --- a/src/mediamuxer_ini.c +++ b/src/mediamuxer_ini.c @@ -68,7 +68,7 @@ do { \ while (token) { \ index = atoi(token); \ if (index < 0 || index > x_list_max -1) { \ - MX_W("%d is not valid index\n", index); \ + MX_W("%d is not valid index", index); \ } else { \ x_list[index] = TRUE; \ } \ @@ -90,7 +90,7 @@ do { \ token = strtok_r(temp_arr, delimiters, &usr_ptr); \ while (token) { \ if (index > x_list_max -1) { \ - MX_E("%d is not valid index\n", index); \ + MX_E("%d is not valid index", index); \ break; \ } else { \ value = atoi(token); \ @@ -120,16 +120,16 @@ int mx_ini_load(mx_ini_t *ini) /* if no file exists. create one with set of default values */ if (!dict) { #ifdef MEDIAMUXER_DEFAULT_INI - MX_L("No inifile found. muxer will create default inifile.\n"); + MX_L("No inifile found. muxer will create default inifile."); if (FALSE == _generate_default_ini()) { MX_W("Creating default inifile failed. \ - MediaMuxer will use default values.\n"); + MediaMuxer will use default values."); } else { /* load default ini */ dict = iniparser_load(MEDIAMUXER_INI_DEFAULT_PATH); } #else - MX_L("No ini file found. \n"); + MX_L("No ini file found."); return MM_ERROR_FILE_NOT_FOUND; #endif } @@ -144,7 +144,7 @@ int mx_ini_load(mx_ini_t *ini) } else { /* if dict is not available just fill the structure with default value */ - MX_W("failed to load ini. using hardcoded default\n"); + MX_W("failed to load ini. using hardcoded default"); strncpy(ini->port_name, DEFAULT_PORT, MEDIAMUXER_INI_MAX_STRLEN - 1); } @@ -156,21 +156,21 @@ int mx_ini_load(mx_ini_t *ini) } else if (0 == strcmp(ini->port_name, "CUSTOM_PORT")) { ini->port_type = CUSTOM_PORT; } else { - MX_E("Invalid port is set to [%s] [%d]\n", ini->port_name, + MX_E("Invalid port is set to [%s] [%d]", ini->port_name, ini->port_type); goto ERROR; } - MX_L("The port is set to [%s] [%d]\n", ini->port_name, ini->port_type); + MX_L("The port is set to [%s] [%d]", ini->port_name, ini->port_type); /* free dict as we got our own structure */ iniparser_freedict(dict); /* dump structure */ - MX_L("muxer settings -----------------------------------\n"); + MX_L("muxer settings -----------------------------------"); /* general */ - MX_L("port_name: %s\n", ini->port_name); - MX_L("port_type : %d\n", ini->port_type); + MX_L("port_name: %s", ini->port_name); + MX_L("port_type : %d", ini->port_type); return MM_ERROR_NONE; ERROR: @@ -182,14 +182,14 @@ static void _mx_ini_check_ini_status(void) struct stat ini_buff; if (g_stat(MEDIAMUXER_INI_DEFAULT_PATH, &ini_buff) < 0) { - MX_W("failed to get muxer ini status\n"); + MX_W("failed to get muxer ini status"); } else { if (ini_buff.st_size < 5) { - MX_W("muxer.ini file size=%d, Corrupted! So, Removed\n", + MX_W("muxer.ini file size=%d, Corrupted! So, Removed", (int)ini_buff.st_size); if (g_remove(MEDIAMUXER_INI_DEFAULT_PATH) == -1) - MX_E("failed to delete corrupted ini\n"); + MX_E("failed to delete corrupted ini"); } } } diff --git a/src/mediamuxer_port.c b/src/mediamuxer_port.c index 57df3f6..942fe35 100644 --- a/src/mediamuxer_port.c +++ b/src/mediamuxer_port.c @@ -58,7 +58,7 @@ int mx_create(MMHandleType *muxer) } new_muxer->muxer_ops = pOps; - MX_I("mx_create allocating new_muxer->muxer_ops %p:\n", + MX_I("mx_create allocating new_muxer->muxer_ops %p:", new_muxer->muxer_ops); pOps->n_size = sizeof(media_port_muxer_ops); /* load ini files */ @@ -247,11 +247,11 @@ int mx_destroy(MMHandleType mediamuxer) /* free mediamuxer structure */ if (mx_handle) { if (mx_handle->muxer_ops) { - MX_I("mx_destroy deallocating mx_handle->muxer_ops %p:\n", + MX_I("mx_destroy deallocating mx_handle->muxer_ops %p:", mx_handle->muxer_ops); g_free((void *)(mx_handle->muxer_ops)); } - MX_I("mx_destroy deallocating mx_handle %p:\n", mx_handle); + MX_I("mx_destroy deallocating mx_handle %p:", mx_handle); g_free((void *)mx_handle); mx_handle = NULL; } diff --git a/src/port_custom/mediamuxer_port_custom.c b/src/port_custom/mediamuxer_port_custom.c index 305167a..3bd4a46 100644 --- a/src/port_custom/mediamuxer_port_custom.c +++ b/src/port_custom/mediamuxer_port_custom.c @@ -51,7 +51,7 @@ static int custom_muxer_init(MMHandleType *pHandle) { int ret = MX_ERROR_NONE; MEDIAMUXER_FENTER(); - MX_E("%s:exit: Not implemented\n", __func__); + MX_E("%s:exit: Not implemented", __func__); MEDIAMUXER_FLEAVE(); return ret; } @@ -60,7 +60,7 @@ static int custom_muxer_set_data_sink(MMHandleType pHandle, char *uri, mediamuxer_output_format_e format) { MEDIAMUXER_FENTER(); - MX_E("%s:exit: Not implemented\n", __func__); + MX_E("%s:exit: Not implemented", __func__); MEDIAMUXER_FLEAVE(); return 0; } diff --git a/src/port_ffmpeg/mediamuxer_port_ffmpeg.c b/src/port_ffmpeg/mediamuxer_port_ffmpeg.c index dce359e..004cffa 100644 --- a/src/port_ffmpeg/mediamuxer_port_ffmpeg.c +++ b/src/port_ffmpeg/mediamuxer_port_ffmpeg.c @@ -51,7 +51,7 @@ static int ffmpeg_muxer_init(MMHandleType *pHandle) { int ret = MX_ERROR_NONE; MEDIAMUXER_FENTER(); - MX_E("%s:exit: Not implemented\n", __func__); + MX_E("%s:exit: Not implemented", __func__); MEDIAMUXER_FLEAVE(); return ret; } @@ -61,7 +61,7 @@ static int ffmpeg_muxer_set_data_sink(MMHandleType pHandle, char *uri, { int ret = MX_ERROR_NONE; MEDIAMUXER_FENTER(); - MX_E("%s:exit: Not implemented\n", __func__); + MX_E("%s:exit: Not implemented", __func__); MEDIAMUXER_FLEAVE(); return ret; } diff --git a/src/port_gst/mediamuxer_port_gst.c b/src/port_gst/mediamuxer_port_gst.c index a1ea5c0..97c6e09 100755 --- a/src/port_gst/mediamuxer_port_gst.c +++ b/src/port_gst/mediamuxer_port_gst.c @@ -84,9 +84,9 @@ static int gst_muxer_init(MMHandleType *pHandle) mxgst_handle_t *new_mediamuxer = NULL; new_mediamuxer = (mxgst_handle_t *) g_malloc(sizeof(mxgst_handle_t)); - MX_I("GST_Muxer_Init allocating memory for new_mediamuxer: %p\n", new_mediamuxer); + MX_I("GST_Muxer_Init allocating memory for new_mediamuxer: %p", new_mediamuxer); if (!new_mediamuxer) { - MX_E("Cannot allocate memory for muxer \n"); + MX_E("Cannot allocate memory for muxer"); ret = MX_ERROR; goto ERROR; } @@ -108,7 +108,7 @@ static int gst_muxer_init(MMHandleType *pHandle) MEDIAMUXER_FLEAVE(); return ret; ERROR: - MX_E("%s: Not implemented\n", __func__); + MX_E("%s: Not implemented", __func__); MEDIAMUXER_FLEAVE(); return ret; } @@ -129,10 +129,33 @@ static int gst_muxer_set_data_sink(MMHandleType pHandle, return ret; } -static GstCaps * __gst_codec_specific_caps(media_format_mimetype_e mimetype) +static GstCaps * __gst_codec_specific_caps(media_format_h format) { MEDIAMUXER_FENTER(); GstCaps *new_caps = NULL; + media_format_type_e formattype = MEDIA_FORMAT_NONE; + media_format_mimetype_e mimetype = MEDIA_FORMAT_MAX; + int fps = 25; + + if (media_format_get_type(format, &formattype)) { + MX_E("media_format_get_type failed"); + return NULL; + } + + if (MEDIA_FORMAT_AUDIO == formattype) { + if (MEDIA_FORMAT_ERROR_NONE != media_format_get_audio_info(format, &mimetype, NULL, NULL, NULL, NULL)) { + MX_E("media_format_get_container_mime failed"); + return NULL; + } + } else if (MEDIA_FORMAT_VIDEO == formattype) { + if (MEDIA_FORMAT_ERROR_NONE != media_format_get_video_info(format, &mimetype, NULL, NULL, NULL, NULL)) { + MX_E("media_format_get_container_mime failed"); + return NULL; + } + if (MEDIA_FORMAT_ERROR_NONE != media_format_get_video_frame_rate(format, &fps)) + MX_E("media_format_get_video_frame_rate failed"); + } + switch (mimetype) { /* video */ case MEDIA_FORMAT_H261: @@ -140,7 +163,12 @@ static GstCaps * __gst_codec_specific_caps(media_format_mimetype_e mimetype) case MEDIA_FORMAT_H263: case MEDIA_FORMAT_H263P: new_caps = gst_caps_new_simple("video/x-h263", - "variant", G_TYPE_STRING, "itu", NULL); + "variant", G_TYPE_STRING, "itu", + NULL); + + if (fps) + gst_caps_set_simple(new_caps, "framerate", GST_TYPE_FRACTION, fps, 1, NULL); + if (!new_caps) { MX_E("Fail to make simple caps"); return NULL; @@ -150,6 +178,8 @@ static GstCaps * __gst_codec_specific_caps(media_format_mimetype_e mimetype) case MEDIA_FORMAT_H264_MP: case MEDIA_FORMAT_H264_HP: new_caps = gst_caps_new_empty_simple("video/x-h264"); + if (fps) + gst_caps_set_simple(new_caps, "framerate", GST_TYPE_FRACTION, fps, 1, NULL); if (!new_caps) { MX_E("Fail to make simple caps"); return NULL; @@ -170,6 +200,8 @@ static GstCaps * __gst_codec_specific_caps(media_format_mimetype_e mimetype) "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + if (fps) + gst_caps_set_simple(new_caps, "framerate", GST_TYPE_FRACTION, fps, 1, NULL); if (!new_caps) { MX_E("Fail to make simple caps"); return NULL; @@ -269,7 +301,7 @@ static GstCaps * __gst_codec_specific_caps(media_format_mimetype_e mimetype) case MEDIA_FORMAT_PCMU: break; default: - MX_E("Unknown media mimeype %d. Assuming H264\n", mimetype); + MX_E("Unknown media mimeype %d. Assuming H264", mimetype); break; } MEDIAMUXER_FLEAVE(); @@ -280,11 +312,11 @@ int _gst_set_caps(MMHandleType pHandle, media_format_h format, int track_index) { MEDIAMUXER_FENTER(); gint ret = MX_ERROR_NONE; - GstCaps *new_caps; + GstCaps *new_caps = NULL; mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; media_format_type_e formattype; mx_gst_track *current = NULL; - media_format_mimetype_e current_mime; + gchar *caps_string = NULL; /* Reach that track index and set the codec data */ for (current = gst_handle->track_info.track_head; current; current = current->next) @@ -297,7 +329,7 @@ int _gst_set_caps(MMHandleType pHandle, media_format_h format, int track_index) } if (media_format_get_type(format, &formattype)) { - MX_E("media_format_get_type failed\n"); + MX_E("media_format_get_type failed"); goto ERROR; } @@ -305,29 +337,15 @@ int _gst_set_caps(MMHandleType pHandle, media_format_h format, int track_index) case MEDIA_FORMAT_AUDIO: /* Following check is safe but not mandatory. */ if ((current->track_index)%NO_OF_TRACK_TYPES != 1) { - MX_E("This is not an audio track_index. Track_index is not in 3*n+1 format\n"); + MX_E("This is not an audio track_index. Track_index is not in 3*n+1 format"); goto ERROR; } - /* return if track_mime is different to current_mime */ - if (media_format_get_audio_info(format, ¤t_mime, NULL, NULL, NULL, NULL) - != MEDIA_FORMAT_ERROR_NONE) { - MX_E("cant read audio mime in packet. returning\n"); - return MX_ERROR_INVALID_ARGUMENT; - } - if (current->caps == NULL) { - new_caps = __gst_codec_specific_caps(current_mime); + new_caps = __gst_codec_specific_caps(format); if (new_caps == NULL) { - MX_E("Setting Audio caps failed\n"); - ret = MX_ERROR_UNKNOWN; - break; - } - gchar *caps_string = NULL; - caps_string = gst_caps_to_string(new_caps); - if (caps_string) { - MX_I("New caps is = %s", caps_string); - g_free(caps_string); + MX_E("Setting Audio caps failed"); + goto ERROR; } current->caps = new_caps; } @@ -335,31 +353,16 @@ int _gst_set_caps(MMHandleType pHandle, media_format_h format, int track_index) case MEDIA_FORMAT_VIDEO: /* Following check is safe but not mandatory. */ if ((current->track_index)%NO_OF_TRACK_TYPES != 0) { - MX_E("This is not an video track_index. Video track_index is not in 3*n format\n"); + MX_E("This is not an video track_index. Video track_index is not in 3*n format"); goto ERROR; } - /* return if track_mime is different to current_mime */ - if (media_format_get_video_info(format, ¤t_mime, NULL, NULL, NULL, NULL) - != MEDIA_FORMAT_ERROR_NONE) { - MX_E("cant read video mime. returning\n"); - return MX_ERROR_INVALID_ARGUMENT; - } - if (current->caps == NULL) { - new_caps = __gst_codec_specific_caps(current_mime); + new_caps = __gst_codec_specific_caps(format); if (new_caps == NULL) { - MX_E("Setting Audio caps failed\n"); - ret = MX_ERROR_UNKNOWN; - break; + MX_E("Setting Audio caps failed"); + goto ERROR; } - gchar *caps_string = NULL; - caps_string = gst_caps_to_string(new_caps); - if (caps_string) { - MX_I("New caps is = %s", caps_string); - g_free(caps_string); - } - current->caps = new_caps; } break; @@ -367,9 +370,16 @@ int _gst_set_caps(MMHandleType pHandle, media_format_h format, int track_index) case MEDIA_FORMAT_CONTAINER: case MEDIA_FORMAT_UNKNOWN: default: - MX_E("Unknown format type\n"); + MX_E("Unknown format type"); break; } + + caps_string = gst_caps_to_string(new_caps); + if (caps_string) { + MX_I("New caps is = %s", caps_string); + g_free(caps_string); + } + MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -391,16 +401,16 @@ static int gst_muxer_add_track(MMHandleType pHandle, mx_gst_track *last = NULL; if (!mx_handle_gst->output_uri) { - MX_E("URI is null. Possibly, set_data_sink failed. returning. \n"); + MX_E("URI is null. Possibly, set_data_sink failed. returning."); return MX_ERROR_INVALID_ARGUMENT; } current = (mx_gst_track *)g_malloc(sizeof(mx_gst_track)); if (!current) { - MX_E("Not able to allocate memory\n"); + MX_E("Not able to allocate memory"); return MX_ERROR; } - MX_I("Memory allocated to track = %p\n", current); + MX_I("Memory allocated to track = %p", current); memset(current, 0, sizeof(mx_gst_track)); current->media_format = (void *)media_format; @@ -410,10 +420,10 @@ static int gst_muxer_add_track(MMHandleType pHandle, current->caps = NULL; current->next = NULL; if (mx_handle_gst->track_info.track_head == NULL) { - MX_I("Adding first-ever track\n"); + MX_I("Adding first-ever track"); mx_handle_gst->track_info.track_head = current; } else { - MX_I("Adding %d-track)\n", 1+mx_handle_gst->track_info.total_track_cnt); + MX_I("Adding %d-track)", 1+mx_handle_gst->track_info.total_track_cnt); last = mx_handle_gst->track_info.track_head; while (last->next != NULL) last = last->next; @@ -425,21 +435,21 @@ static int gst_muxer_add_track(MMHandleType pHandle, &mimetype, NULL, NULL, NULL, NULL) == MEDIA_FORMAT_ERROR_NONE) { if ((mx_handle_gst->muxed_format == MEDIAMUXER_CONTAINER_FORMAT_MP4 && (mimetype == MEDIA_FORMAT_H264_SP || mimetype == MEDIA_FORMAT_H264_MP || mimetype == MEDIA_FORMAT_H264_HP - || mimetype == MEDIA_FORMAT_H263 || mimetype == MEDIA_FORMAT_MPEG4_SP)) || (mx_handle_gst->muxed_format == MEDIAMUXER_CONTAINER_FORMAT_3GP && (mimetype == MEDIA_FORMAT_H264_SP || mimetype == MEDIA_FORMAT_H264_MP || mimetype == MEDIA_FORMAT_H264_HP - || mimetype == MEDIA_FORMAT_H263))) { + || mimetype == MEDIA_FORMAT_H263 + || mimetype == MEDIA_FORMAT_MPEG4_SP))) { current->track_index = NO_OF_TRACK_TYPES*(mx_handle_gst->track_info.video_track_cnt); (mx_handle_gst->track_info.video_track_cnt)++; (mx_handle_gst->track_info.total_track_cnt)++; *track_index = current->track_index; - MX_I("Video track added successfully: %p, with head: %p \n", + MX_I("Video track added successfully: %p, with head: %p", current->media_format, mx_handle_gst->track_info.track_head->media_format); } else { - MX_E("Unsupported/Mismatched video MIME Type: %x\n", mimetype); + MX_E("Unsupported/Mismatched video MIME Type: %x", mimetype); } } else if (media_format_get_audio_info((media_format_h)current->media_format, &mimetype, NULL, NULL, NULL, NULL) == MEDIA_FORMAT_ERROR_NONE) { @@ -462,10 +472,10 @@ static int gst_muxer_add_track(MMHandleType pHandle, (mx_handle_gst->track_info.total_track_cnt)++; *track_index = current->track_index; - MX_I("Audio track added successfully: %p, with head: %p \n", + MX_I("Audio track added successfully: %p, with head: %p", current->media_format, mx_handle_gst->track_info.track_head->media_format); } else { - MX_E("Unsupported/Mismatched audio MIME Type: %x\n", mimetype); + MX_E("Unsupported/Mismatched audio MIME Type: %x", mimetype); } } else if (media_format_get_text_info((media_format_h)current->media_format, &mimetype, &text_type_e) == MEDIA_FORMAT_ERROR_NONE) { @@ -478,14 +488,14 @@ static int gst_muxer_add_track(MMHandleType pHandle, (mx_handle_gst->track_info.total_track_cnt)++; *track_index = current->track_index; - MX_I("Subtitle track added successfully: %p, with head: %p \n", + MX_I("Subtitle track added successfully: %p, with head: %p", current->media_format, mx_handle_gst->track_info.track_head->media_format); } else { - MX_E("Unsupported/Mismatched subtitle MIME Type: %x\n", mimetype); + MX_E("Unsupported/Mismatched subtitle MIME Type: %x", mimetype); } } else { - MX_E("Unsupported A/V/Subs MIME Type: %x\n", mimetype); + MX_E("Unsupported A/V/Subs MIME Type: %x", mimetype); } ret = _gst_set_caps(mx_handle_gst, (media_format_h)current->media_format, *track_index); if (ret != MX_ERROR_NONE) { @@ -585,18 +595,18 @@ static gboolean _mx_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) mxgst_handle_t *gst_handle = (mxgst_handle_t*)data; switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: - MX_I("End of stream\n"); + MX_I("End of stream"); break; case GST_MESSAGE_ERROR: { gchar *debug; GError *error; gst_message_parse_error(msg, &error, &debug); if (!error) { - MX_E("GStreamer callback error message parsing failed\n"); + MX_E("GStreamer callback error message parsing failed"); ret = FALSE; break; } - MX_I("GStreamer callback Error: %s\n", error->message); + MX_I("GStreamer callback Error: %s", error->message); if (error) { if (error->domain == GST_RESOURCE_ERROR) error_val = __gst_handle_resource_error(gst_handle, error->code); @@ -605,7 +615,7 @@ static gboolean _mx_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) else if (error->domain == GST_CORE_ERROR) error_val = __gst_handle_core_error(gst_handle, error->code); else - MX_I("Unknown GStreamer callback error\n"); + MX_I("Unknown GStreamer callback error"); /* Update the user callback with ret value */ ((gst_muxer_error_cb)gst_handle->user_cb[_GST_EVENT_TYPE_ERROR]) (error_val, gst_handle->user_data[_GST_EVENT_TYPE_ERROR]); @@ -613,12 +623,12 @@ static gboolean _mx_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) return ret; } g_free(debug); - MX_E("Error: %s\n", error->message); + MX_E("Error: %s", error->message); g_error_free(error); } break; default: - MX_I("unhandled gst callback message: 0x%x\n", GST_MESSAGE_TYPE(msg)); + MX_I("unhandled gst callback message: 0x%x", GST_MESSAGE_TYPE(msg)); break; } MEDIAMUXER_FLEAVE(); @@ -632,31 +642,31 @@ static gboolean _mx_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) static void _audio_start_feed(GstElement *source, guint size, mx_gst_track *current) { if (current) { - MX_I("\nAudio Start feeding..., current->track_index = %d\n", current->track_index); + MX_I("\nAudio Start feeding..., current->track_index = %d", current->track_index); current->stop_feed = 0; current->start_feed = 1; } else - MX_I("Audio start feed called, however current handle is null\n"); + MX_I("Audio start feed called, however current handle is null"); } static void _video_start_feed(GstElement *source, guint size, mx_gst_track *current) { if (current) { - MX_I("\nVideo Start feeding cb... current->track_index = %d\n", current->track_index); + MX_I("\nVideo Start feeding cb... current->track_index = %d", current->track_index); current->stop_feed = 0; current->start_feed = 1; } else - MX_I("Video start feed called, however, current is null\n"); + MX_I("Video start feed called, however, current is null"); } static void _subtitle_start_feed(GstElement *source, guint size, mx_gst_track *current) { if (current) { - MX_I("Subtitle Start feeding cb... current->track_index = %d\n", current->track_index); + MX_I("Subtitle Start feeding cb... current->track_index = %d", current->track_index); current->stop_feed = 0; current->start_feed = 1; } else - MX_I("Subtitle start feed called, however, current is null\n"); + MX_I("Subtitle start feed called, however, current is null"); } @@ -667,31 +677,31 @@ static void _subtitle_start_feed(GstElement *source, guint size, mx_gst_track *c static void _audio_stop_feed(GstElement *source, mx_gst_track *current) { if (current) { - MX_I("\nAudio Stop feeding cb... current->track_index = %d\n", current->track_index); + MX_I("\nAudio Stop feeding cb... current->track_index = %d", current->track_index); current->stop_feed = 1; current->start_feed = 0; } else - MX_I("Audio stop feed called, however, current is null\n"); + MX_I("Audio stop feed called, however, current is null"); } static void _video_stop_feed(GstElement *source, mx_gst_track *current) { if (current) { - MX_I("\nVideo Stop feeding... current->track_index = %d\n", current->track_index); + MX_I("Video Stop feeding... current->track_index = %d", current->track_index); current->stop_feed = 1; current->start_feed = 0; } else - MX_I("Video stop feed called, however, current is null\n"); + MX_I("Video stop feed called, however, current is null"); } static void _subtitle_stop_feed(GstElement *source, mx_gst_track *current) { if (current) { - MX_I("\nSubtitle Stop feeding... current->track_index = %d\n", current->track_index); + MX_I("Subtitle Stop feeding... current->track_index = %d", current->track_index); current->stop_feed = 1; current->start_feed = 0; } else - MX_I("Subtitle stop feed called, however, current is null\n"); + MX_I("Subtitle stop feed called, however, current is null"); } @@ -727,7 +737,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) && gst_handle->muxed_format != MEDIAMUXER_CONTAINER_FORMAT_AAC_ADTS && gst_handle->muxed_format != MEDIAMUXER_CONTAINER_FORMAT_AMR_NB && gst_handle->muxed_format != MEDIAMUXER_CONTAINER_FORMAT_AMR_WB) { - MX_E("Unsupported container-format. Currently suports only MP4, 3GP, WAV & AMR\n"); + MX_E("Unsupported container-format. Currently suports only MP4, 3GP, WAV & AMR"); ret = MEDIAMUXER_ERROR_INVALID_PATH; goto ERROR; } @@ -756,7 +766,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) } if ((!gst_handle->pipeline) || (!gst_handle->muxer) || (!gst_handle->sink)) { - MX_E("One element could not be created. Exiting.\n"); + MX_E("One element could not be created. Exiting."); ret = MEDIAMUXER_ERROR_RESOURCE_LIMIT; goto ERROR; } @@ -767,11 +777,11 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) if (gst_handle->muxed_format == MEDIAMUXER_CONTAINER_FORMAT_AAC_ADTS) { GstCaps *outcaps = gst_caps_new_simple("audio/mpeg", "stream-format", G_TYPE_STRING, "adts", NULL); if (!gst_element_link_filtered(gst_handle->muxer, gst_handle->sink, outcaps)) - MX_E("muxer-sink link failed\n"); + MX_E("muxer-sink link failed"); gst_caps_unref(outcaps); } else { if (!gst_element_link(gst_handle->muxer, gst_handle->sink)) - MX_E("muxer-sink link failed\n"); + MX_E("muxer-sink link failed"); } if (gst_handle->track_info.video_track_cnt) { /* Video track(s) exist */ @@ -799,13 +809,13 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) MX_I("make mpeg4videoparse element"); } } else { - MX_E("Can't retrive mimetype for the current track. Unsupported MIME Type\n"); + MX_E("Can't retrive mimetype for the current track. Unsupported MIME Type"); ret = MEDIAMUXER_ERROR_INVALID_PARAMETER; goto ERROR; } if ((!current->appsrc) || (!current->parser)) { - MX_E("One element (video_appsrc/vparse) could not be created. Exiting.\n"); + MX_E("One element (video_appsrc/vparse) could not be created. Exiting."); ret = MEDIAMUXER_ERROR_RESOURCE_LIMIT; goto ERROR; } @@ -814,7 +824,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) #ifdef ASYCHRONOUS_WRITE /* ToDo: Use a function pointer, and create independent fucntions to each track */ - MX_I("\nRegistering video callback for cur->tr_ind = %d\n", current->track_index); + MX_I("\nRegistering video callback for cur->tr_ind = %d", current->track_index); g_signal_connect(current->appsrc, "need-data", G_CALLBACK(_video_start_feed), current); g_signal_connect(current->appsrc, "enough-data", @@ -830,7 +840,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) g_object_set(current->appsrc, "max-bytes", (guint64)3 * 1024 * 1024, NULL); if (!gst_element_link(current->appsrc, current->parser)) - MX_E("appsrc-parse failed\n"); + MX_E("appsrc-parse failed"); /* Link videoparse to muxer_video_pad. Request for muxer A/V pads. */ snprintf(track_no, MAX_STRING_LENGTH - 1, "video_%.2d", vid_track_cnt++); /* sprintf(track_no,"video_00"); */ @@ -843,7 +853,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) MX_E("parser get src pad"); if (gst_pad_link(vid_src, video_pad) != GST_PAD_LINK_OK) - MX_E("video parser to muxer link failed\n"); + MX_E("video parser to muxer link failed"); gst_object_unref(GST_OBJECT(vid_src)); gst_object_unref(GST_OBJECT(video_pad)); @@ -872,16 +882,16 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) current->parser = gst_element_factory_make("amrparse", str_parser); MX_I("make amrparse element"); } else if (mimetype == MEDIA_FORMAT_PCM) { - MX_I("Do Nothing, as there is no need of parser for wav\n"); + MX_I("Do Nothing, as there is no need of parser for wav"); } else { MX_I("Do Nothing"); } } else { - MX_E("Can't retrive mimetype for the current track. Unsupported MIME Type. Proceeding to the next track\n"); + MX_E("Can't retrive mimetype for the current track. Unsupported MIME Type. Proceeding to the next track"); } if (!current->appsrc) { - MX_E("One element (audio_appsrc) could not be created. Exiting.\n"); + MX_E("One element (audio_appsrc) could not be created. Exiting."); ret = MEDIAMUXER_ERROR_RESOURCE_LIMIT; goto ERROR; } @@ -889,10 +899,10 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) gst_bin_add_many(GST_BIN(gst_handle->pipeline), current->appsrc, NULL); if (gst_handle->muxed_format == MEDIAMUXER_CONTAINER_FORMAT_AAC_ADTS || mimetype == MEDIA_FORMAT_PCM) { - MX_I("Do Nothing, as there is no need of parser for wav and AAC_ADTS\n"); + MX_I("Do Nothing, as there is no need of parser for wav and AAC_ADTS"); } else { if (!current->parser) { - MX_E("One element (audio-parser) could not be created. Exiting.\n"); + MX_E("One element (audio-parser) could not be created. Exiting."); ret = MEDIAMUXER_ERROR_RESOURCE_LIMIT; goto ERROR; } @@ -901,7 +911,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) #ifdef ASYCHRONOUS_WRITE /* ToDo: Use a function pointer, and create independent fucntions to each track */ - MX_I("\nRegistering audio callback for cur->tr_ind = %d\n", current->track_index); + MX_I("\nRegistering audio callback for cur->tr_ind = %d", current->track_index); g_signal_connect(current->appsrc, "need-data", G_CALLBACK(_audio_start_feed), current); g_signal_connect(current->appsrc, "enough-data", @@ -929,7 +939,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) aud_src = gst_element_get_static_pad(current->parser, "src"); if (gst_pad_link(aud_src, audio_pad) != GST_PAD_LINK_OK) - MX_E("audio parser to muxer link failed\n"); + MX_E("audio parser to muxer link failed"); gst_object_unref(GST_OBJECT(aud_src)); gst_object_unref(GST_OBJECT(audio_pad)); @@ -948,7 +958,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) if (!current->appsrc) { - MX_E("One element (text_appsrc) could not be created. Exiting.\n"); + MX_E("One element (text_appsrc) could not be created. Exiting."); ret = MEDIAMUXER_ERROR_RESOURCE_LIMIT; goto ERROR; } @@ -962,7 +972,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) #ifdef ASYCHRONOUS_WRITE /* ToDo: Use a function pointer, and create independent functions to each track */ - MX_I("\nRegistering subtitle callback for cur->tr_ind = %d\n", current->track_index); + MX_I("\nRegistering subtitle callback for cur->tr_ind = %d", current->track_index); g_signal_connect(current->appsrc, "need-data", G_CALLBACK(_subtitle_start_feed), current); g_signal_connect(current->appsrc, "enough-data", G_CALLBACK(_subtitle_stop_feed), current); #else @@ -973,7 +983,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) snprintf(track_no, MAX_STRING_LENGTH, "subtitle_%.2d", text_track_cnt++); /* snprintf(track_no,"subtitle_00"); */ subtitle_pad = gst_element_get_request_pad(gst_handle->muxer, track_no); subtitle_src = gst_element_get_static_pad(current->appsrc, "src"); - MX_I("Linking subtitle-appsrc to muxersubtitle static-pad\n"); + MX_I("Linking subtitle-appsrc to muxersubtitle static-pad"); if (gst_pad_link(subtitle_src, subtitle_pad) != GST_PAD_LINK_OK) MX_E("subtitle_src and subtitle_pad link failed"); @@ -983,7 +993,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) } } - MX_I("Output_uri= %s\n", gst_handle->output_uri); + MX_I("Output_uri= %s", gst_handle->output_uri); g_object_set(GST_OBJECT(gst_handle->sink), "location", gst_handle->output_uri, NULL); @@ -1027,7 +1037,7 @@ static int gst_muxer_prepare(MMHandleType pHandle) MEDIAMUXER_CHECK_NULL(pHandle); mxgst_handle_t *new_mediamuxer = (mxgst_handle_t *) pHandle; - MX_I("__gst_muxer_prepare adding elements to the pipeline:%p\n", new_mediamuxer); + MX_I("__gst_muxer_prepare adding elements to the pipeline:%p", new_mediamuxer); ret = _gst_create_pipeline(new_mediamuxer); MEDIAMUXER_FLEAVE(); return ret; @@ -1040,7 +1050,7 @@ static int gst_muxer_start(MMHandleType pHandle) MEDIAMUXER_CHECK_NULL(pHandle); mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; - MX_I("__gst_muxer_start making pipeline to playing:%p\n", gst_handle); + MX_I("__gst_muxer_start making pipeline to playing:%p", gst_handle); /* set pipeline state to PLAYING */ MEDIAMUXER_ELEMENT_SET_STATE(GST_ELEMENT_CAST(gst_handle->pipeline), @@ -1050,7 +1060,7 @@ static int gst_muxer_start(MMHandleType pHandle) return ret; STATE_CHANGE_FAILED: - MX_E("muxer state change failed, returning \n"); + MX_E("muxer state change failed, returning"); ret = MX_ERROR_INVALID_ARGUMENT; MEDIAMUXER_FLEAVE(); return ret; @@ -1071,7 +1081,20 @@ static int _gst_copy_media_packet_to_buf(mx_gst_track *current, media_packet_h o char *pkt_codec_data; unsigned int codec_data_size; - if (media_packet_get_codec_data(out_pkt, (void **)&pkt_codec_data, &codec_data_size) == 0) { + if (media_packet_get_buffer_size(out_pkt, &size) != MEDIA_PACKET_ERROR_NONE) { + MX_E("media_packet_get_buffer_size failed"); + return MX_ERROR_UNKNOWN; + } + + if (!size) { + MX_E("media packet size is zero"); + return MX_ERROR_UNKNOWN; + } + + MX_I("Media packet Buffer capacity: %llu", size); + + if (media_packet_get_codec_data(out_pkt, (void **)&pkt_codec_data, &codec_data_size) + == MEDIA_PACKET_ERROR_NONE) { GstCaps *appsrc_caps = NULL; GstCaps *new_appsrc_caps = NULL; GstBuffer *codec_data_buffer = NULL; @@ -1102,20 +1125,17 @@ static int _gst_copy_media_packet_to_buf(mx_gst_track *current, media_packet_h o } - media_packet_get_buffer_size(out_pkt, &size); - MX_I("Media packet Buffer capacity: %llu\n", size); - /* copy data */ data_ptr = (unsigned char *)g_malloc(size); if (!data_ptr) { - MX_E("Memory allocation failed in %s \n", __FUNCTION__); + MX_E("Memory allocation failed in %s", __FUNCTION__); ret = MX_MEMORY_ERROR; goto ERROR; } if (media_packet_get_buffer_data_ptr(out_pkt, &pkt_data)) { MX_E("unable to get the buffer pointer \ - from media_packet_get_buffer_data_ptr\n"); + from media_packet_get_buffer_data_ptr"); ret = MX_ERROR_UNKNOWN; goto ERROR; } @@ -1128,20 +1148,20 @@ static int _gst_copy_media_packet_to_buf(mx_gst_track *current, media_packet_h o size, data_ptr, g_free)); if (media_packet_get_pts(out_pkt, &info)) { - MX_E("unable to get the pts\n"); + MX_E("unable to get the pts"); ret = MX_ERROR_UNKNOWN; goto ERROR; } buffer->pts = info; if (media_packet_get_dts(out_pkt, &info)) { - MX_E("unable to get the dts\n"); + MX_E("unable to get the dts"); ret = MX_ERROR_UNKNOWN; goto ERROR; } buffer->dts = info; if (media_packet_get_duration(out_pkt, &info)) { - MX_E("unable to get the duration\n"); + MX_E("unable to get the duration"); ret = MX_ERROR_UNKNOWN; goto ERROR; } @@ -1149,7 +1169,7 @@ static int _gst_copy_media_packet_to_buf(mx_gst_track *current, media_packet_h o media_buffer_flags_e flags; if (media_packet_get_flags(out_pkt, &flags)) { - MX_E("unable to get the buffer size\n"); + MX_E("unable to get the buffer size"); ret = MX_ERROR_UNKNOWN; goto ERROR; } @@ -1171,28 +1191,29 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; mx_gst_track *current = NULL; bool eos = FALSE; + GstBuffer *gst_inbuf2 = NULL; + uint64_t inbuf_size = 0; + for (current = gst_handle->track_info.track_head; current; current = current->next) if (current->track_index == track_index) break; if ((!current) || (current->track_index != track_index)) { - MX_E("No tracks or mismatched track_index = %d\n", track_index); + MX_E("No tracks or mismatched track_index = %d", track_index); if (current) - MX_E("\ncurrent->track_index=%d\n", current->track_index); + MX_E("\ncurrent->track_index=%d", current->track_index); else if (gst_handle->track_info.track_head) { - MX_E("\n\ngst_handle->track_info.track_head->track_index=%d\n", gst_handle->track_info.track_head->track_index); + MX_E("\n\ngst_handle->track_info.track_head->track_index=%d", gst_handle->track_info.track_head->track_index); if (gst_handle->track_info.track_head->next) - MX_E("ext=%p\tnext->track_index=%d\n", gst_handle->track_info.track_head->next, gst_handle->track_info.track_head->next->track_index); + MX_E("ext=%p\tnext->track_index=%d", gst_handle->track_info.track_head->next, gst_handle->track_info.track_head->next->track_index); } else - MX_E("\n\n****Head is NULL****\n"); + MX_E("****Head is NULL****"); ret = MX_ERROR_INVALID_ARGUMENT; goto ERROR; } - MX_I("Track_index passed = %d, working-with_track_index = %d\n", track_index, current->track_index); + MX_I("Track_index passed = %d, working-with_track_index = %d", track_index, current->track_index); - GstBuffer *gst_inbuf2 = NULL; - gst_inbuf2 = gst_buffer_new(); /* ToDo: Add functionality to the following function */ /* MX_I("\nBefore buff=%x\n", gst_inbuf2); */ if (media_packet_is_end_of_stream(inbuf, &eos) != MEDIA_PACKET_ERROR_NONE) { @@ -1200,6 +1221,16 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, goto ERROR; } + if (media_packet_get_buffer_size(inbuf, &inbuf_size) != MEDIA_PACKET_ERROR_NONE) + MX_E("media_packet_get_buffer_size failed"); + + if (eos && (inbuf_size == 0)) { + MX_I("end of stream"); + gst_app_src_end_of_stream((GstAppSrc *)current->appsrc); + goto LEAVE; + } + + gst_inbuf2 = gst_buffer_new(); ret = _gst_copy_media_packet_to_buf(current, inbuf, gst_inbuf2); if (ret != MX_ERROR_NONE) { MX_E("media packet copy to gstbuffer error"); @@ -1207,78 +1238,82 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, } if (track_index%NO_OF_TRACK_TYPES == 0) { /* NO_OF_TRACK_TYPES*n for video */ - MX_I("Waiting till start_feed of current video track, index=%d is active\n", current->track_index); + MX_I("Waiting till start_feed of current video track, index=%d is active", current->track_index); #ifdef ASYCHRONOUS_WRITE /* poll now to make it synchronous */ while (current->start_feed == 0) g_usleep(WRITE_POLL_PERIOD); - MX_I("pushing video\n"); + MX_I("pushing video"); g_signal_emit_by_name(current->appsrc, "push-buffer", gst_inbuf2, &ret); #else ret = gst_app_src_push_buffer((GstAppSrc *)current->appsrc, gst_inbuf2); #endif - MX_I("attempted a vid-buf push\n"); + MX_I("attempted a vid-buf push"); if (ret != GST_FLOW_OK) { /* We got some error, stop sending data */ - MX_E("--video appsrc push failed--\n"); + MX_E("--video appsrc push failed--"); ret = MX_ERROR_INVALID_ARGUMENT; } - if (eos) { MX_I("end of stream"); gst_app_src_end_of_stream((GstAppSrc *)current->appsrc); } } else if (track_index%NO_OF_TRACK_TYPES == 1) { /* NO_OF_TRACK_TYPES*n+1 for audio */ - MX_I(" Waiting till start_feed of current audio track, index=%d is active\n", current->track_index); + MX_I(" Waiting till start_feed of current audio track, index=%d is active", current->track_index); #ifdef ASYCHRONOUS_WRITE while (current->start_feed == 0) g_usleep(WRITE_POLL_PERIOD); - MX_I("End of sleep, pushing audio\n"); + MX_I("End of sleep, pushing audio"); g_signal_emit_by_name(current->appsrc, "push-buffer", gst_inbuf2, &ret); #else ret = gst_app_src_push_buffer((GstAppSrc *)current->appsrc, gst_inbuf2); #endif - MX_I("Attempted a aud-buf push\n"); + MX_I("Attempted a aud-buf push"); if (ret != GST_FLOW_OK) { /* We got some error, stop sending data */ - MX_E("--audio appsrc push failed--\n"); + MX_E("--audio appsrc push failed--"); } - if (eos) { MX_I("end of stream"); gst_app_src_end_of_stream((GstAppSrc *)current->appsrc); } } else if (track_index%NO_OF_TRACK_TYPES == 2) { /* NO_OF_TRACK_TYPES*n+2 for subtitle */ - MX_I(" Waiting till start_feed of current subtitle, index=%d is active\n", current->track_index); + MX_I(" Waiting till start_feed of current subtitle, index=%d is active", current->track_index); #ifdef ASYCHRONOUS_WRITE while (current->start_feed == 0) g_usleep(WRITE_POLL_PERIOD); - MX_I("End of sleep, pushing subtitle data\n"); + MX_I("End of sleep, pushing subtitle data"); g_signal_emit_by_name(current->appsrc, "push-buffer", gst_inbuf2, &ret); #else ret = gst_app_src_push_buffer((GstAppSrc *)current->appsrc, gst_inbuf2); #endif - MX_I("Attempted subtitle-buf push\n"); + MX_I("Attempted subtitle-buf push"); if (ret != GST_FLOW_OK) { /* We got some error, stop sending data */ - MX_E("--subtitle appsrc push failed--\n"); + MX_E("--subtitle appsrc push failed--"); } if (eos) { MX_I("end of stream"); gst_app_src_end_of_stream((GstAppSrc *)current->appsrc); } } else { - MX_E("Unsupported track index=%d. track_index-mod3= %d. Only 0/1/2 track index is vaild\n", track_index, track_index%NO_OF_TRACK_TYPES); + MX_E("Unsupported track index=%d. track_index-mod3= %d. Only 0/1/2 track index is vaild", track_index, track_index%NO_OF_TRACK_TYPES); ret = MX_ERROR_INVALID_ARGUMENT; } + +LEAVE: /* Unref the buffer, as it is pushed into the appsrc already */ - gst_buffer_unref(gst_inbuf2); + if (gst_inbuf2) + gst_buffer_unref(gst_inbuf2); + MEDIAMUXER_FLEAVE(); return ret; ERROR: + if (gst_inbuf2) + gst_buffer_unref(gst_inbuf2); ret = MX_ERROR_INVALID_ARGUMENT; MEDIAMUXER_FLEAVE(); return ret; @@ -1296,23 +1331,23 @@ static int gst_muxer_close_track(MMHandleType pHandle, int track_index) break; if (!current || current->track_index != track_index) { - (!current) ? MX_E("Current is Null") : MX_E("Mismatched between track index[%d]\n", track_index); + (!current) ? MX_E("Current is Null") : MX_E("Mismatched between track index[%d]", track_index); goto ERROR; } - MX_I("__gst_muxer_stop setting eos to sources:%p\n", gst_handle); + MX_I("__gst_muxer_stop setting eos to sources:%p", gst_handle); if (gst_handle->pipeline != NULL) { if (track_index%NO_OF_TRACK_TYPES == 0) { - MX_I("\n-----EOS for video-appsrc-----\n"); + MX_I("-----EOS for video-appsrc-----"); gst_app_src_end_of_stream((GstAppSrc *)(current->appsrc)); } else if (track_index%NO_OF_TRACK_TYPES == 1) { - MX_I("\n-----EOS for audio-appsrc-----\n"); + MX_I("-----EOS for audio-appsrc-----"); gst_app_src_end_of_stream((GstAppSrc *)(current->appsrc)); } else if (track_index%NO_OF_TRACK_TYPES == 2) { - MX_I("\n-----EOS for subtitle-appsrc-----\n"); + MX_I("-----EOS for subtitle-appsrc-----"); gst_app_src_end_of_stream((GstAppSrc *)(current->appsrc)); } else { - MX_E("Invalid track Index[%d].\n", track_index); + MX_E("Invalid track Index[%d].", track_index); goto ERROR; } } @@ -1371,14 +1406,14 @@ static int gst_muxer_stop(MMHandleType pHandle) MEDIAMUXER_CHECK_NULL(pHandle); mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; - MX_I("gst_muxer_stop making pipeline to ready:%p\n", gst_handle); + MX_I("gst_muxer_stop making pipeline to ready:%p", gst_handle); /* set pipeline state to READY */ MEDIAMUXER_ELEMENT_SET_STATE(GST_ELEMENT_CAST(gst_handle->pipeline), GST_STATE_READY); MEDIAMUXER_FLEAVE(); return ret; STATE_CHANGE_FAILED: - MX_E("muxer state change failed, returning \n"); + MX_E("muxer state change failed, returning"); ret = MX_ERROR_INVALID_ARGUMENT; MEDIAMUXER_FLEAVE(); return ret; @@ -1429,7 +1464,7 @@ static int gst_muxer_unprepare(MMHandleType pHandle) MEDIAMUXER_CHECK_NULL(pHandle); mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; - MX_I("gst_muxer_unprepare setting eos to sources:%p\n", gst_handle); + MX_I("gst_muxer_unprepare setting eos to sources:%p", gst_handle); ret = _gst_destroy_pipeline(gst_handle); MEDIAMUXER_FLEAVE(); return ret; @@ -1442,7 +1477,7 @@ static int gst_muxer_destroy(MMHandleType pHandle) MEDIAMUXER_CHECK_NULL(pHandle); mxgst_handle_t *new_mediamuxer = (mxgst_handle_t *) pHandle; - MX_I("__gst_muxer_destroy deallocating new_mediamuxer:%p\n", new_mediamuxer); + MX_I("__gst_muxer_destroy deallocating new_mediamuxer:%p", new_mediamuxer); MEDIAMUXER_FREEIF(new_mediamuxer->output_uri); g_free(new_mediamuxer); MEDIAMUXER_FLEAVE(); @@ -1457,7 +1492,7 @@ int gst_muxer_set_error_cb(MMHandleType pHandle, gst_muxer_error_cb callback, vo mxgst_handle_t *gst_handle = (mxgst_handle_t *) pHandle; if (gst_handle->user_cb[_GST_EVENT_TYPE_ERROR]) { - MX_E("Already set mediamuxer_error_cb\n"); + MX_E("Already set mediamuxer_error_cb"); ret = MX_ERROR_INVALID_ARGUMENT; goto ERROR; } else { @@ -1467,7 +1502,7 @@ int gst_muxer_set_error_cb(MMHandleType pHandle, gst_muxer_error_cb callback, vo } } - MX_I("Set event handler callback(cb = %p, data = %p)\n", callback, user_data); + MX_I("Set event handler callback(cb = %p, data = %p)", callback, user_data); gst_handle->user_cb[_GST_EVENT_TYPE_ERROR] = (gst_muxer_error_cb) callback; gst_handle->user_data[_GST_EVENT_TYPE_ERROR] = user_data; MEDIAMUXER_FLEAVE(); -- 2.7.4