asfdemux: Change the mismatched definition
[platform/upstream/gst-plugins-ugly.git] / gst / asfdemux / gstasfdemux.c
index d81ad16..7940032 100644 (file)
@@ -319,6 +319,10 @@ gst_asf_demux_init (GstASFDemux * demux)
       GST_DEBUG_FUNCPTR (gst_asf_demux_activate_mode));
   gst_element_add_pad (GST_ELEMENT (demux), demux->sinkpad);
 
+#ifdef TIZEN_FEATURE_ASFDEMUX_DISABLE_UNSUPPORTED_FORMAT
+  demux->is_supported_format = TRUE;
+#endif
+
   /* set initial state */
   gst_asf_demux_reset (demux, FALSE);
 }
@@ -732,31 +736,17 @@ gst_asf_demux_handle_seek_event (GstASFDemux * demux, GstEvent * event)
    * forever */
   GST_PAD_STREAM_LOCK (demux->sinkpad);
 
-  /* we now can stop flushing, since we have the stream lock now */
-  fevent = gst_event_new_flush_stop (TRUE);
-  gst_event_set_seqnum (fevent, seqnum);
-  gst_pad_push_event (demux->sinkpad, gst_event_ref (fevent));
-
-  if (G_LIKELY (flush))
+  if (G_LIKELY (flush)) {
+    /* we now can stop flushing, since we have the stream lock now */
+    fevent = gst_event_new_flush_stop (TRUE);
+    gst_event_set_seqnum (fevent, seqnum);
+    gst_pad_push_event (demux->sinkpad, gst_event_ref (fevent));
     gst_asf_demux_send_event_unlocked (demux, fevent);
-  else
-    gst_event_unref (fevent);
+  }
 
   /* operating on copy of segment until we know the seek worked */
   segment = demux->segment;
 
-  if (G_UNLIKELY (demux->segment_running && !flush)) {
-    GstSegment newsegment;
-    GstEvent *newseg;
-
-    /* create the segment event to close the current segment */
-    gst_segment_copy_into (&segment, &newsegment);
-    newseg = gst_event_new_segment (&newsegment);
-    gst_event_set_seqnum (newseg, seqnum);
-
-    gst_asf_demux_send_event_unlocked (demux, newseg);
-  }
-
   gst_segment_do_seek (&segment, rate, format, flags, cur_type,
       cur, stop_type, stop, &only_need_update);
 
@@ -1192,7 +1182,12 @@ gst_asf_demux_parse_data_object_start (GstASFDemux * demux, guint8 * data)
       "data_offset=%" G_GINT64_FORMAT ", data_size=%" G_GINT64_FORMAT
       ", index_offset=%" G_GUINT64_FORMAT, demux->num_packets,
       demux->data_offset, demux->data_size, demux->index_offset);
-
+#ifdef TIZEN_FEATURE_ASFDEMUX_CHECK_DATA_SIZE
+  if (demux->data_size == 0) {
+    GST_WARNING_OBJECT (demux, "DATA object size is zero");
+    return FALSE;
+  }
+#endif
   return TRUE;
 }
 
@@ -1304,6 +1299,7 @@ all_streams_prerolled (GstASFDemux * demux)
 {
   GstClockTime preroll_time;
   guint i, num_no_data = 0;
+  AsfStreamType prerolled_types = 0, all_types = 0;
 
   /* Allow at least 500ms of preroll_time  */
   preroll_time = MAX (demux->preroll, 500 * GST_MSECOND);
@@ -1317,12 +1313,17 @@ all_streams_prerolled (GstASFDemux * demux)
     gint last_idx;
 
     stream = &demux->stream[i];
+
+    all_types |= stream->type;
+
     if (G_UNLIKELY (stream->payloads->len == 0)) {
       ++num_no_data;
       GST_LOG_OBJECT (stream->pad, "no data queued");
       continue;
     }
 
+    prerolled_types |= stream->type;
+
     /* find last payload with timestamp */
     for (last_idx = stream->payloads->len - 1;
         last_idx >= 0 && (last_payload == NULL
@@ -1340,6 +1341,13 @@ all_streams_prerolled (GstASFDemux * demux)
     }
   }
 
+  GST_LOG_OBJECT (demux, "all_types:%d prerolled_types:%d",
+      all_types, prerolled_types);
+
+  /* If streams of each present type have prerolled, we are good to go */
+  if (all_types != 0 && prerolled_types == all_types)
+    return TRUE;
+
   if (G_UNLIKELY (num_no_data > 0))
     return FALSE;
 
@@ -1403,7 +1411,7 @@ gst_asf_demux_check_segment_ts (GstASFDemux * demux, GstClockTime payload_ts)
 }
 
 static gboolean
