1.1 --- a/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c Fri Dec 01 17:13:06 2006 +0000
1.2 +++ b/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c Fri Dec 01 17:57:15 2006 +0000
1.3 @@ -214,9 +214,9 @@
1.4 GstBuffer *mpeg_buffer;
1.5
1.6 /* Headers */
1.7 - nuv_header *h;
1.8 - nuv_extended_header *eh;
1.9 - nuv_frame_header *fh;
1.10 + nuv_header h;
1.11 + nuv_extended_header eh;
1.12 + nuv_frame_header fh;
1.13
1.14 /* anothers info */
1.15 gint64 time_start;
1.16 @@ -399,7 +399,7 @@
1.17 /* HeaderLoad:
1.18 */
1.19 static GstFlowReturn
1.20 -gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header ** h_ret)
1.21 +gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h)
1.22 {
1.23 GstBuffer *buffer = NULL;
1.24 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
1.25 @@ -407,8 +407,6 @@
1.26 if ((res != GST_FLOW_OK) || (buffer == NULL))
1.27 return res;
1.28
1.29 - nuv_header *h = g_new0 (nuv_header, 1);
1.30 -
1.31 memcpy (h->id, buffer->data, 12);
1.32 memcpy (h->version, buffer->data + 12, 5);
1.33 h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
1.34 @@ -431,7 +429,6 @@
1.35 h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
1.36 h->i_keyframe_distance);
1.37
1.38 - *h_ret = h;
1.39 gst_buffer_unref (buffer);
1.40 return res;
1.41 }
1.42 @@ -480,10 +477,9 @@
1.43 /* FrameHeaderLoad:
1.44 */
1.45 static GstFlowReturn
1.46 -gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header ** h_ret)
1.47 +gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h)
1.48 {
1.49 unsigned char *data;
1.50 - nuv_frame_header *h;
1.51 GstBuffer *buf = NULL;
1.52
1.53 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
1.54 @@ -491,11 +487,11 @@
1.55 if ((res != GST_FLOW_OK) || (buf == NULL)) {
1.56 if (buf != NULL) {
1.57 gst_buffer_unref (buf);
1.58 + buf = NULL;
1.59 }
1.60 return res;
1.61 }
1.62
1.63 - h = g_new0 (nuv_frame_header, 1);
1.64 data = buf->data;
1.65
1.66 h->i_type = GPOINTER_TO_INT (data[0]);
1.67 @@ -511,19 +507,17 @@
1.68 h->i_keyframe ? h->i_keyframe : ' ',
1.69 h->i_filters, h->i_timecode, h->i_length);
1.70
1.71 - *h_ret = h;
1.72 gst_buffer_unref (buf);
1.73 + buf = NULL;
1.74 return GST_FLOW_OK;
1.75 }
1.76
1.77 static GstFlowReturn
1.78 gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
1.79 - nuv_extended_header ** h_ret)
1.80 + nuv_extended_header * h)
1.81 {
1.82 unsigned char *data;
1.83 GstBuffer *buff = NULL;
1.84 - nuv_extended_header *h;
1.85 -
1.86
1.87 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
1.88
1.89 @@ -534,7 +528,6 @@
1.90 return res;
1.91 }
1.92
1.93 - h = g_new0 (nuv_extended_header, 1);
1.94 data = buff->data;
1.95 h->i_version = GST_READ_UINT32_LE (&data[0]);
1.96 h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
1.97 @@ -564,7 +557,6 @@
1.98 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
1.99 h->i_keyframe_adjust_offset);
1.100
1.101 - *h_ret = h;
1.102 gst_buffer_unref (buff);
1.103 return res;
1.104 }
1.105 @@ -637,30 +629,30 @@
1.106 static void
1.107 gst_nuv_demux_create_pads (GstNuvDemux * nuv)
1.108 {
1.109 - if (nuv->priv->h->i_video_blocks != 0) {
1.110 + if (nuv->priv->h.i_video_blocks != 0) {
1.111 GstCaps *video_caps = NULL;
1.112
1.113 video_caps = gst_caps_new_simple ("video/x-divx",
1.114 "divxversion", G_TYPE_INT, 4,
1.115 - "width", G_TYPE_INT, nuv->priv->h->i_width,
1.116 - "height", G_TYPE_INT, nuv->priv->h->i_height,
1.117 - "framerate", GST_TYPE_FRACTION, nuv->priv->h->i_fpsn, nuv->priv->h->i_fpsd,
1.118 - "format", GST_TYPE_FOURCC, nuv->priv->eh->i_video_fcc,
1.119 + "width", G_TYPE_INT, nuv->priv->h.i_width,
1.120 + "height", G_TYPE_INT, nuv->priv->h.i_height,
1.121 + "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd,
1.122 + "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc,
1.123 "pixel-aspect-ratio", GST_TYPE_FRACTION,
1.124 - (gint) (nuv->priv->h->d_aspect * 1000.0f), 1000, NULL);
1.125 + (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL);
1.126
1.127 nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src");
1.128 gst_caps_unref (video_caps);
1.129 }
1.130
1.131 - if (nuv->priv->h->i_audio_blocks != 0) {
1.132 + if (nuv->priv->h.i_audio_blocks != 0) {
1.133 GstCaps *audio_caps = NULL;
1.134
1.135 audio_caps = gst_caps_new_simple ("audio/mpeg",
1.136 - "rate", G_TYPE_INT, nuv->priv->eh->i_audio_sample_rate,
1.137 - "format", GST_TYPE_FOURCC, nuv->priv->eh->i_audio_fcc,
1.138 - "channels", G_TYPE_INT, nuv->priv->eh->i_audio_channels,
1.139 - "mpegversion", G_TYPE_INT, nuv->priv->eh->i_version, NULL);
1.140 + "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate,
1.141 + "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc,
1.142 + "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels,
1.143 + "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL);
1.144
1.145 nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src");
1.146 gst_caps_unref (audio_caps);
1.147 @@ -674,12 +666,6 @@
1.148 {
1.149 GstFlowReturn ret = GST_FLOW_OK;
1.150
1.151 - if (nuv->priv->fh != NULL)
1.152 - {
1.153 - g_free (nuv->priv->fh);
1.154 - nuv->priv->fh = NULL;
1.155 - }
1.156 -
1.157 ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh);
1.158 if (ret != GST_FLOW_OK)
1.159 return ret;
1.160 @@ -714,26 +700,26 @@
1.161 GstPad *pad = NULL;
1.162 guint64 timestamp;
1.163 GstBuffer *buf = NULL;
1.164 - nuv_frame_header *h = NULL;
1.165 + nuv_frame_header h;
1.166
1.167 h = nuv->priv->fh;
1.168
1.169 - if (h->i_type == 'R')
1.170 + if (h.i_type == 'R')
1.171 goto done;
1.172
1.173 - if (h->i_length > 0) {
1.174 - ret = gst_nuv_demux_read_bytes (nuv, h->i_length, TRUE, &buf);
1.175 + if (h.i_length > 0) {
1.176 + ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf);
1.177 if ((ret != GST_FLOW_OK) || (buf == NULL))
1.178 return ret;
1.179
1.180 - if (h->i_timecode < 0) {
1.181 - h->i_timecode = h->i_timecode * -1;
1.182 - nuv->priv->time_diff = h->i_timecode;
1.183 + if (h.i_timecode < 0) {
1.184 + h.i_timecode = h.i_timecode * -1;
1.185 + nuv->priv->time_diff = h.i_timecode;
1.186 }
1.187 else
1.188 - h->i_timecode += nuv->priv->time_diff;
1.189 + h.i_timecode += nuv->priv->time_diff;
1.190
1.191 - timestamp = h->i_timecode * GST_MSECOND;
1.192 + timestamp = h.i_timecode * GST_MSECOND;
1.193 GST_BUFFER_TIMESTAMP (buf) = timestamp;
1.194 }
1.195 else {
1.196 @@ -741,7 +727,7 @@
1.197 }
1.198
1.199
1.200 - switch (h->i_type) {
1.201 + switch (h.i_type) {
1.202 case 'V':
1.203 {
1.204 pad = nuv->priv->src_video_pad;
1.205 @@ -781,15 +767,15 @@
1.206 }
1.207 case 'S':
1.208 {
1.209 - switch (h->i_compression) {
1.210 + switch (h.i_compression) {
1.211 case 'V':
1.212 - GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h->i_timecode);
1.213 + GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode);
1.214 gst_pad_push_event (nuv->priv->src_video_pad,
1.215 - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h->i_timecode * GST_MSECOND,
1.216 + gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND,
1.217 GST_CLOCK_TIME_NONE, 0));
1.218 break;
1.219 case 'A':
1.220 - GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h->i_timecode);
1.221 + GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode);
1.222 gst_pad_push_event (nuv->priv->src_audio_pad,
1.223 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
1.224 GST_CLOCK_TIME_NONE, 0));
1.225 @@ -805,7 +791,7 @@
1.226
1.227 if ((buf != NULL) && (pad != NULL)) {
1.228 /* update average time */
1.229 - nuv->priv->streamer_offset += h->i_length;
1.230 + nuv->priv->streamer_offset += h.i_length;
1.231 gst_segment_set_last_stop (&nuv->priv->segment, GST_FORMAT_TIME, timestamp);
1.232 gst_nuv_demux_update_duration (nuv, timestamp);
1.233
1.234 @@ -839,8 +825,7 @@
1.235 buf = NULL;
1.236 }
1.237 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1.238 - g_free (nuv->priv->fh);
1.239 - nuv->priv->fh = NULL;
1.240 + memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh));
1.241 return ret;
1.242 }
1.243
1.244 @@ -867,23 +852,21 @@
1.245 GstFlowReturn ret = GST_FLOW_OK;
1.246
1.247 /* Load 'D' */
1.248 - nuv_frame_header *h;
1.249 + nuv_frame_header h;
1.250
1.251 ret = gst_nuv_demux_frame_header_load (nuv, &h);
1.252 if (ret != GST_FLOW_OK)
1.253 return ret;
1.254
1.255 - if (h->i_type != 'D') {
1.256 - g_free (h);
1.257 + if (h.i_type != 'D') {
1.258 GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg");
1.259 return GST_FLOW_NOT_SUPPORTED;
1.260 }
1.261
1.262 - if (h->i_length > 0) {
1.263 - if (h->i_compression == 'F') {
1.264 + if (h.i_length > 0) {
1.265 + if (h.i_compression == 'F') {
1.266 nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
1.267 } else {
1.268 - g_free (h);
1.269 GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported");
1.270 return GST_FLOW_NOT_SUPPORTED;
1.271 }
1.272 @@ -891,8 +874,6 @@
1.273 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1.274 }
1.275
1.276 - g_free (h);
1.277 - h = NULL;
1.278 return ret;
1.279 }
1.280
1.281 @@ -927,18 +908,15 @@
1.282 if (buf->data[0] == 'X') {
1.283 gst_buffer_unref (buf);
1.284 buf = NULL;
1.285 - nuv_frame_header *h = NULL;
1.286 + nuv_frame_header h;
1.287
1.288 res = gst_nuv_demux_frame_header_load (nuv, &h);
1.289 if (res != GST_FLOW_OK)
1.290 return res;
1.291
1.292 - if (h->i_length != 512) {
1.293 - g_free (h);
1.294 + if (h.i_length != 512) {
1.295 return GST_FLOW_ERROR;
1.296 }
1.297 - g_free (h);
1.298 - h = NULL;
1.299 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1.300 } else {
1.301 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1.302 @@ -1259,15 +1237,6 @@
1.303 gst_buffer_unref (nuv->priv->mpeg_buffer);
1.304 nuv->priv->mpeg_buffer = NULL;
1.305 }
1.306 -
1.307 - g_free (nuv->priv->h);
1.308 - nuv->priv->h = NULL;
1.309 -
1.310 - g_free (nuv->priv->eh);
1.311 - nuv->priv->eh = NULL;
1.312 -
1.313 - g_free (nuv->priv->fh);
1.314 - nuv->priv->fh = NULL;
1.315 }
1.316
1.317 static void