From 76fe3ad5da0e9b3ba3b8319799955aa54353866e Mon Sep 17 00:00:00 2001 From: Zhao Cancan Date: Tue, 20 Dec 2016 01:11:06 -0500 Subject: [PATCH 01/16] fix memory leak in error cases of feed_task function Change-Id: I7adca39677fb64ce0a48880b433baf0b11751c7e --- packaging/capi-media-codec.spec | 2 +- src/media_codec_port_gst.c | 104 ++++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 92cb31b..293d7b8 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -1,6 +1,6 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API -Version: 0.5.0 +Version: 0.5.1 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index d7856a3..5d0d5d6 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -47,7 +47,7 @@ static mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name static mc_ret_e _mc_gst_destroy_pipeline(mc_gst_core_t *core); static void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data); static int __mc_output_buffer_finalize_cb(media_packet_h packet, int error_code, void *user_data); -static int _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer* buff, bool codec_config); +static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool codec_config); static gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt); static GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h pkt, bool codec_config); static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *buff); @@ -56,12 +56,13 @@ static media_packet_h __mc_gst_make_media_packet(mc_gst_core_t *core, unsigned c static gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data); static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, gpointer data); static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h pkt); -static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t* core, media_packet_h pkt, uint64_t size); +static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h pkt, uint64_t size); static void gst_mediacodec_buffer_finalize(GstMCBuffer *buffer); -static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer*buff, guint streamheader_size); -static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer*buff, guint codecdata_size); +static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *buff, guint streamheader_size); +static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint codecdata_size); static void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_pkt); static int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_pkt); +static void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h pkt); static gint __gst_handle_stream_error(mc_gst_core_t *core, GError *error, GstMessage *message); static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage *message, GError *error); @@ -185,7 +186,7 @@ int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer data get fail"); return MC_ERROR; } @@ -221,7 +222,7 @@ int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer data get fail"); return MC_ERROR; } @@ -581,7 +582,7 @@ int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer*buff, guint stre ret = media_packet_get_buffer_data_ptr(buff->pkt, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer data get fail"); return ret; } @@ -1029,11 +1030,12 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt) return is_updated; } -static int _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer* buff, bool codec_config) +static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool codec_config) { MEDIACODEC_FENTER(); g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); + g_return_val_if_fail(buff != NULL, MC_PARAM_ERROR); int ret = MC_ERROR_NONE; @@ -1041,7 +1043,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstMCBuf if (core->encoder) { mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info; - core->format = __mc_get_gst_input_format(pkt, core->is_hw); + core->format = __mc_get_gst_input_format(buff->pkt, core->is_hw); gst_caps_set_simple(core->caps, "format", G_TYPE_STRING, core->format, "width", G_TYPE_INT, enc_info->width, @@ -1053,7 +1055,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, media_packet_h pkt, GstMCBuf g_object_set(GST_OBJECT(core->codec), "bitrate", enc_info->bitrate, NULL); else g_object_set(GST_OBJECT(core->codec), "target-bitrate", enc_info->bitrate, NULL); - + LOGD("set bitrate = %d.", enc_info->bitrate); } else { mc_decoder_info_t *dec_info = (mc_decoder_info_t *)core->codec_info; @@ -1140,7 +1142,6 @@ static gpointer feed_task(gpointer data) while (g_atomic_int_get(&core->available_queue->running)) { LOGD("waiting for next input...."); in_buf = _mc_get_input_buffer(core); - if (!in_buf) goto LEAVE; @@ -1160,12 +1161,27 @@ static gpointer feed_task(gpointer data) LOGE("media_packet_is_end_of_stream failed"); goto ERROR; } + /* + * receive an eos packet. For decoder + encoder case, encoder always get tbm surface plane first from input data, + * but eos packet only has flag not valid data, so we don't put it to downstream. + */ + if (eos) { + LOGD("end of stream"); + gst_app_src_end_of_stream(GST_APP_SRC(core->appsrc)); + _mc_wait_for_eos(core); + initiative = true; + + _mc_gst_handle_input_buffer_used(core, in_buf); + goto LEAVE; + } buff = _mc_gst_media_packet_to_gstbuffer(core, in_buf, codec_config); if (!buff) { LOGW("gstbuffer can't make"); goto ERROR; } + /* buff took the ownership of the in_buf, so set in_buf to NULL to aviod double unref */ + in_buf = NULL; if (codec_config) initiative = TRUE; @@ -1173,9 +1189,11 @@ static gpointer feed_task(gpointer data) if (initiative) { GstPad *pad; - ret = _mc_gst_update_caps(core, in_buf, buff, codec_config); + ret = _mc_gst_update_caps(core, buff, codec_config); if (ret != MC_ERROR_NONE) { LOGE("failed to update caps"); + /* unref buff->buffer will invoke the finalize() of GstMcBuffer */ + gst_buffer_unref(buff->buffer); goto ERROR; } @@ -1195,16 +1213,11 @@ static gpointer feed_task(gpointer data) initiative = false; - if (eos) { - LOGD("end of stream"); - gst_app_src_end_of_stream(GST_APP_SRC(core->appsrc)); - _mc_wait_for_eos(core); - initiative = true; - } - - continue; ERROR: + if (in_buf) + _mc_gst_handle_input_buffer_used(core, in_buf); + _mc_gst_set_flush_input(core); if (core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) { @@ -2034,10 +2047,10 @@ void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_pkt) GstBuffer *buffer = NULL; media_packet_get_extra(out_pkt, (void**)&buffer); if (buffer) { - LOGD("dq : %d TIMESTAMP = %"GST_TIME_FORMAT " DURATION = %"GST_TIME_FORMAT, + LOGD("dq : v(%d)e(%d) %d TIMESTAMP = %"GST_TIME_FORMAT " DURATION = %"GST_TIME_FORMAT, core->video, core->encoder, core->ftb_count, GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)), GST_TIME_ARGS(GST_BUFFER_DURATION(buffer))); } else { - LOGD("dq : %d ", core->ftb_count); + LOGD("dq : v(%d)e(%d) %d ", core->video, core->encoder, core->ftb_count); } g_mutex_unlock(&core->ports[1]->mutex); @@ -2181,7 +2194,7 @@ gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw) return format; } -GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t* core, media_packet_h pkt, bool codec_config) +GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h pkt, bool codec_config) { int ret = MEDIA_PACKET_ERROR_NONE; GstMCBuffer *mc_buffer = NULL; @@ -2198,7 +2211,7 @@ GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t* core, media_packet ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer data get fail"); return NULL; } @@ -2208,11 +2221,17 @@ GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t* core, media_packet return NULL; } - LOGD("pkt : %p, buf_size : %d", pkt, (int)buf_size); + LOGD("pkt :v(%d)e(%d) %p, buf_size : %d", core->video, core->encoder, pkt, (int)buf_size); ret = __mc_fill_input_buffer(core, pkt, mc_buffer); if (ret != MC_ERROR_NONE) { LOGW("failed to fill inbuf: %s (ox%08x)", _mc_error_to_string(ret), ret); + /* + * if __mc_fill_input_buffer() failed, no memory appended to mc_buffer->buffer, so gst_mediacodec_buffer_finalize() + * will not be invoked + */ + gst_buffer_unref(mc_buffer->buffer); + free(mc_buffer); return NULL; } @@ -2248,7 +2267,7 @@ int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_pkt) int ret = MC_ERROR_NONE; MEDIACODEC_FENTER(); - if (media_packet_create_alloc(fmt, NULL, NULL, &mediabuf)) { + if (media_packet_create(fmt, NULL, NULL, &mediabuf)) { LOGE("media_packet_create_alloc failed\n"); ret = MC_ERROR; goto ERROR; @@ -2272,6 +2291,19 @@ ERROR: return ret; } +void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h pkt) +{ + g_atomic_int_dec_and_test(&core->etb_count); + + if (core && core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) { + ((mc_empty_buffer_cb)core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) + (pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); + } + + if (core) + LOGD("@v(%d)e(%d) input port emptied buffer(%d): %p", core->video, core->encoder, core->etb_count, pkt); +} + gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) { int ret = MC_ERROR_NONE; @@ -2398,7 +2430,7 @@ static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, return reply; } -static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t* core, media_packet_h pkt) +static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h pkt) { int i; int num_bos; @@ -2488,13 +2520,8 @@ static void gst_mediacodec_buffer_finalize(GstMCBuffer *mc_buffer) mc_gst_core_t *core = (mc_gst_core_t *)mc_buffer->core; - g_atomic_int_dec_and_test(&core->etb_count); - if (core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) { - ((mc_empty_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) - (mc_buffer->pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); - } + _mc_gst_handle_input_buffer_used(core, mc_buffer->pkt); - LOGD("@v(%d)e(%d)input port emptied buffer(%d): %p", core->video, core->encoder, core->etb_count, mc_buffer->pkt); free(mc_buffer); mc_buffer = NULL; @@ -2503,7 +2530,7 @@ static void gst_mediacodec_buffer_finalize(GstMCBuffer *mc_buffer) return; } -static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t* core, media_packet_h pkt, uint64_t size) +static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h pkt, uint64_t size) { GstMCBuffer *mc_buffer = NULL; @@ -2604,7 +2631,7 @@ static gint __gst_handle_resource_error(mc_gst_core_t *core, int code) return trans_err; } -static gint __gst_handle_stream_error(mc_gst_core_t *core, GError* error, GstMessage * message) +static gint __gst_handle_stream_error(mc_gst_core_t *core, GError *error, GstMessage *message) { gint trans_err = MEDIACODEC_ERROR_NONE; @@ -2637,7 +2664,7 @@ static gint __gst_handle_stream_error(mc_gst_core_t *core, GError* error, GstMes return trans_err; } -static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage * message, GError* error) +static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage *message, GError *error) { gchar *src_element_name = NULL; GstElement *src_element = NULL; @@ -2725,10 +2752,7 @@ static void _mc_gst_set_flush_input(mc_gst_core_t *core) g_atomic_int_dec_and_test(&core->etb_count); LOGD("%p poped(%d)", pkt, core->etb_count); - if (core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) { - ((mc_empty_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) - (pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); - } + _mc_gst_handle_input_buffer_used(core, pkt); } mc_async_queue_flush(core->available_queue->input); -- 2.7.4 From 11333fa2ba322163aeed745a9d1dfbaf7f71b446 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 23 Dec 2016 13:56:04 +0900 Subject: [PATCH 02/16] Changed to previous codec data configuration logic Change-Id: I3a7a249c2a6ace6ca9e77171221c6675cb03394a --- src/media_codec_port_gst.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 5d0d5d6..3a87d42 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -782,26 +782,22 @@ int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint fixed_ media_packet_get_buffer_size(buff->pkt, &buffer_size); media_packet_get_buffer_data_ptr(buff->pkt, &buff_data); - ret = __mc_get_codecdata_size(core, buff, &codec_data_size); - LOGD("First Frame contains codec_data_size= %d", codec_data_size); - - if ((ret == MC_ERROR_NONE) && (codec_data_size > 0)) { - data = g_malloc0(codec_data_size); + /* For audio, it's necessary to change the offset value of buffer after extracting csd */ + /* it's not necessary to set csd to caps in case of annex-b */ + if (buffer_size > fixed_size) { + data = g_malloc0(fixed_size); gst_buffer_map(buff->buffer, &map, GST_MAP_READ); - memcpy(data, map.data, codec_data_size); - codecdata_buffer = gst_buffer_new_wrapped(data, codec_data_size); + memcpy(data, map.data, fixed_size); + codecdata_buffer = gst_buffer_new_wrapped(data, fixed_size); gst_buffer_unmap(buff->buffer, &map); gst_caps_set_simple(core->caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL); gst_buffer_unref(codecdata_buffer); - GstMemory *memory = NULL; - memory = gst_buffer_peek_memory(buff->buffer, 0); - gst_memory_resize(memory, codec_data_size, buffer_size - codec_data_size); - LOGD("First frame remained size : %d", gst_buffer_get_size(buff->buffer)); - } else { - if (ret != MC_ERROR_NONE) { - LOGE("No valid codec data in the packet!"); - } + gst_buffer_replace_memory(buff->buffer, 0, + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buff_data + fixed_size , buffer_size - fixed_size, 0, + buffer_size - fixed_size, buff, NULL)); + + LOGD("set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer)); } } return ret; -- 2.7.4 From a09f5df82c49a296df57212c8fb0b981fcf55f55 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 23 Dec 2016 16:49:26 +0900 Subject: [PATCH 03/16] Modified spelling and typo Change-Id: I7db668f373bc55e23217da22205d91e628733800 --- include/media_codec_port_gst.h | 18 +- packaging/capi-media-codec.spec | 2 +- src/media_codec_port_gst.c | 392 ++++++++++++++++++++-------------------- 3 files changed, 205 insertions(+), 207 deletions(-) diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index 64536ad..d0aa50d 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -154,21 +154,21 @@ struct _GstMCBuffer { GstBuffer *buffer; int buf_size; mc_gst_core_t* core; - media_packet_h pkt; + media_packet_h packet; bool has_imgb; }; enum { fill_inbuf, fill_outbuf }; -int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); -int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); +int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); +int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); -int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff); -int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer); +int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); +int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); -int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); -int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt); -int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt); +int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); +int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); +int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *packet); mc_gst_core_t *mc_gst_core_new(); void mc_gst_core_free(mc_gst_core_t *core); @@ -184,7 +184,7 @@ mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint6 mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle); -mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt_pool); +mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *packet_pool); #ifdef __cplusplus } diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 293d7b8..2665e0c 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -1,6 +1,6 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API -Version: 0.5.1 +Version: 0.5.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 3a87d42..9d5c3b2 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -47,22 +47,22 @@ static mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name static mc_ret_e _mc_gst_destroy_pipeline(mc_gst_core_t *core); static void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data); static int __mc_output_buffer_finalize_cb(media_packet_h packet, int error_code, void *user_data); -static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool codec_config); +static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config); static gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt); -static GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h pkt, bool codec_config); -static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *buff); +static GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h packet, bool codec_config); +static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer); static gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw); static media_packet_h __mc_gst_make_media_packet(mc_gst_core_t *core, unsigned char *data, int size); static gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data); static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, gpointer data); -static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h pkt); -static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h pkt, uint64_t size); +static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h packet); +static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size); static void gst_mediacodec_buffer_finalize(GstMCBuffer *buffer); -static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *buff, guint streamheader_size); -static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint codecdata_size); -static void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_pkt); -static int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_pkt); -static void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h pkt); +static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint streamheader_size); +static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint codecdata_size); +static void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_packet); +static int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_packet); +static void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h packet); static gint __gst_handle_stream_error(mc_gst_core_t *core, GError *error, GstMessage *message); static gint __gst_transform_gsterror(mc_gst_core_t *core, GstMessage *message, GError *error); @@ -165,12 +165,12 @@ int(*adec_wma_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* * fill_inbuf virtual functions */ -int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff) +int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) { - return core->vtable[fill_inbuf](core, pkt, buff); + return core->vtable[fill_inbuf](core, packet, mcbuffer); } -int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) +int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) { int ret = MC_ERROR_NONE; @@ -178,65 +178,65 @@ int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pkt void *buf_data = NULL; uint64_t buf_size = 0; - ret = media_packet_get_buffer_size(pkt, &buf_size); + ret = media_packet_get_buffer_size(packet, &buf_size); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer size get failed"); return MC_ERROR; } - ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); + ret = media_packet_get_buffer_data_ptr(packet, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer data get fail"); + LOGW("buffer data get failed"); return MC_ERROR; } - mm_vbuffer = __mc_gst_make_tbm_buffer(core, mc_buffer->pkt); + mm_vbuffer = __mc_gst_make_tbm_buffer(core, mcbuffer->packet); if (mm_vbuffer != NULL) { - gst_buffer_prepend_memory(mc_buffer->buffer, + gst_buffer_prepend_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_vbuffer, sizeof(*mm_vbuffer), 0, sizeof(*mm_vbuffer), mm_vbuffer, free)); - LOGD("scmn_mm_vbuffer is appended, %d, %d", sizeof(*mm_vbuffer), gst_buffer_n_memory(mc_buffer->buffer)); + LOGD("mm_vbuffer appended, %d, %d", sizeof(*mm_vbuffer), gst_buffer_n_memory(mcbuffer->buffer)); } if (buf_data != NULL) { - gst_buffer_prepend_memory(mc_buffer->buffer, + gst_buffer_prepend_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, - buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); - LOGD("packet data apended, %d, %d", buf_size, gst_buffer_n_memory(mc_buffer->buffer)); + buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + LOGD("packet data apended, %d, %d", buf_size, gst_buffer_n_memory(mcbuffer->buffer)); } return ret; } -int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) +int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) { int ret = MC_ERROR_NONE; void *buf_data = NULL; uint64_t buf_size = 0; - ret = media_packet_get_buffer_size(pkt, &buf_size); + ret = media_packet_get_buffer_size(packet, &buf_size); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer size get failed"); return MC_ERROR; } - ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); + ret = media_packet_get_buffer_data_ptr(packet, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer data get fail"); + LOGW("buffer data get failed"); return MC_ERROR; } if (buf_data != NULL) { - gst_buffer_append_memory(mc_buffer->buffer, + gst_buffer_append_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, - buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); LOGD("packet data apended"); } return ret; } -int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer) +int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) { int ret = MC_ERROR_NONE; void *uv_ptr = NULL; @@ -256,88 +256,86 @@ int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h width = enc_info->width; height = enc_info->height; - ret = media_packet_get_number_of_video_planes(pkt, &plane_num); + ret = media_packet_get_number_of_video_planes(packet, &plane_num); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_get_number_of_video_planes failed"); return MC_ERROR; } - ret = media_packet_get_video_plane_data_ptr(pkt, 0, &y_ptr); + ret = media_packet_get_video_plane_data_ptr(packet, 0, &y_ptr); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_get_video_plane_data_ptr failed"); return MC_ERROR; } - ret = media_packet_get_video_stride_width(pkt, 0, &stride_width); + ret = media_packet_get_video_stride_width(packet, 0, &stride_width); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_get_video_stride_width failed"); return MC_ERROR; } - ret = media_packet_get_video_stride_height(pkt, 0, &stride_height); + ret = media_packet_get_video_stride_height(packet, 0, &stride_height); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_get_video_stride_width failed"); return MC_ERROR; } if (!core->is_hw) { - if (width == stride_width) { - mc_buffer->buf_size += stride_width * stride_height; + mcbuffer->buf_size += stride_width * stride_height; for (i = 1; i < plane_num; i++) { - media_packet_get_video_plane_data_ptr(pkt, i, &uv_ptr); - media_packet_get_video_stride_width(pkt, i, &stride_width); - media_packet_get_video_stride_height(pkt, i, &stride_height); + media_packet_get_video_plane_data_ptr(packet, i, &uv_ptr); + media_packet_get_video_stride_width(packet, i, &stride_width); + media_packet_get_video_stride_height(packet, i, &stride_height); buf_size = stride_width * stride_height; - memcpy(y_ptr + mc_buffer->buf_size, uv_ptr, buf_size); - mc_buffer->buf_size += buf_size; - LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mc_buffer->buf_size); - + memcpy(y_ptr + mcbuffer->buf_size, uv_ptr, buf_size); + mcbuffer->buf_size += buf_size; + LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mcbuffer->buf_size); } } else { for (j = 0; j < height; j++) { - memcpy(y_ptr + mc_buffer->buf_size, y_ptr + stride, width); - mc_buffer->buf_size += width; + memcpy(y_ptr + mcbuffer->buf_size, y_ptr + stride, width); + mcbuffer->buf_size += width; stride += stride_width; } stride = 0; for (i = 1; i < plane_num; i++) { - media_packet_get_video_plane_data_ptr(pkt, i, &uv_ptr); - media_packet_get_video_stride_width(pkt, i, &stride_width); - media_packet_get_video_stride_height(pkt, i, &stride_height); + media_packet_get_video_plane_data_ptr(packet, i, &uv_ptr); + media_packet_get_video_stride_width(packet, i, &stride_width); + media_packet_get_video_stride_height(packet, i, &stride_height); for (j = 0; j < height>>1; j++) { - memcpy(y_ptr + mc_buffer->buf_size, uv_ptr + stride, width>>1); - mc_buffer->buf_size += width>>1; + memcpy(y_ptr + mcbuffer->buf_size, uv_ptr + stride, width>>1); + mcbuffer->buf_size += width>>1; stride += stride_width; } - memcpy(y_ptr + mc_buffer->buf_size, uv_ptr, buf_size); - LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mc_buffer->buf_size); - mc_buffer->buf_size += buf_size; + memcpy(y_ptr + mcbuffer->buf_size, uv_ptr, buf_size); + LOGD("plane : %d, buf_size : %d, total : %d", i, buf_size, mcbuffer->buf_size); + mcbuffer->buf_size += buf_size; } } } else { MMVideoBuffer *mm_video_buffer = NULL; - mm_video_buffer = __mc_gst_make_tbm_buffer(core, pkt); + mm_video_buffer = __mc_gst_make_tbm_buffer(core, packet); - gst_buffer_prepend_memory(mc_buffer->buffer, + gst_buffer_prepend_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, mm_video_buffer, sizeof(MMVideoBuffer), 0, sizeof(MMVideoBuffer), mm_video_buffer, free)); - LOGD("mm_video_buffer is appended, %d, %d", sizeof(MMVideoBuffer), gst_buffer_n_memory(mc_buffer->buffer)); + LOGD("mm_video_buffer appended, %d, %d", sizeof(MMVideoBuffer), gst_buffer_n_memory(mcbuffer->buffer)); } - gst_buffer_prepend_memory(mc_buffer->buffer, - gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, y_ptr, mc_buffer->buf_size, 0, - mc_buffer->buf_size, mc_buffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + gst_buffer_prepend_memory(mcbuffer->buffer, + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, y_ptr, mcbuffer->buf_size, 0, + mcbuffer->buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); return ret; } @@ -347,12 +345,12 @@ int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h * fill_outbuf virtual functions */ -int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) +int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet) { - return core->vtable[fill_outbuf](core, data, size, out_pkt); + return core->vtable[fill_outbuf](core, data, size, out_packet); } -int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt) +int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *packet) { int i; int stride_width; @@ -454,37 +452,37 @@ int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, in if (tsurf) { media_packet_create_from_tbm_surface(core->output_fmt, tsurf, - (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, pkt); + (media_packet_finalize_cb)__mc_output_buffer_finalize_cb, core, packet); } return MC_ERROR_NONE; } -int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) +int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet) { - void *pkt_data = NULL; + void *packet_data = NULL; int ret = MC_ERROR_NONE; g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); if (core->encoder && core->codec_id == MEDIACODEC_AAC) media_format_set_audio_aac_type(core->output_fmt, FALSE); - ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_pkt); + ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_packet); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_create_alloc failed"); return MC_ERROR; } - media_packet_set_buffer_size(*out_pkt, size); - media_packet_get_buffer_data_ptr(*out_pkt, &pkt_data); - memcpy(pkt_data, data, size); + media_packet_set_buffer_size(*out_packet, size); + media_packet_get_buffer_data_ptr(*out_packet, &packet_data); + memcpy(packet_data, data, size); return MC_ERROR_NONE; } -int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt) +int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet) { - void *pkt_data = NULL; + void *packet_data = NULL; bool codec_config = FALSE; bool sync_flag = FALSE; bool slice = FALSE; @@ -512,15 +510,15 @@ int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in } LOGD("codec_config : %d, sync_flag : %d, slice : %d", codec_config, sync_flag, slice); - ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_pkt); + ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_packet); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("media_packet_create_alloc failed"); return MC_ERROR; } - media_packet_set_buffer_size(*out_pkt, size); - media_packet_get_buffer_data_ptr(*out_pkt, &pkt_data); - memcpy(pkt_data, data, size); + media_packet_set_buffer_size(*out_packet, size); + media_packet_get_buffer_data_ptr(*out_packet, &packet_data); + memcpy(packet_data, data, size); core->need_sync_flag = sync_flag ? 1 : 0; core->need_codec_data = codec_config ? 1 : 0; @@ -563,7 +561,7 @@ static GstCaps *__mc_gst_caps_set_buffer_array(GstCaps * caps, const gchar * nam return caps; } -int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer*buff, guint streamheader_size) +int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint streamheader_size) { int ret = MEDIA_PACKET_ERROR_NONE; void *buf_data = NULL; @@ -574,15 +572,15 @@ int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer*buff, guint stre guint8 *tmp_buf = NULL; GstMapInfo map; - ret = media_packet_get_buffer_size(buff->pkt, &buf_size); + ret = media_packet_get_buffer_size(mcbuffer->packet, &buf_size); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer size get fail"); + LOGW("buffer size get failed"); return ret; } - ret = media_packet_get_buffer_data_ptr(buff->pkt, &buf_data); + ret = media_packet_get_buffer_data_ptr(mcbuffer->packet, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { - LOGW("buffer data get fail"); + LOGW("buffer data get failed"); return ret; } @@ -712,23 +710,23 @@ int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer*buff, guint stre } /* Update gstbuffer's data ptr and size for using previous streamheader.*/ - LOGD("BEFORE : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer)); - gst_buffer_remove_memory_range(buff->buffer, streamheader_size, -1); - gst_buffer_set_size(buff->buffer, buf_size - streamheader_size); - LOGD("AFTER : buff->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer)); + LOGD("BEFORE : mcbuffer->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer)); + gst_buffer_remove_memory_range(mcbuffer->buffer, streamheader_size, -1); + gst_buffer_set_size(mcbuffer->buffer, buf_size - streamheader_size); + LOGD("AFTER : mcbuffer->buffer of size %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer)); return ret; } -int __mc_get_codecdata_size(mc_gst_core_t *core, GstMCBuffer *buff, unsigned int *size) +int __mc_get_codecdata_size(mc_gst_core_t *core, GstMCBuffer *mcbuffer, unsigned int *size) { void *data = NULL; uint64_t data_size = 0; uint64_t codec_size = 0; int ret = MC_ERROR_NONE; - media_packet_get_buffer_size(buff->pkt, &data_size); - media_packet_get_buffer_data_ptr(buff->pkt, &data); + media_packet_get_buffer_size(mcbuffer->packet, &data_size); + media_packet_get_buffer_data_ptr(mcbuffer->packet, &data); switch (core->codec_id) { case MEDIACODEC_H264: @@ -757,7 +755,7 @@ int __mc_get_codecdata_size(mc_gst_core_t *core, GstMCBuffer *buff, unsigned int return ret; } -int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint fixed_size) +int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint fixed_size) { int ret = MC_ERROR_NONE; void *codec_data = NULL; @@ -766,7 +764,7 @@ int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint fixed_ guint8 *data = NULL; GstMapInfo map; - media_packet_get_codec_data(buff->pkt, &codec_data, &codec_data_size); + media_packet_get_codec_data(mcbuffer->packet, &codec_data, &codec_data_size); if (codec_data != NULL) { /* get the codec data from media_packet_get_codec_data() */ data = g_malloc0(codec_data_size); @@ -779,25 +777,25 @@ int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *buff, guint fixed_ uint64_t buffer_size = 0; void *buff_data = NULL; - media_packet_get_buffer_size(buff->pkt, &buffer_size); - media_packet_get_buffer_data_ptr(buff->pkt, &buff_data); + media_packet_get_buffer_size(mcbuffer->packet, &buffer_size); + media_packet_get_buffer_data_ptr(mcbuffer->packet, &buff_data); /* For audio, it's necessary to change the offset value of buffer after extracting csd */ /* it's not necessary to set csd to caps in case of annex-b */ if (buffer_size > fixed_size) { data = g_malloc0(fixed_size); - gst_buffer_map(buff->buffer, &map, GST_MAP_READ); + gst_buffer_map(mcbuffer->buffer, &map, GST_MAP_READ); memcpy(data, map.data, fixed_size); codecdata_buffer = gst_buffer_new_wrapped(data, fixed_size); - gst_buffer_unmap(buff->buffer, &map); + gst_buffer_unmap(mcbuffer->buffer, &map); gst_caps_set_simple(core->caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL); gst_buffer_unref(codecdata_buffer); - gst_buffer_replace_memory(buff->buffer, 0, + gst_buffer_replace_memory(mcbuffer->buffer, 0, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buff_data + fixed_size , buffer_size - fixed_size, 0, - buffer_size - fixed_size, buff, NULL)); + buffer_size - fixed_size, mcbuffer, NULL)); - LOGD("set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(buff->buffer)); + LOGD("set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer)); } } return ret; @@ -921,7 +919,7 @@ void mc_gst_core_free(mc_gst_core_t *core) core->ports[1] = NULL; } - LOGD("gst_core(%p) is destroyed", core); + LOGD("gst_core(%p) destroyed", core); g_free(core); MEDIACODEC_FLEAVE(); @@ -946,7 +944,7 @@ mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core) g_mutex_init(&port->mutex); port->queue = g_queue_new(); - LOGD("gst_port(%p) is created", port); + LOGD("gst_port(%p) created", port); MEDIACODEC_FLEAVE(); return port; @@ -959,7 +957,7 @@ void mc_gst_port_free(mc_gst_port_t *port) g_mutex_clear(&port->mutex); g_queue_free(port->queue); - LOGD("gst_port(%p) is freed", port); + LOGD("gst_port(%p) freed", port); g_free(port); MEDIACODEC_FLEAVE(); @@ -1026,12 +1024,12 @@ gboolean _mc_update_packet_info(mc_gst_core_t *core, media_format_h fmt) return is_updated; } -static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool codec_config) +static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool codec_config) { MEDIACODEC_FENTER(); g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); - g_return_val_if_fail(buff != NULL, MC_PARAM_ERROR); + g_return_val_if_fail(mcbuffer != NULL, MC_PARAM_ERROR); int ret = MC_ERROR_NONE; @@ -1039,7 +1037,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool code if (core->encoder) { mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info; - core->format = __mc_get_gst_input_format(buff->pkt, core->is_hw); + core->format = __mc_get_gst_input_format(mcbuffer->packet, core->is_hw); gst_caps_set_simple(core->caps, "format", G_TYPE_STRING, core->format, "width", G_TYPE_INT, enc_info->width, @@ -1060,7 +1058,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool code "height", G_TYPE_INT, dec_info->height, NULL); - ret = __mc_set_caps_codecdata(core, buff, CODECDATA_NOT_USE); + ret = __mc_set_caps_codecdata(core, mcbuffer, CODECDATA_NOT_USE); if (ret != MC_ERROR_NONE) { LOGW("__mc_set_caps_codecdata failed"); } @@ -1087,7 +1085,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool code case MEDIACODEC_AAC: case MEDIACODEC_AAC_HE: case MEDIACODEC_AAC_HE_PS: - ret = __mc_set_caps_codecdata(core, buff, AAC_CODECDATA_SIZE); + ret = __mc_set_caps_codecdata(core, mcbuffer, AAC_CODECDATA_SIZE); if (ret != MC_ERROR_NONE) { LOGW("__mc_set_caps_codecdata failed"); } @@ -1096,14 +1094,14 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *buff, bool code case MEDIACODEC_WMAV2: case MEDIACODEC_WMAPRO: case MEDIACODEC_WMALSL: - ret = __mc_set_caps_codecdata(core, buff, WMA_CODECDATA_SIZE); + ret = __mc_set_caps_codecdata(core, mcbuffer, WMA_CODECDATA_SIZE); if (ret != MC_ERROR_NONE) { LOGW("__mc_set_caps_codecdata failed"); } break; case MEDIACODEC_VORBIS: case MEDIACODEC_FLAC: - ret = __mc_set_caps_streamheader(core, buff, VORBIS_CODECDATA_SIZE); + ret = __mc_set_caps_streamheader(core, mcbuffer, VORBIS_CODECDATA_SIZE); if (ret != MC_ERROR_NONE) { LOGW("__mc_set_caps_streamheader failed"); } @@ -1130,7 +1128,7 @@ static gpointer feed_task(gpointer data) bool eos = FALSE; media_format_h fmt = NULL; media_packet_h in_buf = NULL; - GstMCBuffer *buff = NULL; + GstMCBuffer *mcbuffer = NULL; bool initiative = true; MEDIACODEC_FENTER(); @@ -1171,12 +1169,12 @@ static gpointer feed_task(gpointer data) goto LEAVE; } - buff = _mc_gst_media_packet_to_gstbuffer(core, in_buf, codec_config); - if (!buff) { + mcbuffer = _mc_gst_media_packet_to_gstbuffer(core, in_buf, codec_config); + if (!mcbuffer) { LOGW("gstbuffer can't make"); goto ERROR; } - /* buff took the ownership of the in_buf, so set in_buf to NULL to aviod double unref */ + /* mcbuffer took the ownership of the in_buf, so set in_buf to NULL to aviod double unref */ in_buf = NULL; if (codec_config) @@ -1185,11 +1183,11 @@ static gpointer feed_task(gpointer data) if (initiative) { GstPad *pad; - ret = _mc_gst_update_caps(core, buff, codec_config); + ret = _mc_gst_update_caps(core, mcbuffer, codec_config); if (ret != MC_ERROR_NONE) { LOGE("failed to update caps"); - /* unref buff->buffer will invoke the finalize() of GstMcBuffer */ - gst_buffer_unref(buff->buffer); + /* unref mcbuff->buffer will invoke the finalize() of GstMcBuffer */ + gst_buffer_unref(mcbuffer->buffer); goto ERROR; } @@ -1201,7 +1199,7 @@ static gpointer feed_task(gpointer data) } /* inject buffer */ - ret = _mc_gst_gstbuffer_to_appsrc(core, buff); + ret = _mc_gst_gstbuffer_to_appsrc(core, mcbuffer); if (ret != GST_FLOW_OK) { LOGE("Failed to push gst buffer"); goto ERROR; @@ -1490,16 +1488,16 @@ static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboo return MC_ERROR_NONE; } -static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *buff) +static int _mc_gst_gstbuffer_to_appsrc(mc_gst_core_t *core, GstMCBuffer *mcbuffer) { MEDIACODEC_FENTER(); int ret = MC_ERROR_NONE; LOGD("pushed buffer to appsrc : %p, buffer of size %" G_GSIZE_FORMAT "", - buff->buffer, gst_buffer_get_size(buff->buffer)); + mcbuffer->buffer, gst_buffer_get_size(mcbuffer->buffer)); - ret = gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), buff->buffer); + ret = gst_app_src_push_buffer(GST_APP_SRC(core->appsrc), mcbuffer->buffer); return ret; } @@ -1714,7 +1712,7 @@ mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint6 int ret = MC_ERROR_NONE; mc_gst_core_t *core = NULL; - media_packet_h out_pkt = NULL; + media_packet_h out_packet = NULL; gint64 end_time = -1; gboolean signalled; @@ -1735,14 +1733,14 @@ mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint6 } if (signalled) - out_pkt = g_queue_pop_head(core->ports[1]->queue); + out_packet = g_queue_pop_head(core->ports[1]->queue); else { LOGW("Failed to get buffer"); ret = MC_OUTPUT_BUFFER_EMPTY; } - *outbuf = out_pkt; - LOGI("@%p v(%d)e(%d) got buffer :%p", core, core->video, core->encoder, out_pkt); + *outbuf = out_packet; + LOGI("@%p v(%d)e(%d) got buffer :%p", core, core->video, core->encoder, out_packet); g_mutex_unlock(&core->ports[1]->mutex); @@ -2031,17 +2029,17 @@ STATE_CHANGE_FAILED: return MC_ERROR; } -void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_pkt) +void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_packet) { g_mutex_lock(&core->ports[1]->mutex); /* push it to output buffer queue */ - g_queue_push_tail(core->ports[1]->queue, out_pkt); + g_queue_push_tail(core->ports[1]->queue, out_packet); g_cond_broadcast(&core->out_buffer_cond); g_atomic_int_inc(&core->ftb_count); GstBuffer *buffer = NULL; - media_packet_get_extra(out_pkt, (void**)&buffer); + media_packet_get_extra(out_packet, (void**)&buffer); if (buffer) { LOGD("dq : v(%d)e(%d) %d TIMESTAMP = %"GST_TIME_FORMAT " DURATION = %"GST_TIME_FORMAT, core->video, core->encoder, core->ftb_count, GST_TIME_ARGS(GST_BUFFER_TIMESTAMP(buffer)), GST_TIME_ARGS(GST_BUFFER_DURATION(buffer))); @@ -2053,7 +2051,7 @@ void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_pkt) if (core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]) { ((mc_fill_buffer_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]) - (out_pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]); + (out_packet, core->user_data[_MEDIACODEC_EVENT_TYPE_FILLBUFFER]); } } @@ -2062,7 +2060,7 @@ void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gp guint n; GstMemory *mem; GstMapInfo map = GST_MAP_INFO_INIT; - media_packet_h out_pkt = NULL; + media_packet_h out_packet = NULL; MEDIACODEC_FENTER(); @@ -2077,27 +2075,27 @@ void __mc_gst_buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gp gst_memory_map(mem, &map, GST_MAP_READ); LOGD("n : %d, map.data : %p, map.size : %d", n, map.data, map.size); - out_pkt = __mc_gst_make_media_packet(core, map.data, map.size); + out_packet = __mc_gst_make_media_packet(core, map.data, map.size); - LOGI("@%p(%d) out_pkt : %p", core, core->encoder, out_pkt); + LOGI("@%p(%d) out_packet : %p", core, core->encoder, out_packet); gst_memory_unmap(mem, &map); - if (out_pkt) { - media_packet_set_extra(out_pkt, buffer); - media_packet_set_pts(out_pkt, GST_BUFFER_TIMESTAMP(buffer)); - media_packet_set_duration(out_pkt, GST_BUFFER_DURATION(buffer)); + if (out_packet) { + media_packet_set_extra(out_packet, buffer); + media_packet_set_pts(out_packet, GST_BUFFER_TIMESTAMP(buffer)); + media_packet_set_duration(out_packet, GST_BUFFER_DURATION(buffer)); if (core->need_codec_data) { - media_packet_set_flags(out_pkt, MEDIA_PACKET_CODEC_CONFIG); + media_packet_set_flags(out_packet, MEDIA_PACKET_CODEC_CONFIG); core->need_codec_data = false; } if (core->need_sync_flag) { - media_packet_set_flags(out_pkt, MEDIA_PACKET_SYNC_FRAME); + media_packet_set_flags(out_packet, MEDIA_PACKET_SYNC_FRAME); core->need_sync_flag = false; } - __mc_push_output_to_queue(core, out_pkt); + __mc_push_output_to_queue(core, out_packet); } else { gst_buffer_unref(buffer); LOGE("Failed to dequeue output packet"); @@ -2190,74 +2188,74 @@ gchar *__mc_get_gst_input_format(media_packet_h packet, bool is_hw) return format; } -GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h pkt, bool codec_config) +GstMCBuffer *_mc_gst_media_packet_to_gstbuffer(mc_gst_core_t *core, media_packet_h packet, bool codec_config) { int ret = MEDIA_PACKET_ERROR_NONE; - GstMCBuffer *mc_buffer = NULL; + GstMCBuffer *mcbuffer = NULL; void *buf_data = NULL; uint64_t buf_size = 0; uint64_t pts = 0; uint64_t dur = 0; - ret = media_packet_get_buffer_size(pkt, &buf_size); + ret = media_packet_get_buffer_size(packet, &buf_size); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("buffer size get fail"); return NULL; } - ret = media_packet_get_buffer_data_ptr(pkt, &buf_data); + ret = media_packet_get_buffer_data_ptr(packet, &buf_data); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGW("buffer data get fail"); return NULL; } - mc_buffer = gst_mediacodec_buffer_new(core, pkt, buf_size); - if (mc_buffer == NULL) { + mcbuffer = gst_mediacodec_buffer_new(core, packet, buf_size); + if (mcbuffer == NULL) { LOGW("failed to create inbuf"); return NULL; } - LOGD("pkt :v(%d)e(%d) %p, buf_size : %d", core->video, core->encoder, pkt, (int)buf_size); + LOGD("packet :v(%d)e(%d) %p, buf_size : %d", core->video, core->encoder, packet, (int)buf_size); - ret = __mc_fill_input_buffer(core, pkt, mc_buffer); + ret = __mc_fill_input_buffer(core, packet, mcbuffer); if (ret != MC_ERROR_NONE) { LOGW("failed to fill inbuf: %s (ox%08x)", _mc_error_to_string(ret), ret); /* - * if __mc_fill_input_buffer() failed, no memory appended to mc_buffer->buffer, so gst_mediacodec_buffer_finalize() + * if __mc_fill_input_buffer() failed, no memory appended to mcbuffer->buffer, so gst_mediacodec_buffer_finalize() * will not be invoked */ - gst_buffer_unref(mc_buffer->buffer); - free(mc_buffer); + gst_buffer_unref(mcbuffer->buffer); + free(mcbuffer); return NULL; } /* pts */ - media_packet_get_pts(pkt, &pts); - GST_BUFFER_PTS(mc_buffer->buffer) = pts; + media_packet_get_pts(packet, &pts); + GST_BUFFER_PTS(mcbuffer->buffer) = pts; /* duration */ - media_packet_get_duration(pkt, &dur); - GST_BUFFER_DURATION(mc_buffer->buffer) = dur; + media_packet_get_duration(packet, &dur); + GST_BUFFER_DURATION(mcbuffer->buffer) = dur; - return mc_buffer; + return mcbuffer; } media_packet_h __mc_gst_make_media_packet(mc_gst_core_t *core, unsigned char *data, int size) { int ret = MEDIA_PACKET_ERROR_NONE; - media_packet_h pkt = NULL; + media_packet_h packet = NULL; - ret = __mc_fill_output_buffer(core, data, size, &pkt); + ret = __mc_fill_output_buffer(core, data, size, &packet); if (ret != MC_ERROR_NONE) { LOGW("failed to fill outbuf: %s (ox%08x)", _mc_error_to_string(ret), ret); return NULL; } - return pkt; + return packet; } -int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_pkt) +int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_packet) { media_packet_h mediabuf = NULL; int ret = MC_ERROR_NONE; @@ -2275,29 +2273,29 @@ int __mc_gst_create_eos_packet(media_format_h fmt, media_packet_h *out_pkt) goto ERROR; } - *out_pkt = mediabuf; + *out_packet = mediabuf; MEDIACODEC_FLEAVE(); return ret; ERROR: if (mediabuf) media_packet_destroy(mediabuf); - *out_pkt = NULL; + *out_packet = NULL; MEDIACODEC_FLEAVE(); return ret; } -void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h pkt) +void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h packet) { g_atomic_int_dec_and_test(&core->etb_count); if (core && core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) { ((mc_empty_buffer_cb)core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) - (pkt, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); + (packet, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); } if (core) - LOGD("@v(%d)e(%d) input port emptied buffer(%d): %p", core->video, core->encoder, core->etb_count, pkt); + LOGD("@v(%d)e(%d) input port emptied buffer(%d): %p", core->video, core->encoder, core->etb_count, packet); } gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) @@ -2311,9 +2309,9 @@ gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) case GST_MESSAGE_EOS: _mc_send_eos_signal(core); - media_packet_h out_pkt = NULL; - if (MC_ERROR_NONE == __mc_gst_create_eos_packet(core->output_fmt, &out_pkt)) { - __mc_push_output_to_queue(core, out_pkt); + media_packet_h out_packet = NULL; + if (MC_ERROR_NONE == __mc_gst_create_eos_packet(core->output_fmt, &out_packet)) { + __mc_push_output_to_queue(core, out_packet); LOGD("send eos packet."); } else { LOGE("failed to create eos packet."); @@ -2426,7 +2424,7 @@ static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, return reply; } -static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h pkt) +static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h packet) { int i; int num_bos; @@ -2434,7 +2432,7 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet tbm_surface_info_s surface_info; tbm_bo_handle handle_bo; - if (!pkt) { + if (!packet) { LOGE("output is null"); return NULL; } @@ -2447,7 +2445,7 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet } memset(mm_vbuffer, 0x00, sizeof(MMVideoBuffer)); - media_packet_get_tbm_surface(pkt, &surface); + media_packet_get_tbm_surface(packet, &surface); num_bos = tbm_surface_internal_get_num_bos(surface); int err = tbm_surface_get_info((tbm_surface_h)surface, &surface_info); if (err != TBM_SURFACE_ERROR_NONE) { @@ -2507,44 +2505,44 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet return mm_vbuffer; } -static void gst_mediacodec_buffer_finalize(GstMCBuffer *mc_buffer) +static void gst_mediacodec_buffer_finalize(GstMCBuffer *mcbuffer) { MEDIACODEC_FENTER(); - if (!mc_buffer) + if (!mcbuffer) return; - mc_gst_core_t *core = (mc_gst_core_t *)mc_buffer->core; + mc_gst_core_t *core = (mc_gst_core_t *)mcbuffer->core; - _mc_gst_handle_input_buffer_used(core, mc_buffer->pkt); + _mc_gst_handle_input_buffer_used(core, mcbuffer->packet); - free(mc_buffer); - mc_buffer = NULL; + free(mcbuffer); + mcbuffer = NULL; MEDIACODEC_FLEAVE(); return; } -static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h pkt, uint64_t size) +static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size) { - GstMCBuffer *mc_buffer = NULL; + GstMCBuffer *mcbuffer = NULL; - mc_buffer = (GstMCBuffer *)malloc(sizeof(*mc_buffer)); + mcbuffer = (GstMCBuffer *)malloc(sizeof(*mcbuffer)); - if (mc_buffer == NULL) { + if (mcbuffer == NULL) { LOGE("malloc fail"); return NULL; } - mc_buffer->buffer = gst_buffer_new(); - mc_buffer->buf_size = 0; + mcbuffer->buffer = gst_buffer_new(); + mcbuffer->buf_size = 0; - LOGD("creating buffer : %p, %p", mc_buffer, mc_buffer->buffer); - mc_buffer->core = core; - mc_buffer->pkt = pkt; + LOGD("creating buffer : %p, %p", mcbuffer, mcbuffer->buffer); + mcbuffer->core = core; + mcbuffer->packet = packet; - return mc_buffer; + return mcbuffer; } static gint __gst_handle_core_error(mc_gst_core_t *core, int code) @@ -2738,17 +2736,17 @@ static int _mc_gst_flush_buffers(mc_gst_core_t *core) static void _mc_gst_set_flush_input(mc_gst_core_t *core) { - media_packet_h pkt = NULL; + media_packet_h packet = NULL; MEDIACODEC_FENTER(); - LOGI("_mc_gst_set_flush_input is called"); + LOGI("_mc_gst_set_flush_input called"); while (!mc_async_queue_is_empty(core->available_queue->input)) { - pkt = mc_async_queue_pop_forced(core->available_queue->input); + packet = mc_async_queue_pop_forced(core->available_queue->input); g_atomic_int_dec_and_test(&core->etb_count); - LOGD("%p poped(%d)", pkt, core->etb_count); + LOGD("%p poped(%d)", packet, core->etb_count); - _mc_gst_handle_input_buffer_used(core, pkt); + _mc_gst_handle_input_buffer_used(core, packet); } mc_async_queue_flush(core->available_queue->input); @@ -2757,19 +2755,19 @@ static void _mc_gst_set_flush_input(mc_gst_core_t *core) static void _mc_gst_set_flush_output(mc_gst_core_t *core) { - media_packet_h pkt = NULL; + media_packet_h packet = NULL; MEDIACODEC_FENTER(); g_mutex_lock(&core->ports[1]->mutex); while (!g_queue_is_empty(core->ports[1]->queue)) { - pkt = g_queue_pop_head(core->ports[1]->queue); + packet = g_queue_pop_head(core->ports[1]->queue); g_atomic_int_dec_and_test(&core->ftb_count); - LOGD("%p poped(%d)", pkt, core->ftb_count); - if (pkt) { - media_packet_destroy(pkt); - LOGD("outpkt destroyed"); - pkt = NULL; + LOGD("%p poped(%d)", packet, core->ftb_count); + if (packet) { + media_packet_destroy(packet); + LOGD("outpacket destroyed"); + packet = NULL; } } g_mutex_unlock(&core->ports[1]->mutex); @@ -3215,7 +3213,7 @@ int _mediacodec_get_mime(mc_gst_core_t *core) return mime; } -mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt_pool) +mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *packet_pool) { int curr_size; int max_size, min_size; @@ -3293,6 +3291,6 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt media_packet_pool_get_size(pool, &min_size, &max_size, &curr_size); LOGD("curr_size is %d min_size is %d and max_size is %d \n", curr_size, min_size, max_size); - *pkt_pool = pool; + *packet_pool = pool; return MC_ERROR_NONE; } -- 2.7.4 From 51c0b73aa8332c36d2f4a325c8e75b2d7316475d Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Tue, 27 Dec 2016 14:15:06 +0900 Subject: [PATCH 04/16] fixed svace issue Change-Id: I9e66e28b513f7f0de72509dee5681b391a4e426c --- packaging/capi-media-codec.spec | 2 +- src/media_codec_port_gst.c | 37 ------------------------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 2665e0c..1646be8 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -1,7 +1,7 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API Version: 0.5.2 -Release: 0 +Release: 1 Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 9d5c3b2..71a3749 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -718,43 +718,6 @@ int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint return ret; } -int __mc_get_codecdata_size(mc_gst_core_t *core, GstMCBuffer *mcbuffer, unsigned int *size) -{ - void *data = NULL; - uint64_t data_size = 0; - uint64_t codec_size = 0; - int ret = MC_ERROR_NONE; - - media_packet_get_buffer_size(mcbuffer->packet, &data_size); - media_packet_get_buffer_data_ptr(mcbuffer->packet, &data); - - switch (core->codec_id) { - case MEDIACODEC_H264: - codec_size = _mc_get_h264_codecdata_size(data, data_size); - break; - case MEDIACODEC_H263: - /* Not need codec data */ - codec_size = 0; - break; - case MEDIACODEC_MPEG4: - codec_size = _mc_check_mpeg4_out_bytestream(data, data_size, NULL, NULL); - break; - default: - LOGE("Current not support yet (0x%x) !", core->codec_id); - return MC_NOT_SUPPORTED; - break; - } - - if (codec_size < 0) { - LOGE("No valid codec data!"); - ret = MC_INVALID_IN_BUF; - } - - *size = codec_size; - - return ret; -} - int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint fixed_size) { int ret = MC_ERROR_NONE; -- 2.7.4 From da85c67174746c8e92925d2fe60dc0f96844881f Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Tue, 10 Jan 2017 18:49:51 +0900 Subject: [PATCH 05/16] fixed build errors due to toolchain upgrade Change-Id: I7fce705cb33d0a3594bc2ce67c8054d96b960018 --- packaging/capi-media-codec.spec | 4 ++-- src/media_codec.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 1646be8..a7c5699 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -1,7 +1,7 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API -Version: 0.5.2 -Release: 1 +Version: 0.5.3 +Release: 0 Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/media_codec.c b/src/media_codec.c index 22cd3d8..45d9454 100755 --- a/src/media_codec.c +++ b/src/media_codec.c @@ -337,7 +337,8 @@ int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type return __convert_error_code(ret, (char *)__FUNCTION__); else handle->state = MEDIACODEC_STATE_IDLE; - return MEDIACODEC_ERROR_NONE; + + return MEDIACODEC_ERROR_NONE; } int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void *user_data) -- 2.7.4 From 95852af79c8874943469ac7f6e18ef0edc65cb90 Mon Sep 17 00:00:00 2001 From: "hk57.kim" Date: Fri, 17 Feb 2017 14:53:43 +0900 Subject: [PATCH 06/16] [4.0] Remove Target_Name Dependency - This is for Tizen 4.0 - We are going to unify repositories as well as build projects. - When you SR this, you need to create JIRA-TRE issue of: : add capi-media-codec-extension-TM1 for TM1 (mobile) (It's add, not replace.) Change-Id: I8c1f38e25323c69ad6dfb41b4a1fdd959df274fb Signed-off-by: hk57.kim --- packaging/capi-media-codec.spec | 91 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index a7c5699..dd71925 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -1,3 +1,7 @@ +# Do not create provides fro extension-tm1 because the main package +# should anchor any reverse-dependencies +%global __provides_exclude_from ^(.*\\.tm1)$ + Name: capi-media-codec Summary: A Media Codec library in Tizen Native API Version: 0.5.3 @@ -19,13 +23,25 @@ BuildRequires: pkgconfig(gstreamer-plugins-base-1.0) BuildRequires: pkgconfig(gstreamer-app-1.0) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(iniparser) -%if "%{tizen_target_name}" == "TM1" + +%description +A Media Codec library in Tizen Native API + +%ifarch %{arm} +# This is for backward-compatibility. This does not deteriorate 4.0 Configurability +# if mobile || "undefined" +%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi" && "%{?profile}" != "common" +%package extension-TM1 +Summary: Extension for mobile TM1 +Requires: %{name} = %{version}-%{release} #!BuildIgnore: kernel-headers BuildConflicts: linux-glibc-devel BuildRequires: kernel-headers-tizen-dev -%endif -%description +%description extension-TM1 +A Media Codec library in Tizen Native API Extension for mobile TM1 +%endif +%endif %package devel @@ -40,9 +56,7 @@ Requires: %{name} = %{version}-%{release} %build -%if "%{tizen_target_name}" == "TM1" -export CFLAGS="$CFLAGS -DTIZEN_PROFILE_LITE" -%endif + %if 0%{?sec_build_binary_debug_enable} export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" @@ -52,7 +66,31 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" export CFLAGS="$CFLAGS -DENABLE_FFMPEG_CODEC" %endif export CFLAGS="$CFLAGS -DSYSCONFDIR=\\\"%{_sysconfdir}\\\"" +export CFLAGS_DEFAULT="$CFLAGS" + +%ifarch %{arm} +# This is for backward-compatibility. This does not deteriorate 4.0 Configurability +# if mobile || "undefined" +%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi" && "%{?profile}" != "common" +# extension-TM1 +export CFLAGS="$CFLAGS_DEFAULT -DTIZEN_PROFILE_LITE" + +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + +make %{?jobs:-j%jobs} + +mkdir -p tm1 +%make_install +ls -al %{buildroot}%{_libdir}/libcapi-media-codec.so.* +cp -a %{buildroot}%{_libdir}/libcapi-media-codec.so.* tm1/ + +%endif +%endif + +# common +export CFLAGS="$CFLAGS_DEFAULT" MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} @@ -68,6 +106,44 @@ cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} %make_install + +%ifarch %{arm} +# This is for backward-compatibility. This does not deteriorate 4.0 Configurability +# if mobile || "undefined" +%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi" && "%{?profile}" != "common" +# extension-TM1 +pushd tm1 +for FILE in libcapi-media-codec.so.*; do mv "$FILE" "%{buildroot}%{_libdir}/$FILE.tm1"; done +popd + +%post extension-TM1 +pushd %{_libdir} +for FILE in libcapi-media-codec.so.*.tm1; do mv "$FILE" "${FILE%.tm1}"; done +popd +/sbin/ldconfig + +%preun extension-TM1 +case "$1" in + 0) + # This is an un-installation. + pushd %{_libdir} + for FILE in libcapi-media-codec.so.*; do mv "$FILE" "${FILE%.tm1}"; done + popd + /sbin/ldconfig + ;; + 1) + # This is an upgrade. + # Do nothing. + : + ;; +esac + +%files extension-TM1 +%manifest capi-media-codec.manifest +%{_libdir}/libcapi-media-codec.so.*.tm1 +%endif +%endif + %post /sbin/ldconfig @@ -77,6 +153,9 @@ cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} %files %manifest capi-media-codec.manifest %{_libdir}/libcapi-media-codec.so.* +%ifarch %{arm} +%exclude %{_libdir}/libcapi-media-codec.so.*.tm1 +%endif %{_datadir}/license/%{name} /usr/bin/* #%{_bindir}/* -- 2.7.4 From 7fd27916ebcaa7c0ae514dda050c44780758c0f7 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Thu, 23 Mar 2017 16:53:12 +0900 Subject: [PATCH 07/16] changed to %license macro Change-Id: I84d92a0317fcce09ed3564ca7006a399384aff25 --- packaging/capi-media-codec.spec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index dd71925..e6ba560 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -99,10 +99,8 @@ make %{?jobs:-j%jobs} %install rm -rf %{buildroot} -mkdir -p %{buildroot}/usr/share/license mkdir -p %{buildroot}/usr/bin cp test/media_codec_test %{buildroot}/usr/bin -cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} %make_install @@ -156,7 +154,7 @@ esac %ifarch %{arm} %exclude %{_libdir}/libcapi-media-codec.so.*.tm1 %endif -%{_datadir}/license/%{name} +%license LICENSE.APLv2 /usr/bin/* #%{_bindir}/* -- 2.7.4 From bfc84017d8a88c86b7658f4108da0831fe3fae0c Mon Sep 17 00:00:00 2001 From: "hk57.kim" Date: Wed, 29 Mar 2017 17:25:47 +0900 Subject: [PATCH 08/16] [Tizen] Fix 'Have choice' issue for TM1 - This is for Tizen 4.0. - Fix buildrequires kernel-headers-tizen-dev --> kernel-headers-3.10-sc7730 for TM1 Change-Id: I31e55eacf2877296341c344bdb858a48854690c1 Signed-off-by: hk57.kim --- packaging/capi-media-codec.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index e6ba560..6b69fe1 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -36,7 +36,7 @@ Summary: Extension for mobile TM1 Requires: %{name} = %{version}-%{release} #!BuildIgnore: kernel-headers BuildConflicts: linux-glibc-devel -BuildRequires: kernel-headers-tizen-dev +BuildRequires: kernel-headers-3.10-sc7730 %description extension-TM1 A Media Codec library in Tizen Native API Extension for mobile TM1 -- 2.7.4 From 5a1179359c3555906e0c5c4055c91cae1e784d7a Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Mon, 17 Apr 2017 16:39:13 +0900 Subject: [PATCH 09/16] fixed svace issues Change-Id: I4bbd1ea2063ff006b12e17e9e05e39d7c3ac789e --- src/media_codec_port_gst.c | 17 +++++++++-------- test/media_codec_test.c | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 71a3749..cb8f751 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -1810,7 +1810,6 @@ static gboolean __mc_gst_init_gstreamer() return TRUE; ERROR: - /* release */ for (i = 0; i < arg_count; i++) { LOGD("free[%d] : %s\n", i, argv2[i]); @@ -2738,21 +2737,19 @@ static void _mc_gst_set_flush_output(mc_gst_core_t *core) } #ifdef TIZEN_PROFILE_LITE -int __tbm_get_physical_addr_bo(tbm_bo_handle tbm_bo_handle_fd_t, int *phy_addr, int *phy_size) +int __tbm_get_physical_addr_bo(tbm_bo_handle handle_bo, int *phy_addr, int *phy_size) { - int tbm_bo_handle_fd; - int ret = 0; - - tbm_bo_handle_fd = tbm_bo_handle_fd_t.u32; - int open_flags = O_RDWR; int ion_fd = -1; struct ion_mmu_data mmu_data; struct ion_custom_data custom_data; - mmu_data.fd_buffer = tbm_bo_handle_fd; + memset(&mmu_data, 0x0, sizeof(ion_mmu_data)); + memset(&custom_data, 0x0, sizeof(ion_custom_data)); + + mmu_data.fd_buffer = handle_bo.u32; custom_data.cmd = 4; custom_data.arg = (unsigned long)&mmu_data; @@ -3199,6 +3196,7 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pac if (media_format_create(&fmt_handle) != MEDIA_FORMAT_ERROR_NONE) { LOGE("media format create failed"); + media_packet_pool_destroy(pool); return MC_ERROR; } @@ -3232,6 +3230,7 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pac ret = media_packet_pool_set_media_format(pool, fmt_handle); if (ret != MEDIA_PACKET_ERROR_NONE) { + media_packet_pool_destroy(pool); LOGE("media_packet_pool_set_media_format failed"); return MC_ERROR; } @@ -3242,12 +3241,14 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pac min_size = max_size; ret = media_packet_pool_set_size(pool, min_size, max_size); if (ret != MEDIA_PACKET_ERROR_NONE) { + media_packet_pool_destroy(pool); LOGE("media_packet_pool_set_size failed"); return MC_ERROR; } ret = media_packet_pool_allocate(pool); if (ret != MEDIA_PACKET_ERROR_NONE) { + media_packet_pool_destroy(pool); LOGE("media_packet_pool_allocate failed"); return MC_OUT_OF_MEMORY; } diff --git a/test/media_codec_test.c b/test/media_codec_test.c index 2ace30b..c9dad16 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -416,7 +416,7 @@ void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_fra goto DONE; } if (!bType) { - if (have_frame && val == 0xB0) + if (val == 0xB0) *have_frame = TRUE; } bType = val; @@ -608,17 +608,20 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram if (header == 0) { g_print ("[ERROR] read header size is 0\n"); *have_frame = FALSE; + return; } /* if it's not a valid sync */ if ((header & 0xffe00000) != 0xffe00000) { g_print ("[ERROR] invalid sync\n"); *have_frame = FALSE; + return; } if (((header >> 19) & 3) == 0x1) { g_print ("[ERROR] invalid MPEG version: %d\n", (header >> 19) & 3); *have_frame = FALSE; + return; } else { if (header & (1 << 20)) { lsf = (header & (1 << 19)) ? 0 : 1; @@ -633,20 +636,28 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram if (!((header >> 17) & 3)) { g_print("[ERROR] invalid layer: %d\n", (header >> 17) & 3); *have_frame = FALSE; + return; } else { layer = 4 - ((header >> 17) & 0x3); + + if (layer < 1) { + *have_frame = FALSE; + return; + } } /* if it's an invalid bitrate */ if (((header >> 12) & 0xf) == 0xf) { g_print ("[ERROR] invalid bitrate: %d\n", (header >> 12) & 0xf); *have_frame = FALSE; + return; } else { bitrate = (header >> 12) & 0xF; hdr_bitrate = mp3types_bitrates[lsf][layer - 1][bitrate] * 1000; /* The caller has ensured we have a valid header, so bitrate can't be zero here. */ if (hdr_bitrate == 0) *have_frame = FALSE; + return; } /* if it's an invalid samplerate */ @@ -1749,7 +1760,9 @@ static void interpret(char *cmd, App *app) case CURRENT_STATUS_PROCESS_INPUT: { app->frame = atoi(cmd); - _mediacodec_process_input(app); + + if (app->frame > 0) + _mediacodec_process_input(app); reset_menu_state(); } break; @@ -1871,11 +1884,11 @@ static void decoder_output_dump(App *app, media_packet_h pkt) void *temp; int i = 0; int stride_width, stride_height; - char filename[100] = {0}; + gchar filename[100] = {0}; FILE *fp = NULL; int ret = 0; - sprintf(filename, "/tmp/dec_output_dump_%d_%d.yuv", app->width, app->height); + g_snprintf(filename, MAX_STRING_LEN, "/tmp/dec_output_dump_%d_%d.yuv", app->width, app->height); fp = fopen(filename, "ab"); media_packet_get_video_plane_data_ptr(pkt, 0, &temp); @@ -1957,12 +1970,12 @@ static void output_dump(App *app, media_packet_h pkt) { void *temp; uint64_t buf_size; - char filename[100] = {0}; + gchar filename[100] = {0}; FILE *fp = NULL; int ret = 0; char adts[100] = {0, }; - sprintf(filename, "/tmp/dec_output_dump_%d.out", app->type); + g_snprintf(filename, MAX_STRING_LEN, "/tmp/dec_output_dump_%d.out", app->type); fp = fopen(filename, "ab"); media_packet_get_buffer_data_ptr(pkt, &temp); -- 2.7.4 From 1f9c03d2ab170d37da8bd92fdf23e29c26c69fa9 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Mon, 24 Apr 2017 13:33:01 +0900 Subject: [PATCH 10/16] fixed svace issue Change-Id: Ifa8e4f545798eb8379d9595fe27a274667201736 --- test/media_codec_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/media_codec_test.c b/test/media_codec_test.c index c9dad16..e94e011 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -655,9 +655,10 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram bitrate = (header >> 12) & 0xF; hdr_bitrate = mp3types_bitrates[lsf][layer - 1][bitrate] * 1000; /* The caller has ensured we have a valid header, so bitrate can't be zero here. */ - if (hdr_bitrate == 0) + if (hdr_bitrate == 0) { *have_frame = FALSE; return; + } } /* if it's an invalid samplerate */ -- 2.7.4 From 9eb4807f1fef0bd18ae11264ef79498371cf62ac Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Tue, 25 Apr 2017 16:29:09 +0900 Subject: [PATCH 11/16] fixed build error and unresolved svace issues in unified version Change-Id: Idab4be2138bc8581eb4af0e3401ee9adad6f9a21 --- include/media_codec_port_gst.h | 3 ++- src/media_codec_port_gst.c | 10 +++++++--- test/media_codec_test.c | 14 ++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index d0aa50d..92b4eee 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -62,6 +62,7 @@ extern "C" { typedef struct _mc_gst_port_t mc_gst_port_t; typedef struct _mc_gst_core_t mc_gst_core_t; typedef struct _GstMCBuffer GstMCBuffer; +typedef struct _ion_mmu_data_t ion_mmu_data_t; typedef enum { BUF_SHARE_METHOD_PADDR = 0, @@ -71,7 +72,7 @@ typedef enum { } buf_share_method_t; #ifdef TIZEN_PROFILE_LITE -struct ion_mmu_data { +struct _ion_mmu_data_t { int master_id; int fd_buffer; unsigned long iova_addr; diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index cb8f751..95fac10 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -2425,6 +2425,11 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet int phy_addr = 0; int phy_size = 0; tbm_bo_handle handle_fd = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_MM); + if (handle_fd == NULL) { + LOGE("Invaild bo handle"); + return NULL; + } + if (__tbm_get_physical_addr_bo(handle_fd, &phy_addr, &phy_size) == 0) { mm_vbuffer->handle.paddr[0] = (void *)phy_addr; LOGD("mm_vbuffer->paddr : %p", mm_vbuffer->handle.paddr[0]); @@ -2743,11 +2748,10 @@ int __tbm_get_physical_addr_bo(tbm_bo_handle handle_bo, int *phy_addr, int *phy_ int open_flags = O_RDWR; int ion_fd = -1; - struct ion_mmu_data mmu_data; + ion_mmu_data_t mmu_data; struct ion_custom_data custom_data; - memset(&mmu_data, 0x0, sizeof(ion_mmu_data)); - memset(&custom_data, 0x0, sizeof(ion_custom_data)); + memset(&mmu_data, 0x0, sizeof(ion_mmu_data_t)); mmu_data.fd_buffer = handle_bo.u32; custom_data.cmd = 4; diff --git a/test/media_codec_test.c b/test/media_codec_test.c index e94e011..1f6096c 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -639,11 +639,6 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram return; } else { layer = 4 - ((header >> 17) & 0x3); - - if (layer < 1) { - *have_frame = FALSE; - return; - } } /* if it's an invalid bitrate */ @@ -783,6 +778,13 @@ void extract_input_aacdec_m4a_test(App * app, unsigned char **data, int *size, b read_size = readsize; app->offset += header_size + readsize; + if (app->offset > app->length) { + read_size = 0; + *have_frame = FALSE; + g_print("[FAIL] offset error \n"); + return; + } + } else { read_size = 0; g_print("[FAIL] Not found aac frame sync. \n"); @@ -1762,7 +1764,7 @@ static void interpret(char *cmd, App *app) { app->frame = atoi(cmd); - if (app->frame > 0) + if (app->frame > 0 && app->frame < 10) _mediacodec_process_input(app); reset_menu_state(); } -- 2.7.4 From 86060365022fb3ea999589d66356832d8fda0c0f Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Tue, 25 Apr 2017 20:40:26 +0900 Subject: [PATCH 12/16] modify checking null Change-Id: I4f84db66ff439bbdad845da2af532c09afaeea44 --- src/media_codec_port_gst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 95fac10..759117c 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -2425,7 +2425,7 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet int phy_addr = 0; int phy_size = 0; tbm_bo_handle handle_fd = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_MM); - if (handle_fd == NULL) { + if (handle_fd.ptr == NULL) { LOGE("Invaild bo handle"); return NULL; } -- 2.7.4 From bb4a4aa75c0dff0943bedac3a689d2876540ffc2 Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Mon, 10 Apr 2017 11:45:02 +0300 Subject: [PATCH 13/16] fixed build with -fno-common ASan build failed with variables redefinition. Change-Id: I61bab52f3e82745c5d8551fb9c1458e1fbdc7007 Signed-off-by: Slava Barinov --- src/media_codec_port.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/media_codec_port.c b/src/media_codec_port.c index 83b618f..f2afd34 100755 --- a/src/media_codec_port.c +++ b/src/media_codec_port.c @@ -25,9 +25,7 @@ #include #include #include - -mc_ini_t mc_ini; -mc_codec_spec_t spec_emul[MEDIA_CODEC_MAX_CODEC_TYPE]; +#include int mc_create(MMHandleType *mediacodec) { -- 2.7.4 From f5f5583413922963709c9a19736c33e1169eaf49 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Tue, 2 May 2017 17:27:02 +0900 Subject: [PATCH 14/16] Sync with tizen_3.0 and add to control buffer overflow Change-Id: Ia4d1007a9b6bc8e6cdd95cbc244b9bc621ff849b --- include/media_codec_port_gst.h | 2 + src/media_codec_port_gst.c | 129 ++++++++++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 26 deletions(-) diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index 92b4eee..98e93c0 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -127,6 +127,7 @@ struct _mc_gst_core_t { bool eos; bool eos_waiting; bool codec_config; + bool need_drain; bool need_feed; bool need_codec_data; bool need_sync_flag; @@ -165,6 +166,7 @@ int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuff int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); +int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index 759117c..ae66a6e 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -57,7 +57,7 @@ static gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer dat static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, gpointer data); static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet_h packet); static GstMCBuffer *gst_mediacodec_buffer_new(mc_gst_core_t *core, media_packet_h packet, uint64_t size); -static void gst_mediacodec_buffer_finalize(GstMCBuffer *buffer); +static void __mc_input_buffer_finalize_cb(GstMCBuffer *buffer); static int __mc_set_caps_streamheader(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint streamheader_size); static int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint codecdata_size); static void __mc_push_output_to_queue(mc_gst_core_t *core, media_packet_h out_packet); @@ -134,10 +134,10 @@ int(*adec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_ int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */ &__mc_fill_packet_with_output_buffer}; -int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Decoder Vtable */ +int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC LC Decoder Vtable */ &__mc_fill_packet_with_output_buffer}; -int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC HE Decoder Vtable */ +int(*adec_aacv12_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC HE Decoder Vtable */ &__mc_fill_packet_with_output_buffer}; int(*adec_mp3_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* MP3 Decoder Vtable */ @@ -202,7 +202,7 @@ int __mc_fill_inbuf_with_mm_video_buffer(mc_gst_core_t *core, media_packet_h pac if (buf_data != NULL) { gst_buffer_prepend_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, - buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb)); LOGD("packet data apended, %d, %d", buf_size, gst_buffer_n_memory(mcbuffer->buffer)); } return ret; @@ -229,13 +229,58 @@ int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packe if (buf_data != NULL) { gst_buffer_append_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, - buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb)); LOGD("packet data apended"); } return ret; } +int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) +{ + int ret = MC_ERROR_NONE; + void *buf_data = NULL; + uint64_t buf_size = 0; + bool codec_config = FALSE; + void *codec_data = NULL; + unsigned int codec_size = 0; + + ret = media_packet_get_buffer_size(packet, &buf_size); + if (ret != MEDIA_PACKET_ERROR_NONE) { + LOGW("buffer size get failed"); + return MC_ERROR; + } + + ret = media_packet_get_buffer_data_ptr(packet, &buf_data); + if (ret != MEDIA_PACKET_ERROR_NONE) { + LOGW("buffer data get failed"); + return MC_ERROR; + } + + if (media_packet_is_codec_config(packet, &codec_config) != MEDIA_PACKET_ERROR_NONE) { + LOGE("media_packet_is_codec_config failed"); + return MC_ERROR; + } + + if (buf_data != NULL) { + media_packet_get_codec_data(packet, &codec_data, &codec_size); + + if (!codec_data && codec_config) { + gst_buffer_append_memory(mcbuffer->buffer, + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, + buf_size, NULL, NULL)); + LOGD("csd packet data apended"); + } else { + gst_buffer_append_memory(mcbuffer->buffer, + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buf_data, buf_size, 0, + buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb)); + LOGD("packet data apended"); + } + } + + return ret; +} + int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer) { int ret = MC_ERROR_NONE; @@ -335,7 +380,7 @@ int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h gst_buffer_prepend_memory(mcbuffer->buffer, gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, y_ptr, mcbuffer->buf_size, 0, - mcbuffer->buf_size, mcbuffer, (GDestroyNotify)gst_mediacodec_buffer_finalize)); + mcbuffer->buf_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb)); return ret; } @@ -750,15 +795,15 @@ int __mc_set_caps_codecdata(mc_gst_core_t *core, GstMCBuffer *mcbuffer, guint fi gst_buffer_map(mcbuffer->buffer, &map, GST_MAP_READ); memcpy(data, map.data, fixed_size); codecdata_buffer = gst_buffer_new_wrapped(data, fixed_size); - gst_buffer_unmap(mcbuffer->buffer, &map); gst_caps_set_simple(core->caps, "codec_data", GST_TYPE_BUFFER, codecdata_buffer, NULL); gst_buffer_unref(codecdata_buffer); gst_buffer_replace_memory(mcbuffer->buffer, 0, - gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, buff_data + fixed_size , buffer_size - fixed_size, 0, - buffer_size - fixed_size, mcbuffer, NULL)); + gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, map.data + fixed_size , buffer_size - fixed_size, 0, + buffer_size - fixed_size, mcbuffer, (GDestroyNotify)__mc_input_buffer_finalize_cb)); - LOGD("set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer)); + LOGD("after : set codec data from packet: %" G_GSIZE_FORMAT "", gst_buffer_get_size(mcbuffer->buffer)); + gst_buffer_unmap(mcbuffer->buffer, &map); } } return ret; @@ -833,6 +878,7 @@ mc_gst_core_t *mc_gst_core_new() g_mutex_init(&core->prepare_lock); g_mutex_init(&core->drain_lock); + core->need_drain = false; core->need_feed = false; core->eos = false; core->need_codec_data = false; @@ -1626,7 +1672,6 @@ mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint int ret = MC_ERROR_NONE; mc_gst_core_t *core = NULL; - gint64 end_time; if (!mc_handle) return MC_PARAM_ERROR; @@ -1635,14 +1680,10 @@ mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint g_mutex_lock(&core->drain_lock); - while (g_atomic_int_get(&core->etb_count) > MAXINUM_QNUM) { - end_time = g_get_monotonic_time() + timeOutUs; + while (g_atomic_int_get(&core->etb_count) == MAXINUM_QNUM) { LOGD("Waiting until packets are drained.."); - - if (!g_cond_wait_until(&core->buffer_cond, &core->drain_lock, end_time)) { - LOGD("time out..."); - break; - } + core->need_drain = true; + g_cond_wait(&core->buffer_cond, &core->drain_lock); } g_mutex_unlock(&core->drain_lock); @@ -2254,17 +2295,23 @@ void _mc_gst_handle_input_buffer_used(mc_gst_core_t *core, media_packet_h packet if (core && core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) { ((mc_empty_buffer_cb)core->user_cb[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]) (packet, core->user_data[_MEDIACODEC_EVENT_TYPE_EMPTYBUFFER]); - } - if (core) - LOGD("@v(%d)e(%d) input port emptied buffer(%d): %p", core->video, core->encoder, core->etb_count, packet); + g_mutex_lock(&core->drain_lock); + + if (core->need_drain) { + LOGD("@v(%d)e(%d) input port used----- single process_input.....", core->video, core->encoder); + core->need_drain = false; + g_cond_signal(&core->buffer_cond); + } + g_mutex_unlock(&core->drain_lock); + } } gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) { int ret = MC_ERROR_NONE; mc_gst_core_t *core = (mc_gst_core_t *)data; - LOGD("@%p v(%d)e(%d)", core, core->video, core->encoder); + LOGD("@%p v(%d)e(%d)bus message : %s", core, core->video, core->encoder, gst_message_type_get_name(GST_MESSAGE_TYPE(msg))); switch (GST_MESSAGE_TYPE(msg)) { @@ -2310,6 +2357,16 @@ gboolean __mc_gst_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) else LOGW("Unexpected error has occured"); + g_mutex_lock(&core->drain_lock); + + if (core->need_drain) { + LOGD("@v(%d)e(%d) input port used----- single process_input.....", core->video, core->encoder); + core->need_drain = false; + g_cond_signal(&core->buffer_cond); + } + + g_mutex_unlock(&core->drain_lock); + if (core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) { ((mc_error_cb) core->user_cb[_MEDIACODEC_EVENT_TYPE_ERROR]) (ret, core->user_data[_MEDIACODEC_EVENT_TYPE_ERROR]); @@ -2356,7 +2413,7 @@ static GstBusSyncReply __mc_gst_bus_sync_callback(GstBus *bus, GstMessage *msg, mc_gst_core_t *core = (mc_gst_core_t *)data; GstBusSyncReply reply = GST_BUS_DROP; - LOGD("__mc_gst_bus_sync_callback is called"); + LOGD("__mc_gst_bus_sync_callback is called : %s", gst_message_type_get_name(GST_MESSAGE_TYPE(msg))); if (!core->pipeline) { LOGE("mediacodec pipeline handle is null"); @@ -2419,6 +2476,8 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet for (i = 0; i < num_bos; i++) { mm_vbuffer->handle.bo[i] = tbm_surface_internal_get_bo(surface, i); LOGD("mm_vbuffer->handle.bo[%d] : %p", i, mm_vbuffer->handle.bo[i]); + tbm_bo_map(mm_vbuffer->handle.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ); + tbm_bo_unmap(mm_vbuffer->handle.bo[i]); } #ifdef TIZEN_PROFILE_LITE @@ -2472,13 +2531,14 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t *core, media_packet return mm_vbuffer; } -static void gst_mediacodec_buffer_finalize(GstMCBuffer *mcbuffer) +static void __mc_input_buffer_finalize_cb(GstMCBuffer *mcbuffer) { MEDIACODEC_FENTER(); if (!mcbuffer) return; + LOGD("============>>>>> _finalize_cb : %p, %p", mcbuffer, mcbuffer->packet); mc_gst_core_t *core = (mc_gst_core_t *)mcbuffer->core; _mc_gst_handle_input_buffer_used(core, mcbuffer->packet); @@ -2684,6 +2744,23 @@ static int _mc_gst_flush_buffers(mc_gst_core_t *core) _mc_gst_set_flush_input(core); + LOGW("Trying send flush_start .... "); + event = gst_event_new_flush_start(); + ret = gst_element_send_event(core->appsrc, event); + if (ret != TRUE) { + LOGE("failed to send Flush_Start event"); + return MC_ERROR; + } + + LOGW("Trying send flush_stop .... "); + event = gst_event_new_flush_stop(TRUE); + ret = gst_element_send_event(core->appsrc, event); + if (ret != TRUE) { + LOGE("failed to send Flush_Stop event"); + return MC_ERROR; + } + + LOGW("Trying send seek .... "); event = gst_event_new_seek(1.0, GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1); @@ -2706,17 +2783,17 @@ static void _mc_gst_set_flush_input(mc_gst_core_t *core) media_packet_h packet = NULL; MEDIACODEC_FENTER(); - LOGI("_mc_gst_set_flush_input called"); + LOGI("_mc_gst_set_flush_input called : input_queue_len = %d, etb_count = %d", core->available_queue->input->length, core->etb_count); while (!mc_async_queue_is_empty(core->available_queue->input)) { packet = mc_async_queue_pop_forced(core->available_queue->input); - g_atomic_int_dec_and_test(&core->etb_count); LOGD("%p poped(%d)", packet, core->etb_count); _mc_gst_handle_input_buffer_used(core, packet); } mc_async_queue_flush(core->available_queue->input); + LOGI("_mc_gst_set_flush_input ended : input_queue_len = %d, etb_count = %d", core->available_queue->input->length, core->etb_count); MEDIACODEC_FLEAVE(); } -- 2.7.4 From 48b40d4ffd885b8a9444fa9e1b2140cd4c9b2a30 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 19 May 2017 17:20:10 +0900 Subject: [PATCH 15/16] Added audioconvert for supporting 16bit pcm when running audio encoder Change-Id: Ifc30775dc202210669112a677b64cb4147e7213e --- include/media_codec_port_gst.h | 3 + packaging/capi-media-codec.spec | 2 +- src/media_codec_ini.c | 3 + src/media_codec_port.c | 2 +- src/media_codec_port_gst.c | 155 ++++++++++++++++++++++++++++++++++++---- test/media_codec_test.c | 12 ++-- 6 files changed, 156 insertions(+), 21 deletions(-) diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index 98e93c0..84ff576 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -98,6 +98,7 @@ struct _mc_gst_core_t { gchar *format; GstElement *pipeline; GstElement *appsrc; + GstElement *audioconvert; GstElement *capsfilter; GstElement *parser; GstElement *fakesink; @@ -147,6 +148,7 @@ struct _mc_gst_core_t { GQueue *output_queue; void *codec_info; + GstBuffer *codec_data; void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM]; void* user_data[_MEDIACODEC_EVENT_TYPE_NUM]; @@ -170,6 +172,7 @@ int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer); int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); +int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet); int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *packet); diff --git a/packaging/capi-media-codec.spec b/packaging/capi-media-codec.spec index 6b69fe1..c58bbf9 100755 --- a/packaging/capi-media-codec.spec +++ b/packaging/capi-media-codec.spec @@ -4,7 +4,7 @@ Name: capi-media-codec Summary: A Media Codec library in Tizen Native API -Version: 0.5.3 +Version: 0.5.4 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_codec_ini.c b/src/media_codec_ini.c index 1bc2c86..676ae83 100755 --- a/src/media_codec_ini.c +++ b/src/media_codec_ini.c @@ -227,6 +227,9 @@ media_format_mimetype_e _mc_convert_media_format_str_to_int(char *sformat) } else if (!strcmp(sformat, "PCM")) { iformat = MEDIA_FORMAT_PCM; goto endf; + } else if (!strcmp(sformat, "PCM_F32LE")) { + iformat = MEDIA_FORMAT_PCM_F32LE; + goto endf; } else if (!strcmp(sformat, "H261")) { iformat = MEDIA_FORMAT_H261; goto endf; diff --git a/src/media_codec_port.c b/src/media_codec_port.c index f2afd34..48760d6 100755 --- a/src/media_codec_port.c +++ b/src/media_codec_port.c @@ -682,7 +682,7 @@ int _mediacodec_foreach_supported_codec(mediacodec_supported_codec_cb callback, { int ret = MEDIACODEC_NONE; int i; - int index; + int index = 0; gboolean codec[CODEC_NR_ITEMS] = {0,}; diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index ae66a6e..9e93383 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,8 @@ static gint __gst_handle_resource_error(mc_gst_core_t *core, int code); static gint __gst_handle_library_error(mc_gst_core_t *core, int code); static gint __gst_handle_core_error(mc_gst_core_t *core, int code); static const gchar * _mc_error_to_string(mc_ret_e err); +static const gchar * _mc_bit_to_string(int bit); +static int _mc_get_support_bit_from_format(media_format_mimetype_e format); static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboolean is_encoder, gboolean is_hw); #ifdef TIZEN_PROFILE_LITE @@ -88,7 +91,7 @@ static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, static void _mc_send_eos_signal(mc_gst_core_t *core); static void _mc_wait_for_eos(mc_gst_core_t *core); -static int _mediacodec_get_mime(mc_gst_core_t *core); +static int _mc_get_mime(mc_gst_core_t *core); /* video vtable */ int(*vdec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer}; @@ -132,7 +135,7 @@ int(*aenc_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_ int(*adec_vtable[])() = {&__mc_fill_input_buffer_with_packet, &__mc_fill_packet_with_output_buffer}; int(*aenc_aac_vtable[])() = {&__mc_fill_input_buffer_with_packet, /* AAC LC Encoder vtable */ - &__mc_fill_packet_with_output_buffer}; + &__mc_fill_aenc_packet_with_output_buffer}; int(*adec_aac_vtable[])() = {&__mc_fill_input_buffer_with_adec_packet, /* AAC LC Decoder Vtable */ &__mc_fill_packet_with_output_buffer}; @@ -571,6 +574,63 @@ int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, in return ret; } +int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet) +{ + int ret = MC_ERROR_NONE; + GstPad *pad; + GstCaps *peercaps; + const GValue *codec_data = NULL; + void *packet_data = NULL; + GstMapInfo map; + guint8 *ptr; + gsize len; + + g_return_val_if_fail(core != NULL, MC_PARAM_ERROR); + + if (core->encoder && core->codec_id == MEDIACODEC_AAC) + media_format_set_audio_aac_type(core->output_fmt, FALSE); + + ret = media_packet_create_alloc(core->output_fmt, __mc_output_buffer_finalize_cb, core, out_packet); + if (ret != MEDIA_PACKET_ERROR_NONE) { + LOGW("media_packet_create_alloc failed"); + return MC_ERROR; + } + + media_packet_set_buffer_size(*out_packet, size); + media_packet_get_buffer_data_ptr(*out_packet, &packet_data); + memcpy(packet_data, data, size); + + if (!core->codec_data) { + pad = gst_element_get_static_pad(core->fakesink, "sink"); + peercaps = gst_pad_get_current_caps(pad); + if (peercaps) { + GstStructure *s; + if (gst_caps_is_empty(peercaps)) { + gst_caps_unref(peercaps); + gst_object_unref(pad); + LOGW("Empty caps"); + return ret; + } + + s = gst_caps_get_structure(peercaps, 0); + codec_data = gst_structure_get_value(s, "codec_data"); + core->codec_data = GST_BUFFER(g_value_dup_boxed(codec_data)); + gst_caps_unref(peercaps); + } + gst_object_unref(pad); + LOGD("codec data set"); + } + + if (core->codec_data) { + gst_buffer_map(core->codec_data, &map, GST_MAP_READ); + ptr = map.data; + len = map.size; + media_packet_set_codec_data(*out_packet, ptr, len); + gst_buffer_unmap(core->codec_data, &map); + } + + return ret; +} static GstCaps *__mc_gst_caps_set_buffer_array(GstCaps * caps, const gchar * name, GstBuffer * buf, ...) { @@ -827,10 +887,13 @@ int _mc_output_media_packet_new(mc_gst_core_t *core, bool video, bool encoder, m media_format_set_video_height(core->output_fmt, info->height); media_format_set_video_avg_bps(core->output_fmt, info->bitrate); } else { + int support_bit = 0; + support_bit = _mc_get_support_bit_from_format(out_mime); + media_format_set_audio_mime(core->output_fmt, out_mime); media_format_set_audio_channel(core->output_fmt, info->channel); media_format_set_audio_samplerate(core->output_fmt, info->samplerate); - media_format_set_audio_bit(core->output_fmt, info->bit); + media_format_set_audio_bit(core->output_fmt, support_bit); media_format_set_audio_avg_bps(core->output_fmt, info->bitrate); } } else { @@ -887,6 +950,7 @@ mc_gst_core_t *mc_gst_core_new() core->prepare_count = 0; core->etb_count = 0; core->ftb_count = 0; + core->codec_data = NULL; g_atomic_int_set(&core->available_queue->running, 1); core->available_queue->thread = g_thread_new("feed thread", &feed_task, core); @@ -923,6 +987,9 @@ void mc_gst_core_free(mc_gst_core_t *core) mc_async_queue_free(async_queue->input); g_free(async_queue); + if (core->codec_data) + gst_buffer_unref(core->codec_data); + if (core->ports[1] != NULL) { mc_gst_port_free(core->ports[1]); core->ports[1] = NULL; @@ -1077,6 +1144,7 @@ static int _mc_gst_update_caps(mc_gst_core_t *core, GstMCBuffer *mcbuffer, bool mc_encoder_info_t *enc_info = (mc_encoder_info_t *)core->codec_info; gst_caps_set_simple(core->caps, + "format", G_TYPE_STRING, _mc_bit_to_string(enc_info->bit), "rate", G_TYPE_INT, enc_info->samplerate, "channels", G_TYPE_INT, enc_info->channel, NULL); @@ -1280,7 +1348,6 @@ static int _mc_link_vtable(mc_gst_core_t *core, mediacodec_codec_type_e id, gboo if (encoder) { core->vtable = aenc_aac_vtable; core->caps = gst_caps_new_simple(core->mime, - "format", G_TYPE_STRING, "F32LE", "layout", G_TYPE_STRING, "interleaved", NULL); g_object_set(GST_OBJECT(core->codec), "compliance", -2, NULL); } else { @@ -1903,6 +1970,15 @@ mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name) goto ERROR; } + if (!core->video && core->encoder) { + core->audioconvert = gst_element_factory_make("audioconvert", NULL); + + if (!core->audioconvert) { + LOGE("capsfilter can't create"); + goto ERROR; + } + } + core->capsfilter = gst_element_factory_make("capsfilter", NULL); if (!core->capsfilter) { @@ -1919,12 +1995,22 @@ mc_ret_e _mc_gst_create_pipeline(mc_gst_core_t *core, gchar *factory_name) g_object_set(core->fakesink, "enable-last-sample", FALSE, NULL); /*__mc_link_elements(core);*/ - gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL); + if (!core->video && core->encoder) { + gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->audioconvert, core->codec, core->fakesink, NULL); - /* link elements */ - if (!(gst_element_link_many(core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL))) { - LOGE("gst_element_link_many is failed"); - goto ERROR; + /* link elements */ + if (!(gst_element_link_many(core->appsrc, core->capsfilter, core->audioconvert, core->codec, core->fakesink, NULL))) { + LOGE("gst_element_link_many is failed"); + goto ERROR; + } + } else { + gst_bin_add_many(GST_BIN(core->pipeline), core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL); + + /* link elements */ + if (!(gst_element_link_many(core->appsrc, core->capsfilter, core->codec, core->fakesink, NULL))) { + LOGE("gst_element_link_many is failed"); + goto ERROR; + } } /* connect signals, bus watcher */ @@ -1971,6 +2057,9 @@ ERROR: if (core->capsfilter) gst_object_unref(GST_OBJECT(core->capsfilter)); + if (core->audioconvert) + gst_object_unref(GST_OBJECT(core->audioconvert)); + if (core->fakesink) gst_object_unref(GST_OBJECT(core->fakesink)); @@ -3185,7 +3274,47 @@ const gchar * _mc_error_to_string(mc_ret_e err) } } -int _mediacodec_get_mime(mc_gst_core_t *core) +const gchar * _mc_bit_to_string(int bit) +{ + switch (bit) { + case 16: + return "S16LE"; + case 32: + return "F32LE"; + default: + return "NULL"; + + } +} + +int _mc_get_support_bit_from_format(media_format_mimetype_e format) +{ + int bit = 0; + + switch (format) { + case MEDIA_FORMAT_PCM_S16LE: + case MEDIA_FORMAT_PCM_S16BE: + case MEDIA_FORMAT_PCM_U16LE: + case MEDIA_FORMAT_PCM_U16BE: + bit = 16; + break; + case MEDIA_FORMAT_PCM_S32LE: + case MEDIA_FORMAT_PCM_S32BE: + case MEDIA_FORMAT_PCM_U32LE: + case MEDIA_FORMAT_PCM_U32BE: + case MEDIA_FORMAT_PCM_F32LE: + case MEDIA_FORMAT_PCM_F32BE: + bit = 32; + break; + default: + LOGE("NOT SUPPORTED!!!!"); + break; + } + + return bit; +} + +int _mc_get_mime(mc_gst_core_t *core) { media_format_mimetype_e mime = MEDIA_FORMAT_MAX; @@ -3212,14 +3341,14 @@ int _mediacodec_get_mime(mc_gst_core_t *core) break; case MEDIACODEC_AAC: if (core->encoder) - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /*FIXME need to change PCM supported by chipset */ else mime = MEDIA_FORMAT_AAC; break; case MEDIACODEC_AAC_HE: if (core->encoder) - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to change PCM supported by chipset */ else mime = MEDIA_FORMAT_AAC_HE; @@ -3281,7 +3410,7 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pac return MC_ERROR; } - mime_format = _mediacodec_get_mime(core); + mime_format = _mc_get_mime(core); if (core->video) { if (core->encoder) { diff --git a/test/media_codec_test.c b/test/media_codec_test.c index 1f6096c..67f0f68 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -873,7 +873,7 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) case MEDIACODEC_AAC: if (encoder) { extractor = aacenc_extractor; - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ } else { extractor = aacdec_extractor; mime = MEDIA_FORMAT_AAC; @@ -882,7 +882,7 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) case MEDIACODEC_AAC_HE: if (encoder) { extractor = aacenc_extractor; - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ } else { extractor = extract_input_aacdec_m4a_test; mime = MEDIA_FORMAT_AAC_HE; @@ -909,7 +909,7 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) case MEDIACODEC_AMR_NB: if (encoder) { extractor = amrenc_extractor; - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ app->is_amr_nb = TRUE; } else { extractor = amrdec_extractor; @@ -919,7 +919,7 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) case MEDIACODEC_AMR_WB: if (encoder) { extractor = amrenc_extractor; - mime = MEDIA_FORMAT_PCM; + mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ app->is_amr_nb = FALSE; } else { extractor = amrdec_extractor; @@ -1244,10 +1244,10 @@ static bool _mediacodec_eos_cb(void *user_data) return TRUE; } -void _foreach_cb(mediacodec_codec_type_e codec_type, void *user_data) +gboolean _foreach_cb(mediacodec_codec_type_e codec_type, void *user_data) { g_print("codec type : %x %s\n", codec_type, codec_type_to_string(codec_type)); - return; + return TRUE; } static void _mediacodec_prepare(App *app, bool frame_all) -- 2.7.4 From 69dd0f486e53d400c726bf18b94d23026ccfeb87 Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 9 Jun 2017 12:38:10 +0900 Subject: [PATCH 16/16] removed unused code Change-Id: Ieca797efb30634bcfd742caba63434074a70406d --- include/media_codec.h | 0 include/media_codec_bitstream.h | 0 include/media_codec_ini.h | 0 include/media_codec_internal.h | 0 include/media_codec_port.h | 0 include/media_codec_port_gst.h | 0 include/media_codec_private.h | 0 include/media_codec_queue.h | 0 include/media_codec_spec_emul.h | 0 include/media_codec_util.h | 10 +- src/media_codec.c | 0 src/media_codec_bitstream.c | 0 src/media_codec_ini.c | 0 src/media_codec_internal.c | 0 src/media_codec_port.c | 0 src/media_codec_port_gst.c | 0 src/media_codec_queue.c | 0 src/media_codec_util.c | 0 test/media_codec_test.c | 403 ++++++++++++++++------------------------ 19 files changed, 166 insertions(+), 247 deletions(-) mode change 100755 => 100644 include/media_codec.h mode change 100755 => 100644 include/media_codec_bitstream.h mode change 100755 => 100644 include/media_codec_ini.h mode change 100755 => 100644 include/media_codec_internal.h mode change 100755 => 100644 include/media_codec_port.h mode change 100755 => 100644 include/media_codec_port_gst.h mode change 100755 => 100644 include/media_codec_private.h mode change 100755 => 100644 include/media_codec_queue.h mode change 100755 => 100644 include/media_codec_spec_emul.h mode change 100755 => 100644 include/media_codec_util.h mode change 100755 => 100644 src/media_codec.c mode change 100755 => 100644 src/media_codec_bitstream.c mode change 100755 => 100644 src/media_codec_ini.c mode change 100755 => 100644 src/media_codec_internal.c mode change 100755 => 100644 src/media_codec_port.c mode change 100755 => 100644 src/media_codec_port_gst.c mode change 100755 => 100644 src/media_codec_queue.c mode change 100755 => 100644 src/media_codec_util.c mode change 100755 => 100644 test/media_codec_test.c diff --git a/include/media_codec.h b/include/media_codec.h old mode 100755 new mode 100644 diff --git a/include/media_codec_bitstream.h b/include/media_codec_bitstream.h old mode 100755 new mode 100644 diff --git a/include/media_codec_ini.h b/include/media_codec_ini.h old mode 100755 new mode 100644 diff --git a/include/media_codec_internal.h b/include/media_codec_internal.h old mode 100755 new mode 100644 diff --git a/include/media_codec_port.h b/include/media_codec_port.h old mode 100755 new mode 100644 diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h old mode 100755 new mode 100644 diff --git a/include/media_codec_private.h b/include/media_codec_private.h old mode 100755 new mode 100644 diff --git a/include/media_codec_queue.h b/include/media_codec_queue.h old mode 100755 new mode 100644 diff --git a/include/media_codec_spec_emul.h b/include/media_codec_spec_emul.h old mode 100755 new mode 100644 diff --git a/include/media_codec_util.h b/include/media_codec_util.h old mode 100755 new mode 100644 index 988a54a..5dde410 --- a/include/media_codec_util.h +++ b/include/media_codec_util.h @@ -55,10 +55,12 @@ void mc_sem_up(mc_sem_t *sem); void mc_hex_dump(char *desc, void *addr, int len); -#define MC_FREEIF(x) \ - if (x) \ - g_free(x); \ - x = NULL; +#define MC_FREEIF(x) \ + do { \ + if (x) \ + g_free(x); \ + x = NULL; \ + } while(0) #ifdef __cplusplus } diff --git a/src/media_codec.c b/src/media_codec.c old mode 100755 new mode 100644 diff --git a/src/media_codec_bitstream.c b/src/media_codec_bitstream.c old mode 100755 new mode 100644 diff --git a/src/media_codec_ini.c b/src/media_codec_ini.c old mode 100755 new mode 100644 diff --git a/src/media_codec_internal.c b/src/media_codec_internal.c old mode 100755 new mode 100644 diff --git a/src/media_codec_port.c b/src/media_codec_port.c old mode 100755 new mode 100644 diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c old mode 100755 new mode 100644 diff --git a/src/media_codec_queue.c b/src/media_codec_queue.c old mode 100755 new mode 100644 diff --git a/src/media_codec_util.c b/src/media_codec_util.c old mode 100755 new mode 100644 diff --git a/test/media_codec_test.c b/test/media_codec_test.c old mode 100755 new mode 100644 index 67f0f68..9c35563 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include #include @@ -58,7 +60,7 @@ #define AAC_CODECDATA_SIZE 16 #define USE_POOL 1 -unsigned char buf_adts[ADTS_HEADER_SIZE]; +guint8 buf_adts[ADTS_HEADER_SIZE]; enum { MC_EXIST_SPS = 1 << 0, @@ -125,18 +127,18 @@ struct _App { gint obj; GTimer *timer; - long start; - long finish; - long process_time; - int frame_count; - - int codecid; - int flag; - bool is_video; - bool is_encoder; - bool hardware; - bool enable_dump; - int frame; + glong start; + glong finish; + glong process_time; + gint frame_count; + + gint codecid; + gint flag; + gboolean is_video; + gboolean is_encoder; + gboolean hardware; + gboolean enable_dump; + gint frame; type_e type; camera_h camera_handle; /* video */ @@ -152,7 +154,7 @@ struct _App { guint channel; guint bit; guint bitrate; - bool is_amr_nb; + gboolean is_amr_nb; /* Render */ @@ -172,24 +174,24 @@ media_format_h fmt = NULL; media_packet_pool_h pkt_pool = NULL; /* Internal Functions */ -static int _create_app(void *data); -static int _terminate_app(void *data); +static gint _create_app(void *data); +static gint _terminate_app(void *data); static void displaymenu(void); static void display_sub_basic(); static void _mediacodec_unprepare(App *app); /* For debugging */ -static void mc_hex_dump(char *desc, void *addr, int len); +static void mc_hex_dump(char *desc, void *addr, gint len); static void decoder_output_dump(App *app, media_packet_h pkt); static void output_dump(App *app, media_packet_h pkt); /* */ const char* codec_type_to_string(mediacodec_codec_type_e media_codec_id); -void (*extractor)(App *app, unsigned char** data, int *size, bool *have_frame); +void (*extractor)(App *app, guint8** data, gint *size, gboolean *have_frame, gboolean *codec_data); -int g_menu_state = CURRENT_STATUS_MAINMENU; +gint g_menu_state = CURRENT_STATUS_MAINMENU; -static int _create_app(void *data) +static gint _create_app(void *data) { g_print("My app is going alive!\n"); App *app = (App*)data; @@ -198,7 +200,7 @@ static int _create_app(void *data) return 0; } -static int _terminate_app(void *data) +static gint _terminate_app(void *data) { g_print("My app is going gone!\n"); App *app = (App*)data; @@ -231,18 +233,18 @@ static const guint mp3types_freqs[3][3] = { {44100, 48000, 32000}, {11025, 12000, 8000} }; -void h264_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void h264_extractor(App *app, guint8 **data, gint *size, gboolean *have_frame, gboolean *codec_data) { - unsigned char val, zero_count; - unsigned char *pNal = app->data + app->offset; - int max = app->length - app->offset; - int index = 0; - int nal_unit_type = 0; - bool init; - bool slice; - bool idr; - static int state; - int read; + guint8 val, zero_count; + guint8 *pNal = app->data + app->offset; + gint max = app->length - app->offset; + gint index = 0; + gint nal_unit_type = 0; + gboolean init; + gboolean slice; + gboolean idr; + static gint state; + gint read; zero_count = 0; @@ -328,12 +330,12 @@ DONE: app->offset += read; } -void h263_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +void h263_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { int len = 0; int read_size = 1, state = 1, bStart = 0; - unsigned char val; - unsigned char *pH263 = app->data + app->offset; + guint8 val; + guint8 *pH263 = app->data + app->offset; *data = pH263; int max = app->length - app->offset; @@ -373,13 +375,13 @@ void h263_extractor(App * app, unsigned char **data, int *size, bool * have_fram *have_frame = TRUE; } -void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +void mpeg4_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { int len = 0; int result = 0; int state = 1, bType = 0; - unsigned char val; - unsigned char *pMpeg4 = app->data + app->offset; + guint8 val; + guint8 *pMpeg4 = app->data + app->offset; *data = pMpeg4; int max = app->length - app->offset; @@ -435,20 +437,20 @@ void mpeg4_extractor(App * app, unsigned char **data, int *size, bool * have_fra * - AMR-NB : mime type ("audio/AMR") / 8Khz / 1 ch / 16 bits * - AMR-WB : mime type ("audio/AMR-WB") / 16Khz / 1 ch / 16 bits **/ -int write_amr_header = 1; /* write magic number for AMR Header at one time */ -static const char AMR_header[] = "#!AMR\n"; -static const char AMRWB_header[] = "#!AMR-WB\n"; +gint write_amr_header = 1; /* write magic number for AMR Header at one time */ +static const gchar AMR_header[] = "#!AMR\n"; +static const gchar AMRWB_header[] = "#!AMR-WB\n"; #define AMR_NB_MIME_HDR_SIZE 6 #define AMR_WB_MIME_HDR_SIZE 9 -static const int block_size_nb[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; -static const int block_size_wb[16] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, 0, 0 }; +static const gint block_size_nb[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; +static const gint block_size_wb[16] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, 0, 0 }; -int *blocksize_tbl; -void amrdec_extractor(App * app, unsigned char **data, int *size, bool * have_frame) +gint *blocksize_tbl; +void amrdec_extractor(App * app, guint8 **data, gint *size, gboolean * have_frame, gboolean *codec_data) { - int readsize = 0, mode_temp; - unsigned int fsize, mode; - unsigned char *pAmr = app->data + app->offset; + gint readsize = 0, mode_temp; + gint fsize, mode; + guint8 *pAmr = app->data + app->offset; /* change the below one to frame count */ if (app->offset == 0) { if (!memcmp(pAmr, AMR_header, AMR_NB_MIME_HDR_SIZE)) { @@ -484,10 +486,10 @@ void amrdec_extractor(App * app, unsigned char **data, int *size, bool * have_fr *have_frame = TRUE; } -void nv12_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void nv12_extractor(App *app, guint8 **data, gint *size, gboolean *have_frame, gboolean *codec_data) { - int yuv_size; - int offset = app->length - app->offset; + gint yuv_size; + gint offset = app->length - app->offset; yuv_size = app->width * app->height * 3 / 2; @@ -497,16 +499,18 @@ void nv12_extractor(App *app, unsigned char **data, int *size, bool *have_frame) *have_frame = TRUE; *data = app->data + app->offset; - if (offset >= yuv_size) + if (yuv_size >= offset) *size = offset; else *size = yuv_size; + + app->offset += *size; } -void yuv_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void yuv_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int yuv_size; - int offset = app->length - app->offset; + gint yuv_size; + gint offset = app->length - app->offset; yuv_size = app->width * app->height * 3 / 2; @@ -522,13 +526,12 @@ void yuv_extractor(App *app, unsigned char **data, int *size, bool *have_frame) *size = yuv_size; app->offset += *size; - } -void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void aacenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; - int offset = app->length - app->offset; + gint read_size; + gint offset = app->length - app->offset; read_size = ((DEFAULT_SAMPLEBYTE * app->channel)*(app->bit/8) * 2); @@ -543,10 +546,10 @@ void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram app->offset += *size; } -void amrenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void amrenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; - int offset = app->length - app->offset; + gint read_size; + gint offset = app->length - app->offset; if (app->is_amr_nb) read_size = AMRNB_PCM_INPUT_SIZE; @@ -569,11 +572,11 @@ void amrenc_extractor(App *app, unsigned char **data, int *size, bool *have_fram * (case of (LC profile) ADTS format) * codec_data : Don't need **/ -void aacdec_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void aacdec_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { int read_size; int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; + guint8 *pData = app->data + app->offset; if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); @@ -591,17 +594,16 @@ void aacdec_extractor(App *app, unsigned char **data, int *size, bool *have_fram *size = read_size; app->offset += *size; - } -void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_frame) +void mp3dec_extractor(App *app, guint8 **data, int *size, gboolean *have_frame, gboolean *codec_data) { - int read_size; + gint read_size; guint header; guint padding, bitrate, lsf = 0, layer = 0, mpg25 = 0; guint hdr_bitrate = 0, sf = 0; - int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; + gint offset = app->length - app->offset; + guint8 *pData = app->data + app->offset; header = GST_READ_UINT32_BE(pData); @@ -693,117 +695,11 @@ void mp3dec_extractor(App *app, unsigned char **data, int *size, bool *have_fram app->offset += *size; } -#if 1 -void extract_input_aacdec_m4a_test(App * app, unsigned char **data, int *size, bool * have_frame) -{ - int readsize = 0, read_size = 0; - unsigned int header_size = ADTS_HEADER_SIZE; - unsigned char buffer[100000]; - unsigned char codecdata[AAC_CODECDATA_SIZE] = { 0, }; - int offset = app->length - app->offset; - unsigned char *pData = app->data + app->offset; - /* - * It is not support full parsing MP4 container box. - * So It MUST start as RAW valid frame sequence. - * Testsuit that are not guaranteed to be available on functionality of all General DEMUXER/PARSER. - */ - - /* change the below one later */ - if (app->offset == 0) { - /* - * CAUTION : Codec data is needed only once in first time - * Codec data is made(or extracted) by MP4 demuxer in 'esds' box. - * So I use this data (byte) as hard coding for temporary our testing. - */ -#if 1 - /* - * The codec_data data is according to AudioSpecificConfig, - * ISO/IEC 14496-3, 1.6.2.1 - * - * below example is test for using "test.aac" or "TestSample-AAC-LC.m4a" - * case : M4A - LC profile - * codec_data=(buffer)119056e5000000000000000000000000 - * savs aac decoder get codec_data. size: 16 (Tag size : 5 byte) - * - codec data: profile : 2 - * - codec data: samplrate: 48000 - * - codec data: channels : 2 - */ - /* 2 bytes are mandatory */ - codecdata[0] = 0x11; /* ex) (5bit) 2 (LC) / (4bit) 3 (48khz)*/ - codecdata[1] = 0x90; /* ex) (4bit) 2 (2ch) */ - /* othter bytes are (optional) epconfig information */ - codecdata[2] = 0x56; - codecdata[3] = 0xE5; - codecdata[4] = 0x00; -#else - /* - * below example is test for using "TestSample-EAAC+.m4a" - * - * case : M4A - HE-AAC v1 and v2 profile - * codec_data=(buffer)138856e5a54880000000000000000000 - * savs aac decoder get codec_data. size: 16 (Tag size : 7 byte) - * - codec data: profile : 2 - * - codec data: samplrate: 22050 - * - codec data: channels : 1 - */ - /* 2 bytes are mandatory */ - codecdata[0] = 0x13; /* ex) (5bit) 2 (LC) / (4bit) 9 (22khz) */ - codecdata[1] = 0x88; /* ex) (4bit) 1 (1ch) */ - /* othter bytes are (optional) epconfig information */ - codecdata[2] = 0x56; - codecdata[3] = 0xE5; - codecdata[4] = 0xA5; - codecdata[5] = 0x48; - codecdata[6] = 0x80; -#endif - - memcpy(buffer, codecdata, AAC_CODECDATA_SIZE); - if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { - read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); - } else { - read_size = 0; - g_print("[FAIL] Not found aac frame sync.....\n"); - } - readsize = read_size - header_size; - memcpy(buffer + AAC_CODECDATA_SIZE, pData + 7, readsize); - read_size = readsize + AAC_CODECDATA_SIZE; /* return combination of (codec_data + raw_data) */ - app->offset += header_size + readsize; - goto DONE; - } - - if ((pData != NULL) && (pData[0] == 0xff) && ((pData[1] & 0xf6) == 0xf0)) { - read_size = ((pData[3] & 0x03) << 11) | (pData[4] << 3) | ((pData[5] & 0xe0) >> 5); - readsize = read_size - header_size; - memcpy(buffer, pData + 7, readsize); /* Make only RAW data, so exclude header 7 bytes */ - read_size = readsize; - app->offset += header_size + readsize; - - if (app->offset > app->length) { - read_size = 0; - *have_frame = FALSE; - g_print("[FAIL] offset error \n"); - return; - } - - } else { - read_size = 0; - g_print("[FAIL] Not found aac frame sync. \n"); - } - DONE: - *data = buffer; - *have_frame = TRUE; - if (read_size >= offset) - *size = offset; - else - *size = read_size; -} -#endif - /** * Extract Input data for AAC encoder **/ /* - void aacenc_extractor(App *app, unsigned char **data, int *size, bool *have_frame) + void aacenc_extractor(App *app, guint8 **data, int *size, gboolean *have_frame) { int read_size; int offset = app->length - app->offset; @@ -824,19 +720,9 @@ void extract_input_aacdec_m4a_test(App * app, unsigned char **data, int *size, b app->offset += *size; } */ -#if 0 -static void _mediacodec_empty_buffer_cb(media_packet_h pkt, void *user_data) -{ - if (pkt != NULL) { - g_print("Used input buffer = %p\n", pkt); - media_packet_destroy(pkt); - } - return; -} -#endif -int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) +int _configure(App *app, int codecid, int flag, gboolean *hardware) { - bool encoder; + gboolean encoder; media_format_mimetype_e mime = 0; encoder = GET_IS_ENCODER(flag) ? 1 : 0; *hardware = GET_IS_HW(flag) ? 1 : 0; @@ -883,9 +769,6 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) if (encoder) { extractor = aacenc_extractor; mime = MEDIA_FORMAT_PCM_F32LE; /* FIXME need to check according to verdor */ - } else { - extractor = extract_input_aacdec_m4a_test; - mime = MEDIA_FORMAT_AAC_HE; } break; case MEDIACODEC_AAC_HE_PS: @@ -935,22 +818,23 @@ int _mediacodec_set_codec(App *app, int codecid, int flag, bool *hardware) static void _mediacodec_process_input(App *app) { - int i; - bool have_frame = FALSE; - int ret; + gint i; + gboolean have_frame = FALSE; + gint ret; static guint64 pts = 0L; void *buf_data_ptr = NULL; media_packet_h pkt = NULL; - unsigned char *tmp; - int read; - int size; - int offset; - int stride_width; + guint8 *tmp; + gint read; + gint size; + gint offset; + gint stride_width; + gboolean codec_config = FALSE; for (i = 0; i < app->frame; i++) { g_print("----------read data------------\n"); - extractor(app, &tmp, &read, &have_frame); + extractor(app, &tmp, &read, &have_frame, &codec_config); if (have_frame) { #ifdef USE_POOL @@ -973,7 +857,6 @@ static void _mediacodec_process_input(App *app) if (app->type != VIDEO_ENC) { media_packet_get_buffer_data_ptr(pkt, &buf_data_ptr); media_packet_set_buffer_size(pkt, (uint64_t)read); - memcpy(buf_data_ptr, tmp, read); g_print("tmp:%p, read:%d\n", tmp, read); } else { @@ -1037,17 +920,18 @@ static void _mediacodec_process_input(App *app) static gboolean read_data(App *app) { guint len = 0; - bool have_frame = FALSE; - int ret; + gboolean have_frame = FALSE; + gboolean codec_config = FALSE; + gint ret; static guint64 pts = 0L; void *buf_data_ptr = NULL; media_packet_h pkt = NULL; - unsigned char *tmp; - int i; - int read; - int size; - int offset; - int stride_width; + guint8 *tmp; + gint i; + gint read; + gint size; + gint offset; + gint stride_width; if (app->offset == 0) { app->frame_count = 0; @@ -1055,7 +939,7 @@ static gboolean read_data(App *app) } g_print("----------read data------------\n"); - extractor(app, &tmp, &read, &have_frame); + extractor(app, &tmp, &read, &have_frame, &codec_config); if (app->offset >= app->length - 4) { /* EOS */ @@ -1185,7 +1069,7 @@ static gboolean _mediacodec_inbuf_used_cb(media_packet_h pkt, void *user_data) return TRUE; } -static bool _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) +static gboolean _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) { media_packet_h out_pkt = NULL; int ret; @@ -1220,7 +1104,7 @@ static bool _mediacodec_outbuf_available_cb(media_packet_h pkt, void *user_data) return TRUE; } -static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data) +static gboolean _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_data) { g_print("_mediacodec_buffer_status_cb %d\n", status); @@ -1234,12 +1118,12 @@ static bool _mediacodec_buffer_status_cb(mediacodec_status_e status, void *user_ return TRUE; } -static bool _mediacodec_error_cb(mediacodec_error_e error, void *user_data) +static gboolean _mediacodec_error_cb(mediacodec_error_e error, void *user_data) { return TRUE; } -static bool _mediacodec_eos_cb(void *user_data) +static gboolean _mediacodec_eos_cb(void *user_data) { return TRUE; } @@ -1250,7 +1134,7 @@ gboolean _foreach_cb(mediacodec_codec_type_e codec_type, void *user_data) return TRUE; } -static void _mediacodec_prepare(App *app, bool frame_all) +static void _mediacodec_prepare(App *app, gboolean frame_all) { int ret; @@ -1271,7 +1155,8 @@ static void _mediacodec_prepare(App *app, bool frame_all) return; } - app->mime = _mediacodec_set_codec(app, app->codecid, app->flag, &app->hardware); + /* get mime and link to each codec parser */ + app->mime = _configure(app, app->codecid, app->flag, &app->hardware); /* set codec info */ ret = media_format_create(&fmt); @@ -1332,7 +1217,7 @@ static void _mediacodec_prepare(App *app, bool frame_all) } -/* get packet pool instance */ + /* get packet pool instance */ ret = mediacodec_get_packet_pool(app->mc_handle[0], &pkt_pool); if (ret != MEDIA_PACKET_ERROR_NONE) { g_print("mediacodec_get_packet_pool failed\n"); @@ -1493,7 +1378,7 @@ void quit_program(App *app) { media_format_unref(fmt); g_main_loop_quit(app->loop); - elm_exit(); + exit(0); } @@ -1505,7 +1390,7 @@ void reset_menu_state() void _interpret_main_menu(char *cmd, App *app) { - int len = strlen(cmd); + gint len = strlen(cmd); if (len == 1) { if (strncmp(cmd, "a", 1) == 0) g_menu_state = CURRENT_STATUS_FILENAME; @@ -1619,8 +1504,11 @@ gboolean timeout_menu_display(void* data) } -static void interpret(char *cmd, App *app) +static void interpret(char *cmd) { + App *app = &s_app; + gint tmp = 0; + switch (g_menu_state) { case CURRENT_STATUS_MAINMENU: _interpret_main_menu(cmd, app); @@ -1631,9 +1519,8 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_CODEC: { - int tmp; - static int cnt = 0; - char **ptr = NULL; + static gint cnt = 0; + gchar **ptr = NULL; switch (cnt) { case 0: tmp = atoi(cmd); @@ -1662,7 +1549,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_VDEC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->width = atoi(cmd); @@ -1682,7 +1569,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_VENC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->width = atoi(cmd); @@ -1710,7 +1597,7 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_SET_ADEC_INFO: { - static int cnt = 0; + static gint cnt = 0; switch (cnt) { case 0: app->samplerate = atoi(cmd); @@ -1737,20 +1624,48 @@ static void interpret(char *cmd, App *app) static int cnt = 0; switch (cnt) { case 0: - app->samplerate = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 96000) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->samplerate = tmp; cnt++; break; case 1: - app->channel = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 6) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->channel = tmp; cnt++; break; case 2: - app->bit = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > 32) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->bit = tmp; cnt++; break; case 3: - app->bitrate = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > INT_MAX) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } app->type = AUDIO_ENC; + app->bitrate = tmp; reset_menu_state(); cnt = 0; @@ -1762,10 +1677,16 @@ static void interpret(char *cmd, App *app) break; case CURRENT_STATUS_PROCESS_INPUT: { - app->frame = atoi(cmd); + tmp = atoi(cmd); + + if (tmp <= 0 || tmp > INT_MAX) { + g_print("Invalid value\n"); + reset_menu_state(); + break; + } + app->frame = tmp; - if (app->frame > 0 && app->frame < 10) - _mediacodec_process_input(app); + _mediacodec_process_input(app); reset_menu_state(); } break; @@ -1814,33 +1735,29 @@ gboolean input(GIOChannel *channel, GIOCondition cond, gpointer data) gchar buf[MAX_STRING_LEN]; gsize read; GError *error = NULL; - App *context = (App*)data; g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error); buf[read] = '\0'; g_strstrip(buf); - interpret(buf, context); + interpret(buf); return TRUE; } int main(int argc, char *argv[]) { - App *app = &s_app; - GIOChannel *stdin_channel; stdin_channel = g_io_channel_unix_new(0); g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, app); + g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL); + App *app = &s_app; displaymenu(); app->loop = g_main_loop_new(NULL, TRUE); app->timer = g_timer_new(); g_main_loop_run(app->loop); - - ops.data = app; return appcore_efl_main(PACKAGE, &argc, &argv, &ops); @@ -1848,11 +1765,11 @@ int main(int argc, char *argv[]) -void mc_hex_dump(char *desc, void *addr, int len) +void mc_hex_dump(char *desc, void *addr, gint len) { int i; - unsigned char buff[17]; - unsigned char *pc = (unsigned char *)addr; + guint8 buff[17]; + guint8 *pc = (guint8 *)addr; if (desc != NULL) g_print("%s:\n", desc); -- 2.7.4