gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c
branchtrunk
changeset 440 1a9af071ab1f
parent 432 ebaf693e0058
child 442 db17a60b9b42
     1.1 --- a/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Thu Mar 22 19:37:16 2007 +0000
     1.2 +++ b/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Fri Mar 23 13:56:18 2007 +0000
     1.3 @@ -61,6 +61,7 @@
     1.4  GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug);
     1.5  #define GST_CAT_DEFAULT nuvdemux_debug
     1.6  #define GST_FLOW_ERROR_NO_DATA  -101
     1.7 +#define GST_FLOW_ERROR_EOS	-102
     1.8  
     1.9  enum
    1.10  {
    1.11 @@ -146,9 +147,9 @@
    1.12  typedef struct
    1.13  {
    1.14      gint             i_version;
    1.15 -    guint32		     i_video_fcc;
    1.16 +    guint32	     i_video_fcc;
    1.17  
    1.18 -    guint32		     i_audio_fcc;
    1.19 +    guint32	     i_audio_fcc;
    1.20      gint             i_audio_sample_rate;
    1.21      gint             i_audio_bits_per_sample;
    1.22      gint             i_audio_channels;
    1.23 @@ -199,9 +200,10 @@
    1.24    GstPad        *src_audio_pad;
    1.25  
    1.26    /* Flow control */
    1.27 -  GstFlowReturn last_video_return;
    1.28 -  GstFlowReturn last_audio_return;
    1.29 -  gboolean      more_data;
    1.30 +  GstFlowReturn     last_video_return;
    1.31 +  GstFlowReturn     last_audio_return;
    1.32 +  gboolean          more_data;
    1.33 +  gboolean	    eos;
    1.34  
    1.35    /* NUV decoding state */
    1.36    GstNuvDemuxState  state;
    1.37 @@ -218,8 +220,8 @@
    1.38    gboolean          new_video_segment;
    1.39  
    1.40    /* Mpeg ExtraData */
    1.41 -  guint64       mpeg_data_size;
    1.42 -  GstBuffer     *mpeg_buffer;
    1.43 +  guint64           mpeg_data_size;
    1.44 +  GstBuffer         *mpeg_buffer;
    1.45  
    1.46    /* Headers */
    1.47    nuv_header h;
    1.48 @@ -1137,6 +1139,14 @@
    1.49  pause:
    1.50    GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
    1.51    gst_pad_pause_task (nuv->priv->sinkpad);
    1.52 +
    1.53 +  if (res == GST_FLOW_ERROR_EOS) {
    1.54 +    g_debug ("EOS EOS EOS EOS EOS EOS");
    1.55 +    gst_nuv_demux_send_eos (nuv);
    1.56 +    nuv->priv->eos = TRUE;
    1.57 +    res = GST_FLOW_OK;
    1.58 +  }
    1.59 +
    1.60    if (GST_FLOW_IS_FATAL (res)) {
    1.61      GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
    1.62          (_("Internal data stream error.")),
    1.63 @@ -1178,8 +1188,7 @@
    1.64        /* got eos */
    1.65      } else if (ret == GST_FLOW_UNEXPECTED) {
    1.66        g_debug ("GOT EOS");
    1.67 -      //gst_nuv_demux_send_eos (nuv);
    1.68 -      return GST_FLOW_WRONG_STATE;
    1.69 +      return GST_FLOW_ERROR_EOS;
    1.70      }
    1.71    } else {
    1.72      if (gst_adapter_available (nuv->priv->adapter) < size) {
    1.73 @@ -1309,7 +1318,7 @@
    1.74    frame_index_data *entry;
    1.75    gint64 segment_start;
    1.76    gint64 segment_stop;
    1.77 -  //GstEvent *newsegment_event;
    1.78 +  GstEvent *newsegment_event;
    1.79  
    1.80  
    1.81    g_debug ("DEMUX SEEK");
    1.82 @@ -1359,10 +1368,8 @@
    1.83  
    1.84    if (cur == GST_CLOCK_TIME_NONE)
    1.85      cur = 0;
    1.86 -
    1.87 -
    1.88 -//  if (stop == GST_CLOCK_TIME_NONE)
    1.89 -//    stop = nuv->priv->duration_time;
    1.90 +  if (stop == GST_CLOCK_TIME_NONE)
    1.91 +    stop = nuv->priv->duration_time;
    1.92  
    1.93    if (cur_type == GST_SEEK_TYPE_SET)
    1.94      segment_start = cur;
    1.95 @@ -1378,8 +1385,8 @@
    1.96    else
    1.97      segment_stop = nuv->priv->segment_stop;
    1.98  
    1.99 -//  segment_start = CLAMP (segment_start, 0, nuv->priv->duration_bytes);
   1.100 -//  segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_bytes);
   1.101 +  segment_start = CLAMP (segment_start, 0, nuv->priv->duration_time);
   1.102 +  segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_time);
   1.103  
   1.104    entry = gst_nuv_demux_do_seek_index (nuv, segment_start,
   1.105        segment_stop, format);
   1.106 @@ -1390,7 +1397,6 @@
   1.107    }
   1.108  
   1.109    g_debug ("found frame at %lld", entry->offset);
   1.110 -  nuv->priv->offset = entry->offset;
   1.111  
   1.112    segment_start = entry->timecode;
   1.113  
   1.114 @@ -1399,23 +1405,21 @@
   1.115  
   1.116    GST_OBJECT_UNLOCK (nuv);
   1.117  
   1.118 -/*
   1.119 -  {
   1.120 -  GstMessage *msg;
   1.121 -  msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME,
   1.122 -    nuv->priv->segment_start);
   1.123 +  if (!nuv->priv->eos) {
   1.124 +    GstMessage *msg;
   1.125 +    msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME,
   1.126 +      nuv->priv->segment_start);
   1.127    
   1.128 -  gst_element_post_message (GST_ELEMENT (nuv), msg);
   1.129 +    gst_element_post_message (GST_ELEMENT (nuv), msg);
   1.130    }
   1.131 -*/
   1.132  
   1.133  
   1.134 -//  newsegment_event = gst_event_new_new_segment (FALSE, rate,
   1.135 -//    GST_FORMAT_TIME, segment_start, segment_stop, segment_start);
   1.136 +  g_debug ("NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" G_GUINT64_FORMAT, segment_start, segment_stop);
   1.137 +  newsegment_event = gst_event_new_new_segment (FALSE, rate,
   1.138 +    GST_FORMAT_TIME, segment_start, segment_stop, segment_start);
   1.139  
   1.140  
   1.141    if (flush) {
   1.142 -    gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ());
   1.143      if (nuv->priv->src_video_pad != NULL) {
   1.144        gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_stop ());
   1.145      }
   1.146 @@ -1423,21 +1427,24 @@
   1.147      if (nuv->priv->src_audio_pad != NULL) {
   1.148        gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_stop ());
   1.149      }
   1.150 +
   1.151 +    gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ());
   1.152    }
   1.153  
   1.154 -/*
   1.155    
   1.156    if (nuv->priv->src_video_pad != NULL) {
   1.157 -    gst_pad_push_event (nuv->priv->src_video_pad, newsegment_event);
   1.158 +    gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
   1.159    }
   1.160    if (nuv->priv->src_audio_pad != NULL) {
   1.161 -    gst_pad_push_event (nuv->priv->src_audio_pad, newsegment_event);
   1.162 +    gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
   1.163    } 
   1.164  
   1.165 -*/
   1.166 +  gst_event_unref (newsegment_event);
   1.167  
   1.168    g_debug ("STARTING TASK AGAIN");
   1.169    nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
   1.170 +  nuv->priv->offset = entry->offset;
   1.171 +
   1.172    gst_pad_start_task (nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
   1.173        nuv->priv->sinkpad);
   1.174