gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c
branchtrunk
changeset 173 a2ec843160c8
parent 172 d591b81268b0
child 181 d9628018e9f7
     1.1 --- a/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Fri Dec 01 21:19:03 2006 +0000
     1.2 +++ b/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Fri Dec 01 21:48:39 2006 +0000
     1.3 @@ -264,6 +264,8 @@
     1.4  static void gst_nuv_demux_update_duration (GstNuvDemux *nuv, guint64 current_timestamp);
     1.5  static gint64 gst_nuv_demux_get_bytes_duration (GstNuvDemux *nuv);
     1.6  static gint64 gst_nuv_demux_get_time_duration (GstNuvDemux *nuv);
     1.7 +GstBuffer * gst_nuv_demux_adapter_take_buffer (GstAdapter * adapter, guint nbytes);
     1.8 +
     1.9  
    1.10  
    1.11  GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
    1.12 @@ -1056,12 +1058,7 @@
    1.13        return GST_FLOW_ERROR_NO_DATA;
    1.14  
    1.15      if (move) {
    1.16 -      guint8 *data = NULL;
    1.17 -      data = (guint8 *) gst_adapter_take (nuv->priv->adapter, size);
    1.18 -      *buffer = gst_buffer_new_alloc (size);
    1.19 -      memcpy (GST_BUFFER_DATA (*buffer), data, size);
    1.20 -      GST_BUFFER_MALLOCDATA (*buffer) = GST_BUFFER_DATA (*buffer);
    1.21 -      g_free (data);
    1.22 +      *buffer = gst_nuv_demux_adapter_take_buffer (nuv->priv->adapter, size);
    1.23      } else {
    1.24        guint8 *data = NULL;
    1.25        data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
    1.26 @@ -1078,15 +1075,12 @@
    1.27    gboolean res = TRUE;
    1.28    GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
    1.29  
    1.30 -  res = gst_pad_activate_push (sinkpad, TRUE);
    1.31 -  /*
    1.32 -
    1.33    if (gst_pad_check_pull_range (sinkpad)) {
    1.34      res = gst_pad_activate_pull (sinkpad, TRUE);
    1.35    } else {
    1.36      res = gst_pad_activate_push (sinkpad, TRUE);
    1.37    }
    1.38 -  */
    1.39 +  
    1.40    g_object_unref (nuv);
    1.41    return res;
    1.42  }
    1.43 @@ -1152,9 +1146,7 @@
    1.44        gint64 stop;
    1.45  
    1.46        gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur, &stop_type, &stop);
    1.47 -
    1.48        GST_DEBUG_OBJECT (nuv, "got seek, start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT, cur, stop);
    1.49 -
    1.50        break;
    1.51      }
    1.52      case GST_EVENT_NEWSEGMENT:
    1.53 @@ -1186,7 +1178,6 @@
    1.54        else
    1.55          nuv->time_qos = -1;
    1.56  */
    1.57 -
    1.58        break;
    1.59      }
    1.60  
    1.61 @@ -1358,6 +1349,48 @@
    1.62      return nuv->priv->duration_time;
    1.63  }
    1.64  
    1.65 +GstBuffer *
    1.66 +gst_nuv_demux_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
    1.67 +{
    1.68 +  GstBuffer *buffer;
    1.69 +  GstBuffer *cur;
    1.70 +  guint8 *data;
    1.71 +
    1.72 +  g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
    1.73 +  g_return_val_if_fail (nbytes > 0, NULL);
    1.74 +
    1.75 +  GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes);
    1.76 +
    1.77 +  /* we don't have enough data, return NULL. This is unlikely
    1.78 +   * as one usually does an _available() first instead of peeking a
    1.79 +   * random size. */
    1.80 +  if (G_UNLIKELY (nbytes > adapter->size))
    1.81 +    return NULL;
    1.82 +
    1.83 +  /* our head buffer has enough data left, return it */
    1.84 +  cur = adapter->buflist->data;
    1.85 +  if (GST_BUFFER_SIZE (cur) >= nbytes + adapter->skip) {
    1.86 +    GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer",
    1.87 +        nbytes);
    1.88 +    buffer = gst_buffer_create_sub (cur, adapter->skip, nbytes);
    1.89 +
    1.90 +    gst_adapter_flush (adapter, nbytes);
    1.91 +
    1.92 +    return buffer;
    1.93 +  }
    1.94 +
    1.95 +  data = gst_adapter_take (adapter, nbytes);
    1.96 +  if (data == NULL)
    1.97 +    return NULL;
    1.98 +
    1.99 +  buffer = gst_buffer_new ();
   1.100 +  GST_BUFFER_DATA (buffer) = data;
   1.101 +  GST_BUFFER_MALLOCDATA (buffer) = data;
   1.102 +  GST_BUFFER_SIZE (buffer) = nbytes;
   1.103 +
   1.104 +  return buffer;
   1.105 +}
   1.106 +
   1.107  
   1.108  static gboolean
   1.109  plugin_init (GstPlugin * plugin)