Advertisement
rotrevrep

gst_matroska_demux_handle_sink_event

Dec 30th, 2015
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.28 KB | None | 0 0
  1. static gboolean
  2. gst_matroska_demux_handle_sink_event (GstPad * pad, GstObject * parent,
  3.     GstEvent * event)
  4. {
  5.   gboolean res = TRUE;
  6.   GstMatroskaDemux *demux = GST_MATROSKA_DEMUX (parent);
  7.  
  8.   GST_DEBUG_OBJECT (demux,
  9.       "have event type %s: %p on sink pad", GST_EVENT_TYPE_NAME (event), event);
  10.  
  11.   switch (GST_EVENT_TYPE (event)) {
  12.     case GST_EVENT_SEGMENT:
  13.     {
  14.       const GstSegment *segment;
  15.  
  16.       /* some debug output */
  17.       gst_event_parse_segment (event, &segment);
  18.       /* FIXME: do we need to update segment base here (like accum in 0.10)? */
  19.       GST_DEBUG_OBJECT (demux,
  20.           "received format %d segment %" GST_SEGMENT_FORMAT, segment->format,
  21.           segment);
  22.  
  23.       if (demux->common.state < GST_MATROSKA_READ_STATE_DATA) {
  24.         GST_DEBUG_OBJECT (demux, "still starting");
  25.         goto exit;
  26.       }
  27.  
  28.       /* we only expect a BYTE segment, e.g. following a seek */
  29.       if (segment->format != GST_FORMAT_BYTES) {
  30.         GST_DEBUG_OBJECT (demux, "unsupported segment format, ignoring");
  31.         goto exit;
  32.       }
  33.  
  34.       GST_DEBUG_OBJECT (demux, "clearing segment state");
  35.       GST_OBJECT_LOCK (demux);
  36.       /* clear current segment leftover */
  37.       gst_adapter_clear (demux->common.adapter);
  38.       /* and some streaming setup */
  39.       demux->common.offset = segment->start;
  40.       /* accumulate base based on current position */
  41.       if (GST_CLOCK_TIME_IS_VALID (demux->common.segment.position))
  42.         demux->common.segment.base +=
  43.             (MAX (demux->common.segment.position, demux->stream_start_time)
  44.             - demux->stream_start_time) / fabs (demux->common.segment.rate);
  45.       /* do not know where we are;
  46.        * need to come across a cluster and generate segment */
  47.       demux->common.segment.position = GST_CLOCK_TIME_NONE;
  48.       demux->cluster_time = GST_CLOCK_TIME_NONE;
  49.       demux->cluster_offset = 0;
  50.       demux->need_segment = TRUE;
  51.       demux->segment_seqnum = gst_event_get_seqnum (event);
  52.       /* but keep some of the upstream segment */
  53.       demux->common.segment.rate = segment->rate;
  54.       /* also check if need to keep some of the requested seek position */
  55.       if (demux->seek_offset == segment->start) {
  56.         GST_DEBUG_OBJECT (demux, "position matches requested seek");
  57.         demux->common.segment.position = demux->requested_seek_time;
  58.       } else {
  59.         GST_DEBUG_OBJECT (demux, "unexpected segment position");
  60.       }
  61.       demux->requested_seek_time = GST_CLOCK_TIME_NONE;
  62.       demux->seek_offset = -1;
  63.       GST_OBJECT_UNLOCK (demux);
  64.     exit:
  65.       /* chain will send initial segment after pads have been added,
  66.        * or otherwise come up with one */
  67.       GST_DEBUG_OBJECT (demux, "eating event");
  68.       gst_event_unref (event);
  69.       res = TRUE;
  70.       break;
  71.     }
  72.     case GST_EVENT_EOS:
  73.     {
  74.       if (demux->common.state != GST_MATROSKA_READ_STATE_DATA) {
  75.         gst_event_unref (event);
  76.         GST_ELEMENT_ERROR (demux, STREAM, DEMUX,
  77.             (NULL), ("got eos and didn't receive a complete header object"));
  78.       } else if (demux->common.num_streams == 0) {
  79.         GST_ELEMENT_ERROR (demux, STREAM, DEMUX,
  80.             (NULL), ("got eos but no streams (yet)"));
  81.       } else {
  82.         gst_matroska_demux_send_event (demux, event);
  83.       }
  84.       break;
  85.     }
  86.     case GST_EVENT_FLUSH_STOP:
  87.     {
  88.       guint64 dur;
  89.  
  90.       gst_adapter_clear (demux->common.adapter);
  91.       GST_OBJECT_LOCK (demux);
  92.       gst_matroska_read_common_reset_streams (&demux->common,
  93.           GST_CLOCK_TIME_NONE, TRUE);
  94.       gst_flow_combiner_reset (demux->flowcombiner);
  95.       dur = demux->common.segment.duration;
  96.       gst_segment_init (&demux->common.segment, GST_FORMAT_TIME);
  97.       demux->common.segment.duration = dur;
  98.       demux->cluster_time = GST_CLOCK_TIME_NONE;
  99.       demux->cluster_offset = 0;
  100.       GST_OBJECT_UNLOCK (demux);
  101.       /* fall-through */
  102.     }
  103.     case GST_EVENT_TAG:
  104.     {
  105.       GstTagList* new_list;
  106.       gchar* title;
  107.       gst_event_parse_tag (event, &new_list);
  108.       gst_tag_list_get_string (new_list, "title", &title);
  109.       g_print ("matroska-title : %s\n", title);
  110.       res = gst_pad_event_default (pad, parent, event);
  111.     }
  112.     default:
  113.       res = gst_pad_event_default (pad, parent, event);
  114.       break;
  115.   }
  116.  
  117.   return res;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement