Cleaned the code whenever needed.
Addressed review comments
Change-Id: I688db93fce1de8ff9ec69b7dd8d5acb029c6109a
Signed-off-by: Mahesh Kondiparthi <kd.mahesh@samsung.com>
* 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()
* @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()
#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)
#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)
#ifdef __cplusplus
}
#endif
-#endif /*__TIZEN_MEDIAMUXER_INI_H__*/
+#endif /* __TIZEN_MEDIAMUXER_INI_H__ */
#ifndef __TIZEN_MEDIAMUXER_PORT_H__
#define __TIZEN_MEDIAMUXER_PORT_H__
-/*=============================================================================
+/* ============================================================================
| |
| INCLUDE FILES |
| |
-==============================================================================*/
+============================================================================= */
#include <glib.h>
#include <mm_types.h>
*/
-/*=============================================================================|
+/* ============================================================================|
| |
| GLOBAL DEFINITIONS AND DECLARATIONS |
| |
-==============================================================================*/
+============================================================================= */
/**
* @brief Called when error occurs in media muxer.
* @details Following error codes can be delivered.
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
* @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
#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
extern "C" {
#endif
-//#define PRINT_ON_CONSOLE
+/* #define PRINT_ON_CONSOLE */
#ifdef PRINT_ON_CONSOLE
#include <stdlib.h>
#include <stdio.h>
#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
#else
#include <stdlib.h>
#include <stdio.h>
-#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();
#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)
extern "C" {
#endif
-/*Place holder */
+/* Place holder */
#ifdef __cplusplus
}
extern "C" {
#endif
-/*Place holder */
+/* Place holder */
#ifdef __cplusplus
}
#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; \
}
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)",
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);
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) {
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;
}
#include <mediamuxer_error.h>
/* 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 = " ,"; \
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
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")) {
/* 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;
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:
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:
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:
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:
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:
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:
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:
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:
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:
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) {
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();
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,
}
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__);
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,
}
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();
#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,
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,
}
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;
}
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;
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;
}
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)++;
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 ||
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;
/* 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;
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;
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;
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
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
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
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
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);
#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");
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);
#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",
#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");
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));
/* 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:
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)
/* 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;
}
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;
}
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;
}
static int _gst_copy_media_packet_to_buf(media_packet_h out_pkt,
- GstBuffer *buffer)
+ GstBuffer *buffer)
{
MEDIAMUXER_FENTER();
void *pkt_data;
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);
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");
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");
}
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;
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;
}
_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();
_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");
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);
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();
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));
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:
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) {
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;
| 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
int track_index_aud2;
/* demuxer sturcture for _demux_mp4() */
-typedef struct _CustomData
-{
+typedef struct _CustomData {
GstElement *pipeline;
GstElement *source;
GstElement *demuxer;
media_format_create(&input_fmt);
- strncpy (g_uri, filename, len);
+ strncpy(g_uri, filename, len);
g_len = len;
bMultipleFiles = 0;
* 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) */
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;
}
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
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;
}
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
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]);
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;
}
| 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;
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)
if (result != readsize)
return -1;
- memcpy(rawdata, buffer,readsize);
+ memcpy(rawdata, buffer, readsize);
return readsize;
}
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);
}
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);
- }
}
}
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;
}
/*-----------------------------------------------------------------------
| 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;
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 {
/* 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);
}
}
-/* Demuxer video-appsink buffer receive callback*/
+/* Demuxer video-appsink buffer receive callback */
static void __video_app_sink_callback(GstElement *sink, CustomData *data)
{
GstBuffer *buffer;
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;
}
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");
/* 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);
}
} 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 */
{
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;
}
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");
/* 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);
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;
}
/* 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;
}
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);
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);
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);
}
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()
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");
}
{
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);
}