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;
180 GST_NUV_DEMUX_HEADER_DATA,
181 GST_NUV_DEMUX_EXTRA_DATA,
182 GST_NUV_DEMUX_MPEG_DATA,
183 GST_NUV_DEMUX_EXTEND_HEADER,
184 GST_NUV_DEMUX_EXTEND_HEADER_DATA,
185 GST_NUV_DEMUX_INDEX_CREATE,
186 GST_NUV_DEMUX_FRAME_HEADER,
188 GST_NUV_DEMUX_INVALID_DATA
191 struct _GstNuvDemuxPrivate
193 /* used for indicate the mode */
196 /* used on push mode */
201 GstPad *src_video_pad;
202 GstPad *src_audio_pad;
205 GstFlowReturn last_video_return;
206 GstFlowReturn last_audio_return;
212 /* NUV decoding state */
213 GstNuvDemuxState state;
216 /* duration information */
217 guint64 duration_bytes;
218 guint64 duration_time;
219 guint64 segment_stop;
220 guint64 segment_start;
222 /* segment control info */
223 gboolean new_audio_segment;
224 gboolean new_video_segment;
227 guint64 mpeg_data_size;
228 GstBuffer *mpeg_buffer;
232 nuv_extended_header eh;
236 guint64 header_lengh;
240 guint64 last_frame_time;
245 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE("sink",
251 static GstStaticPadTemplate audio_src_template =
252 GST_STATIC_PAD_TEMPLATE("audio_src",
255 GST_STATIC_CAPS_ANY);
257 static GstStaticPadTemplate video_src_template =
258 GST_STATIC_PAD_TEMPLATE("video_src",
261 GST_STATIC_CAPS_ANY);
263 static void gst_nuv_demux_dispose(GObject * object);
264 static void gst_nuv_demux_finalize(GObject * object);
265 static GstStateChangeReturn gst_nuv_demux_change_state(GstElement * element,
268 static void gst_nuv_demux_loop(GstPad * pad);
269 static GstFlowReturn gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf);
270 static GstFlowReturn gst_nuv_demux_play(GstPad * pad);
271 static gboolean gst_nuv_demux_sink_activate_pull(GstPad * sinkpad,
273 static gboolean gst_nuv_demux_sink_activate_push(GstPad * pad,
275 static gboolean gst_nuv_demux_sink_activate(GstPad * sinkpad);
276 static gboolean gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event);
277 static gboolean gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event);
278 static frame_index_data *gst_nuv_demux_do_seek_index(GstNuvDemux * nuv,
284 static GstFlowReturn gst_nuv_demux_move_bytes(GstNuvDemux * nuv,
286 static GstFlowReturn gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size,
288 GstBuffer ** buffer);
289 static void gst_nuv_demux_reset(GstNuvDemux * nuv);
290 static void gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv);
291 static void gst_nuv_demux_send_eos(GstNuvDemux * nuv);
292 static void gst_nuv_demux_create_seek_index(GstNuvDemux * nuv);
295 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
296 GstBuffer *gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes);
300 GST_BOILERPLATE(GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
302 /******************************************************************************
304 ******************************************************************************/
305 #if G_BYTE_ORDER == G_BIG_ENDIAN
306 static inline gdouble
307 _gdouble_swap_le_be(gdouble * d)
316 u.i = GUINT64_SWAP_LE_BE(u.i);
320 #define READ_DOUBLE_FROM_LE(d) (_gdouble_swap_le_be((gdouble* ) d))
321 #else /* G_BYTE_ORDER != G_BIG_ENDIAN */
322 #define READ_DOUBLE_FROM_LE(d) *((gdouble* ) (d))
323 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
326 double2fraction(double in, int *num, int *denom)
333 else if (in == 23.976)
341 while (in - floor(in) >= 0.1)
346 *num = (int) floor(in);
350 /* GObject Functions */
353 gst_nuv_demux_base_init(gpointer klass)
355 GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
357 gst_element_class_add_pad_template(element_class,
358 gst_static_pad_template_get
359 (&audio_src_template));
361 gst_element_class_add_pad_template(element_class,
362 gst_static_pad_template_get
363 (&video_src_template));
365 gst_element_class_add_pad_template(element_class,
366 gst_static_pad_template_get
368 gst_element_class_set_details(element_class, &gst_nuv_demux_details);
372 gst_nuv_demux_class_init(GstNuvDemuxClass * klass)
374 GstElementClass *gstelement_class = GST_ELEMENT_CLASS(klass);
375 GObjectClass *gobject_class = (GObjectClass *) klass;
377 GST_DEBUG_CATEGORY_INIT(nuvdemux_debug, "nuvdemux",
378 0, "Demuxer for NUV streams");
380 parent_class = g_type_class_peek_parent(klass);
382 gobject_class->dispose = gst_nuv_demux_dispose;
383 gobject_class->finalize = gst_nuv_demux_finalize;
384 gstelement_class->change_state = gst_nuv_demux_change_state;
386 g_type_class_add_private(gobject_class, sizeof(GstNuvDemuxPrivate));
390 gst_nuv_demux_init(GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
392 nuv->priv = GST_NUV_DEMUX_GET_PRIVATE(nuv);
394 gst_pad_new_from_static_template(&sink_template, "sink");
396 /* creating adapter */
397 nuv->priv->mode = NUV_PUSH_MODE;
398 nuv->priv->adapter = gst_adapter_new();
400 nuv->priv->new_audio_segment = TRUE;
401 nuv->priv->new_video_segment = TRUE;
403 gst_pad_set_activate_function(nuv->priv->sinkpad,
404 gst_nuv_demux_sink_activate);
405 gst_pad_set_activatepull_function(nuv->priv->sinkpad,
406 gst_nuv_demux_sink_activate_pull);
407 gst_pad_set_activatepush_function(nuv->priv->sinkpad,
408 gst_nuv_demux_sink_activate_push);
409 gst_pad_set_chain_function(nuv->priv->sinkpad,
410 GST_DEBUG_FUNCPTR(gst_nuv_demux_chain));
411 gst_pad_set_event_function(nuv->priv->sinkpad,
412 GST_DEBUG_FUNCPTR(gst_nuv_demux_sink_event));
415 gst_element_add_pad(GST_ELEMENT(nuv), nuv->priv->sinkpad);
420 gst_nuv_demux_dispose(GObject * object)
422 GstNuvDemux *nuv = GST_NUV_DEMUX(object);
425 if (nuv->priv->mpeg_buffer != NULL)
427 gst_buffer_unref(nuv->priv->mpeg_buffer);
430 gst_nuv_demux_reset(GST_NUV_DEMUX(object));
431 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(object));
433 if (nuv->priv->adapter != NULL)
435 gst_object_unref(nuv->priv->adapter);
440 gst_nuv_demux_finalize(GObject * object)
442 G_OBJECT_CLASS(parent_class)->finalize(object);
449 gst_nuv_demux_header_load(GstNuvDemux * nuv, nuv_header * h)
451 GstBuffer *buffer = NULL;
452 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 72, TRUE, &buffer);
454 if ((res != GST_FLOW_OK) || (buffer == NULL))
461 memcpy(h->id, buffer->data, 12);
462 memcpy(h->version, buffer->data + 12, 5);
463 h->i_width = GST_READ_UINT32_LE(&buffer->data[20]);
464 h->i_height = GST_READ_UINT32_LE(&buffer->data[24]);
465 h->i_width_desired = GST_READ_UINT32_LE(&buffer->data[28]);
466 h->i_height_desired = GST_READ_UINT32_LE(&buffer->data[32]);
467 h->i_mode = GPOINTER_TO_INT(buffer->data[36]);
468 h->d_aspect = READ_DOUBLE_FROM_LE(&buffer->data[40]);
469 h->d_fps = READ_DOUBLE_FROM_LE(&buffer->data[48]);
470 /* get the num and denom values from fps */
471 double2fraction(h->d_fps, &h->i_fpsn, &h->i_fpsd);
472 h->i_video_blocks = GST_READ_UINT32_LE(&buffer->data[56]);
473 h->i_audio_blocks = GST_READ_UINT32_LE(&buffer->data[60]);
474 h->i_text_blocks = GST_READ_UINT32_LE(&buffer->data[64]);
475 h->i_keyframe_distance = GST_READ_UINT32_LE(&buffer->data[68]);
477 GST_DEBUG_OBJECT(nuv,
478 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d",
479 h->id, h->version, h->i_width, h->i_height,
480 h->d_aspect, h->d_fps, h->i_video_blocks,
481 h->i_audio_blocks, h->i_text_blocks,
482 h->i_keyframe_distance);
488 gst_buffer_unref(buffer);
495 gst_nuv_demux_stream_header_data(GstNuvDemux * nuv)
499 if (nuv->priv->new_file)
500 res = gst_nuv_demux_header_load(nuv, NULL);
502 res = gst_nuv_demux_header_load(nuv, &nuv->priv->h);
504 if (res == GST_FLOW_OK)
505 nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
513 gst_nuv_demux_stream_file_header(GstNuvDemux * nuv)
515 GstFlowReturn res = GST_FLOW_OK;
516 GstBuffer *file_header = NULL;
518 res = gst_nuv_demux_read_bytes(nuv, 12, FALSE, &file_header);
519 if (res == GST_FLOW_OK)
521 if (strncmp((gchar *) file_header->data, "MythTVVideo", 11) ||
522 strncmp((gchar *) file_header->data, "NuppelVideo", 11))
524 nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
528 GST_DEBUG_OBJECT(nuv, "error parsing file header");
529 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
530 res = GST_FLOW_ERROR;
534 if (file_header != NULL)
536 gst_buffer_unref(file_header);
545 gst_nuv_demux_frame_header_load(GstNuvDemux * nuv, nuv_frame_header * h)
548 GstBuffer *buf = NULL;
550 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 12, TRUE, &buf);
552 if ((res != GST_FLOW_OK) || (buf == NULL))
562 h->i_type = GPOINTER_TO_INT(data[0]);
563 h->i_compression = GPOINTER_TO_INT(data[1]);
564 h->i_keyframe = GPOINTER_TO_INT(data[2]);
565 h->i_filters = GPOINTER_TO_INT(data[3]);
566 h->i_timecode = GST_READ_UINT32_LE(&data[4]);
567 h->i_length = GST_READ_UINT32_LE(&data[8]);
569 GST_DEBUG_OBJECT(nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
571 h->i_compression ? h->i_compression : ' ',
572 h->i_keyframe ? h->i_keyframe : ' ',
573 h->i_filters, h->i_timecode, h->i_length);
578 gst_buffer_unref(buf);
586 gst_nuv_demux_extended_header_load(GstNuvDemux * nuv, nuv_extended_header * h)
589 GstBuffer *buff = NULL;
591 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 512, TRUE, &buff);
593 if ((res != GST_FLOW_OK) || (buff == NULL))
602 h->i_version = GST_READ_UINT32_LE(&data[0]);
603 h->i_video_fcc = GST_MAKE_FOURCC(data[4], data[5], data[6], data[7]);
604 h->i_audio_fcc = GST_MAKE_FOURCC(data[8], data[9], data[10], data[11]);
605 h->i_audio_sample_rate = GST_READ_UINT32_LE(&data[12]);
606 h->i_audio_bits_per_sample = GST_READ_UINT32_LE(&data[16]);
607 h->i_audio_channels = GST_READ_UINT32_LE(&data[20]);
608 h->i_audio_compression_ratio = GST_READ_UINT32_LE(&data[24]);
609 h->i_audio_quality = GST_READ_UINT32_LE(&data[28]);
610 h->i_rtjpeg_quality = GST_READ_UINT32_LE(&data[32]);
611 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE(&data[36]);
612 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE(&data[40]);
613 h->i_lavc_bitrate = GST_READ_UINT32_LE(&data[44]);
614 h->i_lavc_qmin = GST_READ_UINT32_LE(&data[48]);
615 h->i_lavc_qmin = GST_READ_UINT32_LE(&data[52]);
616 h->i_lavc_maxqdiff = GST_READ_UINT32_LE(&data[56]);
617 h->i_seekable_offset = GST_READ_UINT64_LE(&data[60]);
618 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE(&data[68]);
620 GST_DEBUG_OBJECT(nuv,
621 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
622 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
623 h->i_version, (gchar *) & h->i_video_fcc,
624 (gchar *) & h->i_audio_fcc, h->i_audio_sample_rate,
625 h->i_audio_bits_per_sample, h->i_audio_channels,
626 h->i_audio_compression_ratio, h->i_audio_quality,
627 h->i_rtjpeg_quality, h->i_rtjpeg_luma_filter,
628 h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
629 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff,
630 h->i_seekable_offset, h->i_keyframe_adjust_offset);
635 gst_buffer_unref(buff);
642 /* Query Functions */
643 static const GstQueryType *
644 gst_nuv_demux_get_src_query_types(GstPad * pad)
646 static const GstQueryType src_types[] = {
656 gst_nuv_demux_handle_src_query(GstPad * pad, GstQuery * query)
658 gboolean res = FALSE;
659 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
662 switch (GST_QUERY_TYPE(query))
664 case GST_QUERY_POSITION:
667 gst_query_parse_position(query, &format, NULL);
670 case GST_FORMAT_TIME:
671 if (GST_CLOCK_TIME_IS_VALID(nuv->priv->last_frame_time))
673 gst_query_set_position(query, GST_FORMAT_TIME,
674 nuv->priv->last_frame_time);
683 case GST_QUERY_DURATION:
686 gst_query_parse_duration(query, &format, NULL);
689 case GST_FORMAT_TIME:
690 if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE)
692 gst_query_set_duration(query, GST_FORMAT_TIME,
693 nuv->priv->duration_time);
708 res = gst_pad_query_default(pad, query);
711 gst_object_unref(nuv);
716 gst_nuv_demux_create_pad(GstNuvDemux * nuv, GstCaps * caps,
717 GstStaticPadTemplate * template, const gchar * name)
720 pad = gst_pad_new_from_static_template(template, name);
721 gst_pad_set_caps(pad, caps);
722 gst_pad_set_active(pad, TRUE);
723 gst_pad_use_fixed_caps(pad);
724 gst_element_add_pad(GST_ELEMENT(nuv), pad);
726 gst_pad_set_event_function(pad,
727 GST_DEBUG_FUNCPTR(gst_nuv_demux_srcpad_event));
729 gst_pad_set_query_type_function(pad,
731 (gst_nuv_demux_get_src_query_types));
733 gst_pad_set_query_function(pad,
735 (gst_nuv_demux_handle_src_query));
742 gst_nuv_demux_create_pads(GstNuvDemux * nuv)
744 if (nuv->priv->h.i_video_blocks != 0)
746 GstCaps *video_caps = NULL;
748 video_caps = gst_caps_new_simple("video/x-divx",
749 "divxversion", G_TYPE_INT, 4,
751 nuv->priv->h.i_width, "height",
752 G_TYPE_INT, nuv->priv->h.i_height,
753 "framerate", GST_TYPE_FRACTION,
755 nuv->priv->h.i_fpsd, "format",
757 nuv->priv->eh.i_video_fcc,
758 "pixel-aspect-ratio",
760 (gint) (nuv->priv->h.d_aspect *
761 1000.0f), 1000, NULL);
763 nuv->priv->src_video_pad =
764 gst_nuv_demux_create_pad(nuv, video_caps, &video_src_template,
766 gst_caps_unref(video_caps);
769 if (nuv->priv->h.i_audio_blocks != 0)
771 GstCaps *audio_caps = NULL;
773 audio_caps = gst_caps_new_simple("audio/mpeg", "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate, "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc, "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels, "layer", G_TYPE_INT, 3, // fixme: magic number
774 "mpegversion", G_TYPE_INT,
775 nuv->priv->eh.i_version, NULL);
777 nuv->priv->src_audio_pad =
778 gst_nuv_demux_create_pad(nuv, audio_caps, &audio_src_template,
780 gst_caps_unref(audio_caps);
783 gst_element_no_more_pads(GST_ELEMENT(nuv));
787 gst_nuv_demux_validate_header(nuv_frame_header * h)
789 gboolean valid = FALSE;
790 //g_usleep (1 * G_USEC_PER_SEC );
795 if (h->i_compression == 0 ||
796 h->i_compression == 1 ||
797 h->i_compression == 2 ||
798 h->i_compression == 'N' ||
799 h->i_compression == 'L') {
804 if (h->i_compression == 0 ||
805 h->i_compression == 1 ||
806 h->i_compression == 2 ||
807 h->i_compression == 3 ||
808 h->i_compression == 'F' ||
809 h->i_compression == 'S' ||
810 h->i_compression == 'N' ||
811 h->i_compression == 'L') {
816 if (h->i_compression == 'B' ||
817 h->i_compression == 'A' ||
818 h->i_compression == 'V' ||
819 h->i_compression == 'S') {
840 gst_nuv_demux_read_head_frame(GstNuvDemux * nuv)
842 GstFlowReturn ret = GST_FLOW_OK;
843 gboolean valid = FALSE;
847 ret = gst_nuv_demux_frame_header_load(nuv, &nuv->priv->fh);
848 if (ret != GST_FLOW_OK)
853 if (gst_nuv_demux_validate_header(&nuv->priv->fh) == TRUE)
857 while (valid == FALSE);
859 nuv->priv->state = GST_NUV_DEMUX_MOVI;
864 gst_nuv_combine_flow(GstNuvDemux * nuv)
866 GstFlowReturn ret_video = nuv->priv->last_video_return;
867 GstFlowReturn ret_audio = nuv->priv->last_audio_return;
869 if ((ret_video != GST_FLOW_OK) && (ret_audio != GST_FLOW_OK))
872 if (GST_FLOW_IS_FATAL(ret_video))
875 if (GST_FLOW_IS_FATAL(ret_audio))
882 gst_nuv_demux_stream_data(GstNuvDemux * nuv)
884 GstFlowReturn ret = GST_FLOW_OK;
887 GstBuffer *buf = NULL;
899 ret = gst_nuv_demux_read_bytes(nuv, h.i_length, TRUE, &buf);
900 if ((ret != GST_FLOW_OK) || (buf == NULL))
905 if ((h.i_timecode < 0))
911 timestamp = h.i_timecode * GST_MSECOND;
912 GST_BUFFER_TIMESTAMP(buf) = timestamp;
924 pad = nuv->priv->src_video_pad;
926 if (nuv->priv->new_video_segment)
929 /* send new segment event */
930 gst_pad_push_event(nuv->priv->src_video_pad,
931 gst_event_new_new_segment(TRUE, 1.0,
936 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE)
938 nuv->priv->time_start = timestamp;
940 nuv->priv->new_video_segment = FALSE;
947 pad = nuv->priv->src_audio_pad;
949 if (nuv->priv->new_audio_segment)
951 /* send new segment event */
952 gst_pad_push_event(nuv->priv->src_audio_pad,
953 gst_event_new_new_segment(TRUE, 1.0,
958 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE)
960 nuv->priv->time_start = timestamp;
962 nuv->priv->new_audio_segment = FALSE;
969 switch (h.i_compression)
972 GST_DEBUG_OBJECT(nuv, "sending new video segment: %d",
974 gst_pad_push_event(nuv->priv->src_video_pad,
975 gst_event_new_new_segment(TRUE, 1.0,
983 GST_DEBUG_OBJECT(nuv, "sending new audio segment: %d",
985 gst_pad_push_event(nuv->priv->src_audio_pad,
986 gst_event_new_new_segment(TRUE, 1.0,
1000 if ((buf != NULL) && (pad != NULL))
1002 /* pushing the buffer */
1003 gst_buffer_set_caps(buf, GST_PAD_CAPS(pad));
1004 ret = gst_pad_push(pad, buf);
1007 if (ret != GST_FLOW_OK)
1009 GST_WARNING_OBJECT(nuv, "error: %d pushing on srcpad %s", ret,
1010 gst_pad_get_name(pad));
1012 if (pad == nuv->priv->src_video_pad)
1014 nuv->priv->last_video_return = ret;
1016 else if (pad == nuv->priv->src_audio_pad)
1018 nuv->priv->last_audio_return = ret;
1021 /* verify anothers flow if is necessary stop task */
1022 if (gst_nuv_combine_flow(nuv) != FALSE)
1028 GST_WARNING_OBJECT(nuv, "error: on push");
1037 gst_buffer_unref(buf);
1040 if (ret == GST_FLOW_OK)
1042 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1043 memset(&nuv->priv->fh, 0, sizeof(nuv->priv->fh));
1048 static GstFlowReturn
1049 gst_nuv_demux_stream_mpeg_data(GstNuvDemux * nuv)
1051 GstFlowReturn ret = GST_FLOW_OK;
1053 /* ffmpeg extra data */
1054 if (nuv->priv->new_file)
1058 gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE, &buf);
1059 gst_buffer_unref(buf);
1063 ret = gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE,
1064 &nuv->priv->mpeg_buffer);
1067 if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL))
1072 GST_BUFFER_SIZE(nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
1073 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1077 static GstFlowReturn
1078 gst_nuv_demux_stream_extra_data(GstNuvDemux * nuv)
1080 GstFlowReturn ret = GST_FLOW_OK;
1085 if (nuv->priv->new_file)
1086 ret = gst_nuv_demux_frame_header_load(nuv, NULL);
1088 ret = gst_nuv_demux_frame_header_load(nuv, &h);
1090 if (ret != GST_FLOW_OK)
1093 if (h.i_type != 'D')
1095 GST_WARNING_OBJECT(nuv, "Unsuported rtjpeg");
1096 return GST_FLOW_NOT_SUPPORTED;
1101 if (h.i_compression == 'F')
1103 nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
1107 GST_WARNING_OBJECT(nuv,
1108 "only file with extended chunk are supported");
1109 return GST_FLOW_NOT_SUPPORTED;
1114 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1120 static GstFlowReturn
1121 gst_nuv_demux_stream_extend_header_data(GstNuvDemux * nuv)
1123 GstFlowReturn ret = GST_FLOW_OK;
1125 if (nuv->priv->new_file)
1126 ret = gst_nuv_demux_extended_header_load(nuv, NULL);
1129 ret = gst_nuv_demux_extended_header_load(nuv, &nuv->priv->eh);
1130 if (ret != GST_FLOW_OK)
1132 gst_nuv_demux_create_pads(nuv);
1135 nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
1139 static GstFlowReturn
1140 gst_nuv_demux_stream_extend_header(GstNuvDemux * nuv)
1142 GstBuffer *buf = NULL;
1143 GstFlowReturn res = GST_FLOW_OK;
1145 res = gst_nuv_demux_read_bytes(nuv, 1, FALSE, &buf);
1146 if ((res != GST_FLOW_OK) || (buf == NULL))
1150 gst_buffer_unref(buf);
1155 if (buf->data[0] == 'X')
1157 gst_buffer_unref(buf);
1161 res = gst_nuv_demux_frame_header_load(nuv, &h);
1162 if (res != GST_FLOW_OK)
1165 if (h.i_length != 512)
1167 return GST_FLOW_ERROR;
1169 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1173 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1174 g_object_unref(buf);
1175 GST_ELEMENT_WARNING(nuv, STREAM, FAILED,
1176 (_("incomplete NUV support")),
1177 ("incomplete NUV support"));
1178 return GST_FLOW_ERROR;
1184 gst_nuv_demux_create_seek_index(GstNuvDemux * nuv)
1189 while (gst_nuv_demux_frame_header_load(nuv, &h) == GST_FLOW_OK)
1191 if ((h.i_type == 'V') && (h.i_keyframe == 0))
1193 frame_index_data *f = g_new0(frame_index_data, 1);
1195 f->offset = nuv->priv->offset - 12;
1196 f->timecode = h.i_timecode * GST_MSECOND;
1198 nuv->priv->index = g_slist_append(nuv->priv->index, f);
1200 if (h.i_type != 'R')
1202 nuv->priv->offset += h.i_length;
1203 if (h.i_type == 'A' || h.i_type == 'V')
1204 nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1207 GST_DEBUG_OBJECT(nuv,
1208 "CREATING INDEX: DONE : DURATION Bytes/Sec: %"
1209 G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, nuv->priv->offset,
1210 nuv->priv->duration_time);
1212 nuv->priv->duration_bytes = nuv->priv->offset;
1213 nuv->priv->offset = nuv->priv->header_lengh;
1216 gst_message_new_duration(GST_OBJECT(nuv), GST_FORMAT_TIME,
1217 nuv->priv->duration_time);
1218 gst_element_post_message(GST_ELEMENT(nuv), msg);
1221 static GstFlowReturn
1222 gst_nuv_demux_play(GstPad * pad)
1224 GstFlowReturn res = GST_FLOW_OK;
1225 GstNuvDemux *nuv = GST_NUV_DEMUX(GST_PAD_PARENT(pad));
1227 switch (nuv->priv->state)
1229 case GST_NUV_DEMUX_START:
1230 res = gst_nuv_demux_stream_file_header(nuv);
1231 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1237 case GST_NUV_DEMUX_HEADER_DATA:
1238 res = gst_nuv_demux_stream_header_data(nuv);
1239 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1245 case GST_NUV_DEMUX_EXTRA_DATA:
1246 res = gst_nuv_demux_stream_extra_data(nuv);
1247 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1253 case GST_NUV_DEMUX_MPEG_DATA:
1254 res = gst_nuv_demux_stream_mpeg_data(nuv);
1255 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1261 case GST_NUV_DEMUX_EXTEND_HEADER:
1262 res = gst_nuv_demux_stream_extend_header(nuv);
1263 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1269 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1270 res = gst_nuv_demux_stream_extend_header_data(nuv);
1271 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1275 //store file header size
1276 nuv->priv->header_lengh = nuv->priv->offset;
1279 case GST_NUV_DEMUX_INDEX_CREATE:
1280 if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file))
1282 gst_nuv_demux_create_seek_index(nuv);
1285 case GST_NUV_DEMUX_FRAME_HEADER:
1286 res = gst_nuv_demux_read_head_frame(nuv);
1287 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1293 case GST_NUV_DEMUX_MOVI:
1294 res = gst_nuv_demux_stream_data(nuv);
1295 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA))
1301 case GST_NUV_DEMUX_INVALID_DATA:
1305 g_assert_not_reached();
1311 GST_LOG_OBJECT(nuv, "pausing task, reason %s", gst_flow_get_name(res));
1312 gst_pad_pause_task(nuv->priv->sinkpad);
1314 if (res == GST_FLOW_ERROR_EOS)
1316 gst_nuv_demux_send_eos(nuv);
1317 nuv->priv->eos = TRUE;
1321 if (GST_FLOW_IS_FATAL(res))
1323 GST_ELEMENT_ERROR(nuv, STREAM, FAILED,
1324 (_("Internal data stream error.")),
1325 ("streaming stopped, reason %s",
1326 gst_flow_get_name(res)));
1328 gst_nuv_demux_send_eos(nuv);
1334 gst_nuv_demux_send_eos(GstNuvDemux * nuv)
1336 gst_element_post_message(GST_ELEMENT(nuv),
1337 gst_message_new_segment_done(GST_OBJECT(nuv),
1338 GST_FORMAT_TIME, -1));
1340 if (nuv->priv->src_video_pad)
1341 gst_pad_push_event(nuv->priv->src_video_pad, gst_event_new_eos());
1342 if (nuv->priv->src_audio_pad)
1343 gst_pad_push_event(nuv->priv->src_audio_pad, gst_event_new_eos());
1346 static GstFlowReturn
1347 gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size, gboolean move,
1348 GstBuffer ** buffer)
1350 GstFlowReturn ret = GST_FLOW_OK;
1357 if (nuv->priv->mode == NUV_PULL_MODE)
1360 gst_pad_pull_range(nuv->priv->sinkpad, nuv->priv->offset, size,
1362 if (ret == GST_FLOW_OK)
1366 nuv->priv->offset += size;
1370 else if (ret == GST_FLOW_UNEXPECTED)
1372 return GST_FLOW_ERROR_EOS;
1377 if (gst_adapter_available(nuv->priv->adapter) < size)
1379 nuv->priv->more_data = TRUE;
1380 return GST_FLOW_ERROR_NO_DATA;
1384 *buffer = gst_adapter_take_buffer(nuv->priv->adapter, size);
1388 guint8 *data = NULL;
1389 data = (guint8 *) gst_adapter_peek(nuv->priv->adapter, size);
1390 *buffer = gst_buffer_new();
1391 gst_buffer_set_data(*buffer, data, size);
1397 static GstFlowReturn
1398 gst_nuv_demux_move_bytes(GstNuvDemux * nuv, guint64 size)
1400 GstFlowReturn ret = GST_FLOW_OK;
1407 if (nuv->priv->mode == NUV_PULL_MODE)
1409 nuv->priv->offset += size;
1413 if (gst_adapter_available(nuv->priv->adapter) < size)
1415 nuv->priv->more_data = TRUE;
1416 return GST_FLOW_ERROR_NO_DATA;
1418 gst_adapter_flush(nuv->priv->adapter, size);
1424 gst_nuv_demux_sink_activate(GstPad * sinkpad)
1426 gboolean res = TRUE;
1427 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1429 if (gst_pad_check_pull_range(sinkpad))
1431 gst_adapter_clear(nuv->priv->adapter);
1432 res = gst_pad_activate_pull(sinkpad, TRUE);
1436 gst_adapter_clear(nuv->priv->adapter);
1437 res = gst_pad_activate_push(sinkpad, TRUE);
1440 g_object_unref(nuv);
1445 gst_nuv_demux_sink_activate_pull(GstPad * sinkpad, gboolean active)
1447 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1451 GST_DEBUG_OBJECT(nuv, "activating pull function");
1452 nuv->priv->mode = NUV_PULL_MODE;
1453 gst_adapter_clear(nuv->priv->adapter);
1455 gst_pad_start_task(sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1460 GST_DEBUG_OBJECT(nuv, "deactivating pull function");
1461 gst_pad_stop_task(sinkpad);
1463 gst_object_unref(nuv);
1469 gst_nuv_demux_sink_activate_push(GstPad * pad, gboolean active)
1471 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1475 nuv->priv->mode = NUV_PUSH_MODE;
1476 gst_adapter_clear(nuv->priv->adapter);
1478 GST_DEBUG_OBJECT(nuv, "activating push/chain function");
1482 GST_DEBUG_OBJECT(nuv, "deactivating push/chain function");
1485 gst_object_unref(nuv);
1490 static frame_index_data *
1491 gst_nuv_demux_do_seek_index(GstNuvDemux * nuv, gint64 seek_pos,
1492 gint64 segment_stop, GstFormat format)
1495 frame_index_data *ret = NULL;
1497 if (nuv->priv->index == NULL)
1502 /* find keyframe closest to the requested position */
1503 for (l = nuv->priv->index; l != NULL; l = l->next)
1505 frame_index_data *f = (frame_index_data *) l->data;
1508 if (format == GST_FORMAT_BYTES)
1512 else if (format == GST_FORMAT_TIME)
1521 if (pos >= seek_pos)
1527 if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE)
1528 && (pos > segment_stop))
1538 gst_nuv_demux_do_seek(GstNuvDemux * nuv, GstEvent * event)
1543 GstSeekType cur_type;
1545 GstSeekType stop_type;
1548 frame_index_data *entry;
1549 gint64 segment_start;
1550 gint64 segment_stop;
1551 GstEvent *newsegment_event;
1558 if (nuv->priv->mode == NUV_PUSH_MODE)
1564 gst_event_parse_seek(event, &rate, &format, &flags,
1565 &cur_type, &cur, &stop_type, &stop);
1570 if (format == GST_FORMAT_TIME) {
1571 GST_DEBUG_OBJECT (nuv, "Can only seek on BYTES");
1578 GST_DEBUG_OBJECT(nuv, "Can only seek with positive rate");
1582 if (cur_type == GST_SEEK_TYPE_SET)
1584 GST_OBJECT_LOCK(nuv);
1585 if (gst_nuv_demux_do_seek_index(nuv, cur, -1, format) == NULL)
1587 GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1588 GST_OBJECT_UNLOCK(nuv);
1591 GST_OBJECT_UNLOCK(nuv);
1594 flush = !!(flags & GST_SEEK_FLAG_FLUSH);
1598 gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_start());
1599 if (nuv->priv->src_video_pad != NULL)
1601 gst_pad_push_event(nuv->priv->src_video_pad,
1602 gst_event_new_flush_start());
1605 if (nuv->priv->src_audio_pad != NULL)
1607 gst_pad_push_event(nuv->priv->src_audio_pad,
1608 gst_event_new_flush_start());
1613 gst_pad_pause_task(nuv->priv->sinkpad);
1616 GST_PAD_STREAM_LOCK(nuv->priv->sinkpad);
1617 GST_OBJECT_LOCK(nuv);
1620 if (cur == GST_CLOCK_TIME_NONE)
1622 if (stop == GST_CLOCK_TIME_NONE)
1623 stop = nuv->priv->duration_time;
1625 if (cur_type == GST_SEEK_TYPE_SET)
1626 segment_start = cur;
1627 else if (cur_type == GST_SEEK_TYPE_CUR)
1628 segment_start = nuv->priv->segment_start + cur;
1630 segment_start = nuv->priv->segment_start;
1632 if (stop_type == GST_SEEK_TYPE_SET)
1633 segment_stop = stop;
1634 else if (stop_type == GST_SEEK_TYPE_CUR)
1635 segment_stop = nuv->priv->segment_stop + stop;
1637 segment_stop = nuv->priv->segment_stop;
1639 segment_start = CLAMP(segment_start, 0, nuv->priv->duration_time);
1640 segment_stop = CLAMP(segment_stop, 0, nuv->priv->duration_time);
1642 entry = gst_nuv_demux_do_seek_index(nuv, segment_start,
1643 segment_stop, format);
1647 GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1651 segment_start = entry->timecode;
1653 nuv->priv->segment_start = segment_start;
1654 nuv->priv->segment_stop = segment_stop;
1656 GST_OBJECT_UNLOCK(nuv);
1658 if (!nuv->priv->eos)
1661 msg = gst_message_new_segment_start(GST_OBJECT(nuv), GST_FORMAT_TIME,
1662 nuv->priv->segment_start);
1664 gst_element_post_message(GST_ELEMENT(nuv), msg);
1667 GST_DEBUG_OBJECT(nuv,
1668 "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %"
1669 G_GUINT64_FORMAT, segment_start, segment_stop);
1671 gst_event_new_new_segment(FALSE, rate, GST_FORMAT_TIME, segment_start,
1672 segment_stop, segment_start);
1677 if (nuv->priv->src_video_pad != NULL)
1679 gst_pad_push_event(nuv->priv->src_video_pad,
1680 gst_event_new_flush_stop());
1683 if (nuv->priv->src_audio_pad != NULL)
1685 gst_pad_push_event(nuv->priv->src_audio_pad,
1686 gst_event_new_flush_stop());
1689 gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_stop());
1693 if (nuv->priv->src_video_pad != NULL)
1695 gst_pad_push_event(nuv->priv->src_video_pad,
1696 gst_event_ref(newsegment_event));
1698 if (nuv->priv->src_audio_pad != NULL)
1700 gst_pad_push_event(nuv->priv->src_audio_pad,
1701 gst_event_ref(newsegment_event));
1704 gst_event_unref(newsegment_event);
1706 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1707 nuv->priv->offset = entry->offset;
1709 gst_pad_start_task(nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1710 nuv->priv->sinkpad);
1712 GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1716 GST_DEBUG_OBJECT(nuv, "Got a seek error");
1717 GST_OBJECT_UNLOCK(nuv);
1718 GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1724 gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event)
1726 gboolean res = FALSE;
1729 nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1731 switch (GST_EVENT_TYPE(event))
1733 case GST_EVENT_SEEK:
1734 res = gst_nuv_demux_do_seek(nuv, event);
1741 gst_object_unref(nuv);
1746 gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event)
1748 gboolean res = FALSE;
1751 nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1753 switch (GST_EVENT_TYPE(event))
1755 case GST_EVENT_NEWSEGMENT:
1764 gst_event_parse_new_segment(event, &update, &rate, &format, &start,
1766 if ((format == GST_FORMAT_BYTES) && (start == 0))
1768 g_debug("NEW SEGMENT 0");
1769 if (nuv->priv->segment > 0)
1771 nuv->priv->new_file = TRUE;
1772 nuv->priv->state = GST_NUV_DEMUX_START;
1773 nuv->priv->offset = 0;
1775 nuv->priv->segment++;
1778 newsegment_event = gst_event_new_new_segment (FALSE, rate,
1779 GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
1781 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1782 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1783 gst_event_unref (newsegment_event);
1785 res = gst_pad_event_default(pad, event);
1789 case GST_EVENT_CUSTOM_DOWNSTREAM:
1792 nuv->priv->new_file = TRUE;
1793 nuv->priv->state = GST_NUV_DEMUX_START;
1794 nuv->priv->offset = 0;
1796 GST_PAD_STREAM_LOCK(pad);
1797 gst_nuv_demux_reset(nuv);
1798 GST_PAD_STREAM_UNLOCK(pad);
1800 res = gst_pad_event_default(pad, event);
1804 res = gst_pad_event_default(pad, event);
1811 static GstFlowReturn
1812 gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf)
1814 GstFlowReturn ret = GST_FLOW_OK;
1815 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1817 if (nuv->priv->mode != NUV_PUSH_MODE)
1820 gst_adapter_push(nuv->priv->adapter, buf);
1822 while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE))
1824 ret = gst_nuv_demux_play(pad);
1827 nuv->priv->more_data = FALSE;
1828 gst_object_unref(nuv);
1834 gst_nuv_demux_loop(GstPad * pad)
1836 gst_nuv_demux_play(pad);
1840 gst_nuv_demux_index_free(gpointer data, gpointer user_data)
1846 gst_nuv_demux_reset(GstNuvDemux * nuv)
1848 nuv->priv->eos = FALSE;
1849 nuv->priv->more_data = FALSE;
1850 nuv->priv->state = GST_NUV_DEMUX_START;
1851 nuv->priv->mode = NUV_PUSH_MODE;
1852 nuv->priv->offset = 0;
1853 nuv->priv->time_start = 0;
1854 nuv->priv->time_qos = GST_CLOCK_TIME_NONE;
1855 nuv->priv->duration_bytes = GST_CLOCK_TIME_NONE;
1856 nuv->priv->duration_time = GST_CLOCK_TIME_NONE;
1857 nuv->priv->last_video_return = GST_FLOW_OK;
1858 nuv->priv->last_audio_return = GST_FLOW_OK;
1859 nuv->priv->header_lengh = 0;
1860 nuv->priv->segment_stop = GST_CLOCK_TIME_NONE;
1861 nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
1862 nuv->priv->new_file = FALSE;
1865 g_slist_foreach(nuv->priv->index, gst_nuv_demux_index_free, NULL);
1866 g_slist_free(nuv->priv->index);
1867 nuv->priv->index = NULL;
1869 gst_adapter_clear(nuv->priv->adapter);
1871 if (nuv->priv->mpeg_buffer != NULL)
1873 gst_buffer_unref(nuv->priv->mpeg_buffer);
1874 nuv->priv->mpeg_buffer = NULL;
1879 gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv)
1881 if (nuv->priv->src_video_pad)
1883 gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_video_pad);
1884 nuv->priv->src_video_pad = NULL;
1887 if (nuv->priv->src_audio_pad)
1889 gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_audio_pad);
1890 nuv->priv->src_audio_pad = NULL;
1894 static GstStateChangeReturn
1895 gst_nuv_demux_change_state(GstElement * element, GstStateChange transition)
1897 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1899 g_debug("Nuvdemux state_change");
1902 case GST_STATE_CHANGE_NULL_TO_READY:
1903 gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1904 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1910 g_debug("Nuvdemux state_change: 1");
1912 ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1913 if (ret == GST_STATE_CHANGE_FAILURE)
1919 g_debug("Nuvdemux state_change: 2");
1923 case GST_STATE_CHANGE_READY_TO_NULL:
1924 gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1925 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1932 g_debug("Nuvdemux state_change: DONE");
1938 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1940 gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes)
1946 g_return_val_if_fail(GST_IS_ADAPTER(adapter), NULL);
1947 g_return_val_if_fail(nbytes > 0, NULL);
1949 GST_LOG_OBJECT(adapter, "taking buffer of %u bytes", nbytes);
1951 /* we don't have enough data, return NULL. This is unlikely
1952 * as one usually does an _available() first instead of peeking a
1954 if (G_UNLIKELY(nbytes > adapter->size))
1957 /* our head buffer has enough data left, return it */
1958 cur = adapter->buflist->data;
1959 if (GST_BUFFER_SIZE(cur) >= nbytes + adapter->skip)
1961 GST_LOG_OBJECT(adapter, "providing buffer of %d bytes via sub-buffer",
1963 buffer = gst_buffer_create_sub(cur, adapter->skip, nbytes);
1965 gst_adapter_flush(adapter, nbytes);
1970 data = gst_adapter_take(adapter, nbytes);
1974 buffer = gst_buffer_new();
1975 GST_BUFFER_DATA(buffer) = data;
1976 GST_BUFFER_MALLOCDATA(buffer) = data;
1977 GST_BUFFER_SIZE(buffer) = nbytes;
1984 gst_nuv_typefind(GstTypeFind * tf, gpointer unused)
1986 guint8 *data = gst_type_find_peek(tf, 0, 11);
1990 if (memcmp(data, "MythTVVideo", 11) == 0
1991 || memcmp(data, "NuppelVideo", 11) == 0)
1993 gst_type_find_suggest(tf, GST_TYPE_FIND_MAXIMUM,
1994 gst_caps_new_simple("video/x-nuv", NULL));
2000 plugin_init(GstPlugin * plugin)
2002 static gchar *exts[] = { "nuv", NULL };
2004 setlocale(LC_ALL, "");
2005 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
2006 #endif /* ENABLE_NLS */
2008 if (!gst_element_register(plugin, "nuvdemux", GST_RANK_SECONDARY,
2009 GST_TYPE_NUV_DEMUX))
2014 if (!gst_type_find_register(plugin, "video/x-nuv", GST_RANK_SECONDARY,
2017 gst_caps_new_simple("video/x-nuv", NULL), NULL,
2020 GST_WARNING("can't register typefind");
2027 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
2030 "Demuxes and muxes audio and video",
2031 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,