[svn r918] moved debian dir from gst-gmyth and libgnomevfs2-mythtv to packages project
2 * GStreamer Copyright (C) <2006> Renato Araujo Oliveira Filho
3 * <renato.filho@indt.org.br> Rosfran Borges <rosfran.borges@indt.org.br>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Library General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version. This library is distributed in the hope
8 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
9 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU Library General Public License for more details. You should
11 * have received a copy of the GNU Library General Public License along
12 * with this library; if not, write to the Free Software Foundation, Inc.,
13 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Element-Checklist-Version: 5
20 * SECTION:element-nuvdemux
24 * Demuxes an .nuv file into raw or compressed audio and/or video streams.
27 * This element currently only supports pull-based scheduling.
29 * <title>Example launch line</title>
32 * gst-launch filesrc test.nuv ! nuvdemux name=demux demux.audio_00 ! decodebin ! audioconvert ! audioresample ! autoaudiosink demux.video_00 ! queue ! decodebin ! ffmpegcolorspace ! videoscale ! autovideosink
34 * Play (parse and decode) an .nuv file and try to output it to
35 * an automatically detected soundcard and videosink. If the NUV file contains
36 * compressed audio or video data, this will only work if you have the
37 * right decoder elements/plugins installed.
48 #include <gst/gsterror.h>
49 #include <gst/gstplugin.h>
53 #include "glib/gi18n.h"
54 #include "gstnuvdemux.h"
56 #define GST_NUV_DEMUX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_NUV_DEMUX, GstNuvDemuxPrivate))
58 GST_DEBUG_CATEGORY_STATIC(nuvdemux_debug);
59 #define GST_CAT_DEFAULT nuvdemux_debug
60 #define GST_FLOW_ERROR_NO_DATA -101
61 #define GST_FLOW_ERROR_EOS -102
68 GST_DEBUG_CATEGORY_EXTERN(GST_CAT_EVENT);
70 static const GstElementDetails gst_nuv_demux_details =
71 GST_ELEMENT_DETAILS("Nuv demuxer",
73 "Demultiplex a .nuv file into audio and video",
74 "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
75 "Rosfran Borges <rosfran.borges@indt.org.br>");
82 gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */
83 gchar version[5]; /* "x.xx\0" */
88 gint i_height_desired;
90 gchar i_mode; /* P progressive, I interlaced */
92 gdouble d_aspect; /* 1.0 squared pixel */
98 gint i_video_blocks; /* 0 no video, -1 unknown */
102 gint i_keyframe_distance;
110 gchar i_type; /* A: audio, V: video, S: sync; T: test R:
111 * Seekpoint (string:RTjjjjjjjj) D: Extra
113 gchar i_compression; /* V: 0 uncompressed 1 RTJpeg 2
114 * RTJpeg+lzo N black frame L copy
115 * last A: 0 uncompressed (44100
116 * 1-bits, 2ch) 1 lzo 2 layer 2 3
117 * layer 3 F flac S shorten N null
118 * frame loudless L copy last S: B
119 * audio and vdeo sync point A audio
120 * sync info (timecode == effective
121 * dsp frequency*100) V next video
122 * sync (timecode == next video frame
123 * num) S audio,video,text correlation
125 gchar i_keyframe; /* 0 keyframe, else no no key frame */
126 guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16
127 * 0x02: gauss 5 pixel (8,1,1,1,1)/12
128 * 0x04: cartoon filter */
130 gint32 i_timecode; /* ms */
132 gint i_length; /* V,A,T: length of following data S:
133 * length of packet correl */
138 * FIXME Not sure of this one
145 gint i_audio_sample_rate;
146 gint i_audio_bits_per_sample;
147 gint i_audio_channels;
148 gint i_audio_compression_ratio;
149 gint i_audio_quality;
150 gint i_rtjpeg_quality;
151 gint i_rtjpeg_luma_filter;
152 gint i_rtjpeg_chroma_filter;
156 gint i_lavc_maxqdiff;
157 gint64 i_seekable_offset;
158 gint64 i_keyframe_adjust_offset;
160 } nuv_extended_header;
170 GST_NUV_DEMUX_HEADER_DATA,
171 GST_NUV_DEMUX_EXTRA_DATA,
172 GST_NUV_DEMUX_MPEG_DATA,
173 GST_NUV_DEMUX_EXTEND_HEADER,
174 GST_NUV_DEMUX_EXTEND_HEADER_DATA,
175 GST_NUV_DEMUX_INDEX_CREATE,
176 GST_NUV_DEMUX_FRAME_HEADER,
178 GST_NUV_DEMUX_INVALID_DATA
181 struct _GstNuvDemuxPrivate {
183 * used for indicate the mode
196 GstPad *src_video_pad;
197 GstPad *src_audio_pad;
202 GstFlowReturn last_video_return;
203 GstFlowReturn last_audio_return;
212 GstNuvDemuxState state;
216 * duration information
218 guint64 duration_bytes;
219 guint64 duration_time;
220 guint64 segment_stop;
221 guint64 segment_start;
224 * segment control info
226 gboolean new_audio_segment;
227 gboolean new_video_segment;
232 guint64 mpeg_data_size;
233 GstBuffer *mpeg_buffer;
239 nuv_extended_header eh;
245 guint64 header_lengh;
249 guint64 last_frame_time;
254 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE("sink",
260 static GstStaticPadTemplate audio_src_template =
261 GST_STATIC_PAD_TEMPLATE("audio_src",
264 GST_STATIC_CAPS_ANY);
266 static GstStaticPadTemplate video_src_template =
267 GST_STATIC_PAD_TEMPLATE("video_src",
270 GST_STATIC_CAPS_ANY);
272 static void gst_nuv_demux_dispose(GObject * object);
273 static void gst_nuv_demux_finalize(GObject * object);
274 static GstStateChangeReturn gst_nuv_demux_change_state(GstElement *
278 static void gst_nuv_demux_loop(GstPad * pad);
279 static GstFlowReturn gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf);
280 static GstFlowReturn gst_nuv_demux_play(GstPad * pad);
281 static gboolean gst_nuv_demux_sink_activate_pull(GstPad * sinkpad,
283 static gboolean gst_nuv_demux_sink_activate_push(GstPad * pad,
285 static gboolean gst_nuv_demux_sink_activate(GstPad * sinkpad);
286 static gboolean gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event);
287 static gboolean gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event);
288 static frame_index_data *gst_nuv_demux_do_seek_index(GstNuvDemux * nuv,
294 static GstFlowReturn gst_nuv_demux_move_bytes(GstNuvDemux * nuv,
296 static GstFlowReturn gst_nuv_demux_read_bytes(GstNuvDemux * nuv,
297 guint64 size, gboolean move,
298 GstBuffer ** buffer);
299 static void gst_nuv_demux_reset(GstNuvDemux * nuv);
300 static void gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv);
301 static void gst_nuv_demux_send_eos(GstNuvDemux * nuv);
302 static void gst_nuv_demux_create_seek_index(GstNuvDemux * nuv);
305 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
306 GstBuffer *gst_adapter_take_buffer(GstAdapter * adapter,
311 GST_BOILERPLATE(GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
313 /******************************************************************************
315 ******************************************************************************/
316 #if G_BYTE_ORDER == G_BIG_ENDIAN
317 static inline gdouble
318 _gdouble_swap_le_be(gdouble * d)
326 u.i = GUINT64_SWAP_LE_BE(u.i);
330 #define READ_DOUBLE_FROM_LE(d) (_gdouble_swap_le_be((gdouble* ) d))
331 #else /* G_BYTE_ORDER != G_BIG_ENDIAN */
332 #define READ_DOUBLE_FROM_LE(d) *((gdouble* ) (d))
333 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
336 double2fraction(double in, int *num, int *denom)
341 } else if (in == 23.976) {
346 while (in - floor(in) >= 0.1) {
350 *num = (int) floor(in);
359 gst_nuv_demux_base_init(gpointer klass)
361 GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
363 gst_element_class_add_pad_template(element_class,
364 gst_static_pad_template_get
365 (&audio_src_template));
367 gst_element_class_add_pad_template(element_class,
368 gst_static_pad_template_get
369 (&video_src_template));
371 gst_element_class_add_pad_template(element_class,
372 gst_static_pad_template_get
374 gst_element_class_set_details(element_class, &gst_nuv_demux_details);
378 gst_nuv_demux_class_init(GstNuvDemuxClass * klass)
380 GstElementClass *gstelement_class = GST_ELEMENT_CLASS(klass);
381 GObjectClass *gobject_class = (GObjectClass *) klass;
383 GST_DEBUG_CATEGORY_INIT(nuvdemux_debug, "nuvdemux",
384 0, "Demuxer for NUV streams");
386 parent_class = g_type_class_peek_parent(klass);
388 gobject_class->dispose = gst_nuv_demux_dispose;
389 gobject_class->finalize = gst_nuv_demux_finalize;
390 gstelement_class->change_state = gst_nuv_demux_change_state;
392 g_type_class_add_private(gobject_class, sizeof(GstNuvDemuxPrivate));
396 gst_nuv_demux_init(GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
398 nuv->priv = GST_NUV_DEMUX_GET_PRIVATE(nuv);
400 gst_pad_new_from_static_template(&sink_template, "sink");
405 nuv->priv->mode = NUV_PUSH_MODE;
406 nuv->priv->adapter = gst_adapter_new();
408 nuv->priv->new_audio_segment = TRUE;
409 nuv->priv->new_video_segment = TRUE;
411 gst_pad_set_activate_function(nuv->priv->sinkpad,
412 gst_nuv_demux_sink_activate);
413 gst_pad_set_activatepull_function(nuv->priv->sinkpad,
414 gst_nuv_demux_sink_activate_pull);
415 gst_pad_set_activatepush_function(nuv->priv->sinkpad,
416 gst_nuv_demux_sink_activate_push);
417 gst_pad_set_chain_function(nuv->priv->sinkpad,
418 GST_DEBUG_FUNCPTR(gst_nuv_demux_chain));
419 gst_pad_set_event_function(nuv->priv->sinkpad,
421 (gst_nuv_demux_sink_event));
424 gst_element_add_pad(GST_ELEMENT(nuv), nuv->priv->sinkpad);
429 gst_nuv_demux_dispose(GObject * object)
431 GstNuvDemux *nuv = GST_NUV_DEMUX(object);
434 if (nuv->priv->mpeg_buffer != NULL) {
435 gst_buffer_unref(nuv->priv->mpeg_buffer);
438 gst_nuv_demux_reset(GST_NUV_DEMUX(object));
439 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(object));
441 if (nuv->priv->adapter != NULL) {
442 gst_object_unref(nuv->priv->adapter);
447 gst_nuv_demux_finalize(GObject * object)
449 G_OBJECT_CLASS(parent_class)->finalize(object);
457 gst_nuv_demux_header_load(GstNuvDemux * nuv, nuv_header * h)
459 GstBuffer *buffer = NULL;
460 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 72, TRUE, &buffer);
462 if ((res != GST_FLOW_OK) || (buffer == NULL)) {
467 memcpy(h->id, buffer->data, 12);
468 memcpy(h->version, buffer->data + 12, 5);
469 h->i_width = GST_READ_UINT32_LE(&buffer->data[20]);
470 h->i_height = GST_READ_UINT32_LE(&buffer->data[24]);
471 h->i_width_desired = GST_READ_UINT32_LE(&buffer->data[28]);
472 h->i_height_desired = GST_READ_UINT32_LE(&buffer->data[32]);
473 h->i_mode = GPOINTER_TO_INT(buffer->data[36]);
474 h->d_aspect = READ_DOUBLE_FROM_LE(&buffer->data[40]);
475 h->d_fps = READ_DOUBLE_FROM_LE(&buffer->data[48]);
477 * get the num and denom values from fps
479 double2fraction(h->d_fps, &h->i_fpsn, &h->i_fpsd);
480 h->i_video_blocks = GST_READ_UINT32_LE(&buffer->data[56]);
481 h->i_audio_blocks = GST_READ_UINT32_LE(&buffer->data[60]);
482 h->i_text_blocks = GST_READ_UINT32_LE(&buffer->data[64]);
483 h->i_keyframe_distance = GST_READ_UINT32_LE(&buffer->data[68]);
485 GST_DEBUG_OBJECT(nuv,
486 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d",
487 h->id, h->version, h->i_width, h->i_height,
488 h->d_aspect, h->d_fps, h->i_video_blocks,
489 h->i_audio_blocks, h->i_text_blocks,
490 h->i_keyframe_distance);
494 if (buffer != NULL) {
495 gst_buffer_unref(buffer);
502 gst_nuv_demux_stream_header_data(GstNuvDemux * nuv)
506 if (nuv->priv->new_file)
507 res = gst_nuv_demux_header_load(nuv, NULL);
509 res = gst_nuv_demux_header_load(nuv, &nuv->priv->h);
511 if (res == GST_FLOW_OK)
512 nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
520 gst_nuv_demux_stream_file_header(GstNuvDemux * nuv)
522 GstFlowReturn res = GST_FLOW_OK;
523 GstBuffer *file_header = NULL;
525 res = gst_nuv_demux_read_bytes(nuv, 12, FALSE, &file_header);
526 if (res == GST_FLOW_OK) {
527 if (strncmp((gchar *) file_header->data, "MythTVVideo", 11) ||
528 strncmp((gchar *) file_header->data, "NuppelVideo", 11)) {
529 nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
531 GST_DEBUG_OBJECT(nuv, "error parsing file header");
532 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
533 res = GST_FLOW_ERROR;
537 if (file_header != NULL) {
538 gst_buffer_unref(file_header);
548 gst_nuv_demux_frame_header_load(GstNuvDemux * nuv, nuv_frame_header * h)
551 GstBuffer *buf = NULL;
553 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 12, TRUE, &buf);
555 if ((res != GST_FLOW_OK) || (buf == NULL)) {
564 h->i_type = GPOINTER_TO_INT(data[0]);
565 h->i_compression = GPOINTER_TO_INT(data[1]);
566 h->i_keyframe = GPOINTER_TO_INT(data[2]);
567 h->i_filters = GPOINTER_TO_INT(data[3]);
568 h->i_timecode = GST_READ_UINT32_LE(&data[4]);
569 h->i_length = GST_READ_UINT32_LE(&data[8]);
571 GST_DEBUG_OBJECT(nuv,
572 "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
573 h->i_type, h->i_compression ? h->i_compression : ' ',
574 h->i_keyframe ? h->i_keyframe : ' ', h->i_filters,
575 h->i_timecode, h->i_length);
579 gst_buffer_unref(buf);
587 gst_nuv_demux_extended_header_load(GstNuvDemux * nuv,
588 nuv_extended_header * h)
591 GstBuffer *buff = NULL;
593 GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 512, TRUE, &buff);
595 if ((res != GST_FLOW_OK) || (buff == NULL)) {
603 h->i_version = GST_READ_UINT32_LE(&data[0]);
604 h->i_video_fcc = GST_MAKE_FOURCC(data[4], data[5], data[6], data[7]);
605 h->i_audio_fcc = GST_MAKE_FOURCC(data[8], data[9], data[10], data[11]);
606 h->i_audio_sample_rate = GST_READ_UINT32_LE(&data[12]);
607 h->i_audio_bits_per_sample = GST_READ_UINT32_LE(&data[16]);
608 h->i_audio_channels = GST_READ_UINT32_LE(&data[20]);
609 h->i_audio_compression_ratio = GST_READ_UINT32_LE(&data[24]);
610 h->i_audio_quality = GST_READ_UINT32_LE(&data[28]);
611 h->i_rtjpeg_quality = GST_READ_UINT32_LE(&data[32]);
612 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE(&data[36]);
613 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE(&data[40]);
614 h->i_lavc_bitrate = GST_READ_UINT32_LE(&data[44]);
615 h->i_lavc_qmin = GST_READ_UINT32_LE(&data[48]);
616 h->i_lavc_qmin = GST_READ_UINT32_LE(&data[52]);
617 h->i_lavc_maxqdiff = GST_READ_UINT32_LE(&data[56]);
618 h->i_seekable_offset = GST_READ_UINT64_LE(&data[60]);
619 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE(&data[68]);
621 GST_DEBUG_OBJECT(nuv,
622 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
623 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
624 h->i_version, (gchar *) & h->i_video_fcc,
625 (gchar *) & h->i_audio_fcc, h->i_audio_sample_rate,
626 h->i_audio_bits_per_sample, h->i_audio_channels,
627 h->i_audio_compression_ratio, h->i_audio_quality,
628 h->i_rtjpeg_quality, h->i_rtjpeg_luma_filter,
629 h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
630 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff,
631 h->i_seekable_offset, h->i_keyframe_adjust_offset);
635 gst_buffer_unref(buff);
645 static const GstQueryType *
646 gst_nuv_demux_get_src_query_types(GstPad * pad)
648 static const GstQueryType src_types[] = {
658 gst_nuv_demux_handle_src_query(GstPad * pad, GstQuery * query)
660 gboolean res = FALSE;
661 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
664 switch (GST_QUERY_TYPE(query)) {
665 case GST_QUERY_POSITION:
668 gst_query_parse_position(query, &format, NULL);
670 case GST_FORMAT_TIME:
671 if (GST_CLOCK_TIME_IS_VALID(nuv->priv->last_frame_time)) {
672 gst_query_set_position(query, GST_FORMAT_TIME,
673 nuv->priv->last_frame_time);
682 case GST_QUERY_DURATION:
685 gst_query_parse_duration(query, &format, NULL);
687 case GST_FORMAT_TIME:
688 if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) {
689 gst_query_set_duration(query, GST_FORMAT_TIME,
690 nuv->priv->duration_time);
704 res = gst_pad_query_default(pad, query);
707 gst_object_unref(nuv);
712 gst_nuv_demux_create_pad(GstNuvDemux * nuv, GstCaps * caps,
713 GstStaticPadTemplate * template,
717 pad = gst_pad_new_from_static_template(template, name);
718 gst_pad_set_caps(pad, caps);
719 gst_pad_set_active(pad, TRUE);
720 gst_pad_use_fixed_caps(pad);
721 gst_element_add_pad(GST_ELEMENT(nuv), pad);
723 gst_pad_set_event_function(pad,
725 (gst_nuv_demux_srcpad_event));
727 gst_pad_set_query_type_function(pad,
729 (gst_nuv_demux_get_src_query_types));
731 gst_pad_set_query_function(pad,
733 (gst_nuv_demux_handle_src_query));
740 gst_nuv_demux_create_pads(GstNuvDemux * nuv)
742 if ((nuv->priv->src_video_pad != NULL) ||
743 (nuv->priv->src_audio_pad != NULL)) {
747 if (nuv->priv->h.i_video_blocks != 0){
748 GstCaps *video_caps = NULL;
750 video_caps = gst_caps_new_simple("video/x-divx",
751 "divxversion", G_TYPE_INT, 4,
753 nuv->priv->h.i_width, "height",
754 G_TYPE_INT, nuv->priv->h.i_height,
755 "framerate", GST_TYPE_FRACTION,
757 nuv->priv->h.i_fpsd, "format",
759 nuv->priv->eh.i_video_fcc,
760 "pixel-aspect-ratio",
762 (gint) (nuv->priv->h.d_aspect *
763 1000.0f), 1000, NULL);
765 nuv->priv->src_video_pad =
766 gst_nuv_demux_create_pad(nuv, video_caps, &video_src_template,
768 gst_caps_unref(video_caps);
771 if (nuv->priv->h.i_audio_blocks != 0) {
772 GstCaps *audio_caps = NULL;
774 audio_caps = gst_caps_new_simple("audio/mpeg",
775 "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate,
776 "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc,
777 "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels,
778 "layer", G_TYPE_INT, 3, // fixme: magic number
779 "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version,
782 nuv->priv->src_audio_pad =
783 gst_nuv_demux_create_pad(nuv, audio_caps, &audio_src_template,
785 gst_caps_unref(audio_caps);
788 gst_element_no_more_pads(GST_ELEMENT(nuv));
792 gst_nuv_demux_validate_header(nuv_frame_header * h)
794 gboolean valid = FALSE;
795 // g_usleep (1 * G_USEC_PER_SEC );
798 * case 'V': if (h->i_compression == 0 || h->i_compression == 1 ||
799 * h->i_compression == 2 || h->i_compression == 'N' ||
800 * h->i_compression == 'L') { valid = TRUE; } break; case 'A': if
801 * (h->i_compression == 0 || h->i_compression == 1 ||
802 * h->i_compression == 2 || h->i_compression == 3 ||
803 * h->i_compression == 'F' || h->i_compression == 'S' ||
804 * h->i_compression == 'N' || h->i_compression == 'L') { valid =
805 * TRUE; } break; case 'S': if (h->i_compression == 'B' ||
806 * h->i_compression == 'A' || h->i_compression == 'V' ||
807 * h->i_compression == 'S') { valid = TRUE; } break;
825 gst_nuv_demux_read_head_frame(GstNuvDemux * nuv)
827 GstFlowReturn ret = GST_FLOW_OK;
828 gboolean valid = FALSE;
831 ret = gst_nuv_demux_frame_header_load(nuv, &nuv->priv->fh);
832 if (ret != GST_FLOW_OK) {
836 if (gst_nuv_demux_validate_header(&nuv->priv->fh) == TRUE)
840 while (valid == FALSE);
842 nuv->priv->state = GST_NUV_DEMUX_MOVI;
847 gst_nuv_combine_flow(GstNuvDemux * nuv)
849 GstFlowReturn ret_video = nuv->priv->last_video_return;
850 GstFlowReturn ret_audio = nuv->priv->last_audio_return;
852 if ((ret_video != GST_FLOW_OK) && (ret_audio != GST_FLOW_OK))
855 if (GST_FLOW_IS_FATAL(ret_video))
858 if (GST_FLOW_IS_FATAL(ret_audio))
865 gst_nuv_demux_stream_data(GstNuvDemux * nuv)
867 GstFlowReturn ret = GST_FLOW_OK;
870 GstBuffer *buf = NULL;
875 if (h.i_type == 'R') {
879 if (h.i_length > 0) {
880 ret = gst_nuv_demux_read_bytes(nuv, h.i_length, TRUE, &buf);
881 if ((ret != GST_FLOW_OK) || (buf == NULL)) {
885 if ((h.i_timecode > 0) && (h.i_type == 'V')) {
886 timestamp = h.i_timecode * GST_MSECOND;
887 GST_BUFFER_TIMESTAMP(buf) = timestamp;
898 pad = nuv->priv->src_video_pad;
900 if (nuv->priv->new_video_segment) {
903 * send new segment event
905 gst_pad_push_event(nuv->priv->src_video_pad,
906 gst_event_new_new_segment(TRUE, 1.0,
912 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
913 nuv->priv->time_start = timestamp;
915 nuv->priv->new_video_segment = FALSE;
922 pad = nuv->priv->src_audio_pad;
924 if (nuv->priv->new_audio_segment) {
926 * send new segment event
928 gst_pad_push_event(nuv->priv->src_audio_pad,
929 gst_event_new_new_segment(TRUE, 1.0,
935 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
936 nuv->priv->time_start = timestamp;
938 nuv->priv->new_audio_segment = FALSE;
945 switch (h.i_compression) {
947 GST_DEBUG_OBJECT(nuv, "sending new video segment: %d",
949 gst_pad_push_event(nuv->priv->src_video_pad,
950 gst_event_new_new_segment(TRUE, 1.0,
958 GST_DEBUG_OBJECT(nuv, "sending new audio segment: %d",
960 gst_pad_push_event(nuv->priv->src_audio_pad,
961 gst_event_new_new_segment(TRUE, 1.0,
976 if ((buf != NULL) && (pad != NULL)) {
980 gst_buffer_set_caps(buf, GST_PAD_CAPS(pad));
981 ret = gst_pad_push(pad, buf);
984 if (ret != GST_FLOW_OK) {
985 GST_WARNING_OBJECT(nuv, "error: %d pushing on srcpad %s", ret,
986 gst_pad_get_name(pad));
988 if (pad == nuv->priv->src_video_pad) {
989 nuv->priv->last_video_return = ret;
990 } else if (pad == nuv->priv->src_audio_pad) {
991 nuv->priv->last_audio_return = ret;
995 * verify anothers flow if is necessary stop task
997 if (gst_nuv_combine_flow(nuv) != FALSE) {
1000 GST_WARNING_OBJECT(nuv, "error: on push");
1008 gst_buffer_unref(buf);
1011 if (ret == GST_FLOW_OK) {
1012 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1013 memset(&nuv->priv->fh, 0, sizeof(nuv->priv->fh));
1018 static GstFlowReturn
1019 gst_nuv_demux_stream_mpeg_data(GstNuvDemux * nuv)
1021 GstFlowReturn ret = GST_FLOW_OK;
1026 if (nuv->priv->new_file) {
1029 gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE,
1031 gst_buffer_unref(buf);
1034 gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE,
1035 &nuv->priv->mpeg_buffer);
1038 if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) {
1042 GST_BUFFER_SIZE(nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
1043 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1047 static GstFlowReturn
1048 gst_nuv_demux_stream_extra_data(GstNuvDemux * nuv)
1050 GstFlowReturn ret = GST_FLOW_OK;
1057 if (nuv->priv->new_file)
1058 ret = gst_nuv_demux_frame_header_load(nuv, NULL);
1060 ret = gst_nuv_demux_frame_header_load(nuv, &h);
1062 if (ret != GST_FLOW_OK)
1065 if (h.i_type != 'D') {
1066 GST_WARNING_OBJECT(nuv, "Unsuported rtjpeg");
1067 return GST_FLOW_NOT_SUPPORTED;
1070 if (h.i_length > 0) {
1071 if (h.i_compression == 'F') {
1072 nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
1074 GST_WARNING_OBJECT(nuv,
1075 "only file with extended chunk are supported");
1076 return GST_FLOW_NOT_SUPPORTED;
1079 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
1085 static GstFlowReturn
1086 gst_nuv_demux_stream_extend_header_data(GstNuvDemux * nuv)
1088 GstFlowReturn ret = GST_FLOW_OK;
1090 if (nuv->priv->new_file)
1091 ret = gst_nuv_demux_extended_header_load(nuv, NULL);
1093 ret = gst_nuv_demux_extended_header_load(nuv, &nuv->priv->eh);
1094 if (ret != GST_FLOW_OK)
1096 gst_nuv_demux_create_pads(nuv);
1099 nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
1103 static GstFlowReturn
1104 gst_nuv_demux_stream_extend_header(GstNuvDemux * nuv)
1106 GstBuffer *buf = NULL;
1107 GstFlowReturn res = GST_FLOW_OK;
1109 res = gst_nuv_demux_read_bytes(nuv, 1, FALSE, &buf);
1110 if ((res != GST_FLOW_OK) || (buf == NULL)) {
1112 gst_buffer_unref(buf);
1117 if (buf->data[0] == 'X') {
1118 gst_buffer_unref(buf);
1122 res = gst_nuv_demux_frame_header_load(nuv, &h);
1123 if (res != GST_FLOW_OK)
1126 if (h.i_length != 512) {
1127 return GST_FLOW_ERROR;
1129 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1131 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1132 g_object_unref(buf);
1133 GST_ELEMENT_WARNING(nuv, STREAM, FAILED,
1134 (_("incomplete NUV support")),
1135 ("incomplete NUV support"));
1136 return GST_FLOW_ERROR;
1142 gst_nuv_demux_create_seek_index(GstNuvDemux * nuv)
1147 while (gst_nuv_demux_frame_header_load(nuv, &h) == GST_FLOW_OK) {
1148 if ((h.i_type == 'V') && (h.i_keyframe == 0)) {
1149 frame_index_data *f = g_new0(frame_index_data, 1);
1151 f->offset = nuv->priv->offset - 12;
1152 f->timecode = h.i_timecode * GST_MSECOND;
1154 nuv->priv->index = g_slist_append(nuv->priv->index, f);
1156 if (h.i_type != 'R') {
1157 nuv->priv->offset += h.i_length;
1158 if (h.i_type == 'A' || h.i_type == 'V')
1159 nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1162 GST_DEBUG_OBJECT(nuv,
1163 "CREATING INDEX: DONE : DURATION Bytes/Sec: %"
1164 G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
1165 nuv->priv->offset, nuv->priv->duration_time);
1167 nuv->priv->duration_bytes = nuv->priv->offset;
1168 nuv->priv->offset = nuv->priv->header_lengh;
1171 gst_message_new_duration(GST_OBJECT(nuv), GST_FORMAT_TIME,
1172 nuv->priv->duration_time);
1173 gst_element_post_message(GST_ELEMENT(nuv), msg);
1176 static GstFlowReturn
1177 gst_nuv_demux_play(GstPad * pad)
1179 GstFlowReturn res = GST_FLOW_OK;
1180 GstNuvDemux *nuv = GST_NUV_DEMUX(GST_PAD_PARENT(pad));
1182 switch (nuv->priv->state) {
1183 case GST_NUV_DEMUX_START:
1184 res = gst_nuv_demux_stream_file_header(nuv);
1185 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1190 case GST_NUV_DEMUX_HEADER_DATA:
1191 res = gst_nuv_demux_stream_header_data(nuv);
1192 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1197 case GST_NUV_DEMUX_EXTRA_DATA:
1198 res = gst_nuv_demux_stream_extra_data(nuv);
1199 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1204 case GST_NUV_DEMUX_MPEG_DATA:
1205 res = gst_nuv_demux_stream_mpeg_data(nuv);
1206 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1211 case GST_NUV_DEMUX_EXTEND_HEADER:
1212 res = gst_nuv_demux_stream_extend_header(nuv);
1213 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1218 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1219 res = gst_nuv_demux_stream_extend_header_data(nuv);
1220 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1223 // store file header size
1224 nuv->priv->header_lengh = nuv->priv->offset;
1227 case GST_NUV_DEMUX_INDEX_CREATE:
1228 if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) {
1229 gst_nuv_demux_create_seek_index(nuv);
1232 case GST_NUV_DEMUX_FRAME_HEADER:
1233 res = gst_nuv_demux_read_head_frame(nuv);
1234 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1239 case GST_NUV_DEMUX_MOVI:
1240 res = gst_nuv_demux_stream_data(nuv);
1241 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1246 case GST_NUV_DEMUX_INVALID_DATA:
1250 g_assert_not_reached();
1256 GST_LOG_OBJECT(nuv, "pausing task, reason %s", gst_flow_get_name(res));
1257 gst_pad_pause_task(nuv->priv->sinkpad);
1259 if (res == GST_FLOW_ERROR_EOS) {
1260 gst_nuv_demux_send_eos(nuv);
1261 nuv->priv->eos = TRUE;
1265 if (GST_FLOW_IS_FATAL(res)) {
1266 GST_ELEMENT_ERROR(nuv, STREAM, FAILED,
1267 (_("Internal data stream error.")),
1268 ("streaming stopped, reason %s",
1269 gst_flow_get_name(res)));
1271 gst_nuv_demux_send_eos(nuv);
1277 gst_nuv_demux_send_eos(GstNuvDemux * nuv)
1279 gst_element_post_message(GST_ELEMENT(nuv),
1280 gst_message_new_segment_done(GST_OBJECT(nuv),
1284 if (nuv->priv->src_video_pad)
1285 gst_pad_push_event(nuv->priv->src_video_pad, gst_event_new_eos());
1286 if (nuv->priv->src_audio_pad)
1287 gst_pad_push_event(nuv->priv->src_audio_pad, gst_event_new_eos());
1290 static GstFlowReturn
1291 gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size, gboolean move,
1292 GstBuffer ** buffer)
1294 GstFlowReturn ret = GST_FLOW_OK;
1300 if (nuv->priv->mode == NUV_PULL_MODE) {
1302 gst_pad_pull_range(nuv->priv->sinkpad, nuv->priv->offset, size,
1304 if (ret == GST_FLOW_OK) {
1306 nuv->priv->offset += size;
1311 } else if (ret == GST_FLOW_UNEXPECTED) {
1312 return GST_FLOW_ERROR_EOS;
1315 if (gst_adapter_available(nuv->priv->adapter) < size) {
1316 nuv->priv->more_data = TRUE;
1317 return GST_FLOW_ERROR_NO_DATA;
1320 *buffer = gst_adapter_take_buffer(nuv->priv->adapter, size);
1322 guint8 *data = NULL;
1323 data = (guint8 *) gst_adapter_peek(nuv->priv->adapter, size);
1324 *buffer = gst_buffer_new();
1325 gst_buffer_set_data(*buffer, data, size);
1331 static GstFlowReturn
1332 gst_nuv_demux_move_bytes(GstNuvDemux * nuv, guint64 size)
1334 GstFlowReturn ret = GST_FLOW_OK;
1340 if (nuv->priv->mode == NUV_PULL_MODE) {
1341 nuv->priv->offset += size;
1343 if (gst_adapter_available(nuv->priv->adapter) < size) {
1344 nuv->priv->more_data = TRUE;
1345 return GST_FLOW_ERROR_NO_DATA;
1347 gst_adapter_flush(nuv->priv->adapter, size);
1353 gst_nuv_demux_sink_activate(GstPad * sinkpad)
1355 gboolean res = TRUE;
1356 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1358 if (gst_pad_check_pull_range(sinkpad)) {
1359 gst_adapter_clear(nuv->priv->adapter);
1360 res = gst_pad_activate_pull(sinkpad, TRUE);
1362 gst_adapter_clear(nuv->priv->adapter);
1363 res = gst_pad_activate_push(sinkpad, TRUE);
1366 g_object_unref(nuv);
1371 gst_nuv_demux_sink_activate_pull(GstPad * sinkpad, gboolean active)
1373 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad));
1376 GST_DEBUG_OBJECT(nuv, "activating pull function");
1377 nuv->priv->mode = NUV_PULL_MODE;
1378 gst_adapter_clear(nuv->priv->adapter);
1380 gst_pad_start_task(sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1383 GST_DEBUG_OBJECT(nuv, "deactivating pull function");
1384 gst_pad_stop_task(sinkpad);
1386 gst_object_unref(nuv);
1392 gst_nuv_demux_sink_activate_push(GstPad * pad, gboolean active)
1394 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1397 nuv->priv->mode = NUV_PUSH_MODE;
1398 gst_adapter_clear(nuv->priv->adapter);
1400 GST_DEBUG_OBJECT(nuv, "activating push/chain function");
1402 GST_DEBUG_OBJECT(nuv, "deactivating push/chain function");
1405 gst_object_unref(nuv);
1410 static frame_index_data *
1411 gst_nuv_demux_do_seek_index(GstNuvDemux * nuv, gint64 seek_pos,
1412 gint64 segment_stop, GstFormat format)
1415 frame_index_data *ret = NULL;
1417 if (nuv->priv->index == NULL) {
1422 * find keyframe closest to the requested position
1424 for (l = nuv->priv->index; l != NULL; l = l->next) {
1425 frame_index_data *f = (frame_index_data *) l->data;
1428 if (format == GST_FORMAT_BYTES) {
1430 } else if (format == GST_FORMAT_TIME) {
1436 if (pos >= seek_pos) {
1441 if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE)
1442 && (pos > segment_stop)) {
1451 gst_nuv_demux_do_seek(GstNuvDemux * nuv, GstEvent * event)
1456 GstSeekType cur_type;
1458 GstSeekType stop_type;
1461 frame_index_data *entry;
1462 gint64 segment_start;
1463 gint64 segment_stop;
1464 GstEvent *newsegment_event;
1466 if (nuv->priv->eos) {
1470 if (nuv->priv->mode == NUV_PUSH_MODE) {
1475 gst_event_parse_seek(event, &rate, &format, &flags,
1476 &cur_type, &cur, &stop_type, &stop);
1481 * if (format == GST_FORMAT_TIME) { GST_DEBUG_OBJECT (nuv, "Can only
1482 * seek on BYTES"); return FALSE; }
1486 GST_DEBUG_OBJECT(nuv, "Can only seek with positive rate");
1490 if (cur_type == GST_SEEK_TYPE_SET) {
1491 GST_OBJECT_LOCK(nuv);
1492 if (gst_nuv_demux_do_seek_index(nuv, cur, -1, format) == NULL) {
1493 GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1494 GST_OBJECT_UNLOCK(nuv);
1497 GST_OBJECT_UNLOCK(nuv);
1500 flush = !!(flags & GST_SEEK_FLAG_FLUSH);
1503 gst_pad_push_event(nuv->priv->sinkpad,
1504 gst_event_new_flush_start());
1505 if (nuv->priv->src_video_pad != NULL) {
1506 gst_pad_push_event(nuv->priv->src_video_pad,
1507 gst_event_new_flush_start());
1510 if (nuv->priv->src_audio_pad != NULL) {
1511 gst_pad_push_event(nuv->priv->src_audio_pad,
1512 gst_event_new_flush_start());
1515 gst_pad_pause_task(nuv->priv->sinkpad);
1518 GST_PAD_STREAM_LOCK(nuv->priv->sinkpad);
1519 GST_OBJECT_LOCK(nuv);
1522 if (cur == GST_CLOCK_TIME_NONE)
1524 if (stop == GST_CLOCK_TIME_NONE)
1525 stop = nuv->priv->duration_time;
1527 if (cur_type == GST_SEEK_TYPE_SET)
1528 segment_start = cur;
1529 else if (cur_type == GST_SEEK_TYPE_CUR)
1530 segment_start = nuv->priv->segment_start + cur;
1532 segment_start = nuv->priv->segment_start;
1534 if (stop_type == GST_SEEK_TYPE_SET)
1535 segment_stop = stop;
1536 else if (stop_type == GST_SEEK_TYPE_CUR)
1537 segment_stop = nuv->priv->segment_stop + stop;
1539 segment_stop = nuv->priv->segment_stop;
1541 segment_start = CLAMP(segment_start, 0, nuv->priv->duration_time);
1542 segment_stop = CLAMP(segment_stop, 0, nuv->priv->duration_time);
1544 entry = gst_nuv_demux_do_seek_index(nuv, segment_start,
1545 segment_stop, format);
1547 if (entry == NULL) {
1548 GST_DEBUG_OBJECT(nuv, "No matching seek entry in index");
1552 segment_start = entry->timecode;
1554 nuv->priv->segment_start = segment_start;
1555 nuv->priv->segment_stop = segment_stop;
1557 GST_OBJECT_UNLOCK(nuv);
1559 if (!nuv->priv->eos) {
1562 gst_message_new_segment_start(GST_OBJECT(nuv), GST_FORMAT_TIME,
1563 nuv->priv->segment_start);
1565 gst_element_post_message(GST_ELEMENT(nuv), msg);
1568 GST_DEBUG_OBJECT(nuv,
1569 "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %"
1570 G_GUINT64_FORMAT, segment_start, segment_stop);
1572 gst_event_new_new_segment(FALSE, rate, GST_FORMAT_TIME,
1573 segment_start, segment_stop,
1578 if (nuv->priv->src_video_pad != NULL) {
1579 gst_pad_push_event(nuv->priv->src_video_pad,
1580 gst_event_new_flush_stop());
1583 if (nuv->priv->src_audio_pad != NULL) {
1584 gst_pad_push_event(nuv->priv->src_audio_pad,
1585 gst_event_new_flush_stop());
1588 gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_stop());
1592 if (nuv->priv->src_video_pad != NULL) {
1593 gst_pad_push_event(nuv->priv->src_video_pad,
1594 gst_event_ref(newsegment_event));
1596 if (nuv->priv->src_audio_pad != NULL) {
1597 gst_pad_push_event(nuv->priv->src_audio_pad,
1598 gst_event_ref(newsegment_event));
1601 gst_event_unref(newsegment_event);
1603 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1604 nuv->priv->offset = entry->offset;
1606 gst_pad_start_task(nuv->priv->sinkpad,
1607 (GstTaskFunction) gst_nuv_demux_loop,
1608 nuv->priv->sinkpad);
1610 GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1614 GST_DEBUG_OBJECT(nuv, "Got a seek error");
1615 GST_OBJECT_UNLOCK(nuv);
1616 GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad);
1622 gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event)
1624 gboolean res = FALSE;
1627 nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1629 switch (GST_EVENT_TYPE(event)) {
1630 case GST_EVENT_SEEK:
1631 res = gst_nuv_demux_do_seek(nuv, event);
1638 gst_object_unref(nuv);
1643 gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event)
1645 gboolean res = FALSE;
1648 nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1650 switch (GST_EVENT_TYPE(event)) {
1651 case GST_EVENT_NEWSEGMENT:
1652 GST_PAD_STREAM_LOCK(pad);
1653 gst_nuv_demux_reset(nuv);
1654 GST_PAD_STREAM_UNLOCK(pad);
1656 //res = gst_pad_event_default(pad, event);
1660 res = gst_pad_event_default(pad, event);
1667 static GstFlowReturn
1668 gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf)
1670 GstFlowReturn ret = GST_FLOW_OK;
1671 GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad));
1673 if (nuv->priv->mode != NUV_PUSH_MODE)
1676 gst_adapter_push(nuv->priv->adapter, buf);
1678 while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) {
1679 ret = gst_nuv_demux_play(pad);
1682 nuv->priv->more_data = FALSE;
1683 gst_object_unref(nuv);
1689 gst_nuv_demux_loop(GstPad * pad)
1691 gst_nuv_demux_play(pad);
1695 gst_nuv_demux_index_free(gpointer data, gpointer user_data)
1701 gst_nuv_demux_reset(GstNuvDemux * nuv)
1703 nuv->priv->eos = FALSE;
1704 nuv->priv->more_data = FALSE;
1705 nuv->priv->state = GST_NUV_DEMUX_START;
1706 nuv->priv->mode = NUV_PUSH_MODE;
1707 nuv->priv->offset = 0;
1708 nuv->priv->time_start = 0;
1709 nuv->priv->time_qos = GST_CLOCK_TIME_NONE;
1710 nuv->priv->duration_bytes = GST_CLOCK_TIME_NONE;
1711 nuv->priv->duration_time = GST_CLOCK_TIME_NONE;
1712 nuv->priv->last_video_return = GST_FLOW_OK;
1713 nuv->priv->last_audio_return = GST_FLOW_OK;
1714 nuv->priv->header_lengh = 0;
1715 nuv->priv->segment_stop = GST_CLOCK_TIME_NONE;
1716 nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
1717 nuv->priv->new_file = FALSE;
1720 g_slist_foreach(nuv->priv->index, gst_nuv_demux_index_free, NULL);
1721 g_slist_free(nuv->priv->index);
1722 nuv->priv->index = NULL;
1724 gst_adapter_clear(nuv->priv->adapter);
1726 if (nuv->priv->mpeg_buffer != NULL) {
1727 gst_buffer_unref(nuv->priv->mpeg_buffer);
1728 nuv->priv->mpeg_buffer = NULL;
1733 gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv)
1735 if (nuv->priv->src_video_pad) {
1736 gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_video_pad);
1737 nuv->priv->src_video_pad = NULL;
1740 if (nuv->priv->src_audio_pad) {
1741 gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_audio_pad);
1742 nuv->priv->src_audio_pad = NULL;
1746 static GstStateChangeReturn
1747 gst_nuv_demux_change_state(GstElement * element, GstStateChange transition)
1749 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1751 switch (transition) {
1752 case GST_STATE_CHANGE_NULL_TO_READY:
1753 gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1754 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1761 GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1762 if (ret == GST_STATE_CHANGE_FAILURE) {
1767 switch (transition) {
1768 case GST_STATE_CHANGE_READY_TO_NULL:
1769 gst_nuv_demux_reset(GST_NUV_DEMUX(element));
1770 gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element));
1779 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1781 gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes)
1787 g_return_val_if_fail(GST_IS_ADAPTER(adapter), NULL);
1788 g_return_val_if_fail(nbytes > 0, NULL);
1790 GST_LOG_OBJECT(adapter, "taking buffer of %u bytes", nbytes);
1793 * we don't have enough data, return NULL. This is unlikely as one
1794 * usually does an _available() first instead of peeking a random
1797 if (G_UNLIKELY(nbytes > adapter->size))
1801 * our head buffer has enough data left, return it
1803 cur = adapter->buflist->data;
1804 if (GST_BUFFER_SIZE(cur) >= nbytes + adapter->skip) {
1805 GST_LOG_OBJECT(adapter,
1806 "providing buffer of %d bytes via sub-buffer",
1808 buffer = gst_buffer_create_sub(cur, adapter->skip, nbytes);
1810 gst_adapter_flush(adapter, nbytes);
1815 data = gst_adapter_take(adapter, nbytes);
1819 buffer = gst_buffer_new();
1820 GST_BUFFER_DATA(buffer) = data;
1821 GST_BUFFER_MALLOCDATA(buffer) = data;
1822 GST_BUFFER_SIZE(buffer) = nbytes;
1829 gst_nuv_typefind(GstTypeFind * tf, gpointer unused)
1831 guint8 *data = gst_type_find_peek(tf, 0, 11);
1834 if (memcmp(data, "MythTVVideo", 11) == 0
1835 || memcmp(data, "NuppelVideo", 11) == 0) {
1836 gst_type_find_suggest(tf, GST_TYPE_FIND_MAXIMUM,
1837 gst_caps_new_simple("video/x-nuv",
1844 plugin_init(GstPlugin * plugin)
1846 static gchar *exts[] = { "nuv", NULL };
1848 setlocale(LC_ALL, "");
1849 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
1850 #endif /* ENABLE_NLS */
1852 if (!gst_element_register(plugin, "nuvdemux", GST_RANK_SECONDARY,
1853 GST_TYPE_NUV_DEMUX)) {
1857 if (!gst_type_find_register(plugin, "video/x-nuv", GST_RANK_SECONDARY,
1860 gst_caps_new_simple("video/x-nuv", NULL),
1862 GST_WARNING("can't register typefind");
1869 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1872 "Demuxes and muxes audio and video",
1873 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,