# HG changeset patch # User renatofilho # Date 1180113779 -3600 # Node ID 03f2acbda6b12679371e31328bf282d823edfe2f # Parent e8fe96f879168efe42ec11319e201b9722e1e7d9 [svn r720] try parse newsegment with byte 0 diff -r e8fe96f87916 -r 03f2acbda6b1 gst-gmyth/nuvdemux/gstnuvdemux.c --- a/gst-gmyth/nuvdemux/gstnuvdemux.c Fri May 25 15:56:10 2007 +0100 +++ b/gst-gmyth/nuvdemux/gstnuvdemux.c Fri May 25 18:22:59 2007 +0100 @@ -203,7 +203,9 @@ GstFlowReturn last_video_return; GstFlowReturn last_audio_return; gboolean more_data; - gboolean eos; + gboolean eos; + gboolean new_file; + guint segment; /* NUV decoding state */ GstNuvDemuxState state; @@ -267,7 +269,7 @@ static gboolean gst_nuv_demux_sink_activate_push (GstPad * pad, gboolean active); static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad); -//static gboolean gst_nuv_demux_sink_event (GstPad *pad, GstEvent *event); +static gboolean gst_nuv_demux_sink_event (GstPad *pad, GstEvent *event); static gboolean gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event); static frame_index_data * gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos, gint64 segment_stop, GstFormat format); @@ -387,10 +389,9 @@ gst_nuv_demux_sink_activate_push); gst_pad_set_chain_function (nuv->priv->sinkpad, GST_DEBUG_FUNCPTR (gst_nuv_demux_chain)); -/* gst_pad_set_event_function (nuv->priv->sinkpad, - gst_nuv_demux_sink_event); -*/ + GST_DEBUG_FUNCPTR (gst_nuv_demux_sink_event)); + gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad); @@ -433,27 +434,29 @@ goto done; } - memcpy (h->id, buffer->data, 12); - memcpy (h->version, buffer->data + 12, 5); - h->i_width = GST_READ_UINT32_LE (&buffer->data[20]); - h->i_height = GST_READ_UINT32_LE (&buffer->data[24]); - h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]); - h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]); - h->i_mode = GPOINTER_TO_INT (buffer->data[36]); - h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]); - h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]); - /* get the num and denom values from fps */ - double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd); - h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]); - h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]); - h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]); - h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]); + if (h != NULL) { + memcpy (h->id, buffer->data, 12); + memcpy (h->version, buffer->data + 12, 5); + h->i_width = GST_READ_UINT32_LE (&buffer->data[20]); + h->i_height = GST_READ_UINT32_LE (&buffer->data[24]); + h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]); + h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]); + h->i_mode = GPOINTER_TO_INT (buffer->data[36]); + h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]); + h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]); + /* get the num and denom values from fps */ + double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd); + h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]); + h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]); + h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]); + h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]); - GST_DEBUG_OBJECT (nuv, - "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id, - h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps, - h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks, - h->i_keyframe_distance); + GST_DEBUG_OBJECT (nuv, + "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id, + h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps, + h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks, + h->i_keyframe_distance); + } done: if (buffer != NULL) { @@ -468,7 +471,11 @@ { GstFlowReturn res; - res = gst_nuv_demux_header_load (nuv, &nuv->priv->h); + if (nuv->priv->new_file) + res = gst_nuv_demux_header_load (nuv, NULL); + else + res = gst_nuv_demux_header_load (nuv, &nuv->priv->h); + if (res == GST_FLOW_OK) nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA; return res; @@ -516,7 +523,12 @@ goto done; } + if (h == NULL) + goto done; + data = buf->data; +<<<<<<< .mine +======= /* verifies if it is a MythTV file header */ if ( ( data[0] == 'M' || data[0] == 'N') && data[6] == 'V' ) { nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA; @@ -525,6 +537,7 @@ /* it is not a NUV file header, so now can move the 12 bytes */ res = gst_nuv_demux_move_bytes (nuv, 12); +>>>>>>> .r719 h->i_type = GPOINTER_TO_INT (data[0]); h->i_compression = GPOINTER_TO_INT (data[1]); h->i_keyframe = GPOINTER_TO_INT (data[2]); @@ -560,6 +573,9 @@ goto done; } + if (h == NULL) + goto done; + 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]); @@ -957,8 +973,15 @@ GstFlowReturn ret = GST_FLOW_OK; /* ffmpeg extra data */ - ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, + if (nuv->priv->new_file) { + GstBuffer *buf; + ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, &buf); + gst_buffer_unref (buf); + } else { + ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, &nuv->priv->mpeg_buffer); + } + if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) { return ret; } @@ -976,7 +999,11 @@ /* Load 'D' */ nuv_frame_header h; - ret = gst_nuv_demux_frame_header_load (nuv, &h); + if (nuv->priv->new_file) + ret = gst_nuv_demux_frame_header_load (nuv, NULL); + else + ret = gst_nuv_demux_frame_header_load (nuv, &h); + if (ret != GST_FLOW_OK) return ret; @@ -1004,11 +1031,15 @@ { GstFlowReturn ret = GST_FLOW_OK; - ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh); - if (ret != GST_FLOW_OK) - return ret; + if (nuv->priv->new_file) + ret = gst_nuv_demux_extended_header_load (nuv, NULL); + else { + ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh); + if (ret != GST_FLOW_OK) + return ret; + gst_nuv_demux_create_pads (nuv); + } - gst_nuv_demux_create_pads (nuv); nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE; return ret; } @@ -1133,7 +1164,7 @@ break; case GST_NUV_DEMUX_INDEX_CREATE: - if (nuv->priv->mode == NUV_PULL_MODE) { + if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) { gst_nuv_demux_create_seek_index (nuv); } @@ -1527,6 +1558,54 @@ return res; } +static gboolean +gst_nuv_demux_sink_event (GstPad * pad, GstEvent * event) +{ + gboolean res = FALSE; + GstNuvDemux *nuv; + + nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_NEWSEGMENT: + { + gboolean update; + gdouble rate; + GstFormat format; + gint64 start; + gint64 stop; + gint64 position; + + gst_event_parse_new_segment (event, &update, &rate, &format, &start, &stop, &position); + if ((format == GST_FORMAT_BYTES) && (start == 0)) { + g_debug ("NEW SEGMENT 0"); + if (nuv->priv->segment > 0) { + nuv->priv->new_file = TRUE; + nuv->priv->state = GST_NUV_DEMUX_START; + nuv->priv->offset = 0; + } + nuv->priv->segment++; + + /* + newsegment_event = gst_event_new_new_segment (FALSE, rate, + GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE); + + gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event)); + gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event)); + gst_event_unref (newsegment_event); + */ + res = gst_pad_event_default(pad, event); + } + break; + } + default: + res = gst_pad_event_default (pad, event); + break; + } + + return res; +} + static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf) { @@ -1577,6 +1656,7 @@ nuv->priv->header_lengh = 0; nuv->priv->segment_stop = GST_CLOCK_TIME_NONE; nuv->priv->segment_start = GST_CLOCK_TIME_NONE; + nuv->priv->new_file = FALSE; //clear index list g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL); @@ -1732,6 +1812,6 @@ GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "nuvdemux", - "Demuxes and muxes audio and video", + "Demuxes and muxes audio and video", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)