2 * Copyright (C) <2006> Renato Araujo Oliveira Filho <renato.filho@indt.org.br>
3 * Rosfran Borges <rosfran.borges@indt.org.br>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 /* Element-Checklist-Version: 5 */
23 * SECTION:element-nuvdemux
27 * Demuxes an .nuv file into raw or compressed audio and/or video streams.
30 * This element currently only supports pull-based scheduling.
32 * <title>Example launch line</title>
35 * gst-launch filesrc test.nuv ! nuvdemux name=demux demux.audio_00 ! decodebin ! audioconvert ! audioresample ! autoaudiosink demux.video_00 ! queue ! decodebin ! ffmpegcolorspace ! videoscale ! autovideosink
37 * Play (parse and decode) an .nuv file and try to output it to
38 * an automatically detected soundcard and videosink. If the NUV file contains
39 * compressed audio or video data, this will only work if you have the
40 * right decoder elements/plugins installed.
51 #include <gst/gsterror.h>
52 #include <gst/gstplugin.h>
56 #include "glib/gi18n.h"
57 #include "gstnuvdemux.h"
59 #define GST_NUV_DEMUX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_NUV_DEMUX, GstNuvDemuxPrivate))
61 GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug);
62 #define GST_CAT_DEFAULT nuvdemux_debug
63 #define GST_FLOW_ERROR_NO_DATA -101
64 #define GST_FLOW_ERROR_EOS -102
72 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_EVENT);
74 static const GstElementDetails gst_nuv_demux_details =
75 GST_ELEMENT_DETAILS ("Nuv demuxer",
77 "Demultiplex a .nuv file into audio and video",
78 "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
79 "Rosfran Borges <rosfran.borges@indt.org.br>");
85 gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */
86 gchar version[5]; /* "x.xx\0" */
91 gint i_height_desired;
93 gchar i_mode; /* P progressive, I interlaced */
95 gdouble d_aspect; /* 1.0 squared pixel */
101 gint i_video_blocks; /* 0 no video, -1 unknown */
105 gint i_keyframe_distance;
112 gchar i_type; /* A: audio, V: video, S: sync; T: test
113 R: Seekpoint (string:RTjjjjjjjj)
114 D: Extra data for codec */
115 gchar i_compression; /* V: 0 uncompressed
120 A: 0 uncompressed (44100 1-bits, 2ch)
126 N null frame loudless
128 S: B audio and vdeo sync point
129 A audio sync info (timecode == effective
131 V next video sync (timecode == next video
133 S audio,video,text correlation */
134 gchar i_keyframe; /* 0 keyframe, else no no key frame */
135 guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16
136 0x02: gauss 5 pixel (8,1,1,1,1)/12
137 0x04: cartoon filter */
139 gint32 i_timecode; /* ms */
141 gint i_length; /* V,A,T: length of following data
142 S: length of packet correl */
146 /* FIXME Not sure of this one */
153 gint i_audio_sample_rate;
154 gint i_audio_bits_per_sample;
155 gint i_audio_channels;
156 gint i_audio_compression_ratio;
157 gint i_audio_quality;
158 gint i_rtjpeg_quality;
159 gint i_rtjpeg_luma_filter;
160 gint i_rtjpeg_chroma_filter;
164 gint i_lavc_maxqdiff;
165 gint64 i_seekable_offset;
166 gint64 i_keyframe_adjust_offset;
168 } nuv_extended_header;
179 GST_NUV_DEMUX_HEADER_DATA,
180 GST_NUV_DEMUX_EXTRA_DATA,
181 GST_NUV_DEMUX_MPEG_DATA,
182 GST_NUV_DEMUX_EXTEND_HEADER,
183 GST_NUV_DEMUX_EXTEND_HEADER_DATA,
184 GST_NUV_DEMUX_INDEX_CREATE,
185 GST_NUV_DEMUX_FRAME_HEADER,
187 GST_NUV_DEMUX_INVALID_DATA
190 struct _GstNuvDemuxPrivate {
191 /* used for indicate the mode */
194 /* used on push mode */
199 GstPad *src_video_pad;
200 GstPad *src_audio_pad;
203 GstFlowReturn last_video_return;
204 GstFlowReturn last_audio_return;
208 /* NUV decoding state */
209 GstNuvDemuxState state;
212 /* duration information */
213 guint64 duration_bytes;
214 guint64 duration_time;
215 guint64 segment_stop;
216 guint64 segment_start;
218 /* segment control info */
219 gboolean new_audio_segment;
220 gboolean new_video_segment;
223 guint64 mpeg_data_size;
224 GstBuffer *mpeg_buffer;
228 nuv_extended_header eh;
236 guint64 last_frame_time;
241 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
244 GST_STATIC_CAPS ("video/x-nuv"));
246 static GstStaticPadTemplate audio_src_template =
247 GST_STATIC_PAD_TEMPLATE ("audio_src",
250 GST_STATIC_CAPS_ANY);
252 static GstStaticPadTemplate video_src_template =
253 GST_STATIC_PAD_TEMPLATE ("video_src",
256 GST_STATIC_CAPS_ANY);
258 static void gst_nuv_demux_dispose (GObject * object);
259 static void gst_nuv_demux_finalize (GObject * object);
260 static GstStateChangeReturn gst_nuv_demux_change_state (GstElement * element,
261 GstStateChange transition);
262 static void gst_nuv_demux_loop (GstPad * pad);
263 static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf);
264 static GstFlowReturn gst_nuv_demux_play (GstPad * pad);
265 static gboolean gst_nuv_demux_sink_activate_pull (GstPad * sinkpad,
267 static gboolean gst_nuv_demux_sink_activate_push (GstPad * pad,
269 static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad);
270 //static gboolean gst_nuv_demux_sink_event (GstPad *pad, GstEvent *event);
271 static gboolean gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event);
272 static frame_index_data * gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos,
273 gint64 segment_stop, GstFormat format);
277 static GstFlowReturn gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size,
278 gboolean move, GstBuffer ** buffer);
279 static void gst_nuv_demux_reset (GstNuvDemux * nuv);
280 static void gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv);
281 static void gst_nuv_demux_send_eos (GstNuvDemux * nuv);
282 static void gst_nuv_demux_create_seek_index (GstNuvDemux * nuv);
285 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
286 GstBuffer * gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes);
290 GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
292 /******************************************************************************
294 ******************************************************************************/
295 #if G_BYTE_ORDER == G_BIG_ENDIAN
296 static inline gdouble
297 _gdouble_swap_le_be (gdouble * d)
306 u.i = GUINT64_SWAP_LE_BE (u.i);
310 #define READ_DOUBLE_FROM_LE(d) (_gdouble_swap_le_be((gdouble* ) d))
311 #else /* G_BYTE_ORDER != G_BIG_ENDIAN */
312 #define READ_DOUBLE_FROM_LE(d) *((gdouble* ) (d))
313 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
316 double2fraction (double in, int *num, int *denom)
321 } else if (in == 23.976) {
326 while (in - floor(in) >= 0.1) {
330 *num = (int)floor(in);
334 /* GObject Functions */
337 gst_nuv_demux_base_init (gpointer klass)
339 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
341 gst_element_class_add_pad_template (element_class,
342 gst_static_pad_template_get (&audio_src_template));
344 gst_element_class_add_pad_template (element_class,
345 gst_static_pad_template_get (&video_src_template));
347 gst_element_class_add_pad_template (element_class,
348 gst_static_pad_template_get (&sink_template));
349 gst_element_class_set_details (element_class, &gst_nuv_demux_details);
353 gst_nuv_demux_class_init (GstNuvDemuxClass * klass)
355 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
356 GObjectClass *gobject_class = (GObjectClass *) klass;
358 GST_DEBUG_CATEGORY_INIT (nuvdemux_debug, "nuvdemux",
359 0, "Demuxer for NUV streams");
361 parent_class = g_type_class_peek_parent (klass);
363 gobject_class->dispose = gst_nuv_demux_dispose;
364 gobject_class->finalize = gst_nuv_demux_finalize;
365 gstelement_class->change_state = gst_nuv_demux_change_state;
367 g_type_class_add_private (gobject_class, sizeof (GstNuvDemuxPrivate));
371 gst_nuv_demux_init (GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
373 nuv->priv = GST_NUV_DEMUX_GET_PRIVATE (nuv);
374 nuv->priv->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
376 /* creating adapter */
377 nuv->priv->mode = NUV_PUSH_MODE;
378 nuv->priv->adapter = gst_adapter_new ();
380 g_debug ("Adapter %p", nuv->priv->adapter);
382 nuv->priv->new_audio_segment = TRUE;
383 nuv->priv->new_video_segment = TRUE;
385 gst_pad_set_activate_function (nuv->priv->sinkpad, gst_nuv_demux_sink_activate);
386 gst_pad_set_activatepull_function (nuv->priv->sinkpad,
387 gst_nuv_demux_sink_activate_pull);
388 gst_pad_set_activatepush_function (nuv->priv->sinkpad,
389 gst_nuv_demux_sink_activate_push);
390 gst_pad_set_chain_function (nuv->priv->sinkpad,
391 GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
393 gst_pad_set_event_function (nuv->priv->sinkpad,
394 gst_nuv_demux_sink_event);
397 gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad);
402 gst_nuv_demux_dispose (GObject * object)
404 GstNuvDemux *nuv = GST_NUV_DEMUX (object);
406 g_debug ("NUV DISPOSE");
408 if (nuv->priv->mpeg_buffer != NULL) {
409 gst_buffer_unref (nuv->priv->mpeg_buffer);
412 gst_nuv_demux_reset (GST_NUV_DEMUX (object));
413 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (object));
415 if (nuv->priv->adapter != NULL) {
416 gst_object_unref (nuv->priv->adapter);
421 gst_nuv_demux_finalize (GObject * object)
423 G_OBJECT_CLASS (parent_class)->finalize (object);
430 gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h)
432 GstBuffer *buffer = NULL;
433 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
435 if ((res != GST_FLOW_OK) || (buffer == NULL)) {
439 memcpy (h->id, buffer->data, 12);
440 memcpy (h->version, buffer->data + 12, 5);
441 h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
442 h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
443 h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
444 h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
445 h->i_mode = GPOINTER_TO_INT (buffer->data[36]);
446 h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
447 h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
448 /* get the num and denom values from fps */
449 double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd);
450 h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
451 h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
452 h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
453 h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
455 GST_DEBUG_OBJECT (nuv,
456 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
457 h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
458 h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
459 h->i_keyframe_distance);
462 if (buffer != NULL) {
463 gst_buffer_unref (buffer);
470 gst_nuv_demux_stream_header_data (GstNuvDemux * nuv)
474 res = gst_nuv_demux_header_load (nuv, &nuv->priv->h);
475 if (res == GST_FLOW_OK)
476 nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
484 gst_nuv_demux_stream_file_header (GstNuvDemux * nuv)
486 GstFlowReturn res = GST_FLOW_OK;
487 GstBuffer *file_header = NULL;
489 res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header);
490 if (res == GST_FLOW_OK) {
491 if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) ||
492 strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) {
493 nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
495 GST_DEBUG_OBJECT (nuv, "error parsing file header");
496 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
497 res = GST_FLOW_ERROR;
501 if (file_header != NULL) {
502 gst_buffer_unref (file_header);
511 gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h)
514 GstBuffer *buf = NULL;
516 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
518 if ((res != GST_FLOW_OK) || (buf == NULL)) {
524 h->i_type = GPOINTER_TO_INT (data[0]);
525 h->i_compression = GPOINTER_TO_INT (data[1]);
526 h->i_keyframe = GPOINTER_TO_INT (data[2]);
527 h->i_filters = GPOINTER_TO_INT (data[3]);
528 h->i_timecode = GST_READ_UINT32_LE (&data[4]);
529 h->i_length = GST_READ_UINT32_LE (&data[8]);
531 GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
533 h->i_compression ? h->i_compression : ' ',
534 h->i_keyframe ? h->i_keyframe : ' ',
535 h->i_filters, h->i_timecode, h->i_length);
539 gst_buffer_unref (buf);
547 gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
548 nuv_extended_header * h)
551 GstBuffer *buff = NULL;
553 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
555 if ((res != GST_FLOW_OK) || (buff == NULL)) {
560 h->i_version = GST_READ_UINT32_LE (&data[0]);
561 h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
562 h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]);
563 h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]);
564 h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]);
565 h->i_audio_channels = GST_READ_UINT32_LE (&data[20]);
566 h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]);
567 h->i_audio_quality = GST_READ_UINT32_LE (&data[28]);
568 h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]);
569 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]);
570 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]);
571 h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]);
572 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]);
573 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]);
574 h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]);
575 h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]);
576 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]);
578 GST_DEBUG_OBJECT (nuv,
579 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
580 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
581 h->i_version, (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc,
582 h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels,
583 h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality,
584 h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
585 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
586 h->i_keyframe_adjust_offset);
590 gst_buffer_unref (buff);
597 /* Query Functions */
598 static const GstQueryType *
599 gst_nuv_demux_get_src_query_types (GstPad * pad)
601 static const GstQueryType src_types[] = {
611 gst_nuv_demux_handle_src_query (GstPad * pad, GstQuery * query)
613 gboolean res = FALSE;
614 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
616 switch (GST_QUERY_TYPE (query)) {
617 case GST_QUERY_POSITION:
618 if (GST_CLOCK_TIME_IS_VALID (nuv->priv->last_frame_time)) {
619 gst_query_set_position (query, GST_FORMAT_TIME, nuv->priv->last_frame_time);
623 case GST_QUERY_DURATION:
625 if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) {
626 gst_query_set_duration (query, GST_FORMAT_TIME, nuv->priv->duration_time);
636 gst_object_unref (nuv);
642 gst_nuv_demux_create_pad (GstNuvDemux *nuv, GstCaps *caps, GstStaticPadTemplate *template, const gchar* name)
645 pad = gst_pad_new_from_static_template (template, name);
646 gst_pad_set_caps (pad, caps);
647 gst_pad_set_active (pad, TRUE);
648 gst_pad_use_fixed_caps (pad);
649 gst_element_add_pad (GST_ELEMENT (nuv), pad);
651 gst_pad_set_event_function (pad,
652 GST_DEBUG_FUNCPTR (gst_nuv_demux_srcpad_event));
654 gst_pad_set_query_type_function (pad,
655 GST_DEBUG_FUNCPTR (gst_nuv_demux_get_src_query_types));
657 gst_pad_set_query_function (pad,
658 GST_DEBUG_FUNCPTR (gst_nuv_demux_handle_src_query));
665 gst_nuv_demux_create_pads (GstNuvDemux * nuv)
667 if (nuv->priv->h.i_video_blocks != 0) {
668 GstCaps *video_caps = NULL;
670 video_caps = gst_caps_new_simple ("video/x-divx",
671 "divxversion", G_TYPE_INT, 4,
672 "width", G_TYPE_INT, nuv->priv->h.i_width,
673 "height", G_TYPE_INT, nuv->priv->h.i_height,
674 "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd,
675 "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc,
676 "pixel-aspect-ratio", GST_TYPE_FRACTION,
677 (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL);
679 nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src");
680 gst_caps_unref (video_caps);
683 if (nuv->priv->h.i_audio_blocks != 0) {
684 GstCaps *audio_caps = NULL;
686 audio_caps = gst_caps_new_simple ("audio/mpeg",
687 "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate,
688 "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc,
689 "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels,
690 "layer", G_TYPE_INT, 3, // fixme: magic number
691 "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL);
693 nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src");
694 gst_caps_unref (audio_caps);
697 gst_element_no_more_pads (GST_ELEMENT (nuv));
701 gst_nuv_demux_validate_header (nuv_frame_header *h)
703 gboolean valid = FALSE;
704 //g_debug ("Type %d = Compression %d", h->i_type, h->i_compression);
705 //g_usleep (1 * G_USEC_PER_SEC );
709 if (h->i_compression == 0 ||
710 h->i_compression == 1 ||
711 h->i_compression == 2 ||
712 h->i_compression == 'N' ||
713 h->i_compression == 'L') {
718 if (h->i_compression == 0 ||
719 h->i_compression == 1 ||
720 h->i_compression == 2 ||
721 h->i_compression == 3 ||
722 h->i_compression == 'F' ||
723 h->i_compression == 'S' ||
724 h->i_compression == 'N' ||
725 h->i_compression == 'L') {
730 if (h->i_compression == 'B' ||
731 h->i_compression == 'A' ||
732 h->i_compression == 'V' ||
733 h->i_compression == 'S') {
754 gst_nuv_demux_read_head_frame (GstNuvDemux * nuv)
756 GstFlowReturn ret = GST_FLOW_OK;
757 gboolean valid = FALSE;
760 ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh);
761 if (ret != GST_FLOW_OK) {
765 if (gst_nuv_demux_validate_header (&nuv->priv->fh) == TRUE)
768 } while (valid == FALSE);
770 nuv->priv->state = GST_NUV_DEMUX_MOVI;
775 gst_nuv_combine_flow (GstNuvDemux *nuv)
777 GstFlowReturn ret_video = nuv->priv->last_video_return;
778 GstFlowReturn ret_audio = nuv->priv->last_audio_return;
780 if ((ret_video != GST_FLOW_OK) &&
781 (ret_audio != GST_FLOW_OK))
784 if (GST_FLOW_IS_FATAL (ret_video))
787 if (GST_FLOW_IS_FATAL (ret_audio))
794 gst_nuv_demux_stream_data (GstNuvDemux * nuv)
796 GstFlowReturn ret = GST_FLOW_OK;
799 GstBuffer *buf = NULL;
807 if (h.i_length > 0) {
808 ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf);
809 if ((ret != GST_FLOW_OK) || (buf == NULL)) {
813 if ((h.i_timecode < 0)) {
818 timestamp = h.i_timecode * GST_MSECOND;
819 GST_BUFFER_TIMESTAMP (buf) = timestamp;
829 pad = nuv->priv->src_video_pad;
831 if (nuv->priv->new_video_segment) {
833 /* send new segment event*/
834 gst_pad_push_event (nuv->priv->src_video_pad,
835 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
836 GST_CLOCK_TIME_NONE, 0));
838 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
839 nuv->priv->time_start = timestamp;
841 nuv->priv->new_video_segment = FALSE;
848 pad = nuv->priv->src_audio_pad;
850 if (nuv->priv->new_audio_segment) {
851 /* send new segment event*/
852 gst_pad_push_event (nuv->priv->src_audio_pad,
853 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
854 GST_CLOCK_TIME_NONE, 0));
856 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
857 nuv->priv->time_start = timestamp;
859 nuv->priv->new_audio_segment = FALSE;
866 switch (h.i_compression) {
868 GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode);
869 gst_pad_push_event (nuv->priv->src_video_pad,
870 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND,
871 GST_CLOCK_TIME_NONE, 0));
874 GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode);
875 gst_pad_push_event (nuv->priv->src_audio_pad,
876 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
877 GST_CLOCK_TIME_NONE, 0));
888 if ((buf != NULL) && (pad != NULL)) {
889 /* pushing the buffer */
890 gst_buffer_set_caps (buf, GST_PAD_CAPS (pad));
891 ret = gst_pad_push (pad, buf);
894 if (ret != GST_FLOW_OK) {
895 GST_WARNING_OBJECT (nuv, "error: %d pushing on srcpad %s", ret, gst_pad_get_name (pad));
897 if (pad == nuv->priv->src_video_pad) {
898 nuv->priv->last_video_return = ret;
900 else if (pad == nuv->priv->src_audio_pad) {
901 nuv->priv->last_audio_return = ret;
904 /* verify anothers flow if is necessary stop task */
905 if (gst_nuv_combine_flow (nuv) != FALSE) {
908 GST_WARNING_OBJECT (nuv, "error: on push");
916 gst_buffer_unref (buf);
919 if (ret == GST_FLOW_OK) {
920 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
921 memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh));
927 gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv)
929 GstFlowReturn ret = GST_FLOW_OK;
931 /* ffmpeg extra data */
932 ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE,
933 &nuv->priv->mpeg_buffer);
934 if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) {
938 GST_BUFFER_SIZE (nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
939 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
944 gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv)
946 GstFlowReturn ret = GST_FLOW_OK;
951 ret = gst_nuv_demux_frame_header_load (nuv, &h);
952 if (ret != GST_FLOW_OK)
955 if (h.i_type != 'D') {
956 GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg");
957 return GST_FLOW_NOT_SUPPORTED;
960 if (h.i_length > 0) {
961 if (h.i_compression == 'F') {
962 nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
964 GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported");
965 return GST_FLOW_NOT_SUPPORTED;
968 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
975 gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv)
977 GstFlowReturn ret = GST_FLOW_OK;
979 ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh);
980 if (ret != GST_FLOW_OK)
983 gst_nuv_demux_create_pads (nuv);
984 nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
989 gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv)
991 GstBuffer *buf = NULL;
992 GstFlowReturn res = GST_FLOW_OK;
994 res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf);
995 if ((res != GST_FLOW_OK) || (buf == NULL)) {
997 gst_buffer_unref (buf);
1002 if (buf->data[0] == 'X') {
1003 gst_buffer_unref (buf);
1007 res = gst_nuv_demux_frame_header_load (nuv, &h);
1008 if (res != GST_FLOW_OK)
1011 if (h.i_length != 512) {
1012 return GST_FLOW_ERROR;
1014 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1016 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1017 g_object_unref (buf);
1018 GST_ELEMENT_WARNING (nuv, STREAM, FAILED,
1019 (_("incomplete NUV support")), ("incomplete NUV support"));
1020 return GST_FLOW_ERROR;
1026 gst_nuv_demux_create_seek_index (GstNuvDemux * nuv)
1030 g_debug ("CREATING INDEX");
1032 while (gst_nuv_demux_frame_header_load (nuv, &h) == GST_FLOW_OK) {
1033 if (h.i_keyframe == 0) {
1034 //if (h.i_type == 'V') {
1035 frame_index_data *f = g_new0 (frame_index_data, 1);
1036 g_debug ("KEY FRAME AT %lld", nuv->priv->offset);
1038 f->offset = nuv->priv->offset - 12;
1039 f->timecode = h.i_timecode * GST_MSECOND;
1041 nuv->priv->index = g_slist_append (nuv->priv->index, f);
1043 if (h.i_type != 'R') {
1044 nuv->priv->offset += h.i_length;
1045 if (h.i_type == 'A' || h.i_type == 'V')
1046 nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1049 g_debug ("CREATING INDEX: DONE : DURATION Bytes/Sec: %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, nuv->priv->offset, nuv->priv->duration_time);
1050 nuv->priv->duration_bytes = nuv->priv->offset;
1051 nuv->priv->offset = nuv->priv->header_lengh;
1053 msg = gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, nuv->priv->duration_time);
1054 gst_element_post_message (GST_ELEMENT (nuv), msg);
1058 static GstFlowReturn
1059 gst_nuv_demux_play (GstPad * pad)
1061 GstFlowReturn res = GST_FLOW_OK;
1062 GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad));
1064 switch (nuv->priv->state) {
1065 case GST_NUV_DEMUX_START:
1066 res = gst_nuv_demux_stream_file_header (nuv);
1067 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1072 case GST_NUV_DEMUX_HEADER_DATA:
1073 res = gst_nuv_demux_stream_header_data (nuv);
1074 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1079 case GST_NUV_DEMUX_EXTRA_DATA:
1080 res = gst_nuv_demux_stream_extra_data (nuv);
1081 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1086 case GST_NUV_DEMUX_MPEG_DATA:
1087 res = gst_nuv_demux_stream_mpeg_data (nuv);
1088 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1093 case GST_NUV_DEMUX_EXTEND_HEADER:
1094 res = gst_nuv_demux_stream_extend_header (nuv);
1095 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1100 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1101 res = gst_nuv_demux_stream_extend_header_data (nuv);
1102 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1105 //store file header size
1106 nuv->priv->header_lengh = nuv->priv->offset;
1109 case GST_NUV_DEMUX_INDEX_CREATE:
1110 if (nuv->priv->mode == NUV_PULL_MODE) {
1111 gst_nuv_demux_create_seek_index (nuv);
1113 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1116 case GST_NUV_DEMUX_FRAME_HEADER:
1117 res = gst_nuv_demux_read_head_frame (nuv);
1118 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1123 case GST_NUV_DEMUX_MOVI:
1124 res = gst_nuv_demux_stream_data (nuv);
1125 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1130 case GST_NUV_DEMUX_INVALID_DATA:
1134 g_assert_not_reached ();
1140 GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
1141 gst_pad_pause_task (nuv->priv->sinkpad);
1143 if (res == GST_FLOW_ERROR_EOS) {
1144 g_debug ("EOS EOS EOS EOS EOS EOS");
1145 gst_nuv_demux_send_eos (nuv);
1146 nuv->priv->eos = TRUE;
1150 if (GST_FLOW_IS_FATAL (res)) {
1151 GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
1152 (_("Internal data stream error.")),
1153 ("streaming stopped, reason %s", gst_flow_get_name (res)));
1155 gst_nuv_demux_send_eos (nuv);
1161 gst_nuv_demux_send_eos (GstNuvDemux * nuv)
1163 gst_element_post_message (GST_ELEMENT (nuv),
1164 gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));
1166 if (nuv->priv->src_video_pad)
1167 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_eos ());
1168 if (nuv->priv->src_audio_pad)
1169 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_eos ());
1172 static GstFlowReturn
1173 gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move,
1174 GstBuffer ** buffer)
1176 GstFlowReturn ret = GST_FLOW_OK;
1182 if (nuv->priv->mode == NUV_PULL_MODE) {
1183 ret = gst_pad_pull_range (nuv->priv->sinkpad, nuv->priv->offset, size, buffer);
1184 if (ret == GST_FLOW_OK) {
1186 nuv->priv->offset += size;
1189 } else if (ret == GST_FLOW_UNEXPECTED) {
1190 g_debug ("GOT EOS");
1191 return GST_FLOW_ERROR_EOS;
1194 if (gst_adapter_available (nuv->priv->adapter) < size) {
1195 nuv->priv->more_data = TRUE;
1196 return GST_FLOW_ERROR_NO_DATA;
1199 *buffer = gst_adapter_take_buffer (nuv->priv->adapter, size);
1201 guint8 *data = NULL;
1202 data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
1203 *buffer = gst_buffer_new ();
1204 gst_buffer_set_data (*buffer, data, size);
1211 gst_nuv_demux_sink_activate (GstPad * sinkpad)
1213 gboolean res = TRUE;
1214 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1216 g_debug ("SINK ACTIVATE");
1218 if (gst_pad_check_pull_range (sinkpad)) {
1220 gst_adapter_clear (nuv->priv->adapter);
1221 res = gst_pad_activate_pull (sinkpad, TRUE);
1224 gst_adapter_clear (nuv->priv->adapter);
1225 res = gst_pad_activate_push (sinkpad, TRUE);
1228 g_object_unref (nuv);
1233 gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
1235 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1238 GST_DEBUG_OBJECT (nuv, "activating pull function");
1239 nuv->priv->mode = NUV_PULL_MODE;
1240 gst_adapter_clear (nuv->priv->adapter);
1242 gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
1244 GST_DEBUG_OBJECT (nuv, "deactivating pull function");
1245 g_debug ("STOP TASK");
1246 gst_pad_stop_task (sinkpad);
1248 gst_object_unref (nuv);
1254 gst_nuv_demux_sink_activate_push (GstPad * pad, gboolean active)
1256 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1259 nuv->priv->mode = NUV_PUSH_MODE;
1260 gst_adapter_clear (nuv->priv->adapter);
1262 GST_DEBUG_OBJECT (nuv, "activating push/chain function");
1264 GST_DEBUG_OBJECT (nuv, "deactivating push/chain function");
1267 gst_object_unref (nuv);
1272 static frame_index_data *
1273 gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos,
1274 gint64 segment_stop, GstFormat format)
1277 frame_index_data *ret = NULL;
1279 if (nuv->priv->index == NULL) {
1283 /* find keyframe closest to the requested position */
1284 for (l = nuv->priv->index; l != NULL; l = l->next) {
1285 frame_index_data *f = (frame_index_data *) l->data;
1288 if (format == GST_FORMAT_BYTES) {
1290 } else if (format == GST_FORMAT_TIME) {
1296 if (pos >= seek_pos) {
1300 if ((segment_stop != -1) && (pos > segment_stop))
1308 gst_nuv_demux_do_seek (GstNuvDemux *nuv, GstEvent * event)
1313 GstSeekType cur_type;
1315 GstSeekType stop_type;
1318 frame_index_data *entry;
1319 gint64 segment_start;
1320 gint64 segment_stop;
1321 GstEvent *newsegment_event;
1324 g_debug ("DEMUX SEEK");
1325 gst_event_parse_seek (event, &rate, &format, &flags,
1326 &cur_type, &cur, &stop_type, &stop);
1329 if (format == GST_FORMAT_TIME) {
1330 GST_DEBUG_OBJECT (nuv, "Can only seek on BYTES");
1336 GST_DEBUG_OBJECT (nuv, "Can only seek with positive rate");
1340 if (cur_type == GST_SEEK_TYPE_SET) {
1341 GST_OBJECT_LOCK (nuv);
1342 if (gst_nuv_demux_do_seek_index (nuv, cur, -1, format) == NULL) {
1343 GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1344 GST_OBJECT_UNLOCK (nuv);
1347 GST_OBJECT_UNLOCK (nuv);
1349 flush = !!(flags & GST_SEEK_FLAG_FLUSH);
1352 gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_start ());
1353 if (nuv->priv->src_video_pad != NULL) {
1354 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_start ());
1357 if (nuv->priv->src_audio_pad != NULL) {
1358 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_start ());
1362 gst_pad_pause_task (nuv->priv->sinkpad);
1365 GST_PAD_STREAM_LOCK (nuv->priv->sinkpad);
1366 GST_OBJECT_LOCK (nuv);
1369 if (cur == GST_CLOCK_TIME_NONE)
1371 if (stop == GST_CLOCK_TIME_NONE)
1372 stop = nuv->priv->duration_time;
1374 if (cur_type == GST_SEEK_TYPE_SET)
1375 segment_start = cur;
1376 else if (cur_type == GST_SEEK_TYPE_CUR)
1377 segment_start = nuv->priv->segment_start + cur;
1379 segment_start = nuv->priv->segment_start;
1381 if (stop_type == GST_SEEK_TYPE_SET)
1382 segment_stop = stop;
1383 else if (stop_type == GST_SEEK_TYPE_CUR)
1384 segment_stop = nuv->priv->segment_stop + stop;
1386 segment_stop = nuv->priv->segment_stop;
1388 segment_start = CLAMP (segment_start, 0, nuv->priv->duration_time);
1389 segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_time);
1391 entry = gst_nuv_demux_do_seek_index (nuv, segment_start,
1392 segment_stop, format);
1394 if (entry == NULL) {
1395 GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1399 g_debug ("found frame at %lld", entry->offset);
1401 segment_start = entry->timecode;
1403 nuv->priv->segment_start = segment_start;
1404 nuv->priv->segment_stop = segment_stop;
1406 GST_OBJECT_UNLOCK (nuv);
1408 if (!nuv->priv->eos) {
1410 msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME,
1411 nuv->priv->segment_start);
1413 gst_element_post_message (GST_ELEMENT (nuv), msg);
1417 g_debug ("NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" G_GUINT64_FORMAT, segment_start, segment_stop);
1418 newsegment_event = gst_event_new_new_segment (FALSE, rate,
1419 GST_FORMAT_TIME, segment_start, segment_stop, segment_start);
1423 if (nuv->priv->src_video_pad != NULL) {
1424 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_stop ());
1427 if (nuv->priv->src_audio_pad != NULL) {
1428 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_stop ());
1431 gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ());
1435 if (nuv->priv->src_video_pad != NULL) {
1436 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1438 if (nuv->priv->src_audio_pad != NULL) {
1439 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1442 gst_event_unref (newsegment_event);
1444 g_debug ("STARTING TASK AGAIN");
1445 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1446 nuv->priv->offset = entry->offset;
1448 gst_pad_start_task (nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1449 nuv->priv->sinkpad);
1451 GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1455 GST_DEBUG_OBJECT (nuv, "Got a seek error");
1456 GST_OBJECT_UNLOCK (nuv);
1457 GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1463 gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event)
1465 gboolean res = FALSE;
1468 nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1470 switch (GST_EVENT_TYPE (event)) {
1471 case GST_EVENT_SEEK:
1473 res = gst_nuv_demux_do_seek (nuv, event);
1480 gst_object_unref (nuv);
1484 static GstFlowReturn
1485 gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
1487 GstFlowReturn ret = GST_FLOW_OK;
1488 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1490 if (nuv->priv->mode != NUV_PUSH_MODE)
1493 g_debug ("CHAIN ADP %p", nuv->priv->adapter);
1495 gst_adapter_push (nuv->priv->adapter, buf);
1497 while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) {
1498 ret = gst_nuv_demux_play (pad);
1501 nuv->priv->more_data = FALSE;
1502 gst_object_unref (nuv);
1504 g_debug ("CHAIN END");
1510 gst_nuv_demux_loop (GstPad * pad)
1512 gst_nuv_demux_play (pad);
1516 gst_nuv_demux_index_free (gpointer data, gpointer user_data)
1522 gst_nuv_demux_reset (GstNuvDemux * nuv)
1525 nuv->priv->more_data = FALSE;
1526 nuv->priv->state = GST_NUV_DEMUX_START;
1527 nuv->priv->mode = NUV_PUSH_MODE;
1528 nuv->priv->offset = 0;
1529 nuv->priv->time_start = 0;
1530 nuv->priv->time_qos = GST_CLOCK_TIME_NONE;
1531 nuv->priv->duration_bytes = GST_CLOCK_TIME_NONE;
1532 nuv->priv->duration_time = GST_CLOCK_TIME_NONE;
1533 nuv->priv->last_video_return = GST_FLOW_OK;
1534 nuv->priv->last_audio_return = GST_FLOW_OK;
1535 nuv->priv->header_lengh = 0;
1536 nuv->priv->segment_stop = GST_CLOCK_TIME_NONE;
1537 nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
1540 g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL);
1541 g_slist_free (nuv->priv->index);
1542 nuv->priv->index = NULL;
1544 gst_adapter_clear (nuv->priv->adapter);
1546 if (nuv->priv->mpeg_buffer != NULL) {
1547 gst_buffer_unref (nuv->priv->mpeg_buffer);
1548 nuv->priv->mpeg_buffer = NULL;
1553 gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv)
1555 if (nuv->priv->src_video_pad) {
1556 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_video_pad);
1557 nuv->priv->src_video_pad = NULL;
1560 if (nuv->priv->src_audio_pad) {
1561 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_audio_pad);
1562 nuv->priv->src_audio_pad = NULL;
1566 static GstStateChangeReturn
1567 gst_nuv_demux_change_state (GstElement * element, GstStateChange transition)
1569 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1571 switch (transition) {
1572 case GST_STATE_CHANGE_NULL_TO_READY:
1573 g_debug ("NULL_TO_READY");
1574 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1575 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1581 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1582 if (ret == GST_STATE_CHANGE_FAILURE) {
1586 switch (transition) {
1587 case GST_STATE_CHANGE_PAUSED_TO_READY:
1588 case GST_STATE_CHANGE_READY_TO_NULL:
1589 g_debug ("PAUSED_TO_READY");
1590 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1591 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1601 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1603 gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
1609 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1610 g_return_val_if_fail (nbytes > 0, NULL);
1612 GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes);
1614 /* we don't have enough data, return NULL. This is unlikely
1615 * as one usually does an _available() first instead of peeking a
1617 if (G_UNLIKELY (nbytes > adapter->size))
1620 /* our head buffer has enough data left, return it */
1621 cur = adapter->buflist->data;
1622 if (GST_BUFFER_SIZE (cur) >= nbytes + adapter->skip) {
1623 GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer",
1625 buffer = gst_buffer_create_sub (cur, adapter->skip, nbytes);
1627 gst_adapter_flush (adapter, nbytes);
1632 data = gst_adapter_take (adapter, nbytes);
1636 buffer = gst_buffer_new ();
1637 GST_BUFFER_DATA (buffer) = data;
1638 GST_BUFFER_MALLOCDATA (buffer) = data;
1639 GST_BUFFER_SIZE (buffer) = nbytes;
1647 plugin_init (GstPlugin * plugin)
1650 setlocale (LC_ALL, "");
1651 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1652 #endif /* ENABLE_NLS */
1654 if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY,
1655 GST_TYPE_NUV_DEMUX)) {
1661 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1664 "Demuxes and muxes audio and video",
1665 plugin_init, VERSION, "LGPL", "NuvDemux", "")