-gst_asf_demux_check_first_ts (GstASFDemux * demux, gboolean force)
+gst_asf_demux_get_first_ts (GstASFDemux * demux)
 {
   if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (demux->first_ts))) {
     GstClockTime first_ts = GST_CLOCK_TIME_NONE;
@@ -1434,26 +1442,24 @@ gst_asf_demux_check_first_ts (GstASFDemux * demux, gboolean force)
 
       /* there are some DVR ms files where first packet has TS of 0 (instead of -1) while subsequent packets have
          regular (singificantly larger) timestamps. If we don't deal with it, we may end up with huge gap in timestamps
-         which makes playback stuck. The 0 timestamp may also be valid though, if the second packet timestamp continues 
+         which makes playback stuck. The 0 timestamp may also be valid though, if the second packet timestamp continues
          from it. I havent found a better way to distinguish between these two, except to set an arbitrary boundary
          and disregard the first 0 timestamp if the second timestamp is bigger than the boundary) */
 
-      if (stream_min_ts == 0 && stream_min_ts2 == GST_CLOCK_TIME_NONE && !force)        /* still waiting for the second timestamp */
-        return FALSE;
+      GST_DEBUG_OBJECT (demux,
+          "stream #%u stream_min_ts %" GST_TIME_FORMAT " stream_min_ts2 %"
+          GST_TIME_FORMAT, stream->id, GST_TIME_ARGS (stream_min_ts),
+          GST_TIME_ARGS (stream_min_ts2));
 
       if (stream_min_ts == 0 && stream_min_ts2 > GST_SECOND)    /* first timestamp is 0 and second is significantly larger, disregard the 0 */
         stream_min_ts = stream_min_ts2;
 
-      /* if we don't have timestamp for this stream, wait for more data */
-      if (!GST_CLOCK_TIME_IS_VALID (stream_min_ts) && !force)
-        return FALSE;
-
       if (GST_CLOCK_TIME_IS_VALID (stream_min_ts) &&
           (!GST_CLOCK_TIME_IS_VALID (first_ts) || first_ts > stream_min_ts))
         first_ts = stream_min_ts;
     }
 
-    if (!GST_CLOCK_TIME_IS_VALID (first_ts))    /* can happen with force = TRUE */
+    if (!GST_CLOCK_TIME_IS_VALID (first_ts))    /* can happen */
       first_ts = 0;
 
     demux->first_ts = first_ts;
@@ -1547,14 +1553,14 @@ gst_asf_demux_check_activate_streams (GstASFDemux * demux, gboolean force)
   if (demux->activated_streams)
     return TRUE;
 
-  if (G_UNLIKELY (!gst_asf_demux_check_first_ts (demux, force)))
-    return FALSE;
-
   if (!all_streams_prerolled (demux) && !force) {
     GST_DEBUG_OBJECT (demux, "not all streams with data beyond preroll yet");
     return FALSE;
   }
 
