changeset 7562:c5a09fa0a5fa 8u11-b04

RT-36287: FX to handle less clear images Reviewed by: Alexander Matveev, Kirill Kirichenko, Marc Sch?nefeld and Alexander Vorobyev
author Marc Owerfeldt <marc.owerfeldt@oracle.com>
date Fri, 11 Apr 2014 13:20:15 -0700
parents 962d35fbbce5
children 29459d248710 811e831e34ea
files modules/media/src/main/native/gstreamer/gstreamer-lite/gst-plugins-good/gst/isomp4/qtdemux.c
diffstat 1 files changed, 71 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/media/src/main/native/gstreamer/gstreamer-lite/gst-plugins-good/gst/isomp4/qtdemux.c	Tue Apr 08 08:35:28 2014 -0700
+++ b/modules/media/src/main/native/gstreamer/gstreamer-lite/gst-plugins-good/gst/isomp4/qtdemux.c	Fri Apr 11 13:20:15 2014 -0700
@@ -5888,6 +5888,9 @@
     gint i, count;
     guint64 time, stime;
     guint8 *buffer;
+#ifdef GSTREAMER_LITE
+    guint32 buffer_length;
+#endif
 
     GST_DEBUG_OBJECT (qtdemux, "looking for edit list");
     if (!(elst = qtdemux_tree_get_child_by_type (edts, FOURCC_elst)))
@@ -5899,11 +5902,17 @@
 
     /* we might allocate a bit too much, at least allocate 1 segment */
 #ifdef GSTREAMER_LITE
-    n_segments = MAX (n_segments, 1);
-    if (n_segments < G_MAXSIZE / sizeof(QtDemuxSegment))
-        stream->segments = g_new (QtDemuxSegment, n_segments);
-    else
+    if (n_segments < G_MAXSIZE / sizeof(QtDemuxSegment)) {
+        stream->segments = g_try_malloc (sizeof(QtDemuxSegment) * n_segments);
+          
+        if (stream->segments == NULL) {
+            return FALSE;
+        }
+        
+        buffer_length = QT_UINT32 (buffer);
+    } else {
         return FALSE;
+    }
 #else
     stream->segments = g_new (QtDemuxSegment, MAX (n_segments, 1));
 #endif // GSTREAMER_LITE
@@ -5918,6 +5927,62 @@
       QtDemuxSegment *segment;
       guint32 rate_int;
 
+#ifdef GSTREAMER_LITE
+        guint32 idx;
+        
+        idx = 20 + i * 12;
+        
+        if (idx <= buffer_length - 4) {
+            media_time = QT_UINT32 (buffer + idx);
+            
+            /* -1 media time is an empty segment, just ignore it */
+            if (media_time == G_MAXUINT32) {
+                continue;
+            }
+        } else {
+            return FALSE;
+        }
+        
+        idx = 16 + i * 12;
+        
+        if (idx <= buffer_length - 4) {
+            duration = QT_UINT32 (buffer + idx);
+        } else {
+            return FALSE;
+        }
+        
+        segment = &stream->segments[count++];
+        
+        /* time and duration expressed in global timescale */
+        segment->time = stime;
+        /* add non scaled values so we don't cause roundoff errors */
+        time += duration;
+        stime = gst_util_uint64_scale (time, GST_SECOND, qtdemux->timescale);
+        segment->stop_time = stime;
+        segment->duration = stime - segment->time;
+        /* media_time expressed in stream timescale */
+        segment->media_start =
+        gst_util_uint64_scale (media_time, GST_SECOND, stream->timescale);
+        segment->media_stop = segment->media_start + segment->duration;
+        
+        idx = 24 + i * 12;
+        
+        if (idx <= buffer_length - 4) {
+            rate_int = GST_READ_UINT32_BE (buffer + idx);
+            
+            if (rate_int <= 1) {
+                /* 0 is not allowed, some programs write 1 instead of the floating point
+                 * value */
+                GST_WARNING_OBJECT (qtdemux, "found suspicious rate %" G_GUINT32_FORMAT,
+                                    rate_int);
+                segment->rate = 1;
+            } else {
+                segment->rate = rate_int / 65536.0;
+            }
+        } else {
+            return FALSE;
+        }
+#else
       media_time = QT_UINT32 (buffer + 20 + i * 12);
 
       /* -1 media time is an empty segment, just ignore it */
@@ -5950,7 +6015,8 @@
       } else {
         segment->rate = rate_int / 65536.0;
       }
-
+#endif
+        
       GST_DEBUG_OBJECT (qtdemux, "created segment %d time %" GST_TIME_FORMAT
           ", duration %" GST_TIME_FORMAT ", media_time %" GST_TIME_FORMAT
           ", rate %g, (%d)", i, GST_TIME_ARGS (segment->time),