[svn r661] Fixed starvation loop when reading an unlimited-size buffer (LiveTV) from the FileTransfer; MonitorHandler is a GThread now.
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;
232 guint64 header_lengh;
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 nuv->priv->new_audio_segment = TRUE;
381 nuv->priv->new_video_segment = TRUE;
383 gst_pad_set_activate_function (nuv->priv->sinkpad, gst_nuv_demux_sink_activate);
384 gst_pad_set_activatepull_function (nuv->priv->sinkpad,
385 gst_nuv_demux_sink_activate_pull);
386 gst_pad_set_activatepush_function (nuv->priv->sinkpad,
387 gst_nuv_demux_sink_activate_push);
388 gst_pad_set_chain_function (nuv->priv->sinkpad,
389 GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
391 gst_pad_set_event_function (nuv->priv->sinkpad,
392 gst_nuv_demux_sink_event);
395 gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad);
400 gst_nuv_demux_dispose (GObject * object)
402 GstNuvDemux *nuv = GST_NUV_DEMUX (object);
405 if (nuv->priv->mpeg_buffer != NULL) {
406 gst_buffer_unref (nuv->priv->mpeg_buffer);
409 gst_nuv_demux_reset (GST_NUV_DEMUX (object));
410 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (object));
412 if (nuv->priv->adapter != NULL) {
413 gst_object_unref (nuv->priv->adapter);
418 gst_nuv_demux_finalize (GObject * object)
420 G_OBJECT_CLASS (parent_class)->finalize (object);
427 gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h)
429 GstBuffer *buffer = NULL;
430 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
432 if ((res != GST_FLOW_OK) || (buffer == NULL)) {
436 memcpy (h->id, buffer->data, 12);
437 memcpy (h->version, buffer->data + 12, 5);
438 h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
439 h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
440 h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
441 h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
442 h->i_mode = GPOINTER_TO_INT (buffer->data[36]);
443 h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
444 h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
445 /* get the num and denom values from fps */
446 double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd);
447 h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
448 h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
449 h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
450 h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
452 GST_DEBUG_OBJECT (nuv,
453 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
454 h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
455 h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
456 h->i_keyframe_distance);
459 if (buffer != NULL) {
460 gst_buffer_unref (buffer);
467 gst_nuv_demux_stream_header_data (GstNuvDemux * nuv)
471 res = gst_nuv_demux_header_load (nuv, &nuv->priv->h);
472 if (res == GST_FLOW_OK)
473 nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA;
481 gst_nuv_demux_stream_file_header (GstNuvDemux * nuv)
483 GstFlowReturn res = GST_FLOW_OK;
484 GstBuffer *file_header = NULL;
486 res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header);
487 if (res == GST_FLOW_OK) {
488 if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) ||
489 strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) {
490 nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA;
492 GST_DEBUG_OBJECT (nuv, "error parsing file header");
493 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
494 res = GST_FLOW_ERROR;
498 if (file_header != NULL) {
499 gst_buffer_unref (file_header);
508 gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h)
511 GstBuffer *buf = NULL;
513 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
515 if ((res != GST_FLOW_OK) || (buf == NULL)) {
521 h->i_type = GPOINTER_TO_INT (data[0]);
522 h->i_compression = GPOINTER_TO_INT (data[1]);
523 h->i_keyframe = GPOINTER_TO_INT (data[2]);
524 h->i_filters = GPOINTER_TO_INT (data[3]);
525 h->i_timecode = GST_READ_UINT32_LE (&data[4]);
526 h->i_length = GST_READ_UINT32_LE (&data[8]);
528 GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
530 h->i_compression ? h->i_compression : ' ',
531 h->i_keyframe ? h->i_keyframe : ' ',
532 h->i_filters, h->i_timecode, h->i_length);
536 gst_buffer_unref (buf);
544 gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
545 nuv_extended_header * h)
548 GstBuffer *buff = NULL;
550 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
552 if ((res != GST_FLOW_OK) || (buff == NULL)) {
557 h->i_version = GST_READ_UINT32_LE (&data[0]);
558 h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
559 h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]);
560 h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]);
561 h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]);
562 h->i_audio_channels = GST_READ_UINT32_LE (&data[20]);
563 h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]);
564 h->i_audio_quality = GST_READ_UINT32_LE (&data[28]);
565 h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]);
566 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]);
567 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]);
568 h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]);
569 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]);
570 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]);
571 h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]);
572 h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]);
573 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]);
575 GST_DEBUG_OBJECT (nuv,
576 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
577 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
578 h->i_version, (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc,
579 h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels,
580 h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality,
581 h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
582 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
583 h->i_keyframe_adjust_offset);
587 gst_buffer_unref (buff);
594 /* Query Functions */
595 static const GstQueryType *
596 gst_nuv_demux_get_src_query_types (GstPad * pad)
598 static const GstQueryType src_types[] = {
608 gst_nuv_demux_handle_src_query (GstPad * pad, GstQuery * query)
610 gboolean res = FALSE;
611 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
613 switch (GST_QUERY_TYPE (query)) {
614 case GST_QUERY_POSITION:
615 if (GST_CLOCK_TIME_IS_VALID (nuv->priv->last_frame_time)) {
616 gst_query_set_position (query, GST_FORMAT_TIME, nuv->priv->last_frame_time);
620 case GST_QUERY_DURATION:
622 if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) {
623 gst_query_set_duration (query, GST_FORMAT_TIME, nuv->priv->duration_time);
633 gst_object_unref (nuv);
639 gst_nuv_demux_create_pad (GstNuvDemux *nuv, GstCaps *caps, GstStaticPadTemplate *template, const gchar* name)
642 pad = gst_pad_new_from_static_template (template, name);
643 gst_pad_set_caps (pad, caps);
644 gst_pad_set_active (pad, TRUE);
645 gst_pad_use_fixed_caps (pad);
646 gst_element_add_pad (GST_ELEMENT (nuv), pad);
648 gst_pad_set_event_function (pad,
649 GST_DEBUG_FUNCPTR (gst_nuv_demux_srcpad_event));
651 gst_pad_set_query_type_function (pad,
652 GST_DEBUG_FUNCPTR (gst_nuv_demux_get_src_query_types));
654 gst_pad_set_query_function (pad,
655 GST_DEBUG_FUNCPTR (gst_nuv_demux_handle_src_query));
662 gst_nuv_demux_create_pads (GstNuvDemux * nuv)
664 if (nuv->priv->h.i_video_blocks != 0) {
665 GstCaps *video_caps = NULL;
667 video_caps = gst_caps_new_simple ("video/x-divx",
668 "divxversion", G_TYPE_INT, 4,
669 "width", G_TYPE_INT, nuv->priv->h.i_width,
670 "height", G_TYPE_INT, nuv->priv->h.i_height,
671 "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd,
672 "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc,
673 "pixel-aspect-ratio", GST_TYPE_FRACTION,
674 (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL);
676 nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src");
677 gst_caps_unref (video_caps);
680 if (nuv->priv->h.i_audio_blocks != 0) {
681 GstCaps *audio_caps = NULL;
683 audio_caps = gst_caps_new_simple ("audio/mpeg",
684 "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate,
685 "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc,
686 "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels,
687 "layer", G_TYPE_INT, 3, // fixme: magic number
688 "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL);
690 nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src");
691 gst_caps_unref (audio_caps);
694 gst_element_no_more_pads (GST_ELEMENT (nuv));
698 gst_nuv_demux_validate_header (nuv_frame_header *h)
700 gboolean valid = FALSE;
701 //g_usleep (1 * G_USEC_PER_SEC );
705 if (h->i_compression == 0 ||
706 h->i_compression == 1 ||
707 h->i_compression == 2 ||
708 h->i_compression == 'N' ||
709 h->i_compression == 'L') {
714 if (h->i_compression == 0 ||
715 h->i_compression == 1 ||
716 h->i_compression == 2 ||
717 h->i_compression == 3 ||
718 h->i_compression == 'F' ||
719 h->i_compression == 'S' ||
720 h->i_compression == 'N' ||
721 h->i_compression == 'L') {
726 if (h->i_compression == 'B' ||
727 h->i_compression == 'A' ||
728 h->i_compression == 'V' ||
729 h->i_compression == 'S') {
750 gst_nuv_demux_read_head_frame (GstNuvDemux * nuv)
752 GstFlowReturn ret = GST_FLOW_OK;
753 gboolean valid = FALSE;
756 ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh);
757 if (ret != GST_FLOW_OK) {
761 if (gst_nuv_demux_validate_header (&nuv->priv->fh) == TRUE)
764 } while (valid == FALSE);
766 nuv->priv->state = GST_NUV_DEMUX_MOVI;
771 gst_nuv_combine_flow (GstNuvDemux *nuv)
773 GstFlowReturn ret_video = nuv->priv->last_video_return;
774 GstFlowReturn ret_audio = nuv->priv->last_audio_return;
776 if ((ret_video != GST_FLOW_OK) &&
777 (ret_audio != GST_FLOW_OK))
780 if (GST_FLOW_IS_FATAL (ret_video))
783 if (GST_FLOW_IS_FATAL (ret_audio))
790 gst_nuv_demux_stream_data (GstNuvDemux * nuv)
792 GstFlowReturn ret = GST_FLOW_OK;
795 GstBuffer *buf = NULL;
800 if (h.i_type == 'R') {
804 if (h.i_length > 0) {
805 ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf);
806 if ((ret != GST_FLOW_OK) || (buf == NULL)) {
810 if ((h.i_timecode < 0)) {
815 timestamp = h.i_timecode * GST_MSECOND;
816 GST_BUFFER_TIMESTAMP (buf) = timestamp;
826 pad = nuv->priv->src_video_pad;
828 if (nuv->priv->new_video_segment) {
830 /* send new segment event*/
831 gst_pad_push_event (nuv->priv->src_video_pad,
832 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
833 GST_CLOCK_TIME_NONE, 0));
835 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
836 nuv->priv->time_start = timestamp;
838 nuv->priv->new_video_segment = FALSE;
845 pad = nuv->priv->src_audio_pad;
847 if (nuv->priv->new_audio_segment) {
848 /* send new segment event*/
849 gst_pad_push_event (nuv->priv->src_audio_pad,
850 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
851 GST_CLOCK_TIME_NONE, 0));
853 if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) {
854 nuv->priv->time_start = timestamp;
856 nuv->priv->new_audio_segment = FALSE;
863 switch (h.i_compression) {
865 GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode);
866 gst_pad_push_event (nuv->priv->src_video_pad,
867 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND,
868 GST_CLOCK_TIME_NONE, 0));
871 GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode);
872 gst_pad_push_event (nuv->priv->src_audio_pad,
873 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
874 GST_CLOCK_TIME_NONE, 0));
885 if ((buf != NULL) && (pad != NULL)) {
886 /* pushing the buffer */
887 gst_buffer_set_caps (buf, GST_PAD_CAPS (pad));
888 ret = gst_pad_push (pad, buf);
891 if (ret != GST_FLOW_OK) {
892 GST_WARNING_OBJECT (nuv, "error: %d pushing on srcpad %s", ret, gst_pad_get_name (pad));
894 if (pad == nuv->priv->src_video_pad) {
895 nuv->priv->last_video_return = ret;
897 else if (pad == nuv->priv->src_audio_pad) {
898 nuv->priv->last_audio_return = ret;
901 /* verify anothers flow if is necessary stop task */
902 if (gst_nuv_combine_flow (nuv) != FALSE) {
905 GST_WARNING_OBJECT (nuv, "error: on push");
913 gst_buffer_unref (buf);
916 if (ret == GST_FLOW_OK) {
917 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
918 memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh));
924 gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv)
926 GstFlowReturn ret = GST_FLOW_OK;
928 /* ffmpeg extra data */
929 ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE,
930 &nuv->priv->mpeg_buffer);
931 if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) {
935 GST_BUFFER_SIZE (nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size;
936 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
941 gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv)
943 GstFlowReturn ret = GST_FLOW_OK;
948 ret = gst_nuv_demux_frame_header_load (nuv, &h);
949 if (ret != GST_FLOW_OK)
952 if (h.i_type != 'D') {
953 GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg");
954 return GST_FLOW_NOT_SUPPORTED;
957 if (h.i_length > 0) {
958 if (h.i_compression == 'F') {
959 nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA;
961 GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported");
962 return GST_FLOW_NOT_SUPPORTED;
965 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER;
972 gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv)
974 GstFlowReturn ret = GST_FLOW_OK;
976 ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh);
977 if (ret != GST_FLOW_OK)
980 gst_nuv_demux_create_pads (nuv);
981 nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE;
986 gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv)
988 GstBuffer *buf = NULL;
989 GstFlowReturn res = GST_FLOW_OK;
991 res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf);
992 if ((res != GST_FLOW_OK) || (buf == NULL)) {
994 gst_buffer_unref (buf);
999 if (buf->data[0] == 'X') {
1000 gst_buffer_unref (buf);
1004 res = gst_nuv_demux_frame_header_load (nuv, &h);
1005 if (res != GST_FLOW_OK)
1008 if (h.i_length != 512) {
1009 return GST_FLOW_ERROR;
1011 nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
1013 nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA;
1014 g_object_unref (buf);
1015 GST_ELEMENT_WARNING (nuv, STREAM, FAILED,
1016 (_("incomplete NUV support")), ("incomplete NUV support"));
1017 return GST_FLOW_ERROR;
1023 gst_nuv_demux_create_seek_index (GstNuvDemux * nuv)
1028 while (gst_nuv_demux_frame_header_load (nuv, &h) == GST_FLOW_OK) {
1029 if ((h.i_type == 'V') && (h.i_keyframe == 0)) {
1030 frame_index_data *f = g_new0 (frame_index_data, 1);
1032 f->offset = nuv->priv->offset - 12;
1033 f->timecode = h.i_timecode * GST_MSECOND;
1035 nuv->priv->index = g_slist_append (nuv->priv->index, f);
1037 if (h.i_type != 'R') {
1038 nuv->priv->offset += h.i_length;
1039 if (h.i_type == 'A' || h.i_type == 'V')
1040 nuv->priv->duration_time = h.i_timecode * GST_MSECOND;
1043 GST_DEBUG_OBJECT (nuv, "CREATING INDEX: DONE : DURATION Bytes/Sec: %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
1044 nuv->priv->offset, nuv->priv->duration_time);
1046 nuv->priv->duration_bytes = nuv->priv->offset;
1047 nuv->priv->offset = nuv->priv->header_lengh;
1049 msg = gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, nuv->priv->duration_time);
1050 gst_element_post_message (GST_ELEMENT (nuv), msg);
1053 static GstFlowReturn
1054 gst_nuv_demux_play (GstPad * pad)
1056 GstFlowReturn res = GST_FLOW_OK;
1057 GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad));
1059 switch (nuv->priv->state) {
1060 case GST_NUV_DEMUX_START:
1061 res = gst_nuv_demux_stream_file_header (nuv);
1062 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1067 case GST_NUV_DEMUX_HEADER_DATA:
1068 res = gst_nuv_demux_stream_header_data (nuv);
1069 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1074 case GST_NUV_DEMUX_EXTRA_DATA:
1075 res = gst_nuv_demux_stream_extra_data (nuv);
1076 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1081 case GST_NUV_DEMUX_MPEG_DATA:
1082 res = gst_nuv_demux_stream_mpeg_data (nuv);
1083 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1088 case GST_NUV_DEMUX_EXTEND_HEADER:
1089 res = gst_nuv_demux_stream_extend_header (nuv);
1090 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1095 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
1096 res = gst_nuv_demux_stream_extend_header_data (nuv);
1097 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1100 //store file header size
1101 nuv->priv->header_lengh = nuv->priv->offset;
1104 case GST_NUV_DEMUX_INDEX_CREATE:
1105 if (nuv->priv->mode == NUV_PULL_MODE) {
1106 gst_nuv_demux_create_seek_index (nuv);
1109 case GST_NUV_DEMUX_FRAME_HEADER:
1110 res = gst_nuv_demux_read_head_frame (nuv);
1111 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1116 case GST_NUV_DEMUX_MOVI:
1117 res = gst_nuv_demux_stream_data (nuv);
1118 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1123 case GST_NUV_DEMUX_INVALID_DATA:
1127 g_assert_not_reached ();
1133 GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
1134 gst_pad_pause_task (nuv->priv->sinkpad);
1136 if (res == GST_FLOW_ERROR_EOS) {
1137 gst_nuv_demux_send_eos (nuv);
1138 nuv->priv->eos = TRUE;
1142 if (GST_FLOW_IS_FATAL (res)) {
1143 GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
1144 (_("Internal data stream error.")),
1145 ("streaming stopped, reason %s", gst_flow_get_name (res)));
1147 gst_nuv_demux_send_eos (nuv);
1153 gst_nuv_demux_send_eos (GstNuvDemux * nuv)
1155 gst_element_post_message (GST_ELEMENT (nuv),
1156 gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));
1158 if (nuv->priv->src_video_pad)
1159 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_eos ());
1160 if (nuv->priv->src_audio_pad)
1161 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_eos ());
1164 static GstFlowReturn
1165 gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move,
1166 GstBuffer ** buffer)
1168 GstFlowReturn ret = GST_FLOW_OK;
1175 if (nuv->priv->mode == NUV_PULL_MODE) {
1176 ret = gst_pad_pull_range (nuv->priv->sinkpad, nuv->priv->offset, size, buffer);
1177 if (ret == GST_FLOW_OK) {
1179 nuv->priv->offset += size;
1182 } else if (ret == GST_FLOW_UNEXPECTED) {
1183 return GST_FLOW_ERROR_EOS;
1186 if (gst_adapter_available (nuv->priv->adapter) < size) {
1187 nuv->priv->more_data = TRUE;
1188 return GST_FLOW_ERROR_NO_DATA;
1191 *buffer = gst_adapter_take_buffer (nuv->priv->adapter, size);
1193 guint8 *data = NULL;
1194 data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
1195 *buffer = gst_buffer_new ();
1196 gst_buffer_set_data (*buffer, data, size);
1203 gst_nuv_demux_sink_activate (GstPad * sinkpad)
1205 gboolean res = TRUE;
1206 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1208 if (gst_pad_check_pull_range (sinkpad)) {
1209 gst_adapter_clear (nuv->priv->adapter);
1210 res = gst_pad_activate_pull (sinkpad, TRUE);
1212 gst_adapter_clear (nuv->priv->adapter);
1213 res = gst_pad_activate_push (sinkpad, TRUE);
1216 g_object_unref (nuv);
1221 gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
1223 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
1226 GST_DEBUG_OBJECT (nuv, "activating pull function");
1227 nuv->priv->mode = NUV_PULL_MODE;
1228 gst_adapter_clear (nuv->priv->adapter);
1230 gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
1232 GST_DEBUG_OBJECT (nuv, "deactivating pull function");
1233 gst_pad_stop_task (sinkpad);
1235 gst_object_unref (nuv);
1241 gst_nuv_demux_sink_activate_push (GstPad * pad, gboolean active)
1243 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1246 nuv->priv->mode = NUV_PUSH_MODE;
1247 gst_adapter_clear (nuv->priv->adapter);
1249 GST_DEBUG_OBJECT (nuv, "activating push/chain function");
1251 GST_DEBUG_OBJECT (nuv, "deactivating push/chain function");
1254 gst_object_unref (nuv);
1259 static frame_index_data *
1260 gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos,
1261 gint64 segment_stop, GstFormat format)
1264 frame_index_data *ret = NULL;
1266 if (nuv->priv->index == NULL) {
1270 /* find keyframe closest to the requested position */
1271 for (l = nuv->priv->index; l != NULL; l = l->next) {
1272 frame_index_data *f = (frame_index_data *) l->data;
1275 if (format == GST_FORMAT_BYTES) {
1277 } else if (format == GST_FORMAT_TIME) {
1283 if (pos >= seek_pos) {
1288 if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE) && (pos > segment_stop)) {
1297 gst_nuv_demux_do_seek (GstNuvDemux *nuv, GstEvent * event)
1302 GstSeekType cur_type;
1304 GstSeekType stop_type;
1307 frame_index_data *entry;
1308 gint64 segment_start;
1309 gint64 segment_stop;
1310 GstEvent *newsegment_event;
1312 if (nuv->priv->eos) {
1316 if (nuv->priv->mode == NUV_PUSH_MODE) {
1321 gst_event_parse_seek (event, &rate, &format, &flags,
1322 &cur_type, &cur, &stop_type, &stop);
1327 if (format == GST_FORMAT_TIME) {
1328 GST_DEBUG_OBJECT (nuv, "Can only seek on BYTES");
1334 GST_DEBUG_OBJECT (nuv, "Can only seek with positive rate");
1338 if (cur_type == GST_SEEK_TYPE_SET) {
1339 GST_OBJECT_LOCK (nuv);
1340 if (gst_nuv_demux_do_seek_index (nuv, cur, -1, format) == NULL) {
1341 GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1342 GST_OBJECT_UNLOCK (nuv);
1345 GST_OBJECT_UNLOCK (nuv);
1348 flush = !!(flags & GST_SEEK_FLAG_FLUSH);
1351 gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_start ());
1352 if (nuv->priv->src_video_pad != NULL) {
1353 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_start ());
1356 if (nuv->priv->src_audio_pad != NULL) {
1357 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_start ());
1361 gst_pad_pause_task (nuv->priv->sinkpad);
1364 GST_PAD_STREAM_LOCK (nuv->priv->sinkpad);
1365 GST_OBJECT_LOCK (nuv);
1368 if (cur == GST_CLOCK_TIME_NONE)
1370 if (stop == GST_CLOCK_TIME_NONE)
1371 stop = nuv->priv->duration_time;
1373 if (cur_type == GST_SEEK_TYPE_SET)
1374 segment_start = cur;
1375 else if (cur_type == GST_SEEK_TYPE_CUR)
1376 segment_start = nuv->priv->segment_start + cur;
1378 segment_start = nuv->priv->segment_start;
1380 if (stop_type == GST_SEEK_TYPE_SET)
1381 segment_stop = stop;
1382 else if (stop_type == GST_SEEK_TYPE_CUR)
1383 segment_stop = nuv->priv->segment_stop + stop;
1385 segment_stop = nuv->priv->segment_stop;
1387 segment_start = CLAMP (segment_start, 0, nuv->priv->duration_time);
1388 segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_time);
1390 entry = gst_nuv_demux_do_seek_index (nuv, segment_start,
1391 segment_stop, format);
1393 if (entry == NULL) {
1394 GST_DEBUG_OBJECT (nuv, "No matching seek entry in index");
1398 segment_start = entry->timecode;
1400 nuv->priv->segment_start = segment_start;
1401 nuv->priv->segment_stop = segment_stop;
1403 GST_OBJECT_UNLOCK (nuv);
1405 if (!nuv->priv->eos) {
1407 msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME,
1408 nuv->priv->segment_start);
1410 gst_element_post_message (GST_ELEMENT (nuv), msg);
1413 GST_DEBUG_OBJECT (nuv, "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" G_GUINT64_FORMAT,
1414 segment_start, segment_stop);
1415 newsegment_event = gst_event_new_new_segment (FALSE, rate,
1416 GST_FORMAT_TIME, segment_start, segment_stop, segment_start);
1420 if (nuv->priv->src_video_pad != NULL) {
1421 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_stop ());
1424 if (nuv->priv->src_audio_pad != NULL) {
1425 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_stop ());
1428 gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ());
1432 if (nuv->priv->src_video_pad != NULL) {
1433 gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event));
1435 if (nuv->priv->src_audio_pad != NULL) {
1436 gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event));
1439 gst_event_unref (newsegment_event);
1441 nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER;
1442 nuv->priv->offset = entry->offset;
1444 gst_pad_start_task (nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop,
1445 nuv->priv->sinkpad);
1447 GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1451 GST_DEBUG_OBJECT (nuv, "Got a seek error");
1452 GST_OBJECT_UNLOCK (nuv);
1453 GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad);
1459 gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event)
1461 gboolean res = FALSE;
1464 nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1466 switch (GST_EVENT_TYPE (event)) {
1467 case GST_EVENT_SEEK:
1468 res = gst_nuv_demux_do_seek (nuv, event);
1475 gst_object_unref (nuv);
1479 static GstFlowReturn
1480 gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
1482 GstFlowReturn ret = GST_FLOW_OK;
1483 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
1485 if (nuv->priv->mode != NUV_PUSH_MODE)
1488 gst_adapter_push (nuv->priv->adapter, buf);
1490 while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) {
1491 ret = gst_nuv_demux_play (pad);
1494 nuv->priv->more_data = FALSE;
1495 gst_object_unref (nuv);
1501 gst_nuv_demux_loop (GstPad * pad)
1503 gst_nuv_demux_play (pad);
1507 gst_nuv_demux_index_free (gpointer data, gpointer user_data)
1513 gst_nuv_demux_reset (GstNuvDemux * nuv)
1515 nuv->priv->eos = FALSE;
1516 nuv->priv->more_data = FALSE;
1517 nuv->priv->state = GST_NUV_DEMUX_START;
1518 nuv->priv->mode = NUV_PUSH_MODE;
1519 nuv->priv->offset = 0;
1520 nuv->priv->time_start = 0;
1521 nuv->priv->time_qos = GST_CLOCK_TIME_NONE;
1522 nuv->priv->duration_bytes = GST_CLOCK_TIME_NONE;
1523 nuv->priv->duration_time = GST_CLOCK_TIME_NONE;
1524 nuv->priv->last_video_return = GST_FLOW_OK;
1525 nuv->priv->last_audio_return = GST_FLOW_OK;
1526 nuv->priv->header_lengh = 0;
1527 nuv->priv->segment_stop = GST_CLOCK_TIME_NONE;
1528 nuv->priv->segment_start = GST_CLOCK_TIME_NONE;
1531 g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL);
1532 g_slist_free (nuv->priv->index);
1533 nuv->priv->index = NULL;
1535 gst_adapter_clear (nuv->priv->adapter);
1537 if (nuv->priv->mpeg_buffer != NULL) {
1538 gst_buffer_unref (nuv->priv->mpeg_buffer);
1539 nuv->priv->mpeg_buffer = NULL;
1544 gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv)
1546 if (nuv->priv->src_video_pad) {
1547 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_video_pad);
1548 nuv->priv->src_video_pad = NULL;
1551 if (nuv->priv->src_audio_pad) {
1552 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_audio_pad);
1553 nuv->priv->src_audio_pad = NULL;
1557 static GstStateChangeReturn
1558 gst_nuv_demux_change_state (GstElement * element, GstStateChange transition)
1560 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1562 switch (transition) {
1563 case GST_STATE_CHANGE_NULL_TO_READY:
1564 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1565 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1571 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1572 if (ret == GST_STATE_CHANGE_FAILURE) {
1576 switch (transition) {
1577 case GST_STATE_CHANGE_READY_TO_NULL:
1578 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
1579 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
1589 #if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6)
1591 gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes)
1597 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1598 g_return_val_if_fail (nbytes > 0, NULL);
1600 GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes);
1602 /* we don't have enough data, return NULL. This is unlikely
1603 * as one usually does an _available() first instead of peeking a
1605 if (G_UNLIKELY (nbytes > adapter->size))
1608 /* our head buffer has enough data left, return it */
1609 cur = adapter->buflist->data;
1610 if (GST_BUFFER_SIZE (cur) >= nbytes + adapter->skip) {
1611 GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer",
1613 buffer = gst_buffer_create_sub (cur, adapter->skip, nbytes);
1615 gst_adapter_flush (adapter, nbytes);
1620 data = gst_adapter_take (adapter, nbytes);
1624 buffer = gst_buffer_new ();
1625 GST_BUFFER_DATA (buffer) = data;
1626 GST_BUFFER_MALLOCDATA (buffer) = data;
1627 GST_BUFFER_SIZE (buffer) = nbytes;
1634 gst_nuv_typefind (GstTypeFind * tf, gpointer unused)
1636 guint8 *data = gst_type_find_peek (tf, 0, 11);
1639 if (memcmp (data, "MythTVVideo", 11) == 0
1640 || memcmp (data, "NuppelVideo", 11) == 0) {
1641 gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM,
1642 gst_caps_new_simple ("video/x-nuv", NULL));
1648 plugin_init (GstPlugin * plugin)
1650 static gchar *exts[] = { "nuv", NULL };
1652 setlocale (LC_ALL, "");
1653 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1654 #endif /* ENABLE_NLS */
1656 if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY,
1657 GST_TYPE_NUV_DEMUX)) {
1661 if (!gst_type_find_register (plugin, "video/x-nuv", GST_RANK_SECONDARY,
1664 gst_caps_new_simple ("video/x-nuv", NULL), NULL, NULL)) {
1665 GST_WARNING ("can't register typefind");
1672 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1675 "Demuxes and muxes audio and video",
1676 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)