# HG changeset patch # User renatofilho # Date 1164995835 0 # Node ID 5e4ac847bdfa265e11e576683f9355fd48e2db85 # Parent 318e94209a114f96f6e2b54db19e155748032ee5 [svn r171] diff -r 318e94209a11 -r 5e4ac847bdfa gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c --- a/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c Fri Dec 01 17:13:06 2006 +0000 +++ b/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c Fri Dec 01 17:57:15 2006 +0000 @@ -214,9 +214,9 @@ GstBuffer *mpeg_buffer; /* Headers */ - nuv_header *h; - nuv_extended_header *eh; - nuv_frame_header *fh; + nuv_header h; + nuv_extended_header eh; + nuv_frame_header fh; /* anothers info */ gint64 time_start; @@ -399,7 +399,7 @@ /* HeaderLoad: */ static GstFlowReturn -gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header ** h_ret) +gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h) { GstBuffer *buffer = NULL; GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer); @@ -407,8 +407,6 @@ if ((res != GST_FLOW_OK) || (buffer == NULL)) return res; - nuv_header *h = g_new0 (nuv_header, 1); - memcpy (h->id, buffer->data, 12); memcpy (h->version, buffer->data + 12, 5); h->i_width = GST_READ_UINT32_LE (&buffer->data[20]); @@ -431,7 +429,6 @@ h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks, h->i_keyframe_distance); - *h_ret = h; gst_buffer_unref (buffer); return res; } @@ -480,10 +477,9 @@ /* FrameHeaderLoad: */ static GstFlowReturn -gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header ** h_ret) +gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h) { unsigned char *data; - nuv_frame_header *h; GstBuffer *buf = NULL; GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf); @@ -491,11 +487,11 @@ if ((res != GST_FLOW_OK) || (buf == NULL)) { if (buf != NULL) { gst_buffer_unref (buf); + buf = NULL; } return res; } - h = g_new0 (nuv_frame_header, 1); data = buf->data; h->i_type = GPOINTER_TO_INT (data[0]); @@ -511,19 +507,17 @@ h->i_keyframe ? h->i_keyframe : ' ', h->i_filters, h->i_timecode, h->i_length); - *h_ret = h; gst_buffer_unref (buf); + buf = NULL; return GST_FLOW_OK; } static GstFlowReturn gst_nuv_demux_extended_header_load (GstNuvDemux * nuv, - nuv_extended_header ** h_ret) + nuv_extended_header * h) { unsigned char *data; GstBuffer *buff = NULL; - nuv_extended_header *h; - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff); @@ -534,7 +528,6 @@ return res; } - h = g_new0 (nuv_extended_header, 1); data = buff->data; h->i_version = GST_READ_UINT32_LE (&data[0]); h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]); @@ -564,7 +557,6 @@ h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset, h->i_keyframe_adjust_offset); - *h_ret = h; gst_buffer_unref (buff); return res; } @@ -637,30 +629,30 @@ static void gst_nuv_demux_create_pads (GstNuvDemux * nuv) { - if (nuv->priv->h->i_video_blocks != 0) { + if (nuv->priv->h.i_video_blocks != 0) { GstCaps *video_caps = NULL; video_caps = gst_caps_new_simple ("video/x-divx", "divxversion", G_TYPE_INT, 4, - "width", G_TYPE_INT, nuv->priv->h->i_width, - "height", G_TYPE_INT, nuv->priv->h->i_height, - "framerate", GST_TYPE_FRACTION, nuv->priv->h->i_fpsn, nuv->priv->h->i_fpsd, - "format", GST_TYPE_FOURCC, nuv->priv->eh->i_video_fcc, + "width", G_TYPE_INT, nuv->priv->h.i_width, + "height", G_TYPE_INT, nuv->priv->h.i_height, + "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd, + "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc, "pixel-aspect-ratio", GST_TYPE_FRACTION, - (gint) (nuv->priv->h->d_aspect * 1000.0f), 1000, NULL); + (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL); nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src"); gst_caps_unref (video_caps); } - if (nuv->priv->h->i_audio_blocks != 0) { + if (nuv->priv->h.i_audio_blocks != 0) { GstCaps *audio_caps = NULL; audio_caps = gst_caps_new_simple ("audio/mpeg", - "rate", G_TYPE_INT, nuv->priv->eh->i_audio_sample_rate, - "format", GST_TYPE_FOURCC, nuv->priv->eh->i_audio_fcc, - "channels", G_TYPE_INT, nuv->priv->eh->i_audio_channels, - "mpegversion", G_TYPE_INT, nuv->priv->eh->i_version, NULL); + "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate, + "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc, + "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels, + "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL); nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src"); gst_caps_unref (audio_caps); @@ -674,12 +666,6 @@ { GstFlowReturn ret = GST_FLOW_OK; - if (nuv->priv->fh != NULL) - { - g_free (nuv->priv->fh); - nuv->priv->fh = NULL; - } - ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh); if (ret != GST_FLOW_OK) return ret; @@ -714,26 +700,26 @@ GstPad *pad = NULL; guint64 timestamp; GstBuffer *buf = NULL; - nuv_frame_header *h = NULL; + nuv_frame_header h; h = nuv->priv->fh; - if (h->i_type == 'R') + if (h.i_type == 'R') goto done; - if (h->i_length > 0) { - ret = gst_nuv_demux_read_bytes (nuv, h->i_length, TRUE, &buf); + if (h.i_length > 0) { + ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf); if ((ret != GST_FLOW_OK) || (buf == NULL)) return ret; - if (h->i_timecode < 0) { - h->i_timecode = h->i_timecode * -1; - nuv->priv->time_diff = h->i_timecode; + if (h.i_timecode < 0) { + h.i_timecode = h.i_timecode * -1; + nuv->priv->time_diff = h.i_timecode; } else - h->i_timecode += nuv->priv->time_diff; + h.i_timecode += nuv->priv->time_diff; - timestamp = h->i_timecode * GST_MSECOND; + timestamp = h.i_timecode * GST_MSECOND; GST_BUFFER_TIMESTAMP (buf) = timestamp; } else { @@ -741,7 +727,7 @@ } - switch (h->i_type) { + switch (h.i_type) { case 'V': { pad = nuv->priv->src_video_pad; @@ -781,15 +767,15 @@ } case 'S': { - switch (h->i_compression) { + switch (h.i_compression) { case 'V': - GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h->i_timecode); + GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode); gst_pad_push_event (nuv->priv->src_video_pad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h->i_timecode * GST_MSECOND, + gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND, GST_CLOCK_TIME_NONE, 0)); break; case 'A': - GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h->i_timecode); + GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode); gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, 0)); @@ -805,7 +791,7 @@ if ((buf != NULL) && (pad != NULL)) { /* update average time */ - nuv->priv->streamer_offset += h->i_length; + nuv->priv->streamer_offset += h.i_length; gst_segment_set_last_stop (&nuv->priv->segment, GST_FORMAT_TIME, timestamp); gst_nuv_demux_update_duration (nuv, timestamp); @@ -839,8 +825,7 @@ buf = NULL; } nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER; - g_free (nuv->priv->fh); - nuv->priv->fh = NULL; + memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh)); return ret; } @@ -867,23 +852,21 @@ GstFlowReturn ret = GST_FLOW_OK; /* Load 'D' */ - nuv_frame_header *h; + nuv_frame_header h; ret = gst_nuv_demux_frame_header_load (nuv, &h); if (ret != GST_FLOW_OK) return ret; - if (h->i_type != 'D') { - g_free (h); + if (h.i_type != 'D') { GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg"); return GST_FLOW_NOT_SUPPORTED; } - if (h->i_length > 0) { - if (h->i_compression == 'F') { + if (h.i_length > 0) { + if (h.i_compression == 'F') { nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA; } else { - g_free (h); GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported"); return GST_FLOW_NOT_SUPPORTED; } @@ -891,8 +874,6 @@ nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER; } - g_free (h); - h = NULL; return ret; } @@ -927,18 +908,15 @@ if (buf->data[0] == 'X') { gst_buffer_unref (buf); buf = NULL; - nuv_frame_header *h = NULL; + nuv_frame_header h; res = gst_nuv_demux_frame_header_load (nuv, &h); if (res != GST_FLOW_OK) return res; - if (h->i_length != 512) { - g_free (h); + if (h.i_length != 512) { return GST_FLOW_ERROR; } - g_free (h); - h = NULL; nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA; } else { nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA; @@ -1259,15 +1237,6 @@ gst_buffer_unref (nuv->priv->mpeg_buffer); nuv->priv->mpeg_buffer = NULL; } - - g_free (nuv->priv->h); - nuv->priv->h = NULL; - - g_free (nuv->priv->eh); - nuv->priv->eh = NULL; - - g_free (nuv->priv->fh); - nuv->priv->fh = NULL; } static void