+  if (G_UNLIKELY (!gst_asf_demux_get_first_ts (demux)))
+    return FALSE;
+
   for (i = 0; i < demux->num_streams; ++i) {
     AsfStream *stream = &demux->stream[i];
 
@@ -1659,7 +1665,7 @@ gst_asf_demux_find_stream_with_complete_payload (GstASFDemux * demux)
 
         if (G_UNLIKELY (GST_CLOCK_TIME_IS_VALID (payload->ts) &&
                 (payload->ts < demux->segment.start))) {
-          if (G_UNLIKELY ((!demux->keyunit_sync) && (!demux->accurate)
+          if (G_UNLIKELY ((demux->keyunit_sync) && (!demux->accurate)
                   && payload->keyframe)) {
             GST_DEBUG_OBJECT (stream->pad,
                 "Found keyframe, updating segment start to %" GST_TIME_FORMAT,
@@ -1743,7 +1749,7 @@ gst_asf_demux_push_complete_payloads (GstASFDemux * demux, gboolean force)
       }
 
       /* FIXME : only if ACCURATE ! */
-      if (G_LIKELY (!demux->keyunit_sync && !demux->accurate
+      if (G_LIKELY (demux->keyunit_sync && !demux->accurate
               && (GST_CLOCK_TIME_IS_VALID (payload->ts)))
           && !GST_ASF_DEMUX_IS_REVERSE_PLAYBACK (demux->segment)) {
         GST_DEBUG ("Adjusting newsegment start to %" GST_TIME_FORMAT,
@@ -2677,7 +2683,7 @@ gst_asf_demux_add_audio_stream (GstASFDemux * demux,
   src_pad = gst_pad_new_from_static_template (&audio_src_template, name);
   g_free (name);
 
-  /* Swallow up any left over data and set up the 
+  /* Swallow up any left over data and set up the
    * standard properties from the header info */
   if (size_left) {
     GST_INFO_OBJECT (demux, "Audio header contains %d bytes of "
@@ -2734,6 +2740,14 @@ gst_asf_demux_add_audio_stream (GstASFDemux * demux,
 
   ++demux->num_audio_streams;
 
+#ifdef TIZEN_FEATURE_ASFDEMUX_POST_TAG_MSG
+  if (tags) {
+    /* post now, send event on pad later */
+    gst_element_post_message (GST_ELEMENT_CAST (demux),
+        gst_message_new_tag (GST_OBJECT_CAST (demux), gst_tag_list_copy (tags)));
+  }
+#endif
+
   return gst_asf_demux_setup_pad (demux, src_pad, caps, id, FALSE, NULL, tags);
 }
 
@@ -2830,10 +2844,18 @@ gst_asf_demux_add_video_stream (GstASFDemux * demux,
           streamheader = gst_buffer_ref (buf);
           gst_asf_demux_add_stream_headers_to_caps (demux, buf, caps_s);
           gst_structure_remove_field (caps_s, "codec_data");
+          gst_structure_set (caps_s, "stream-format", G_TYPE_STRING,
+              "byte-stream", NULL);
+        } else {
+          gst_structure_set (caps_s, "stream-format", G_TYPE_STRING, "avc",
+              NULL);
         }
 
         gst_buffer_unmap (buf, &mapinfo);
       }
+    } else {
+      gst_structure_set (caps_s, "stream-format", G_TYPE_STRING, "byte-stream",
+          NULL);
     }
   }
 
@@ -2930,6 +2952,14 @@ gst_asf_demux_add_video_stream (GstASFDemux * demux,
 
   ++demux->num_video_streams;
 
+#ifdef TIZEN_FEATURE_ASFDEMUX_POST_TAG_MSG
+  if (tags) {
+    /* post now, send event on pad later */
+    gst_element_post_message (GST_ELEMENT_CAST (demux),
+        gst_message_new_tag (GST_OBJECT_CAST (demux), gst_tag_list_copy (tags)));
+  }
+#endif
+
   return gst_asf_demux_setup_pad (demux, src_pad, caps, id, TRUE,
       streamheader, tags);
 }
@@ -3129,7 +3159,15 @@ gst_asf_demux_parse_stream_object (GstASFDemux * demux, guint8 * data,
               &data, &size)) {
         goto not_enough_data;
       }
-
+#ifdef TIZEN_FEATURE_ASFDEMUX_DISABLE_UNSUPPORTED_FORMAT
+      /* Compare video format WMV*, WVC* */
+      if (((video_format_object.tag & 0x00ffffff) == (guint32)(('W')|('M')<<8|('V')<<16))
+          || ((video_format_object.tag & 0x00ffffff) == (guint32)(('W')|('V')<<8|('C')<<16))) {
+          GST_ERROR_OBJECT (demux, "WMV file format is not supported.");
+          demux->is_supported_format = FALSE;
+          return NULL;
+      }
+#endif
       stream = gst_asf_demux_add_video_stream (demux, &video_format_object,
           stream_id, &data, &size);
 
@@ -3144,8 +3182,10 @@ gst_asf_demux_parse_stream_object (GstASFDemux * demux, guint8 * data,
       break;
   }
 
-  if (stream)
+  if (stream) {
     stream->inspect_payload = inspect_payload;
+    stream->type = stream_type;
+  }
   return stream;
 
 not_enough_data:
@@ -4215,6 +4255,13 @@ gst_asf_demux_process_ext_stream_props (GstASFDemux * demux, guint8 * data,
   stream = gst_asf_demux_parse_stream_object (demux, stream_obj_data, len);
   g_free (stream_obj_data);
 
+#ifdef TIZEN_FEATURE_ASFDEMUX_DISABLE_UNSUPPORTED_FORMAT
+  if ((stream == NULL) && (demux->is_supported_format == FALSE)) {
+    g_free (esp.payload_extensions);
+    return GST_FLOW_NOT_SUPPORTED;
+  }
+#endif
+
 done:
 
   if (stream) {
@@ -4435,6 +4482,12 @@ gst_asf_demux_process_object (GstASFDemux * demux, guint8 ** p_data,
   switch (obj.id) {
     case ASF_OBJ_STREAM:
       gst_asf_demux_parse_stream_object (demux, *p_data, obj_data_size);
+#ifdef TIZEN_FEATURE_ASFDEMUX_DISABLE_UNSUPPORTED_FORMAT
+      if (demux->is_supported_format == FALSE) {
+        ret = GST_FLOW_NOT_SUPPORTED;
+        break;
+      }
+#endif
       ret = GST_FLOW_OK;
       break;
     case ASF_OBJ_FILE: