From: Mahesh Kondiparthi Date: Thu, 29 Oct 2015 10:43:31 +0000 (+0530) Subject: Applied Coding rules for indentation. X-Git-Tag: submit/tizen/20151207.043145~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=608f72100ef46fd0b65a8f84b7cc13464a2aa60f;p=platform%2Fcore%2Fapi%2Fmediamuxer.git Applied Coding rules for indentation. Cleaned the code whenever needed. Addressed review comments Change-Id: I688db93fce1de8ff9ec69b7dd8d5acb029c6109a Signed-off-by: Mahesh Kondiparthi --- diff --git a/doc/mediamuxer_doc.h b/doc/mediamuxer_doc.h index 91e2e9e..bd7a867 100755 --- a/doc/mediamuxer_doc.h +++ b/doc/mediamuxer_doc.h @@ -47,11 +47,11 @@ * mediamuxer_start() * while() * if (is_track(1)_data_available) - * mediamuxer_write_sample(track(1)), + * mediamuxer_write_sample(track(1)), * else - * mediamuxer_close_track(1) + * mediamuxer_close_track(1) * if (is_track(2)_data_available) - * mediamuxer_write_sample(track(2)) + * mediamuxer_write_sample(track(2)) * else * mediamuxer_close_track(2) * mediamuxer_stop() diff --git a/include/mediamuxer.h b/include/mediamuxer.h index 6b601b8..34577cc 100755 --- a/include/mediamuxer.h +++ b/include/mediamuxer.h @@ -261,7 +261,7 @@ int mediamuxer_resume(mediamuxer_h muxer); * @retval #MEDIAMUXER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIAMUXER_ERROR_INVALID_STATE Invalid state * @pre The media muxer state must be set to #MEDIAMUXER_STATE_MUXING - * or #MEDIAMUXER_STATE_PAUSED. + * or #MEDIAMUXER_STATE_PAUSED. * @post The media muxer state will be #MEDIAMUXER_STATE_READY. * @see mediamuxer_start() * @see mediamuxer_unprepare() diff --git a/include/mediamuxer_error.h b/include/mediamuxer_error.h index bad4cc7..853296c 100755 --- a/include/mediamuxer_error.h +++ b/include/mediamuxer_error.h @@ -52,7 +52,7 @@ extern "C" { #define MX_ERROR_FILE_WRITE (MX_ERROR_CLASS | 0x07) /**< End of file */ #define MX_ERROR_END_OF_FILE (MX_ERROR_CLASS | 0x08) -/**< Not supported API*/ +/**< Not supported API */ #define MX_ERROR_NOT_SUPPORT_API (MX_ERROR_CLASS | 0x09) /**< port regitstration failed error */ #define MX_ERROR_PORT_REG_FAILED (MX_ERROR_CLASS | 0x0a) @@ -74,7 +74,7 @@ extern "C" { #define MX_ERROR_COMMON_INVALID_PERMISSION (MX_ERROR_COMMON_CLASS | 6) /**< Out of array */ #define MX_ERROR_COMMON_OUT_OF_ARRAY (MX_ERROR_COMMON_CLASS | 7) -/**< Out of value range*/ +/**< Out of value range */ #define MX_ERROR_COMMON_OUT_OF_RANGE (MX_ERROR_COMMON_CLASS | 8) /**< Attribute doesn't exist. */ #define MX_ERROR_COMMON_ATTR_NOT_EXIST (MX_ERROR_COMMON_CLASS | 9) diff --git a/include/mediamuxer_ini.h b/include/mediamuxer_ini.h index b493d26..8a668aa 100755 --- a/include/mediamuxer_ini.h +++ b/include/mediamuxer_ini.h @@ -82,4 +82,4 @@ int mx_ini_load(mx_ini_t *ini); #ifdef __cplusplus } #endif -#endif /*__TIZEN_MEDIAMUXER_INI_H__*/ +#endif /* __TIZEN_MEDIAMUXER_INI_H__ */ diff --git a/include/mediamuxer_port.h b/include/mediamuxer_port.h index 93396fb..cbc4b00 100755 --- a/include/mediamuxer_port.h +++ b/include/mediamuxer_port.h @@ -17,11 +17,11 @@ #ifndef __TIZEN_MEDIAMUXER_PORT_H__ #define __TIZEN_MEDIAMUXER_PORT_H__ -/*============================================================================= +/* ============================================================================ | | | INCLUDE FILES | | | -==============================================================================*/ +============================================================================= */ #include #include @@ -300,11 +300,11 @@ extern "C" { */ -/*=============================================================================| +/* ============================================================================| | | | GLOBAL DEFINITIONS AND DECLARATIONS | | | -==============================================================================*/ +============================================================================= */ /** * @brief Called when error occurs in media muxer. * @details Following error codes can be delivered. @@ -344,11 +344,11 @@ typedef struct _media_port_muxer_ops { int (*set_error_cb)(MMHandleType pHandle, mx_error_cb callback, void* user_data); } media_port_muxer_ops; -/*============================================================================= +/* ============================================================================ | | | GLOBAL FUNCTION PROTOTYPES | | | -==============================================================================*/ +============================================================================= */ /** * This function creates a muxer object for parsing multimedia contents. \n @@ -502,7 +502,7 @@ int mx_write_sample(MMHandleType mediamuxer, int track_index, media_packet_h inb * @param track_index [in] selected track * * @return This function returns zero on success, or negative value with error - code. + code. * @see mx_unprepare * * @par Example diff --git a/include/mediamuxer_private.h b/include/mediamuxer_private.h index 479d4e6..881167d 100755 --- a/include/mediamuxer_private.h +++ b/include/mediamuxer_private.h @@ -29,24 +29,26 @@ extern "C" { #endif #define LOG_TAG "TIZEN_N_MEDIAMUXER" -#define MUXER_CHECK_CONDITION(condition,error,msg) \ - do \ - { \ - if (condition) {} else \ - { MX_E("[%s] %s(0x%08x)",__FUNCTION__, msg,error); return error;}; \ - }while(0) +#define MUXER_CHECK_CONDITION(condition, error, msg) \ + do { \ + if (condition) { \ + } else { \ + MX_E("[%s] %s(0x%08x)", __FUNCTION__, msg, error); \ + return error; \ + } \ + } while (0) #define MUXER_INSTANCE_CHECK(muxer) \ MUXER_CHECK_CONDITION(muxer != NULL, \ - MEDIAMUXER_ERROR_INVALID_PARAMETER,"MUXER_ERROR_INVALID_PARAMETER") + MEDIAMUXER_ERROR_INVALID_PARAMETER, "MUXER_ERROR_INVALID_PARAMETER") -#define MUXER_STATE_CHECK(muxer,expected_state) \ +#define MUXER_STATE_CHECK(muxer, expected_state) \ MUXER_CHECK_CONDITION(muxer->state == expected_state, \ - MEDIAMUXER_ERROR_INVALID_STATE,"MUXER_ERROR_INVALID_STATE") + MEDIAMUXER_ERROR_INVALID_STATE, "MUXER_ERROR_INVALID_STATE") #define MUXER_NULL_ARG_CHECK(arg) \ - MUXER_CHECK_CONDITION(arg != NULL,MEDIAMUXER_ERROR_INVALID_PARAMETER, \ - "MUXER_ERROR_INVALID_PARAMETER") + MUXER_CHECK_CONDITION(arg != NULL, MEDIAMUXER_ERROR_INVALID_PARAMETER, \ + "MUXER_ERROR_INVALID_PARAMETER") /** * @brief Enumerations of media muxer state diff --git a/include/mediamuxer_util.h b/include/mediamuxer_util.h index 95c1030..dff07bc 100755 --- a/include/mediamuxer_util.h +++ b/include/mediamuxer_util.h @@ -27,13 +27,13 @@ extern "C" { #endif -//#define PRINT_ON_CONSOLE +/* #define PRINT_ON_CONSOLE */ #ifdef PRINT_ON_CONSOLE #include #include #define PRINT_F g_print -#define MX_FENTER(); PRINT_F("function:[%s] ENTER\n",__func__); -#define MX_FLEAVE(); PRINT_F("function [%s] LEAVE\n",__func__); +#define MX_FENTER(); PRINT_F("function:[%s] ENTER\n", __func__); +#define MX_FLEAVE(); PRINT_F("function [%s] LEAVE\n", __func__); #define MX_C PRINT_F #define MX_E PRINT_F #define MX_W PRINT_F @@ -43,25 +43,24 @@ 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_C LOGE /*MMF_DEBUG_LEVEL_0 */ -#define MX_E LOGE /*MMF_DEBUG_LEVEL_1 */ -#define MX_W LOGW /*MMF_DEBUG_LEVEL_2 */ -#define MX_I LOGI /*MMF_DEBUG_LEVEL_3 */ -#define MX_L LOGI /*MMF_DEBUG_LEVEL_4 */ -#define MX_V LOGV /*MMF_DEBUG_LEVEL_5 */ -#define MX_F LOGF /*MMF_DEBUG_LEVEL_6 */ +#define MX_FENTER(); LOGI("function:[%s] ENTER\n", __func__); +#define MX_FLEAVE(); LOGI("function [%s] LEAVE\n", __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 */ +#define MX_I LOGI /* MMF_DEBUG_LEVEL_3 */ +#define MX_L LOGI /* MMF_DEBUG_LEVEL_4 */ +#define MX_V LOGV /* MMF_DEBUG_LEVEL_5 */ +#define MX_F LOGF /* MMF_DEBUG_LEVEL_6 */ #endif /* general */ #define MEDIAMUXER_FREEIF(x) \ - do \ - { \ - if ( x ) \ - g_free( x ); \ + do { \ + if (x) \ + g_free(x); \ x = NULL; \ - }while(0) + } while (0) #if 1 #define MEDIAMUXER_FENTER(); MX_FENTER(); @@ -71,22 +70,18 @@ extern "C" { #define MEDIAMUXER_FLEAVE(); #endif -#define MEDIAMUXER_CHECK_NULL( x_var ) \ - do \ - { \ - if ( ! x_var ) \ - { \ - MX_E("[%s] is NULL\n", #x_var ); \ +#define MEDIAMUXER_CHECK_NULL(x_var) \ + do { \ + if (!x_var) { \ + MX_E("[%s] is NULL\n", #x_var); \ goto ERROR; \ } \ } while (0) -#define MEDIAMUXER_CHECK_SET_AND_PRINT( x_var, x_cond, ret, ret_val, err_text )\ - do \ - { \ - if ( x_var != x_cond ) \ - { \ +#define MEDIAMUXER_CHECK_SET_AND_PRINT(x_var, x_cond, ret, ret_val, err_text)\ + do { \ + if (x_var != x_cond) { \ ret = ret_val; \ - MX_E("%s\n", #err_text ); \ + MX_E("%s\n", #err_text); \ goto ERROR; \ } \ } while (0) diff --git a/include/port_custom/mediamuxer_port_custom.h b/include/port_custom/mediamuxer_port_custom.h index 7739f91..d1846cb 100755 --- a/include/port_custom/mediamuxer_port_custom.h +++ b/include/port_custom/mediamuxer_port_custom.h @@ -23,7 +23,7 @@ extern "C" { #endif -/*Place holder */ +/* Place holder */ #ifdef __cplusplus } diff --git a/include/port_ffmpeg/mediamuxer_port_ffmpeg.h b/include/port_ffmpeg/mediamuxer_port_ffmpeg.h index 2ae9320..93f70de 100755 --- a/include/port_ffmpeg/mediamuxer_port_ffmpeg.h +++ b/include/port_ffmpeg/mediamuxer_port_ffmpeg.h @@ -23,7 +23,7 @@ extern "C" { #endif -/*Place holder */ +/* Place holder */ #ifdef __cplusplus } diff --git a/include/port_gst/mediamuxer_port_gst.h b/include/port_gst/mediamuxer_port_gst.h index c826b3a..e7a3ed7 100755 --- a/include/port_gst/mediamuxer_port_gst.h +++ b/include/port_gst/mediamuxer_port_gst.h @@ -26,11 +26,10 @@ #define MAX_STRING_LENGTH 25 #define NO_OF_TRACK_TYPES 3 /* Audio, Video and Subtitle */ -#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 ) ); \ - 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 )); \ +#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)); \ + 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)); \ goto STATE_CHANGE_FAILED; \ } diff --git a/src/mediamuxer.c b/src/mediamuxer.c index d3a1b4a..f19c255 100644 --- a/src/mediamuxer.c +++ b/src/mediamuxer.c @@ -112,7 +112,7 @@ int mediamuxer_add_track(mediamuxer_h muxer, media_format_h media_format, int *t MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle; handle = (mediamuxer_s *)(muxer); - if (handle->muxer_state == MEDIAMUXER_STATE_IDLE){ + 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)", @@ -188,9 +188,8 @@ int mediamuxer_write_sample(mediamuxer_h muxer, int track_index, media_packet_h int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); - if (track_index < 0 || inbuf == NULL) { + if (track_index < 0 || inbuf == NULL) return MEDIAMUXER_ERROR_INVALID_PARAMETER; - } if (handle->muxer_state == MEDIAMUXER_STATE_READY || handle->muxer_state == MEDIAMUXER_STATE_MUXING) { ret = mx_write_sample(handle->mx_handle, track_index, inbuf); @@ -219,9 +218,8 @@ int mediamuxer_close_track(mediamuxer_h muxer, int track_index) int ret = MEDIAMUXER_ERROR_NONE; MUXER_INSTANCE_CHECK(muxer); mediamuxer_s *handle = (mediamuxer_s *)(muxer); - if (track_index < 0) { + if (track_index < 0) return MEDIAMUXER_ERROR_INVALID_PARAMETER; - } if (handle->muxer_state == MEDIAMUXER_STATE_MUXING || handle->muxer_state == MEDIAMUXER_STATE_IDLE || handle->muxer_state == MEDIAMUXER_STATE_READY) { @@ -424,16 +422,15 @@ int mediamuxer_unset_error_cb(mediamuxer_h muxer) 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\n", error); return 0; } mediamuxer_s * handle = (mediamuxer_s *) user_data; - if (handle->error_cb ) { + 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); - } + else + MX_I("_mediamuxer_error_cb: ERROR %d to report. But call back is not set\n", error); + return 0; } diff --git a/src/mediamuxer_ini.c b/src/mediamuxer_ini.c index d829dd5..fcebd5a 100644 --- a/src/mediamuxer_ini.c +++ b/src/mediamuxer_ini.c @@ -28,72 +28,58 @@ #include /* macro */ -#define MEDIAMUXER_INI_GET_STRING( x_dict, x_item, x_ini, x_default ) \ - do \ - { \ +#define MEDIAMUXER_INI_GET_STRING(x_dict, x_item, x_ini, x_default) \ + do { \ gchar* str = iniparser_getstring(x_dict, x_ini, x_default); \ \ - if ( str && \ - ( strlen( str ) > 0 ) && \ - ( strlen( str ) < MEDIAMUXER_INI_MAX_STRLEN ) ) \ - { \ - strcpy ( x_item, str ); \ + if (str && \ + (strlen(str) > 0) && \ + (strlen(str) < MEDIAMUXER_INI_MAX_STRLEN)) { \ + strcpy(x_item, str); \ + } else { \ + strcpy(x_item, x_default); \ } \ - else \ - { \ - strcpy ( x_item, x_default ); \ - } \ - }while(0) + } while (0) -#define MEDIAMUXER_INI_GET_COLOR( x_dict, x_item, x_ini, x_default ) \ - do \ - { \ +#define MEDIAMUXER_INI_GET_COLOR(x_dict, x_item, x_ini, x_default) \ + do { \ gchar* str = iniparser_getstring(x_dict, x_ini, x_default); \ \ - if ( str && \ - ( strlen( str ) > 0 ) && \ - ( strlen( str ) < MEDIAMUXER_INI_MAX_STRLEN ) ) \ - { \ + if (str && \ + (strlen(str) > 0) && \ + (strlen(str) < MEDIAMUXER_INI_MAX_STRLEN)) { \ x_item = (guint) strtoul(str, NULL, 16); \ - } \ - else \ - { \ + } else { \ x_item = (guint) strtoul(x_default, NULL, 16); \ } \ - }while(0) + } while (0) /* x_ini is the list of index to set TRUE at x_list[index] */ -#define MEDIAMUXER_INI_GET_BOOLEAN_FROM_LIST( x_dict, x_list, \ - x_list_max, x_ini, x_default ) \ -do \ -{ \ +#define MEDIAMUXER_INI_GET_BOOLEAN_FROM_LIST(x_dict, x_list, \ + x_list_max, x_ini, x_default) \ +do { \ int index = 0; \ const char *delimiters = " ,"; \ char *usr_ptr = NULL; \ char *token = NULL; \ gchar temp_arr[MEDIAMUXER_INI_MAX_STRLEN] = {0}; \ - MMMEDIAMUXER_INI_GET_STRING( x_dict, temp_arr, x_ini, x_default); \ - token = strtok_r( temp_arr, delimiters, &usr_ptr ); \ - while (token) \ - { \ + MMMEDIAMUXER_INI_GET_STRING(x_dict, temp_arr, x_ini, x_default); \ + token = strtok_r(temp_arr, delimiters, &usr_ptr); \ + while (token) { \ index = atoi(token); \ - if (index < 0 || index > x_list_max -1) \ - { \ + if (index < 0 || index > x_list_max -1) { \ MX_W("%d is not valid index\n", index); \ - } \ - else \ - { \ + } else { \ x_list[index] = TRUE; \ } \ - token = strtok_r( NULL, delimiters, &usr_ptr ); \ + token = strtok_r(NULL, delimiters, &usr_ptr); \ } \ -}while(0) +} while (0) /* x_ini is the list of value to be set at x_list[index] */ -#define MEDIAMUXER_INI_GET_INT_FROM_LIST( x_dict, x_list, \ - x_list_max, x_ini, x_default ) \ -do \ -{ \ +#define MEDIAMUXER_INI_GET_INT_FROM_LIST(x_dict, x_list, \ + x_list_max, x_ini, x_default) \ +do { \ int index = 0; \ int value = 0; \ const char *delimiters = " ,"; \ @@ -101,23 +87,19 @@ do \ char *token = NULL; \ gchar temp_arr[MEDIAMUXER_INI_MAX_STRLEN] = {0}; \ MMMEDIAMUXER_INI_GET_STRING(x_dict, temp_arr, x_ini, x_default); \ - token = strtok_r( temp_arr, delimiters, &usr_ptr ); \ - while (token) \ - { \ - if ( index > x_list_max -1) \ - { \ + 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); \ break; \ - } \ - else \ - { \ + } else { \ value = atoi(token); \ x_list[index] = value; \ index++; \ } \ - token = strtok_r( NULL, delimiters, &usr_ptr ); \ + token = strtok_r(NULL, delimiters, &usr_ptr); \ } \ -}while(0) +} while (0) /* internal functions, macros here */ #ifdef MEDIAMUXER_DEFAULT_INI @@ -158,14 +140,13 @@ int mx_ini_load(mx_ini_t *ini) if (dict) { /* if dict is available */ /* general */ MEDIAMUXER_INI_GET_STRING(dict, ini->port_name, - "port_in_use:mediamuxer_port", - DEFAULT_PORT); + "port_in_use:mediamuxer_port", DEFAULT_PORT); } else { /* if dict is not available just fill the structure with default value */ MX_W("failed to load ini. using hardcoded default\n"); strncpy(ini->port_name, DEFAULT_PORT, - MEDIAMUXER_INI_MAX_STRLEN - 1); + MEDIAMUXER_INI_MAX_STRLEN - 1); } if (0 == strcmp(ini->port_name, "GST_PORT")) { diff --git a/src/mediamuxer_port.c b/src/mediamuxer_port.c index 1b46378..d22d6c4 100644 --- a/src/mediamuxer_port.c +++ b/src/mediamuxer_port.c @@ -61,12 +61,12 @@ int mx_create(MMHandleType *muxer) /* load ini files */ result = mx_ini_load(&new_muxer->ini); MEDIAMUXER_CHECK_SET_AND_PRINT(result, MX_ERROR_NONE, result, - MX_COURRPTED_INI, "can't load ini"); + MX_COURRPTED_INI, "can't load ini"); register_port_func[new_muxer->ini.port_type](pOps); result = pOps->init(&new_muxer->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(result, MX_ERROR_NONE, result, - MX_NOT_INITIALIZED, "mx_create failed"); + MX_NOT_INITIALIZED, "mx_create failed"); *muxer = (MMHandleType) new_muxer; MEDIAMUXER_FLEAVE(); return result; @@ -107,7 +107,7 @@ int mx_add_track(MMHandleType mediamuxer, media_format_h media_format, int *trac MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->add_track(mx_handle->mxport_handle, media_format, track_index); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while adding track"); + "error while adding track"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -125,7 +125,7 @@ int mx_prepare(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->prepare(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while preparing"); + "error while preparing"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -143,7 +143,7 @@ int mx_start(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->start(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while starting"); + "error while starting"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -161,7 +161,7 @@ int mx_write_sample(MMHandleType mediamuxer, int track_index, media_packet_h inb MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->write_sample(mx_handle->mxport_handle, track_index, inbuf); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while writing sample"); + "error while writing sample"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -179,7 +179,7 @@ int mx_close_track(MMHandleType mediamuxer, int track_index) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->close_track(mx_handle->mxport_handle, track_index); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while closing track"); + "error while closing track"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -197,7 +197,7 @@ int mx_pause(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->pause(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while pausing"); + "error while pausing"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -215,7 +215,7 @@ int mx_resume(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->resume(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while resuming"); + "error while resuming"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -233,7 +233,7 @@ int mx_stop(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->stop(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while stopping"); + "error while stopping"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -251,7 +251,7 @@ int mx_unprepare(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->unprepare(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while destroying"); + "error while destroying"); MEDIAMUXER_FLEAVE(); return ret; ERROR: @@ -269,7 +269,7 @@ int mx_destroy(MMHandleType mediamuxer) MEDIAMUXER_CHECK_NULL(pOps); ret = pOps->destroy(mx_handle->mxport_handle); MEDIAMUXER_CHECK_SET_AND_PRINT(ret, MX_ERROR_NONE, ret, MX_ERROR, - "error while destroying"); + "error while destroying"); /* free mediamuxer structure */ if (mx_handle) { @@ -296,7 +296,7 @@ int mx_set_error_cb(MMHandleType muxer, MEDIAMUXER_CHECK_NULL(mx_handle); media_port_muxer_ops *pOps = mx_handle->muxer_ops; MEDIAMUXER_CHECK_NULL(pOps); - result = pOps->set_error_cb(mx_handle->mxport_handle, callback,user_data); + result = pOps->set_error_cb(mx_handle->mxport_handle, callback, user_data); MEDIAMUXER_CHECK_SET_AND_PRINT(result, MX_ERROR_NONE, result, MX_ERROR, "error while setting error call back"); MEDIAMUXER_FLEAVE(); diff --git a/src/port_custom/mediamuxer_port_custom.c b/src/port_custom/mediamuxer_port_custom.c index 83ccafa..887be98 100644 --- a/src/port_custom/mediamuxer_port_custom.c +++ b/src/port_custom/mediamuxer_port_custom.c @@ -24,7 +24,7 @@ static int custom_muxer_init(MMHandleType *pHandle); static int custom_muxer_set_data_sink(MMHandleType pHandle, char *uri, mediamuxer_output_format_e format); -/*Media Muxer API common*/ +/* Media Muxer API common */ static media_port_muxer_ops def_mux_ops = { .n_size = 0, .init = custom_muxer_init, @@ -60,7 +60,7 @@ static int custom_muxer_init(MMHandleType *pHandle) } static int custom_muxer_set_data_sink(MMHandleType pHandle, char *uri, - mediamuxer_output_format_e format) + mediamuxer_output_format_e format) { MEDIAMUXER_FENTER(); MX_E("%s:exit: Not implemented\n", __func__); diff --git a/src/port_ffmpeg/mediamuxer_port_ffmpeg.c b/src/port_ffmpeg/mediamuxer_port_ffmpeg.c index 7857b7c..54d23f9 100644 --- a/src/port_ffmpeg/mediamuxer_port_ffmpeg.c +++ b/src/port_ffmpeg/mediamuxer_port_ffmpeg.c @@ -24,7 +24,7 @@ static int ffmpeg_muxer_init(MMHandleType *pHandle); static int ffmpeg_muxer_set_data_sink(MMHandleType pHandle, char *uri, mediamuxer_output_format_e format); -/*Media Muxer API common*/ +/* Media Muxer API common */ static media_port_muxer_ops def_mux_ops = { .n_size = 0, .init = ffmpeg_muxer_init, @@ -60,7 +60,7 @@ static int ffmpeg_muxer_init(MMHandleType *pHandle) } static int ffmpeg_muxer_set_data_sink(MMHandleType pHandle, char *uri, - mediamuxer_output_format_e format) + mediamuxer_output_format_e format) { int ret = MX_ERROR_NONE; MEDIAMUXER_FENTER(); diff --git a/src/port_gst/mediamuxer_port_gst.c b/src/port_gst/mediamuxer_port_gst.c index bfaa39a..f1da983 100644 --- a/src/port_gst/mediamuxer_port_gst.c +++ b/src/port_gst/mediamuxer_port_gst.c @@ -22,8 +22,8 @@ #define EOS_POLL_PERIOD 1000 #define WRITE_POLL_PERIOD 100 -/*#define SEND_FULL_CAPS_VIA_CODEC_DATA *//*For debug purpose*/ -#define ASYCHRONOUS_WRITE /*write sample is not blocking */ +/* #define SEND_FULL_CAPS_VIA_CODEC_DATA *//* For debug purpose */ +#define ASYCHRONOUS_WRITE /* write sample is not blocking */ static int gst_muxer_init(MMHandleType *pHandle); static int gst_muxer_set_data_sink(MMHandleType pHandle, char *uri, @@ -43,7 +43,7 @@ static int gst_muxer_destroy(MMHandleType pHandle); static int gst_set_error_cb(MMHandleType pHandle, gst_error_cb callback, void* user_data); -/*Media Muxer API common*/ +/* Media Muxer API common */ static media_port_muxer_ops def_mux_ops = { .n_size = 0, .init = gst_muxer_init, @@ -115,7 +115,7 @@ ERROR: } static int gst_muxer_set_data_sink(MMHandleType pHandle, - char *uri, mediamuxer_output_format_e format) + char *uri, mediamuxer_output_format_e format) { MEDIAMUXER_FENTER(); int ret = MX_ERROR_NONE; @@ -134,7 +134,7 @@ ERROR: } static int gst_muxer_add_track(MMHandleType pHandle, - media_format_h media_format, int *track_index) + media_format_h media_format, int *track_index) { MEDIAMUXER_FENTER(); int ret = MX_ERROR_NONE; @@ -159,7 +159,7 @@ static int gst_muxer_add_track(MMHandleType pHandle, MX_I("Adding first-ever track\n"); 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)\n", 1+mx_handle_gst->track_info.total_track_cnt); last = mx_handle_gst->track_info.track_head; while (last->next != NULL) last = last->next; @@ -168,10 +168,10 @@ static int gst_muxer_add_track(MMHandleType pHandle, } if (media_format_get_video_info(media_format, &mimetype, NULL, NULL, NULL, NULL) != - MEDIA_FORMAT_ERROR_INVALID_OPERATION) { - if (mimetype == MEDIA_FORMAT_H264_SP || - mimetype == MEDIA_FORMAT_H264_MP || - mimetype == MEDIA_FORMAT_H264_HP) { + MEDIA_FORMAT_ERROR_INVALID_OPERATION) { + if (mimetype == MEDIA_FORMAT_H264_SP + || mimetype == MEDIA_FORMAT_H264_MP + || mimetype == MEDIA_FORMAT_H264_HP) { current->track_index = NO_OF_TRACK_TYPES*(mx_handle_gst->track_info.video_track_cnt); (mx_handle_gst->track_info.video_track_cnt)++; @@ -184,7 +184,7 @@ static int gst_muxer_add_track(MMHandleType pHandle, MX_E("Unsupported MIME Type\n"); } } else if (media_format_get_audio_info(media_format, &mimetype, NULL, NULL, NULL, NULL) != - MEDIA_FORMAT_ERROR_INVALID_OPERATION) { + MEDIA_FORMAT_ERROR_INVALID_OPERATION) { if (mimetype == MEDIA_FORMAT_AAC || mimetype == MEDIA_FORMAT_AAC_LC || mimetype == MEDIA_FORMAT_AAC_HE || @@ -219,23 +219,23 @@ static gint __gst_handle_resource_error(mxgst_handle_t* gst_handle, int code) g_return_val_if_fail(gst_handle, MX_PARAM_ERROR); switch (code) { - /* ToDo: Add individual actions as and when needed */ - case GST_RESOURCE_ERROR_NO_SPACE_LEFT: - trans_err = MX_ERROR_COMMON_NO_FREE_SPACE; - break; - case GST_RESOURCE_ERROR_WRITE: - case GST_RESOURCE_ERROR_FAILED: - case GST_RESOURCE_ERROR_SEEK: - case GST_RESOURCE_ERROR_TOO_LAZY: - case GST_RESOURCE_ERROR_BUSY: - case GST_RESOURCE_ERROR_OPEN_WRITE: - case GST_RESOURCE_ERROR_OPEN_READ_WRITE: - case GST_RESOURCE_ERROR_CLOSE: - case GST_RESOURCE_ERROR_SYNC: - case GST_RESOURCE_ERROR_SETTINGS: - default: - trans_err = MX_INTERNAL_ERROR; - break; + /* ToDo: Add individual actions as and when needed */ + case GST_RESOURCE_ERROR_NO_SPACE_LEFT: + trans_err = MX_ERROR_COMMON_NO_FREE_SPACE; + break; + case GST_RESOURCE_ERROR_WRITE: + case GST_RESOURCE_ERROR_FAILED: + case GST_RESOURCE_ERROR_SEEK: + case GST_RESOURCE_ERROR_TOO_LAZY: + case GST_RESOURCE_ERROR_BUSY: + case GST_RESOURCE_ERROR_OPEN_WRITE: + case GST_RESOURCE_ERROR_OPEN_READ_WRITE: + case GST_RESOURCE_ERROR_CLOSE: + case GST_RESOURCE_ERROR_SYNC: + case GST_RESOURCE_ERROR_SETTINGS: + default: + trans_err = MX_INTERNAL_ERROR; + break; } MEDIAMUXER_FLEAVE(); return trans_err; @@ -248,24 +248,24 @@ static gint __gst_handle_core_error(mxgst_handle_t* gst_handle, int code) /* g_return_val_if_fail(core, MX_PARAM_ERROR); */ switch (code) { - /* ToDo: Add individual actions as and when needed */ - case GST_CORE_ERROR_MISSING_PLUGIN: - case GST_CORE_ERROR_STATE_CHANGE: - case GST_CORE_ERROR_SEEK: - case GST_CORE_ERROR_NOT_IMPLEMENTED: - case GST_CORE_ERROR_FAILED: - case GST_CORE_ERROR_TOO_LAZY: - case GST_CORE_ERROR_PAD: - case GST_CORE_ERROR_THREAD: - case GST_CORE_ERROR_NEGOTIATION: - case GST_CORE_ERROR_EVENT: - case GST_CORE_ERROR_CAPS: - case GST_CORE_ERROR_TAG: - case GST_CORE_ERROR_CLOCK: - case GST_CORE_ERROR_DISABLED: - default: - trans_err = MX_INTERNAL_ERROR; - break; + /* ToDo: Add individual actions as and when needed */ + case GST_CORE_ERROR_MISSING_PLUGIN: + case GST_CORE_ERROR_STATE_CHANGE: + case GST_CORE_ERROR_SEEK: + case GST_CORE_ERROR_NOT_IMPLEMENTED: + case GST_CORE_ERROR_FAILED: + case GST_CORE_ERROR_TOO_LAZY: + case GST_CORE_ERROR_PAD: + case GST_CORE_ERROR_THREAD: + case GST_CORE_ERROR_NEGOTIATION: + case GST_CORE_ERROR_EVENT: + case GST_CORE_ERROR_CAPS: + case GST_CORE_ERROR_TAG: + case GST_CORE_ERROR_CLOCK: + case GST_CORE_ERROR_DISABLED: + default: + trans_err = MX_INTERNAL_ERROR; + break; } MEDIAMUXER_FLEAVE(); return trans_err; @@ -278,16 +278,16 @@ static gint __gst_handle_library_error(mxgst_handle_t* gst_handle, int code) g_return_val_if_fail(gst_handle, MX_PARAM_ERROR); switch (code) { - /* ToDo: Add individual actions as and when needed */ - case GST_LIBRARY_ERROR_FAILED: - case GST_LIBRARY_ERROR_TOO_LAZY: - case GST_LIBRARY_ERROR_INIT: - case GST_LIBRARY_ERROR_SHUTDOWN: - case GST_LIBRARY_ERROR_SETTINGS: - case GST_LIBRARY_ERROR_ENCODE: - default: - trans_err = MX_INTERNAL_ERROR; - break; + /* ToDo: Add individual actions as and when needed */ + case GST_LIBRARY_ERROR_FAILED: + case GST_LIBRARY_ERROR_TOO_LAZY: + case GST_LIBRARY_ERROR_INIT: + case GST_LIBRARY_ERROR_SHUTDOWN: + case GST_LIBRARY_ERROR_SETTINGS: + case GST_LIBRARY_ERROR_ENCODE: + default: + trans_err = MX_INTERNAL_ERROR; + break; } MEDIAMUXER_FLEAVE(); return trans_err; @@ -299,38 +299,38 @@ static gboolean _mx_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) int ret = MX_ERROR_NONE; mxgst_handle_t *gst_handle = (mxgst_handle_t*)data; switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_EOS: - MX_I("End of stream\n"); - break; - case GST_MESSAGE_ERROR: { - gchar *debug; - GError *error; - gst_message_parse_error(msg, &error, &debug); - if (!error) { - MX_E("GST error message parsing failed"); - break; - } - MX_E("Error: %s\n", error->message); - if (error) { - if (error->domain == GST_RESOURCE_ERROR) - ret = __gst_handle_resource_error(gst_handle, error->code); - else if (error->domain == GST_LIBRARY_ERROR) - ret = __gst_handle_library_error(gst_handle, error->code); - else if (error->domain == GST_CORE_ERROR) - ret = __gst_handle_core_error(gst_handle, error->code); - else - MX_E("Unexpected error has occured"); - /* ToDo: Update the user callback with ret... */ - return ret; - } - g_free(debug); - MX_E("Error: %s\n", error->message); - g_error_free(error); + case GST_MESSAGE_EOS: + MX_I("End of stream\n"); + break; + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; + gst_message_parse_error(msg, &error, &debug); + if (!error) { + MX_E("GST error message parsing failed"); + break; } - break; - default: - MX_E("unhandled message: 0x%x", GST_MESSAGE_TYPE(msg)); - break; + MX_E("Error: %s\n", error->message); + if (error) { + if (error->domain == GST_RESOURCE_ERROR) + ret = __gst_handle_resource_error(gst_handle, error->code); + else if (error->domain == GST_LIBRARY_ERROR) + ret = __gst_handle_library_error(gst_handle, error->code); + else if (error->domain == GST_CORE_ERROR) + ret = __gst_handle_core_error(gst_handle, error->code); + else + MX_E("Unexpected error has occured"); + /* ToDo: Update the user callback with ret... */ + return ret; + } + g_free(debug); + MX_E("Error: %s\n", error->message); + g_error_free(error); + } + break; + default: + MX_E("unhandled message: 0x%x", GST_MESSAGE_TYPE(msg)); + break; } MEDIAMUXER_FLEAVE(); return TRUE; @@ -343,7 +343,7 @@ 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\n", current->track_index); current->stop_feed = 0; current->start_feed = 1; } else @@ -353,7 +353,7 @@ static void _audio_start_feed(GstElement *source, guint size, mx_gst_track *curr 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\n", current->track_index); current->stop_feed = 0; current->start_feed = 1; } else @@ -367,7 +367,7 @@ static void _video_start_feed(GstElement *source, guint size, mx_gst_track *curr 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\n", current->track_index); current->stop_feed = 1; current->start_feed = 0; } else @@ -377,7 +377,7 @@ static void _audio_stop_feed(GstElement *source, mx_gst_track *current) 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("\nVideo Stop feeding... current->track_index = %d\n", current->track_index); current->stop_feed = 1; current->start_feed = 0; } else @@ -428,8 +428,8 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) for (current = gst_handle->track_info.track_head; current; current = current->next) { if (current->track_index%NO_OF_TRACK_TYPES == 0) { /* Video track */ - sprintf(str_appsrc,"video_appsrc%d",current->track_index); - sprintf(str_parser,"video_parser%d",current->track_index); + sprintf(str_appsrc, "video_appsrc%d", current->track_index); + sprintf(str_parser, "video_parser%d", current->track_index); current->appsrc = gst_element_factory_make("appsrc", str_appsrc); current->parser = gst_element_factory_make("h264parse", str_parser); @@ -454,12 +454,12 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) #else g_object_set(current->appsrc, "block", TRUE, NULL); gst_app_src_set_stream_type((GstAppSrc *)current->appsrc, - GST_APP_STREAM_TYPE_STREAM); + GST_APP_STREAM_TYPE_STREAM); #endif gst_element_link(current->appsrc, current->parser); /* Link videoparse to muxer_video_pad. Request for muxer A/V pads. */ - sprintf(track_no,"video_%.2d",vid_track_cnt++); /* sprintf(track_no,"video_00"); */ + sprintf(track_no, "video_%.2d", vid_track_cnt++); /* sprintf(track_no,"video_00"); */ video_pad = gst_element_get_request_pad(gst_handle->muxer, track_no); vid_src = gst_element_get_static_pad(current->parser, "src"); @@ -474,8 +474,8 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) for (current = gst_handle->track_info.track_head; current; current = current->next) { if (current->track_index%NO_OF_TRACK_TYPES == 1) { - sprintf(str_appsrc,"audio_appsrc%d",current->track_index); - sprintf(str_parser,"audio_parser%d",current->track_index); + sprintf(str_appsrc, "audio_appsrc%d", current->track_index); + sprintf(str_parser, "audio_parser%d", current->track_index); current->appsrc = gst_element_factory_make("appsrc", str_appsrc); current->parser = gst_element_factory_make("aacparse", str_parser); @@ -492,7 +492,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 callback for cur->tr_ind = %d",current->track_index); + MX_I("\nRegistering 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", @@ -500,12 +500,12 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) #else g_object_set(current->appsrc, "block", TRUE, NULL); gst_app_src_set_stream_type((GstAppSrc *)current->appsrc, - GST_APP_STREAM_TYPE_STREAM); + GST_APP_STREAM_TYPE_STREAM); #endif gst_element_link(current->appsrc, current->parser); /* Link videoparse to muxer_video_pad. Request for muxer A/V pads. */ - sprintf(track_no,"audio_%.2d",aud_track_cnt++); /* sprintf(track_no,"audio_00"); */ + sprintf(track_no, "audio_%.2d", aud_track_cnt++); /* sprintf(track_no,"audio_00"); */ audio_pad = gst_element_get_request_pad(gst_handle->muxer, track_no); aud_src = gst_element_get_static_pad(current->parser, "src"); @@ -523,7 +523,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) MX_I("Output_uri= %s\n", gst_handle->output_uri); g_object_set(GST_OBJECT(gst_handle->sink), "location", - gst_handle->output_uri, NULL); + gst_handle->output_uri, NULL); /* connect signals, bus watcher */ bus = gst_pipeline_get_bus(GST_PIPELINE(gst_handle->pipeline)); @@ -532,7 +532,7 @@ mx_ret_e _gst_create_pipeline(mxgst_handle_t *gst_handle) /* set pipeline state to READY */ MEDIAMUXER_ELEMENT_SET_STATE(GST_ELEMENT_CAST(gst_handle->pipeline), - GST_STATE_READY); + GST_STATE_READY); return MX_ERROR_NONE; STATE_CHANGE_FAILED: @@ -541,7 +541,7 @@ ERROR: if (gst_handle->pipeline) gst_object_unref(GST_OBJECT(gst_handle->pipeline)); - for (current = gst_handle->track_info.track_head; current; current=current->next) { + for (current = gst_handle->track_info.track_head; current; current = current->next) { if (current->appsrc) gst_object_unref(GST_OBJECT(current->appsrc)); if (current->parser) @@ -586,7 +586,7 @@ static int gst_muxer_start(MMHandleType pHandle) /* set pipeline state to PLAYING */ MEDIAMUXER_ELEMENT_SET_STATE(GST_ELEMENT_CAST(gst_handle->pipeline), - GST_STATE_PLAYING); + GST_STATE_PLAYING); MEDIAMUXER_FLEAVE(); return ret; @@ -604,113 +604,113 @@ ERROR: } int __gst_codec_specific_caps(GstCaps *new_cap, - media_format_mimetype_e mimetype) + media_format_mimetype_e mimetype) { MEDIAMUXER_FENTER(); GValue val = G_VALUE_INIT; switch (mimetype) { - /*video*/ - case MEDIA_FORMAT_H261: - break; - case MEDIA_FORMAT_H263: - break; - case MEDIA_FORMAT_H263P: - break; - case MEDIA_FORMAT_H264_SP: - break; - case MEDIA_FORMAT_H264_MP: - break; - case MEDIA_FORMAT_H264_HP: - break; - case MEDIA_FORMAT_MJPEG: - break; - case MEDIA_FORMAT_MPEG1: - break; - case MEDIA_FORMAT_MPEG2_SP: - break; - case MEDIA_FORMAT_MPEG2_MP: - break; - case MEDIA_FORMAT_MPEG2_HP: - break; - case MEDIA_FORMAT_MPEG4_SP: - break; - case MEDIA_FORMAT_MPEG4_ASP: - break; - case MEDIA_FORMAT_HEVC: - break; - case MEDIA_FORMAT_VP8: - break; - case MEDIA_FORMAT_VP9: - break; - case MEDIA_FORMAT_VC1: - break; - case MEDIA_FORMAT_I420: - break; - case MEDIA_FORMAT_NV12: - break; - case MEDIA_FORMAT_NV12T: - break; - case MEDIA_FORMAT_YV12: - break; - case MEDIA_FORMAT_NV21: - break; - case MEDIA_FORMAT_NV16: - break; - case MEDIA_FORMAT_YUYV: - break; - case MEDIA_FORMAT_UYVY: - break; - case MEDIA_FORMAT_422P: - break; - case MEDIA_FORMAT_RGB565: - break; - case MEDIA_FORMAT_RGB888: - break; - case MEDIA_FORMAT_RGBA: - break; - case MEDIA_FORMAT_ARGB: - break; - /*audio*/ - case MEDIA_FORMAT_L16: - break; - case MEDIA_FORMAT_ALAW: - break; - case MEDIA_FORMAT_ULAW: - break; - case MEDIA_FORMAT_AMR: - break; - case MEDIA_FORMAT_AMR_WB: - break; - case MEDIA_FORMAT_G729: - break; - case MEDIA_FORMAT_AAC: - g_value_init(&val, G_TYPE_INT); - g_value_set_int(&val, 4); - gst_caps_set_value(new_cap, "mpegversion", &val); - break; - case MEDIA_FORMAT_AAC_HE: - g_value_init(&val, G_TYPE_INT); - g_value_set_int(&val, 4); - gst_caps_set_value(new_cap, "mpegversion", &val); - break; - case MEDIA_FORMAT_AAC_HE_PS: - g_value_init(&val, G_TYPE_INT); - g_value_set_int(&val, 4); - gst_caps_set_value(new_cap, "mpegversion", &val); - break; - case MEDIA_FORMAT_MP3: - break; - case MEDIA_FORMAT_VORBIS: - break; - case MEDIA_FORMAT_PCM: - break; - case MEDIA_FORMAT_PCMA: - break; - case MEDIA_FORMAT_PCMU: - break; - default: - MX_E("Unknown media mimeype %d. Assuming H264\n", mimetype); - break; + /* video */ + case MEDIA_FORMAT_H261: + break; + case MEDIA_FORMAT_H263: + break; + case MEDIA_FORMAT_H263P: + break; + case MEDIA_FORMAT_H264_SP: + break; + case MEDIA_FORMAT_H264_MP: + break; + case MEDIA_FORMAT_H264_HP: + break; + case MEDIA_FORMAT_MJPEG: + break; + case MEDIA_FORMAT_MPEG1: + break; + case MEDIA_FORMAT_MPEG2_SP: + break; + case MEDIA_FORMAT_MPEG2_MP: + break; + case MEDIA_FORMAT_MPEG2_HP: + break; + case MEDIA_FORMAT_MPEG4_SP: + break; + case MEDIA_FORMAT_MPEG4_ASP: + break; + case MEDIA_FORMAT_HEVC: + break; + case MEDIA_FORMAT_VP8: + break; + case MEDIA_FORMAT_VP9: + break; + case MEDIA_FORMAT_VC1: + break; + case MEDIA_FORMAT_I420: + break; + case MEDIA_FORMAT_NV12: + break; + case MEDIA_FORMAT_NV12T: + break; + case MEDIA_FORMAT_YV12: + break; + case MEDIA_FORMAT_NV21: + break; + case MEDIA_FORMAT_NV16: + break; + case MEDIA_FORMAT_YUYV: + break; + case MEDIA_FORMAT_UYVY: + break; + case MEDIA_FORMAT_422P: + break; + case MEDIA_FORMAT_RGB565: + break; + case MEDIA_FORMAT_RGB888: + break; + case MEDIA_FORMAT_RGBA: + break; + case MEDIA_FORMAT_ARGB: + break; + /* audio */ + case MEDIA_FORMAT_L16: + break; + case MEDIA_FORMAT_ALAW: + break; + case MEDIA_FORMAT_ULAW: + break; + case MEDIA_FORMAT_AMR: + break; + case MEDIA_FORMAT_AMR_WB: + break; + case MEDIA_FORMAT_G729: + break; + case MEDIA_FORMAT_AAC: + g_value_init(&val, G_TYPE_INT); + g_value_set_int(&val, 4); + gst_caps_set_value(new_cap, "mpegversion", &val); + break; + case MEDIA_FORMAT_AAC_HE: + g_value_init(&val, G_TYPE_INT); + g_value_set_int(&val, 4); + gst_caps_set_value(new_cap, "mpegversion", &val); + break; + case MEDIA_FORMAT_AAC_HE_PS: + g_value_init(&val, G_TYPE_INT); + g_value_set_int(&val, 4); + gst_caps_set_value(new_cap, "mpegversion", &val); + break; + case MEDIA_FORMAT_MP3: + break; + case MEDIA_FORMAT_VORBIS: + break; + case MEDIA_FORMAT_PCM: + break; + case MEDIA_FORMAT_PCMA: + break; + case MEDIA_FORMAT_PCMU: + break; + default: + MX_E("Unknown media mimeype %d. Assuming H264\n", mimetype); + break; } MEDIAMUXER_FLEAVE(); return 0; @@ -762,161 +762,160 @@ int _gst_set_caps(MMHandleType pHandle, media_packet_h packet, int track_index) } switch (formattype) { - case MEDIA_FORMAT_AUDIO: - /* Following check is safe but not mandatory. */ - if ((current->track_index)%NO_OF_TRACK_TYPES != 1) { - MX_E("\n\nThis is not an audio track_index. Track_index is not in 3*n+1 format\n\n"); - goto ERROR; - } - if (media_packet_get_extra(packet, - (void **)&codec_data)) { - MX_E("media_packet_get_extra call failed\n"); - ret = MX_ERROR_UNKNOWN; - break; - } - codec_data_size = strlen(codec_data) + 1; - MX_I("Extracted codec data is =%s size is %d\n", codec_data, codec_data_size); + case MEDIA_FORMAT_AUDIO: + /* Following check is safe but not mandatory. */ + if ((current->track_index)%NO_OF_TRACK_TYPES != 1) { + MX_E("\n\nThis is not an audio track_index. Track_index is not in 3*n+1 format\n\n"); + goto ERROR; + } + if (media_packet_get_extra(packet, + (void **)&codec_data)) { + MX_E("media_packet_get_extra call failed\n"); + ret = MX_ERROR_UNKNOWN; + break; + } + codec_data_size = strlen(codec_data) + 1; + MX_I("Extracted codec data is =%s size is %d\n", codec_data, codec_data_size); - if (current->caps == NULL || - g_strcmp0(codec_data, current->caps) != 0) { + if (current->caps == NULL || + g_strcmp0(codec_data, current->caps) != 0) { #ifndef SEND_FULL_CAPS_VIA_CODEC_DATA - if (media_format_get_audio_info(format, - &mimetype, &channel, &samplerate, - &bit, &avg_bps)) { - MX_E("media_format_get_audio_info call failed\n"); + if (media_format_get_audio_info(format, + &mimetype, &channel, &samplerate, + &bit, &avg_bps)) { + MX_E("media_format_get_audio_info call failed\n"); + ret = MX_ERROR_UNKNOWN; + break; + } + if (current->caps == NULL) { + current->caps = (char *)g_malloc(codec_data_size); + if (current->caps == NULL) { + MX_E("[%s][%d]memory allocation failed\n", __func__, __LINE__); ret = MX_ERROR_UNKNOWN; break; } + } + new_cap = gst_caps_from_string(codec_data); + if (__gst_codec_specific_caps(new_cap, mimetype)) { + MX_E("Setting Audio caps failed\n"); + gst_caps_unref(new_cap); + ret = MX_ERROR_UNKNOWN; + break; + } + caps_string = gst_caps_to_string(new_cap); + MX_I("New cap set by codec data is = %s\n", + caps_string); + if (caps_string) + g_free(caps_string); + g_object_set(current->appsrc, + "caps", new_cap, NULL); + MX_I("copying current->caps = codec_data\n"); + g_stpcpy(current->caps, codec_data); +#else + /* Debugging purpose. The whole caps filter can be sent via codec_data */ + new_cap = gst_caps_from_string(codec_data); + MX_I("codec cap is=%s\n", codec_data); + g_object_set(current->appsrc, + "caps", new_cap, NULL); + if (current->caps == NULL) { + current->caps = (char *)g_malloc(codec_data_size); if (current->caps == NULL) { - current->caps = (char *)g_malloc(codec_data_size); - if (current->caps == NULL) { - MX_E("[%s][%d]memory allocation failed\n", __func__, __LINE__); - ret = MX_ERROR_UNKNOWN; - break; - } - } - new_cap = gst_caps_from_string(codec_data); - if (__gst_codec_specific_caps(new_cap, mimetype)) { - MX_E("Setting Audio caps failed\n"); + MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); gst_caps_unref(new_cap); ret = MX_ERROR_UNKNOWN; break; } - caps_string = gst_caps_to_string(new_cap); - MX_I("New cap set by codec data is = %s\n", - caps_string); - if (caps_string) - g_free(caps_string); - g_object_set(current->appsrc, - "caps", new_cap, NULL); - MX_I("copying current->caps = codec_data\n"); - g_stpcpy(current->caps, codec_data); -#else - /*Debugging purpose. The whole caps filter can be sent via codec_data*/ - new_cap = gst_caps_from_string(codec_data); - MX_I("codec cap is=%s\n", codec_data); - g_object_set(current->appsrc, - "caps", new_cap, NULL); - if (current->caps == NULL) { - current->caps = (char *)g_malloc(codec_data_size); - if (current->caps == NULL) { - MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); - gst_caps_unref(new_cap); - ret = MX_ERROR_UNKNOWN; - break; - } - } - g_stpcpy(current->caps, codec_data); -#endif - gst_caps_unref(new_cap); } + g_stpcpy(current->caps, codec_data); +#endif + gst_caps_unref(new_cap); + } + break; + case MEDIA_FORMAT_VIDEO: + /* Following check is safe but not mandatory. */ + if ((current->track_index)%NO_OF_TRACK_TYPES != 0) { + MX_E("\n\nThis is not an video track_index. Video track_index is not in 3*n format\n\n"); + goto ERROR; + } + if (media_packet_get_extra(packet, + (void **)&codec_data)) { + MX_E("media_packet_get_extra call failed\n"); + ret = MX_ERROR_UNKNOWN; break; - case MEDIA_FORMAT_VIDEO: - /* Following check is safe but not mandatory. */ - if ((current->track_index)%NO_OF_TRACK_TYPES != 0) { - MX_E("\n\nThis is not an video track_index. Video track_index is not in 3*n format\n\n"); - goto ERROR; - } - if (media_packet_get_extra(packet, - (void **)&codec_data)) { - MX_E("media_packet_get_extra call failed\n"); - ret = MX_ERROR_UNKNOWN; - break; - } - codec_data_size = strlen(codec_data) + 1; - MX_I("codec data is =%s size is %d\n", - codec_data, codec_data_size); - if (current->caps == NULL || - g_strcmp0(codec_data, current->caps) != 0) { + } + codec_data_size = strlen(codec_data) + 1; + MX_I("codec data is =%s size is %d\n", + codec_data, codec_data_size); + if (current->caps == NULL || + g_strcmp0(codec_data, current->caps) != 0) { #ifndef SEND_FULL_CAPS_VIA_CODEC_DATA - if (media_format_get_video_info(format, - &mimetype, &width, &height, - &avg_bps, &max_bps)) { - MX_E("media_format_get_video_info call failed\n"); + if (media_format_get_video_info(format, + &mimetype, &width, &height, + &avg_bps, &max_bps)) { + MX_E("media_format_get_video_info call failed\n"); + ret = MX_ERROR_UNKNOWN; + break; + } + if (current->caps == NULL) { + current->caps = (char *)g_malloc(codec_data_size); + if (current->caps == NULL) { + MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); ret = MX_ERROR_UNKNOWN; break; } + } + new_cap = gst_caps_from_string(codec_data); + MX_I("New cap set by codec data is=%s\n", codec_data); + if (__gst_codec_specific_caps(new_cap, mimetype)) { + MX_E("Setting Audio caps failed\n"); + gst_caps_unref(new_cap); + ret = MX_ERROR_UNKNOWN; + break; + } + g_stpcpy(current->caps, codec_data); + + if (media_format_get_video_frame_rate(format, &numerator)) + MX_E("media_format_get_video_info call failed\n"); + g_value_init(&val, GST_TYPE_FRACTION); + gst_value_set_fraction(&val, numerator, denominator); + gst_caps_set_value(new_cap, "framerate", &val); + caps_string = gst_caps_to_string(new_cap); + MX_I("New cap set by codec data is = %s\n", + caps_string); + if (caps_string) + g_free(caps_string); + g_object_set(current->appsrc, "caps", new_cap, NULL); +#else + /* Debugging purpose. The whole caps filter can be sent via codec_data */ + media_packet_get_extra(packet, &codec_data); + codec_data_size = strlen(codec_data) + 1; + MX_I("extracted codec data is =%s\n", codec_data); + new_cap = gst_caps_from_string(codec_data); + MX_I("New cap is=%s\n", codec_data); + g_object_set(gst_handle->video_appsrc, "caps", new_cap, NULL); + if (current->caps == NULL) { + current->caps = (char *)g_malloc(codec_data_size); if (current->caps == NULL) { - current->caps = (char *)g_malloc(codec_data_size); - if (current->caps == NULL) { - MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); - ret = MX_ERROR_UNKNOWN; - break; - } - } - new_cap = gst_caps_from_string(codec_data); - MX_I("New cap set by codec data is=%s\n", codec_data); - if (__gst_codec_specific_caps(new_cap, mimetype)) { - MX_E("Setting Audio caps failed\n"); + MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); gst_caps_unref(new_cap); ret = MX_ERROR_UNKNOWN; break; } - g_stpcpy(current->caps, codec_data); - - if (media_format_get_video_frame_rate(format, &numerator)) { - MX_E("media_format_get_video_info call failed\n"); - } - g_value_init(&val, GST_TYPE_FRACTION); - gst_value_set_fraction(&val, numerator, denominator); - gst_caps_set_value(new_cap, "framerate", &val); - caps_string = gst_caps_to_string(new_cap); - MX_I("New cap set by codec data is = %s\n", - caps_string); - if (caps_string) - g_free(caps_string); - g_object_set(current->appsrc, "caps", new_cap, NULL); -#else - /*Debugging purpose. The whole caps filter can be sent via codec_data*/ - media_packet_get_extra(packet, &codec_data);, - codec_data_size = strlen(codec_data) + 1; - MX_I("extracted codec data is =%s\n", codec_data); - new_cap = gst_caps_from_string(codec_data); - MX_I("New cap is=%s\n", codec_data); - g_object_set(gst_handle->video_appsrc, "caps", new_cap, NULL); - if (current->caps == NULL) { - current->caps = (char *)g_malloc(codec_data_size); - if (current->caps == NULL) { - MX_E("[%s][%d] memory allocation failed\n", __func__, __LINE__); - gst_caps_unref(new_cap); - ret = MX_ERROR_UNKNOWN; - break; - } - } - g_stpcpy(current->caps, codec_data); -#endif - gst_caps_unref(new_cap); } - break; - case MEDIA_FORMAT_CONTAINER: - case MEDIA_FORMAT_TEXT: - case MEDIA_FORMAT_UNKNOWN: - default: - MX_E("Unknown format type\n"); + g_stpcpy(current->caps, codec_data); +#endif + gst_caps_unref(new_cap); + } + break; + case MEDIA_FORMAT_CONTAINER: + case MEDIA_FORMAT_TEXT: + case MEDIA_FORMAT_UNKNOWN: + default: + MX_E("Unknown format type\n"); } MEDIAMUXER_FLEAVE(); return ret; @@ -927,7 +926,7 @@ ERROR: } static int _gst_copy_media_packet_to_buf(media_packet_h out_pkt, - GstBuffer *buffer) + GstBuffer *buffer) { MEDIAMUXER_FENTER(); void *pkt_data; @@ -937,7 +936,7 @@ static int _gst_copy_media_packet_to_buf(media_packet_h out_pkt, MEDIAMUXER_CHECK_NULL(out_pkt); /* GstMapInfo map; */ int ret = MX_ERROR_NONE; - /* copy data*/ + /* copy data */ media_packet_get_buffer_size(out_pkt, &size); MX_I("Media packet Buffer capacity: %llu\n", size); data_ptr = (unsigned char *) g_malloc(size); @@ -953,16 +952,16 @@ static int _gst_copy_media_packet_to_buf(media_packet_h out_pkt, ret = MX_ERROR_UNKNOWN; goto ERROR; } - /*if (!gst_buffer_map (buffer, &map, GST_MAP_READ)) { + /* if (!gst_buffer_map (buffer, &map, GST_MAP_READ)) { MX_E("gst_buffer_map failed\n"); ret = MX_ERROR_UNKNOWN; goto ERROR; - }*/ + } */ uint64_t info; memcpy(data_ptr, (char *)pkt_data, size); gst_buffer_insert_memory(buffer, -1, - gst_memory_new_wrapped(0, data_ptr, size, 0, - size, data_ptr, g_free)); + gst_memory_new_wrapped(0, data_ptr, size, 0, + size, data_ptr, g_free)); if (media_packet_get_pts(out_pkt, &info)) { MX_E("unable to get the pts\n"); @@ -983,7 +982,7 @@ static int _gst_copy_media_packet_to_buf(media_packet_h out_pkt, goto ERROR; } buffer->duration = info; - /*TBD: set falgs is not available now in media_packet*/ + /* TBD: set falgs is not available now in media_packet */ media_buffer_flags_e flags; if (media_packet_get_flags(out_pkt, &flags)) { MX_E("unable to get the buffer size\n"); @@ -997,7 +996,7 @@ ERROR: } static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, - media_packet_h inbuf) + media_packet_h inbuf) { MEDIAMUXER_FENTER(); int ret = MX_ERROR_NONE; @@ -1015,7 +1014,7 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int 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); if (gst_handle->track_info.track_head->next) - MX_E("\n\next=%p\tnext->track_index=%d\n", gst_handle->track_info.track_head->next,gst_handle->track_info.track_head->next->track_index); + MX_E("\n\next=%p\tnext->track_index=%d\n", 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"); ret = MX_ERROR_INVALID_ARGUMENT; @@ -1023,7 +1022,7 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, } _gst_set_caps(pHandle, inbuf, track_index); - 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\n", track_index, current->track_index); GstBuffer *gst_inbuf2 = NULL; gst_inbuf2 = gst_buffer_new(); @@ -1032,9 +1031,9 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, _gst_copy_media_packet_to_buf(inbuf, gst_inbuf2); 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\n", current->track_index); #ifdef ASYCHRONOUS_WRITE - /*poll now to make it synchronous*/ + /* poll now to make it synchronous */ while (current->start_feed == 0) g_usleep(WRITE_POLL_PERIOD); MX_I("pushing video\n"); @@ -1050,7 +1049,7 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, MX_E("--video appsrc push failed--\n"); } } 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\n", current->track_index); #ifdef ASYCHRONOUS_WRITE while (current->start_feed == 0) g_usleep(WRITE_POLL_PERIOD); @@ -1065,7 +1064,7 @@ static int gst_muxer_write_sample(MMHandleType pHandle, int track_index, MX_E("--audio appsrc push failed--\n"); } } 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\n", track_index, track_index%NO_OF_TRACK_TYPES); ret = MX_ERROR_INVALID_ARGUMENT; } MEDIAMUXER_FLEAVE(); @@ -1091,7 +1090,7 @@ static int gst_muxer_close_track(MMHandleType pHandle, int track_index) goto ERROR; MX_I("__gst_muxer_stop setting eos to sources:%p\n", gst_handle); - if (gst_handle->pipeline!= NULL) { + if (gst_handle->pipeline != NULL) { if (track_index%NO_OF_TRACK_TYPES == 0) { MX_I("\n-----EOS for videoappsrc-----\n"); gst_app_src_end_of_stream((GstAppSrc *)(current->appsrc)); @@ -1177,7 +1176,7 @@ static int gst_muxer_stop(MMHandleType pHandle) MX_I("gst_muxer_stop making pipeline to ready:%p\n", gst_handle); /* set pipeline state to READY */ MEDIAMUXER_ELEMENT_SET_STATE(GST_ELEMENT_CAST(gst_handle->pipeline), - GST_STATE_READY); + GST_STATE_READY); MEDIAMUXER_FLEAVE(); return ret; STATE_CHANGE_FAILED: @@ -1202,9 +1201,8 @@ mx_ret_e _gst_destroy_pipeline(mxgst_handle_t *gst_handle) gst_element_set_state(gst_handle->pipeline, GST_STATE_NULL); /* Free resources & set unused pointers to NULL */ - if (gst_handle->output_uri != NULL) { + if (gst_handle->output_uri != NULL) gst_handle->output_uri = NULL; - } current = gst_handle->track_info.track_head; while (current) { @@ -1276,8 +1274,7 @@ int gst_set_error_cb(MMHandleType pHandle, gst_error_cb callback, void* user_dat MX_E("Already set mediamuxer_error_cb\n"); ret = MX_ERROR_INVALID_ARGUMENT; goto ERROR; - } - else { + } else { if (!callback) { ret = MX_ERROR_INVALID_ARGUMENT; goto ERROR; diff --git a/test/mediamuxer_test.c b/test/mediamuxer_test.c index 6d3e015..da3282a 100644 --- a/test/mediamuxer_test.c +++ b/test/mediamuxer_test.c @@ -41,7 +41,7 @@ | GLOBAL VARIABLE DEFINITIONS: | -----------------------------------------------------------------------*/ #define PACKAGE "mediamuxer_test" -#define TEST_FILE_SIZE (10 * 1024 * 1024) /*10M - test case */ +#define TEST_FILE_SIZE (10 * 1024 * 1024) /* 10M - test case */ #define MAX_STRING_LEN 256 #define MAX_HANDLE 10 #define DEFAULT_OUT_BUF_WIDTH 640 @@ -117,8 +117,7 @@ int track_index_aud; int track_index_aud2; /* demuxer sturcture for _demux_mp4() */ -typedef struct _CustomData -{ +typedef struct _CustomData { GstElement *pipeline; GstElement *source; GstElement *demuxer; @@ -196,7 +195,7 @@ static void _input_raw_filepath(char *filename) media_format_create(&input_fmt); - strncpy (g_uri, filename, len); + strncpy(g_uri, filename, len); g_len = len; bMultipleFiles = 0; @@ -213,7 +212,8 @@ static void _input_raw_filepath(char *filename) * This is needed as MediaCodec encoder generates a packet of raw AAC data. * Note the packetLen must count in the ADTS header itself. **/ -void _add_adts_header_for_aacenc(unsigned char *buffer, int packetLen) { +void _add_adts_header_for_aacenc(unsigned char *buffer, int packetLen) +{ int profile = 2; /* AAC LC (0x01) */ int freqIdx = 3; /* 48KHz (0x03) */ int chanCfg = 2; /* CPE (0x02) */ @@ -271,8 +271,8 @@ static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data) g_print("A%d write sample call. packet add:%p\n", ++count, pkt); - if (media_packet_get_buffer_size(pkt,&size)) { - g_print("unable to get the buffer size actual =%"PRIu64"\n",size); + if (media_packet_get_buffer_size(pkt, &size)) { + g_print("unable to get the buffer size actual =%"PRIu64"\n", size); return; } @@ -281,20 +281,19 @@ static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data) media_packet_get_duration(pkt, &duration); /* offset */ media_packet_get_flags(pkt, &flags); - media_packet_get_extra(pkt,(void**)&codec_data); + media_packet_get_extra(pkt, (void**)&codec_data); codec_data_size = strlen(codec_data) + 1; - g_print("***pkt attributes before writing *** Size=%"PRIu64", pts=%"PRIu64", dts=%"PRIu64", duration=%"PRIu64", flags=%d\n",size,pts,dts,duration,(int)flags); - g_print("Codec_data=%s\ncodec_data_size = %d\n",(char*)codec_data,codec_data_size); + g_print("***pkt attributes before writing *** Size=%"PRIu64", pts=%"PRIu64", dts=%"PRIu64", duration=%"PRIu64", flags=%d\n", size, pts, dts, duration, (int)flags); + g_print("Codec_data=%s\ncodec_data_size = %d\n", (char*)codec_data, codec_data_size); #if DUMP_OUTBUF if (count == 0) { fp_in = fopen("/opt/usr/codec_dump_mxr.aac", "wb"); - if (fp_in != NULL) { + if (fp_in != NULL) validate_dump = true; - } else { + else g_print("Error - Cannot open file for file dump, Please chek root\n"); - } } #endif @@ -335,11 +334,11 @@ void _mediacodec_set_aenc_info(int samplerate, int chnnel, int bit, int bitrate) void _mediacodec_set_venc_info(int width, int height, float fps, int target_bits) { g_print("_mediacodec_set_venc_info\n"); - if (g_media_codec[0] != NULL) { + if (g_media_codec[0] != NULL) mediacodec_set_venc_info(g_media_codec[0], width, height, fps, target_bits); - } else { + else g_print("mediacodec handle is not created\n"); - } + return; } @@ -349,7 +348,6 @@ static void _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data) if (pkt != NULL) { #if USE_INPUT_QUEUE media_packet_unset_flags(pkt, MEDIA_PACKET_CODEC_CONFIG); - //mc_async_queue_push(input_avaliable, pkt); g_queue_push_tail(&input_available, pkt); g_print("availablebuf = %p\n", pkt); #else @@ -390,15 +388,14 @@ void _mediacodec_prepare(void) g_print("\n*****NULL******\n"); ret = media_format_set_audio_mime(input_fmt, mimetype); - if (ret != MEDIA_FORMAT_ERROR_NONE) { + if (ret != MEDIA_FORMAT_ERROR_NONE) g_print("->media_format_set_audio_mime failed mime: %d\n", ret); - } media_format_set_audio_channel(input_fmt, channel); media_format_set_audio_samplerate(input_fmt, samplerate); media_format_set_audio_bit(input_fmt, bit); } - for (i=0; i < g_handle_num; i++) { + for (i = 0; i < g_handle_num; i++) { if (g_media_codec[i] != NULL) { g_print("setting codec callbacks"); mediacodec_set_input_buffer_used_cb(g_media_codec[i], _mediacodec_empty_buffer_cb, g_media_codec[i]); @@ -432,11 +429,10 @@ void _mediacodec_set_codec(int codecid, int flag) g_print("_mediacodec_configure\n"); g_print("codecid = 0x%x, flag = %d\n", codecid, flag); g_print("MyTag; codecid = %d, flag = %d\n", codecid, flag); - if (g_media_codec[0] != NULL) - { + if (g_media_codec[0] != NULL) { ret = mediacodec_set_codec(g_media_codec[0], (mediacodec_codec_type_e)codecid, flag); - if (ret!= MEDIACODEC_ERROR_NONE) { - g_print("mediacodec set codec is failed, ret = %d, ret_hex=%x\n", ret,ret); + if (ret != MEDIACODEC_ERROR_NONE) { + g_print("mediacodec set codec is failed, ret = %d, ret_hex=%x\n", ret, ret); return; } @@ -472,9 +468,9 @@ void _mediacodec_set_codec(int codecid, int flag) | HELPER FUNCTION | -----------------------------------------------------------------------*/ /* To aid muxer-codec test */ -int __extract_input_per_frame (FILE *fp, unsigned char *rawdata) +int __extract_input_per_frame(FILE *fp, unsigned char *rawdata) { - int readsize=0; + int readsize = 0; while (!feof(fp)) readsize += fread(rawdata+readsize, 1, 1, fp); return readsize; @@ -492,7 +488,7 @@ unsigned int __bytestream2yuv420(FILE *fd, unsigned char* yuv) read_size = width*height*3/2; - result = fread(buffer, 1,read_size, fd); + result = fread(buffer, 1, read_size, fd); g_print("3\n"); if (result != read_size) @@ -519,7 +515,7 @@ unsigned int __extract_input_aacenc(FILE *fd, unsigned char* rawdata) if (result != readsize) return -1; - memcpy(rawdata, buffer,readsize); + memcpy(rawdata, buffer, readsize); return readsize; } @@ -563,11 +559,11 @@ int __mediacodec_process_input(void) media_packet_get_buffer_data_ptr(in_buf, &data); if (data == NULL) return MEDIACODEC_ERROR_INVALID_PARAMETER; - printf("use_encoder=%d\n",use_encoder); + printf("use_encoder=%d\n", use_encoder); if (use_encoder) { if (use_video) { - /* Video Encoder */ + /* Video Encoder */ g_print("4 Video Encoder\n"); if (bMultipleFiles) { buf_size = __extract_input_per_frame(fp_src, data); @@ -585,20 +581,19 @@ int __mediacodec_process_input(void) } g_print("input pts = %"PRIu64"\n", pts); - media_packet_set_pts (in_buf, pts); + media_packet_set_pts(in_buf, pts); if (fps != 0) pts += (GST_SECOND / fps); } else { /* Audio Encoder - AAC */ buf_size = __extract_input_aacenc(fp_src, data); - printf("audio buf_size=%d\n",buf_size); - /* pts is not needed for muxer, if adts header is present*/ + printf("audio buf_size=%d\n", buf_size); + /* pts is not needed for muxer, if adts header is present */ /* media_packet_set_pts (in_buf, pts); */ g_print("----pts calculation: input pts = %"PRIu64", buf_size=%d samplerate=%d, samplebyte=%d\n", pts, buf_size, samplerate, samplebyte); - if (samplerate != 0) { + if (samplerate != 0) pts += ((GST_SECOND / samplerate) * samplebyte); - } } } @@ -606,26 +601,26 @@ int __mediacodec_process_input(void) if (use_video && buf_size == 4) { media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM); media_packet_set_buffer_size(in_buf, 4); - mediacodec_process_input (g_media_codec[0], in_buf, 0); + mediacodec_process_input(g_media_codec[0], in_buf, 0); g_print("\n\nEOS packet is sent\n"); return MEDIACODEC_ERROR_INVALID_INBUFFER; } media_packet_set_buffer_size(in_buf, buf_size); - g_print("%s - input_buf size = %4d (0x%x) at %4d frame, %p\n",__func__, buf_size, buf_size, frame_count, in_buf); + g_print("%s - input_buf size = %4d (0x%x) at %4d frame, %p\n", __func__, buf_size, buf_size, frame_count, in_buf); - ret = mediacodec_process_input (g_media_codec[0], in_buf, 0); + ret = mediacodec_process_input(g_media_codec[0], in_buf, 0); if (use_video && buf_size == -1) { - g_print("%s - END : input_buf size = %d frame_count : %d\n",__func__, buf_size, frame_count); + g_print("%s - END : input_buf size = %d frame_count : %d\n", __func__, buf_size, frame_count); return MEDIACODEC_ERROR_INVALID_INBUFFER; } } else { - g_print("%s - [WARN] Check to input buf_size = %4d at %4d frame, %p\n",__func__, buf_size, frame_count, in_buf); + g_print("%s - [WARN] Check to input buf_size = %4d at %4d frame, %p\n", __func__, buf_size, frame_count, in_buf); return MEDIACODEC_ERROR_INVALID_INBUFFER; } frame_count++; - g_print("returning, ret=%d, expected ret=%d\n",ret, MEDIACODEC_ERROR_NONE); + g_print("returning, ret=%d, expected ret=%d\n", ret, MEDIACODEC_ERROR_NONE); return ret; } @@ -654,7 +649,7 @@ void _mediacodec_process_all(void) /*----------------------------------------------------------------------- | HELPER FUNCTION | -----------------------------------------------------------------------*/ -/* Demuxer audio-appsink buffer receive callback*/ +/* Demuxer audio-appsink buffer receive callback */ static void __audio_app_sink_callback(GstElement *sink, CustomData *data) { GstBuffer *buffer; @@ -674,7 +669,7 @@ static void __audio_app_sink_callback(GstElement *sink, CustomData *data) buffer = gst_sample_get_buffer(sample); if (buffer) { if (gst_buffer_map(buffer, &map, GST_MAP_READ)) { - if (!GST_BUFFER_FLAG_IS_SET(buffer,GST_BUFFER_FLAG_DELTA_UNIT)) { + if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) { /* g_print( " Key Frame \n"); */ key = 1; } else { @@ -744,7 +739,6 @@ static void __audio_app_sink_callback(GstElement *sink, CustomData *data) /* Print count and size to indicate a received buffer */ g_print("Received audio buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n", ++count, ns, buffer->pts); - //g_print("Audio write sample call. packet add : %p\n", aud_pkt); mediamuxer_write_sample(myMuxer, track_index_aud, aud_pkt); if (validate_multitrack) mediamuxer_write_sample(myMuxer, track_index_aud2, aud_pkt); @@ -754,7 +748,7 @@ static void __audio_app_sink_callback(GstElement *sink, CustomData *data) } } -/* Demuxer video-appsink buffer receive callback*/ +/* Demuxer video-appsink buffer receive callback */ static void __video_app_sink_callback(GstElement *sink, CustomData *data) { GstBuffer *buffer; @@ -797,7 +791,7 @@ static void __video_app_sink_callback(GstElement *sink, CustomData *data) vsize = map.size; media_format_set_video_width(vidfmt, vsize/2+1); media_format_set_video_height(vidfmt, vsize/2+1); - /*frame rate is came from the caps filter of demuxer*/ + /* frame rate is came from the caps filter of demuxer */ if (media_format_set_video_frame_rate(vidfmt, 30)) { g_print("media_format_set_video_frame_rate failed\n"); return; @@ -814,7 +808,7 @@ static void __video_app_sink_callback(GstElement *sink, CustomData *data) } media_packet_get_buffer_data_ptr(vid_pkt, (void**)&dptr); - memcpy((char*)dptr, map.data,map.size); + memcpy((char*)dptr, map.data, map.size); if (media_packet_set_buffer_size(vid_pkt, (uint64_t)(map.size))) { g_print("video set_buffer_size failed\n"); @@ -854,7 +848,6 @@ static void __video_app_sink_callback(GstElement *sink, CustomData *data) /* Print count and size to indicate a received buffer */ g_print("Received video buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n", ++count, ns, buffer->pts); - //g_print("Video write sample call. packet add : %p\n", vid_pkt); mediamuxer_write_sample(myMuxer, track_index_vid, vid_pkt); media_packet_destroy(vid_pkt); } @@ -925,7 +918,7 @@ static void __on_pad_added(GstElement *element, GstPad *pad, CustomData *data) } else if (have_vid_track && g_str_has_prefix(new_pad_type, "video/x-h264")) { new_pad_vid_caps = gst_pad_get_current_caps(pad); caps = gst_caps_to_string(new_pad_vid_caps); - g_print(" Video caps :%s\n",caps); + g_print(" Video caps :%s\n", caps); vid_caps = caps; /* Link demuxer with videoqueue */ @@ -960,26 +953,25 @@ static gboolean __bus_call(GstBus *bus, GstMessage *mesg, gpointer data) { GMainLoop *dmxr_loop = (GMainLoop*)data; - switch (GST_MESSAGE_TYPE(mesg)) - { - case GST_MESSAGE_EOS: - g_print("Demuxer: End of stream\n"); - g_main_loop_quit(dmxr_loop); - break; + switch (GST_MESSAGE_TYPE(mesg)) { + case GST_MESSAGE_EOS: + g_print("Demuxer: End of stream\n"); + g_main_loop_quit(dmxr_loop); + break; - case GST_MESSAGE_ERROR: - { - gchar *dbg; - GError *err; - gst_message_parse_error(mesg, &err, &dbg); - g_free(dbg); - g_printerr("Demuxer-Error: %s\n", err->message); - g_error_free(err); - g_main_loop_quit(dmxr_loop); - break; - } - default: - break; + case GST_MESSAGE_ERROR: + { + gchar *dbg; + GError *err; + gst_message_parse_error(mesg, &err, &dbg); + g_free(dbg); + g_printerr("Demuxer-Error: %s\n", err->message); + g_error_free(err); + g_main_loop_quit(dmxr_loop); + break; + } + default: + break; } return TRUE; } @@ -1000,11 +992,11 @@ int _demux_mp4() return -1; } - gst_init(NULL,NULL); + gst_init(NULL, NULL); loop_dmx = g_main_loop_new(NULL, FALSE); data.loop = loop_dmx; - /* Create gstreamer elements for demuxer*/ + /* Create gstreamer elements for demuxer */ data.pipeline = gst_pipeline_new("DemuxerPipeline"); data.source = gst_element_factory_make("filesrc", "file-source"); data.demuxer = gst_element_factory_make("qtdemux", "mp4-demuxer"); @@ -1028,7 +1020,7 @@ int _demux_mp4() /* Add gstreamer-elements into gst-pipeline */ gst_bin_add_many(GST_BIN(data.pipeline), data.source, data.demuxer, data.dummysink, \ - data.audioqueue, data.videoqueue,data.audio_appsink, data.video_appsink, NULL); + data.audioqueue, data.videoqueue, data.audio_appsink, data.video_appsink, NULL); /* we set the input filename to the source element */ g_object_set(G_OBJECT(data.source), "location", file_mp4, NULL); @@ -1068,13 +1060,12 @@ int test_mediamuxer_create() g_print("test_mediamuxer_create\n"); g_print("myMuxer = %p\n", myMuxer); - if (mediamuxer_create(&myMuxer) != MEDIAMUXER_ERROR_NONE) { + if (mediamuxer_create(&myMuxer) != MEDIAMUXER_ERROR_NONE) g_print("mediamuxer create is failed\n"); - } g_print("Muxer->mx_handle created successfully with address = %p\n", - (void *)((mediamuxer_s *)myMuxer)->mx_handle); - g_print("Muxer handle created successfully with address = %p\n",myMuxer); + (void *)((mediamuxer_s *)myMuxer)->mx_handle); + g_print("Muxer handle created successfully with address = %p\n", myMuxer); return 0; } @@ -1087,9 +1078,8 @@ int test_mediamuxer_set_data_sink() /* Set data source after creating */ ret = mediamuxer_set_data_sink(myMuxer, op_uri, MEDIAMUXER_CONTAINER_FORMAT_MP4); - if (ret != MEDIAMUXER_ERROR_NONE) { + if (ret != MEDIAMUXER_ERROR_NONE) g_print("mediamuxer_set_data_sink is failed\n"); - } return 0; } @@ -1121,7 +1111,7 @@ int test_mediamuxer_add_track_video() g_print("Video Mimetype trying to set: %x (H264 : %x)\n", (int)(mimetype), (int)(MEDIA_FORMAT_H264_SP)); g_print("Video param trying to set: (width, height, avg_bps, max_bps): %d %d %d %d \n", - width, height, avg_bps, max_bps); + width, height, avg_bps, max_bps); /* To add video track */ mediamuxer_add_track(myMuxer, media_format, &track_index_vid); @@ -1164,7 +1154,7 @@ int test_mediamuxer_add_track_audio() g_print("Audio Mimetype trying to set: %x (AAC : %x)\n", (int)(mimetype), (int)(MEDIA_FORMAT_AAC_LC)); g_print("Audio Param trying to set: (ch, samplert, bt, avg_bps) %d %d %d %d \n", - channel, samplerate, bit, avg_bps); + channel, samplerate, bit, avg_bps); /* To add audio track */ mediamuxer_add_track(myMuxer, media_format_a, &track_index_aud); @@ -1208,7 +1198,7 @@ int test_mediamuxer_pause() g_print("test_mediamuxer_pause\n"); mediamuxer_state_e state; if (mediamuxer_get_state(myMuxer, &state) == MEDIAMUXER_ERROR_NONE) { - g_print("Mediamuxer_state=%d\n",state); + g_print("Mediamuxer_state=%d\n", state); if (state == MEDIAMUXER_STATE_MUXING) mediamuxer_pause(myMuxer); } @@ -1250,7 +1240,7 @@ int test_mediamuxer_destroy() void app_err_cb(mediamuxer_error_e error, void *user_data) { - printf("Got Error %d from mediamuxer\n",error); + printf("Got Error %d from mediamuxer\n", error); } int test_mediamuxer_set_error_cb() @@ -1344,17 +1334,15 @@ void _interpret_main_menu(char *cmd) g_print("unknown menu command. Please try again\n"); } } else if (len == 2 && validate_with_codec) { - if (strncmp(cmd, "cv", 2) == 0) { + if (strncmp(cmd, "cv", 2) == 0) g_menu_state = CURRENT_STATUS_RAW_VIDEO_FILENAME; - } else if (strncmp(cmd, "ve", 2) == 0) { + else if (strncmp(cmd, "ve", 2) == 0) g_menu_state = CURRENT_STATUS_SET_VENC_INFO; - } else if (strncmp(cmd, "ca", 2) == 0) { + else if (strncmp(cmd, "ca", 2) == 0) g_menu_state = CURRENT_STATUS_RAW_AUDIO_FILENAME; - } else if (strncmp(cmd, "ae", 2) == 0) { + else if (strncmp(cmd, "ae", 2) == 0) g_menu_state = CURRENT_STATUS_SET_AENC_INFO; - } - } - else { + } else { g_print("unknown menu command. Please try again\n"); } @@ -1395,101 +1383,100 @@ static void interpret(char *cmd) { switch (g_menu_state) { - case CURRENT_STATUS_MAINMENU: { - _interpret_main_menu(cmd); + case CURRENT_STATUS_MAINMENU: { + _interpret_main_menu(cmd); + break; + } + case CURRENT_STATUS_MP4_FILENAME: { + input_filepath(cmd); + strcpy(file_mp4, cmd); + g_menu_state = CURRENT_STATUS_MAINMENU; + break; + } + case CURRENT_STATUS_RAW_VIDEO_FILENAME: { /* "cv" */ + use_video = 1; + static int codecid = 0; + _input_raw_filepath(cmd); + use_encoder = 1; + codecid = 0x2030; /* video */ + _mediacodec_set_codec(codecid, 5); + reset_menu_state(); + g_menu_state = CURRENT_STATUS_MAINMENU; + break; + } + case CURRENT_STATUS_SET_VENC_INFO: /* "ve" */ + { + static int cnt = 0; + switch (cnt) { + case 0: + width = atoi(cmd); + cnt++; + break; + case 1: + height = atoi(cmd); + cnt++; + break; + case 2: + fps = atol(cmd); + cnt++; + break; + case 3: + target_bits = atoi(cmd); + g_print("width = %d, height = %d, fps = %f, target_bits = %d\n", width, height, fps, target_bits); + _mediacodec_set_venc_info(width, height, fps, target_bits); + _mediacodec_prepare(); + reset_menu_state(); + cnt = 0; + break; + default: + break; + } + } + break; + + case CURRENT_STATUS_RAW_AUDIO_FILENAME: + { /* "ca" */ + use_video = 0; + static int codecid = 0; + _input_raw_filepath(cmd); + use_encoder = 1; + codecid = 0x1060; /* audio */ + _mediacodec_set_codec(codecid, 9); + reset_menu_state(); + g_menu_state = CURRENT_STATUS_MAINMENU; + break; + } + + case CURRENT_STATUS_SET_AENC_INFO: /* ae */ + { + static int cnt = 0; + switch (cnt) { + case 0: + samplerate = atoi(cmd); + cnt++; break; - } - case CURRENT_STATUS_MP4_FILENAME: { - input_filepath(cmd); - strcpy(file_mp4, cmd); - g_menu_state = CURRENT_STATUS_MAINMENU; + case 1: + channel = atoi(cmd); + cnt++; break; - } - case CURRENT_STATUS_RAW_VIDEO_FILENAME: { /* "cv" */ - use_video = 1; - static int codecid = 0; - _input_raw_filepath(cmd); - use_encoder = 1; - codecid = 0x2030; /* video */ - _mediacodec_set_codec(codecid, 5); - reset_menu_state(); - g_menu_state = CURRENT_STATUS_MAINMENU; + case 2: + bit = atoi(cmd); + cnt++; break; - } - case CURRENT_STATUS_SET_VENC_INFO: /* "ve" */ - { - static int cnt = 0; - switch (cnt) { - case 0: - width = atoi(cmd); - cnt++; - break; - case 1: - height = atoi(cmd); - cnt++; - break; - case 2: - fps = atol(cmd); - cnt++; - break; - case 3: - target_bits = atoi(cmd); - g_print("width = %d, height = %d, fps = %f, target_bits = %d\n", width, height, fps, target_bits); - _mediacodec_set_venc_info(width, height, fps, target_bits); - _mediacodec_prepare(); - reset_menu_state(); - cnt = 0; - break; - default: - break; - } - } - break; - - case CURRENT_STATUS_RAW_AUDIO_FILENAME: - { /* "ca" */ - use_video = 0; - static int codecid = 0; - _input_raw_filepath(cmd); - use_encoder = 1; - codecid = 0x1060; /* audio */ - _mediacodec_set_codec(codecid, 9); + case 3: + bitrate = atoi(cmd); + _mediacodec_set_aenc_info(samplerate, channel, bit, bitrate); + _mediacodec_prepare(); reset_menu_state(); - g_menu_state = CURRENT_STATUS_MAINMENU; + cnt = 0; + break; + default: break; } - - case CURRENT_STATUS_SET_AENC_INFO: /* ae */ - { - static int cnt = 0; - switch (cnt) - { - case 0: - samplerate = atoi(cmd); - cnt++; - break; - case 1: - channel = atoi(cmd); - cnt++; - break; - case 2: - bit = atoi(cmd); - cnt++; - break; - case 3: - bitrate = atoi(cmd); - _mediacodec_set_aenc_info(samplerate, channel,bit,bitrate); - _mediacodec_prepare(); - reset_menu_state(); - cnt = 0; - break; - default: - break; - } - } - break; - default: - break; + } + break; + default: + break; } g_timeout_add(100, timeout_menu_display, 0); }