From 388bf06e1b69471661cd0dd59cafb29768b461b2 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Thu, 2 Oct 2014 16:57:17 +0900 Subject: [PATCH] Fix close routine at decoder plugin. Open flag in decoder context was not set into false when closing contxt. In addition to this, unnecessary sources are removed. Change-Id: Ie13514bc532be10fcdb59889d95c48bc5bbcba3c Signed-off-by: Kitae Kim --- src/gstmarudec.c | 137 +++++++++---------------------------------------- src/gstmarudevice.c | 12 +---- src/gstmaruenc.c | 2 +- src/gstmaruinterface.c | 49 +----------------- src/gstmarumem.c | 1 - src/gstmaruutils.c | 5 +- 6 files changed, 29 insertions(+), 177 deletions(-) diff --git a/src/gstmarudec.c b/src/gstmarudec.c index 313eff3..8608554 100644 --- a/src/gstmarudec.c +++ b/src/gstmarudec.c @@ -67,7 +67,7 @@ static gint gst_marudec_frame (GstMaruDec *marudec, guint8 *data, const GstTSInfo *dec_info, gint64 in_offset, GstFlowReturn *ret); static gboolean gst_marudec_open (GstMaruDec *marudec); -static int gst_marudec_close (GstMaruDec *marudec); +static void gst_marudec_close (GstMaruDec *marudec); static const GstTSInfo * @@ -154,14 +154,9 @@ gst_marudec_do_qos (GstMaruDec *marudec, GstClockTime timestamp, return TRUE; } else { if (diff >= 0) { -// if (marudec->waiting_for_key) { if (0) { res = FALSE; } -#if 0 - else { - } -#endif GstClockTime stream_time, jitter; GstMessage *qos_msg; @@ -296,7 +291,7 @@ gst_marudec_base_init (GstMaruDecClass *klass) srccaps = gst_maru_codectype_to_audio_caps (NULL, codec->name, FALSE, codec); break; default: - GST_LOG("unknown media type.\n"); + GST_LOG("unknown media type"); break; } @@ -368,11 +363,6 @@ gst_marudec_init (GstMaruDec *marudec) marudec->queued = NULL; gst_segment_init (&marudec->segment, GST_FORMAT_TIME); - - marudec->dev = g_malloc0 (sizeof(CodecDevice)); - if (!marudec->dev) { - GST_ERROR_OBJECT (marudec, "failed to allocate memory for CodecDevice"); - } } static void @@ -380,10 +370,9 @@ gst_marudec_finalize (GObject *object) { GstMaruDec *marudec = (GstMaruDec *) object; - if (marudec->context) { - g_free (marudec->context); - marudec->context = NULL; - } + GST_DEBUG_OBJECT (marudec, "finalize object and release context"); + g_free (marudec->context); + marudec->context = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -441,15 +430,12 @@ gst_marudec_sink_event (GstPad *pad, GstEvent *event) case GST_EVENT_FLUSH_STOP: { if (marudec->opened) { + GST_DEBUG_OBJECT (marudec, "flush decoded buffers"); interface->flush_buffers (marudec->context, marudec->dev); } gst_marudec_reset_ts (marudec); gst_marudec_reset_qos (marudec); -#if 0 - gst_marudec_flush_pcache (marudec); - marudec->waiting_for_key = TRUE; -#endif gst_segment_init (&marudec->segment, GST_FORMAT_TIME); clear_queued (marudec); } @@ -507,7 +493,7 @@ gst_marudec_sink_event (GstPad *pad, GstEvent *event) return ret; } - if (marudec->context->codec) { + if (marudec->opened) { gst_marudec_drain (marudec); } @@ -553,8 +539,8 @@ gst_marudec_setcaps (GstPad *pad, GstCaps *caps) GST_OBJECT_UNLOCK (marudec); gst_marudec_drain (marudec); GST_OBJECT_LOCK (marudec); - gst_marudec_close (marudec); } + gst_marudec_close (marudec); GST_LOG_OBJECT (marudec, "size %dx%d", marudec->context->video.width, marudec->context->video.height); @@ -583,14 +569,6 @@ gst_marudec_setcaps (GstPad *pad, GstCaps *caps) GST_DEBUG_OBJECT (marudec, "sink caps have pixel-aspect-ratio of %d:%d", gst_value_get_fraction_numerator (par), gst_value_get_fraction_denominator (par)); - -#if 0 // TODO - if (marudec->par) { - g_free(marudec->par); - } - marudec->par = g_new0 (GValue, 1); - gst_value_init_and_copy (marudec->par, par); -#endif } fps = gst_structure_get_value (structure, "framerate"); @@ -615,12 +593,6 @@ gst_marudec_setcaps (GstPad *pad, GstCaps *caps) if (!gst_marudec_open (marudec)) { GST_DEBUG_OBJECT (marudec, "Failed to open"); -#if 0 - if (marudec->par) { - g_free(marudec->par); - marudec->par = NULL; - } -#endif GST_OBJECT_UNLOCK (marudec); gst_object_unref (marudec); @@ -648,13 +620,15 @@ gst_marudec_open (GstMaruDec *marudec) oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec)); + marudec->dev = g_try_malloc0 (sizeof(CodecDevice)); if (!marudec->dev) { + GST_ERROR_OBJECT (marudec, "failed to allocate memory for CodecDevice"); return FALSE; } - if (gst_maru_avcodec_open (marudec->context, - oclass->codec, marudec->dev) < 0) { - gst_marudec_close (marudec); + if (gst_maru_avcodec_open (marudec->context, oclass->codec, marudec->dev) < 0) { + g_free(marudec->dev); + marudec->dev = NULL; GST_ERROR_OBJECT (marudec, "maru_%sdec: Failed to open codec", oclass->codec->name); return FALSE; @@ -689,28 +663,30 @@ gst_marudec_open (GstMaruDec *marudec) return TRUE; } -static int +static void gst_marudec_close (GstMaruDec *marudec) { - int ret = 0; + if (!marudec->opened) { + GST_DEBUG_OBJECT (marudec, "not opened yet"); + return; + } - if (marudec->context->codecdata) { + if (marudec->context) { g_free(marudec->context->codecdata); marudec->context->codecdata = NULL; } if (!marudec->dev) { - return -1; + return; } - ret = gst_maru_avcodec_close (marudec->context, marudec->dev); + gst_maru_avcodec_close (marudec->context, marudec->dev); + marudec->opened = FALSE; if (marudec->dev) { g_free(marudec->dev); marudec->dev = NULL; } - - return ret; } @@ -795,10 +771,6 @@ gst_marudec_negotiate (GstMaruDec *marudec, gboolean force) GST_TYPE_FRACTION, marudec->format.video.fps_n, marudec->format.video.fps_d, NULL); } -#if 0 - gst_marudec_add_pixel_aspect_ratio (marudec, - gst_caps_get_structure (caps, 0)); -#endif } } break; @@ -971,10 +943,6 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size, decode = gst_marudec_do_qos (marudec, dec_info->timestamp, &mode_switch); - if (decode) { - // FIXME - } - GST_DEBUG_OBJECT (marudec, "decode video: input buffer size %d", size); len = interface->decode_video (marudec, data, size, @@ -984,12 +952,11 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size, } *ret = get_output_buffer (marudec, outbuf); - if (G_UNLIKELY (*ret != GST_FLOW_OK)) { GST_DEBUG_OBJECT (marudec, "no output buffer"); len = -1; GST_DEBUG_OBJECT (marudec, "return flow %d, out %p, len %d", - *ret, *outbuf, len); + *ret, *outbuf, len); return len; } @@ -1115,7 +1082,6 @@ gst_marudec_audio_frame (GstMaruDec *marudec, CodecElement *codec, return len; } - // GST_BUFFER_SIZE (*outbuf) = have_data; GST_BUFFER_SIZE (*outbuf) = len; if (GST_CLOCK_TIME_IS_VALID (dec_info->timestamp)) { @@ -1195,7 +1161,6 @@ gst_marudec_frame (GstMaruDec *marudec, guint8 *data, guint size, dec_info, &outbuf, ret); if (outbuf == NULL && marudec->discont) { GST_DEBUG_OBJECT (marudec, "no buffer but keeping timestamp"); -// marudec->clear_ts = FALSE; } break; default: @@ -1282,66 +1247,21 @@ gst_marudec_chain (GstPad *pad, GstBuffer *buffer) } discont = GST_BUFFER_IS_DISCONT (buffer); - - // FIXME if (G_UNLIKELY (discont)) { GST_DEBUG_OBJECT (marudec, "received DISCONT"); gst_marudec_drain (marudec); -// gst_marudec_flush_pcache (marudec); interface->flush_buffers (marudec->context, marudec->dev); marudec->discont = TRUE; gst_marudec_reset_ts (marudec); } -// marudec->clear_ts = TRUE; oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec)); -#if 0 - if (G_UNLIKELY (marudec->waiting_for_key)) { - if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT) && - oclass->codec->media_type != AVMEDIA_TYPE_AUDIO) { - // skip_keyframe - } - marudec->waiting_for_key = FALSE; - } - - if (marudec->pcache) { - GST_LOG_OBJECT (marudec, "join parse cache"); - buffer = gst_buffer_join (marudec->pcache, buffer); - marudec->pcache = NULL; - } -#endif in_timestamp = GST_BUFFER_TIMESTAMP (buffer); in_duration = GST_BUFFER_DURATION (buffer); in_offset = GST_BUFFER_OFFSET (buffer); in_info = gst_ts_info_store (marudec, in_timestamp, in_duration, in_offset); - -#if 0 - if (in_timestamp != -1) { - if (!marudec->reordered_in && marudec->last_in != -1) { - if (in_timestamp < marudec->last_in) { - GST_LOG_OBJECT (marudec, "detected reordered input timestamps"); - marudec->reordered_in = TRUE; - marudec->last_diff = GST_CLOCK_TIME_NONE; - } else if (in_timestamp > marudec->last_in) { - GstClockTime diff; - diff = in_timestamp - marudec->last_in; - if (marudec->last_frames) { - diff /= marudec->last_frames; - } - - GST_LOG_OBJECT (marudec, "estimated duration %" GST_TIME_FORMAT " %u", - GST_TIME_ARGS (diff), marudec->last_frames); - - marudec->last_diff = diff; - } - } - marudec->last_in = in_timestamp; - marudec->last_frames; - } -#endif - GST_LOG_OBJECT (marudec, "Received new data of size %u, offset: %" G_GUINT64_FORMAT ", ts:%" GST_TIME_FORMAT ", dur: %" GST_TIME_FORMAT ", info %d", @@ -1355,17 +1275,6 @@ gst_marudec_chain (GstPad *pad, GstBuffer *buffer) gst_marudec_frame (marudec, in_buf, in_size, &have_data, dec_info, in_offset, &ret); -#if 0 - if (marudec->clear_ts) { - in_timestamp = GST_CLOCK_TIME_NONE; - in_duration = GST_CLOCK_TIME_NONE; - in_offset = GST_BUFFER_OFFSET_NONE; - in_info = GST_TS_INFO_NONE; - } else { - marudec->clear_ts = TRUE; - } -#endif - gst_buffer_unref (buffer); return ret; diff --git a/src/gstmarudevice.c b/src/gstmarudevice.c index 9e871c4..3e00b74 100644 --- a/src/gstmarudevice.c +++ b/src/gstmarudevice.c @@ -52,8 +52,6 @@ int opened_cnt = 0; int gst_maru_codec_device_open (CodecDevice *dev, int media_type) { - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - g_mutex_lock (&gst_avcodec_mutex); if (device_fd == -1) { if ((device_fd = open(CODEC_DEV, O_RDWR)) < 0) { @@ -94,8 +92,6 @@ gst_maru_codec_device_open (CodecDevice *dev, int media_type) GST_DEBUG ("open count: %d", opened_cnt); g_mutex_unlock (&gst_avcodec_mutex); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return 0; } @@ -104,11 +100,9 @@ gst_maru_codec_device_close (CodecDevice *dev) { int fd = 0; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - fd = dev->fd; if (fd < 0) { - GST_ERROR ("Failed to get %s fd.\n", CODEC_DEV); + GST_ERROR ("Failed to get %s fd %d", CODEC_DEV, fd); return -1; } @@ -127,15 +121,13 @@ gst_maru_codec_device_close (CodecDevice *dev) GST_INFO ("close %s", CODEC_DEV); if (close(fd) != 0) { - GST_ERROR ("failed to close %s fd: %d\n", CODEC_DEV, fd); + GST_ERROR ("failed to close %s fd: %d", CODEC_DEV, fd); } dev->fd = device_fd = -1; } dev->buf = MAP_FAILED; g_mutex_unlock (&gst_avcodec_mutex); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return 0; } diff --git a/src/gstmaruenc.c b/src/gstmaruenc.c index 715aef9..074c780 100644 --- a/src/gstmaruenc.c +++ b/src/gstmaruenc.c @@ -135,7 +135,7 @@ gst_maruenc_base_init (GstMaruEncClass *klass) sinkcaps = gst_maru_codectype_to_audio_caps (NULL, codec->name, TRUE, codec); break; default: - GST_LOG("unknown media type.\n"); + GST_LOG("unknown media type"); break; } diff --git a/src/gstmaruinterface.c b/src/gstmaruinterface.c index a2f4f4f..a5f0d67 100644 --- a/src/gstmaruinterface.c +++ b/src/gstmaruinterface.c @@ -78,8 +78,6 @@ _codec_invoke_qemu(int32_t ctx_index, int32_t api_index, CodecIOParams ioparam = { 0, }; int ret = -1; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - ioparam.api_index = api_index; ioparam.ctx_index = ctx_index; ioparam.mem_offset = mem_offset; @@ -91,8 +89,6 @@ _codec_invoke_qemu(int32_t ctx_index, int32_t api_index, ret = ioctl(fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, buffer_id); } - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return ret; } @@ -102,7 +98,6 @@ secure_device_mem (int fd, guint ctx_id, guint buf_size, gpointer* buffer) int ret = 0; CodecBufferId opaque; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); opaque.buffer_index = ctx_id; opaque.buffer_size = buf_size; @@ -113,8 +108,6 @@ secure_device_mem (int fd, guint ctx_id, guint buf_size, gpointer* buffer) *buffer = (gpointer)((uint32_t)device_mem + opaque.buffer_size); GST_DEBUG ("device_mem %p, offset_size 0x%x", device_mem, opaque.buffer_size); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return ret; } @@ -124,25 +117,17 @@ release_device_mem (int fd, gpointer start) int ret; uint32_t offset = start - device_mem; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - GST_DEBUG ("release device_mem start: %p, offset: 0x%x", start, offset); ret = ioctl (fd, CODEC_CMD_RELEASE_BUFFER, &offset); if (ret < 0) { - GST_ERROR ("failed to release buffer\n"); + GST_ERROR ("failed to release buffer"); } - - CODEC_LOG (DEBUG, "leave: %s\n", __func__); } static void codec_buffer_free (gpointer start) { - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - release_device_mem (device_fd, start); - - CODEC_LOG (DEBUG, "leave: %s\n", __func__); } static GstFlowReturn @@ -156,8 +141,6 @@ codec_buffer_alloc_and_copy (GstPad *pad, guint64 offset, guint size, CodecContext *ctx; CodecDevice *dev; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - *buf = gst_buffer_new (); marudec = (GstMaruDec *)gst_pad_get_element_private(pad); @@ -206,8 +189,6 @@ codec_buffer_alloc_and_copy (GstPad *pad, guint64 offset, guint size, gst_buffer_set_caps (*buf, caps); } - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return GST_FLOW_OK; } @@ -219,8 +200,6 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev) CodecBufferId opaque; int ret; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - if (ioctl(dev->fd, CODEC_CMD_GET_CONTEXT_INDEX, &ctx->index) < 0) { GST_ERROR ("failed to get a context index"); return -1; @@ -257,31 +236,21 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev) release_device_mem(dev->fd, device_mem + opaque.buffer_size); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return opened; } static void codec_deinit (CodecContext *ctx, CodecDevice *dev) { - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - GST_INFO ("close context %d", ctx->index); _codec_invoke_qemu (ctx->index, CODEC_DEINIT, 0, dev->fd, NULL); - - CODEC_LOG (DEBUG, "leave: %s\n", __func__); } static void codec_flush_buffers (CodecContext *ctx, CodecDevice *dev) { - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - GST_DEBUG ("flush buffers of context: %d", ctx->index); _codec_invoke_qemu (ctx->index, CODEC_FLUSH_BUFFERS, 0, dev->fd, NULL); - - CODEC_LOG (DEBUG, "leave: %s\n", __func__); } static int @@ -294,8 +263,6 @@ codec_decode_video (GstMaruDec *marudec, uint8_t *in_buf, int in_size, gpointer buffer = NULL; CodecBufferId opaque = { 0, }; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer); if (ret < 0) { GST_ERROR ("failed to get available memory to write inbuf"); @@ -325,8 +292,6 @@ codec_decode_video (GstMaruDec *marudec, uint8_t *in_buf, int in_size, ret, *out_buf, len); } - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return len; } @@ -339,8 +304,6 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples, gpointer buffer = NULL; CodecBufferId opaque; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer); if (ret < 0) { GST_ERROR ("failed to get available memory to write inbuf"); @@ -369,8 +332,6 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples, release_device_mem(dev->fd, device_mem + opaque.buffer_size); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return len; } @@ -385,8 +346,6 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf, gpointer buffer = NULL; CodecBufferId opaque; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer); if (ret < 0) { GST_ERROR ("failed to small size of buffer"); @@ -411,8 +370,6 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf, release_device_mem(dev->fd, device_mem + opaque.buffer_size); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return len; } @@ -426,8 +383,6 @@ static codec_encode_audio (CodecContext *ctx, uint8_t *out_buf, gpointer buffer = NULL; CodecBufferId opaque; - CODEC_LOG (DEBUG, "enter: %s\n", __func__); - ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer); if (ret < 0) { return -1; @@ -450,8 +405,6 @@ static codec_encode_audio (CodecContext *ctx, uint8_t *out_buf, release_device_mem(dev->fd, device_mem + opaque.buffer_size); - CODEC_LOG (DEBUG, "leave: %s\n", __func__); - return ret; } diff --git a/src/gstmarumem.c b/src/gstmarumem.c index 9b91e85..6bee84c 100644 --- a/src/gstmarumem.c +++ b/src/gstmarumem.c @@ -205,7 +205,6 @@ codec_decode_audio_data_from (int *have_data, int16_t *samples, size += resample_size; } - // return len; return resample_size; } diff --git a/src/gstmaruutils.c b/src/gstmaruutils.c index 1680d1a..c6fd4e2 100644 --- a/src/gstmaruutils.c +++ b/src/gstmaruutils.c @@ -450,7 +450,7 @@ gst_maru_caps_with_codecname (const char *name, int media_type, buf = GST_BUFFER_CAST (gst_value_get_mini_object (value)); size = GST_BUFFER_SIZE (buf); data = GST_BUFFER_DATA (buf); - GST_DEBUG ("extradata: %p, size: %d\n", data, size); + GST_DEBUG ("extradata: %p, size: %d", data, size); if (ctx->codecdata) { g_free (ctx->codecdata); @@ -467,7 +467,7 @@ gst_maru_caps_with_codecname (const char *name, int media_type, } else if (ctx->codecdata == NULL) { ctx->codecdata_size = 0; ctx->codecdata = g_malloc0 (GST_ROUND_UP_16(FF_INPUT_BUFFER_PADDING_SIZE)); - GST_DEBUG ("no extra data.\n"); + GST_DEBUG ("no extra data"); } if ((strcmp (name, "mpeg4") == 0)) { @@ -1223,7 +1223,6 @@ gst_maru_codecname_to_caps (const char *name, CodecContext *ctx, gboolean encode memcpy (GST_BUFFER_DATA(data), ctx->codecdata, ctx->codecdata_size); gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL); - gst_buffer_unref (data); } GST_LOG ("caps for codec %s %" GST_PTR_FORMAT, name, caps); -- 2.7.4