[svn r51] Check for the GST interfaces library (gst_x_overlay* functions).
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>
55 //#include "gst/gst-i18n-plugin.h"
56 #include <glib/gi18n.h>
57 #include "gstnuvdemux.h"
59 GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug);
60 #define GST_CAT_DEFAULT nuvdemux_debug
63 #define GST_FLOW_ERROR_NO_DATA -101
65 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_EVENT);
67 static const GstElementDetails gst_nuv_demux_details =
68 GST_ELEMENT_DETAILS ("Nuv demuxer",
70 "Demultiplex a .nuv file into audio and video",
71 "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
72 "Rosfran Borges <rosfran.borges@indt.org.br>");
74 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
77 GST_STATIC_CAPS ("video/x-nuv"));
79 static GstStaticPadTemplate audio_src_template =
80 GST_STATIC_PAD_TEMPLATE ("audio_src",
85 static GstStaticPadTemplate video_src_template =
86 GST_STATIC_PAD_TEMPLATE ("video_src",
91 /* NUV Demux indexes init/dispose callers */
92 static void gst_nuv_demux_finalize (GObject * object);
93 static GstStateChangeReturn gst_nuv_demux_change_state (GstElement * element,
94 GstStateChange transition);
95 static void gst_nuv_demux_loop (GstPad * pad);
96 static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf);
97 static GstFlowReturn gst_nuv_demux_play (GstPad * pad);
98 static gboolean gst_nuv_demux_sink_activate_pull (GstPad * sinkpad,
100 static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad);
101 static GstFlowReturn gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size,
102 gboolean move, GstBuffer ** buffer);
103 static void gst_nuv_demux_reset (GstNuvDemux * nuv);
104 static gboolean gst_nuv_demux_handle_sink_event (GstPad * sinkpad,
106 static void gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv);
107 static void gst_nuv_demux_send_eos (GstNuvDemux * nuv);
109 /* GObject methods */
110 GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
112 #if G_BYTE_ORDER == G_BIG_ENDIAN
113 static inline gdouble
114 _gdouble_swap_le_be (gdouble * d)
123 u.i = GUINT64_SWAP_LE_BE (u.i);
127 #define READ_DOUBLE_FROM_LE(d) (_gdouble_swap_le_be((gdouble* ) d))
128 #else /* G_BYTE_ORDER != G_BIG_ENDIAN */
129 #define READ_DOUBLE_FROM_LE(d) *((gdouble* ) (d))
130 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
134 gst_nuv_demux_base_init (gpointer klass)
136 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
138 gst_element_class_add_pad_template (element_class,
139 gst_static_pad_template_get (&audio_src_template));
141 gst_element_class_add_pad_template (element_class,
142 gst_static_pad_template_get (&video_src_template));
144 gst_element_class_add_pad_template (element_class,
145 gst_static_pad_template_get (&sink_template));
146 gst_element_class_set_details (element_class, &gst_nuv_demux_details);
150 gst_nuv_demux_class_init (GstNuvDemuxClass * klass)
152 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
153 GObjectClass *gobject_class = (GObjectClass *) klass;
155 GST_DEBUG_CATEGORY_INIT (nuvdemux_debug, "nuvdemux",
156 0, "Demuxer for NUV streams");
158 parent_class = g_type_class_peek_parent (klass);
160 gobject_class->finalize = gst_nuv_demux_finalize;
161 gstelement_class->change_state = gst_nuv_demux_change_state;
165 gst_nuv_demux_init (GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
167 nuv->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
169 gst_pad_set_activate_function (nuv->sinkpad, gst_nuv_demux_sink_activate);
171 gst_pad_set_activatepull_function (nuv->sinkpad,
172 gst_nuv_demux_sink_activate_pull);
174 gst_pad_set_chain_function (nuv->sinkpad,
175 GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
177 gst_pad_set_event_function (nuv->sinkpad, gst_nuv_demux_handle_sink_event);
179 gst_element_add_pad (GST_ELEMENT (nuv), nuv->sinkpad);
182 nuv->mpeg_buffer = NULL;
186 gst_nuv_demux_reset (nuv);
190 gst_nuv_demux_finalize (GObject * object)
192 GstNuvDemux *nuv = GST_NUV_DEMUX (object);
194 if (nuv->mpeg_buffer != NULL) {
195 gst_buffer_unref (nuv->mpeg_buffer);
198 gst_nuv_demux_destoy_src_pad (nuv);
199 gst_nuv_demux_reset (nuv);
200 if (nuv->adapter != NULL) {
201 gst_object_unref (nuv->adapter);
203 G_OBJECT_CLASS (parent_class)->finalize (object);
206 /*****************************************************************************
208 *****************************************************************************/
211 gst_nuv_demux_handle_sink_event (GstPad * sinkpad, GstEvent * event)
213 gboolean res = FALSE;
215 switch (GST_EVENT_TYPE (event)) {
216 case GST_EVENT_NEWSEGMENT:
220 return gst_pad_event_default (sinkpad, event);
224 gst_event_unref (event);
232 gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header ** h_ret)
234 GstBuffer *buffer = NULL;
235 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
237 if (res != GST_FLOW_OK)
240 nuv_header *h = g_new0 (nuv_header, 1);
242 memcpy (h->id, buffer->data, 12);
243 memcpy (h->version, buffer->data + 12, 5);
244 h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
245 h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
246 h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
247 h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
248 h->i_mode = buffer->data[36];
249 h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
250 h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
251 h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
252 h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
253 h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
254 h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
256 GST_DEBUG_OBJECT (nuv,
257 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
258 h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
259 h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
260 h->i_keyframe_distance);
263 gst_buffer_unref (buffer);
268 gst_nuv_demux_stream_header_data (GstNuvDemux * nuv)
270 GstFlowReturn res = gst_nuv_demux_header_load (nuv, &nuv->h);
272 if (res == GST_FLOW_OK)
273 nuv->state = GST_NUV_DEMUX_EXTRA_DATA;
281 gst_nuv_demux_stream_file_header (GstNuvDemux * nuv)
283 GstFlowReturn res = GST_FLOW_OK;
284 GstBuffer *file_header = NULL;
286 res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header);
287 if (res != GST_FLOW_OK) {
290 if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) ||
291 strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) {
292 nuv->state = GST_NUV_DEMUX_HEADER_DATA;
294 GST_DEBUG_OBJECT (nuv, "error parsing file header");
295 nuv->state = GST_NUV_DEMUX_INVALID_DATA;
296 res = GST_FLOW_ERROR;
299 if (file_header != NULL) {
300 gst_buffer_unref (file_header);
308 gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header ** h_ret)
312 GstBuffer *buf = NULL;
314 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
316 if (res != GST_FLOW_OK) {
318 gst_buffer_unref (buf);
323 h = g_new0 (nuv_frame_header, 1);
327 h->i_compression = data[1];
328 h->i_keyframe = data[2];
329 h->i_filters = data[3];
331 h->i_timecode = GST_READ_UINT32_LE (&data[4]);
332 h->i_length = GST_READ_UINT32_LE (&data[8]);
333 GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%u l=%u",
335 h->i_compression ? h->i_compression : ' ',
336 h->i_keyframe ? h->i_keyframe : ' ',
337 h->i_filters, h->i_timecode, h->i_length);
340 gst_buffer_unref (buf);
345 gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
346 nuv_extended_header ** h_ret)
349 GstBuffer *buff = NULL;
350 nuv_extended_header *h;
353 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
355 if (res != GST_FLOW_OK) {
357 gst_buffer_unref (buff);
362 h = g_new0 (nuv_extended_header, 1);
364 h->i_version = GST_READ_UINT32_LE (&data[0]);
365 h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
366 h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]);
367 h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]);
368 h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]);
369 h->i_audio_channels = GST_READ_UINT32_LE (&data[20]);
370 h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]);
371 h->i_audio_quality = GST_READ_UINT32_LE (&data[28]);
372 h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]);
373 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]);
374 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]);
375 h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]);
376 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]);
377 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]);
378 h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]);
379 h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]);
380 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]);
382 GST_DEBUG_OBJECT (nuv,
383 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
384 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld",
385 h->i_version, (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc,
386 h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels,
387 h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality,
388 h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
389 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
390 h->i_keyframe_adjust_offset);
393 gst_buffer_unref (buff);
398 gst_nuv_demux_handle_src_event (GstPad * pad, GstEvent * event)
400 gst_event_unref (event);
406 gst_nuv_demux_create_pads (GstNuvDemux * nuv)
408 if (nuv->h->i_video_blocks != 0) {
409 GstCaps *video_caps = NULL;
412 gst_pad_new_from_static_template (&video_src_template, "video_src");
414 video_caps = gst_caps_new_simple ("video/x-divx",
415 "divxversion", G_TYPE_INT, 4,
416 "width", G_TYPE_INT, nuv->h->i_width,
417 "height", G_TYPE_INT, nuv->h->i_height,
418 "framerate", GST_TYPE_FRACTION, (gint) (nuv->h->d_fps * 1000.0f), 1000,
419 "pixel-aspect-ratio", GST_TYPE_FRACTION,
420 (gint) (nuv->h->d_aspect * 1000.0f), 1000, NULL);
422 gst_pad_use_fixed_caps (nuv->src_video_pad);
423 gst_pad_set_active (nuv->src_video_pad, TRUE);
424 gst_pad_set_caps (nuv->src_video_pad, video_caps);
426 gst_pad_set_event_function (nuv->src_video_pad,
427 gst_nuv_demux_handle_src_event);
428 gst_pad_set_active (nuv->src_video_pad, TRUE);
429 gst_element_add_pad (GST_ELEMENT (nuv), nuv->src_video_pad);
430 gst_caps_unref (video_caps);
433 if (nuv->h->i_audio_blocks != 0) {
434 GstCaps *audio_caps = NULL;
437 gst_pad_new_from_static_template (&audio_src_template, "audio_src");
439 audio_caps = gst_caps_new_simple ("audio/mpeg",
440 "rate", G_TYPE_INT, nuv->eh->i_audio_sample_rate,
441 "format", GST_TYPE_FOURCC, nuv->eh->i_audio_fcc,
442 "channels", G_TYPE_INT, nuv->eh->i_audio_channels,
443 "mpegversion", G_TYPE_INT, nuv->eh->i_version, NULL);
445 gst_pad_use_fixed_caps (nuv->src_audio_pad);
446 gst_pad_set_active (nuv->src_audio_pad, TRUE);
447 gst_pad_set_caps (nuv->src_audio_pad, audio_caps);
448 gst_pad_set_active (nuv->src_audio_pad, TRUE);
449 gst_element_add_pad (GST_ELEMENT (nuv), nuv->src_audio_pad);
451 gst_pad_set_event_function (nuv->src_audio_pad,
452 gst_nuv_demux_handle_src_event);
453 gst_caps_unref (audio_caps);
456 gst_element_no_more_pads (GST_ELEMENT (nuv));
460 gst_nuv_demux_read_head_frame (GstNuvDemux * nuv)
462 GstFlowReturn ret = GST_FLOW_OK;
464 ret = gst_nuv_demux_frame_header_load (nuv, &nuv->fh);
465 if (ret != GST_FLOW_OK)
468 nuv->state = GST_NUV_DEMUX_MOVI;
473 gst_nuv_demux_stream_data (GstNuvDemux * nuv)
475 GstFlowReturn ret = GST_FLOW_OK;
476 GstBuffer *buf = NULL;
477 nuv_frame_header *h = nuv->fh;
479 if (h->i_type == 'R')
482 ret = gst_nuv_demux_read_bytes (nuv, h->i_length, TRUE, &buf);
483 if (ret != GST_FLOW_OK) {
487 GST_BUFFER_TIMESTAMP (buf) = h->i_timecode * GST_MSECOND;
492 GST_BUFFER_OFFSET (buf) = nuv->video_offset;
493 gst_buffer_set_caps (buf, GST_PAD_CAPS (nuv->src_video_pad));
494 ret = gst_pad_push (nuv->src_video_pad, buf);
500 GST_BUFFER_OFFSET (buf) = nuv->audio_offset;
501 gst_buffer_set_caps (buf, GST_PAD_CAPS (nuv->src_audio_pad));
502 ret = gst_pad_push (nuv->src_audio_pad, buf);
508 switch (h->i_compression) {
510 gst_pad_push_event (nuv->src_video_pad,
511 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
514 gst_pad_push_event (nuv->src_audio_pad,
515 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
526 nuv->state = GST_NUV_DEMUX_FRAME_HEADER;
533 gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv)
535 GstFlowReturn ret = GST_FLOW_OK;
537 /* ffmpeg extra data */
539 gst_nuv_demux_read_bytes (nuv, nuv->mpeg_data_size, TRUE,
541 if (ret != GST_FLOW_OK) {
542 return GST_FLOW_ERROR;
544 GST_BUFFER_SIZE (nuv->mpeg_buffer) = nuv->mpeg_data_size;
545 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER;
550 gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv)
552 GstFlowReturn ret = GST_FLOW_OK;
557 ret = gst_nuv_demux_frame_header_load (nuv, &h);
558 if (ret != GST_FLOW_OK)
561 if (h->i_type != 'D') {
563 return GST_FLOW_ERROR;
566 if (h->i_length > 0) {
567 if (h->i_compression == 'F') {
568 nuv->state = GST_NUV_DEMUX_MPEG_DATA;
571 return GST_FLOW_ERROR;
574 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER;
583 gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv)
585 GstFlowReturn ret = GST_FLOW_OK;
587 ret = gst_nuv_demux_extended_header_load (nuv, &nuv->eh);
588 if (ret != GST_FLOW_OK)
591 gst_nuv_demux_create_pads (nuv);
592 nuv->state = GST_NUV_DEMUX_FRAME_HEADER;
597 gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv)
599 GstBuffer *buf = NULL;
600 GstFlowReturn res = GST_FLOW_OK;
602 res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf);
603 if (res != GST_FLOW_OK) {
605 gst_buffer_unref (buf);
610 if (buf->data[0] == 'X') {
611 gst_buffer_unref (buf);
613 nuv_frame_header *h = NULL;
615 res = gst_nuv_demux_frame_header_load (nuv, &h);
616 if (res != GST_FLOW_OK)
619 if (h->i_length != 512) {
621 return GST_FLOW_ERROR;
625 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
627 nuv->state = GST_NUV_DEMUX_INVALID_DATA;
628 g_object_unref (buf);
629 GST_ELEMENT_WARNING (nuv, STREAM, FAILED,
630 (_("incomplete NUV support")), ("incomplete NUV support"));
631 return GST_FLOW_ERROR;
637 gst_nuv_demux_play (GstPad * pad)
639 GstFlowReturn res = GST_FLOW_OK;
640 GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad));
642 switch (nuv->state) {
643 case GST_NUV_DEMUX_START:
644 res = gst_nuv_demux_stream_file_header (nuv);
645 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
648 if (nuv->state != GST_NUV_DEMUX_HEADER_DATA)
651 case GST_NUV_DEMUX_HEADER_DATA:
652 res = gst_nuv_demux_stream_header_data (nuv);
653 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
656 if (nuv->state != GST_NUV_DEMUX_EXTRA_DATA)
659 case GST_NUV_DEMUX_EXTRA_DATA:
660 res = gst_nuv_demux_stream_extra_data (nuv);
661 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
664 if (nuv->state != GST_NUV_DEMUX_MPEG_DATA)
667 case GST_NUV_DEMUX_MPEG_DATA:
668 res = gst_nuv_demux_stream_mpeg_data (nuv);
669 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
673 if (nuv->state != GST_NUV_DEMUX_EXTEND_HEADER)
676 case GST_NUV_DEMUX_EXTEND_HEADER:
677 res = gst_nuv_demux_stream_extend_header (nuv);
678 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
681 if (nuv->state != GST_NUV_DEMUX_EXTEND_HEADER_DATA)
684 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
685 res = gst_nuv_demux_stream_extend_header_data (nuv);
686 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
690 if (nuv->state != GST_NUV_DEMUX_FRAME_HEADER)
693 case GST_NUV_DEMUX_FRAME_HEADER:
694 res = gst_nuv_demux_read_head_frame (nuv);
695 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
698 if (nuv->state != GST_NUV_DEMUX_MOVI)
701 case GST_NUV_DEMUX_MOVI:
702 res = gst_nuv_demux_stream_data (nuv);
703 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
707 case GST_NUV_DEMUX_INVALID_DATA:
711 g_assert_not_reached ();
714 GST_DEBUG_OBJECT (nuv, "state: %d res:%s", nuv->state,
715 gst_flow_get_name (res));
720 GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
721 gst_pad_pause_task (nuv->sinkpad);
722 if (GST_FLOW_IS_FATAL (res)) {
723 GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
724 (_("Internal data stream error.")),
725 ("streaming stopped, reason %s", gst_flow_get_name (res)));
727 gst_nuv_demux_send_eos (nuv);
733 gst_nuv_demux_send_eos (GstNuvDemux * nuv)
735 gst_element_post_message (GST_ELEMENT (nuv),
736 gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));
738 if (nuv->src_video_pad)
739 gst_pad_push_event (nuv->src_video_pad, gst_event_new_eos ());
740 if (nuv->src_audio_pad)
741 gst_pad_push_event (nuv->src_audio_pad, gst_event_new_eos ());
745 gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move,
748 GstFlowReturn ret = GST_FLOW_OK;
751 *buffer = gst_buffer_new ();
755 if (nuv->mode == 0) {
756 ret = gst_pad_pull_range (nuv->sinkpad, nuv->offset, size, buffer);
757 if (ret == GST_FLOW_OK) {
762 } else if (ret == GST_FLOW_UNEXPECTED) {
763 gst_nuv_demux_send_eos (nuv);
764 return GST_FLOW_WRONG_STATE;
767 if (gst_adapter_available (nuv->adapter) < size)
768 return GST_FLOW_ERROR_NO_DATA;
772 data = (guint8 *) gst_adapter_take (nuv->adapter, size);
773 *buffer = gst_buffer_new ();
774 gst_buffer_set_data (*buffer, data, size);
778 data = (guint8 *) gst_adapter_peek (nuv->adapter, size);
779 *buffer = gst_buffer_new ();
780 gst_buffer_set_data (*buffer, data, size);
787 gst_nuv_demux_sink_activate (GstPad * sinkpad)
790 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
792 if (gst_pad_check_pull_range (sinkpad)) {
795 res = gst_pad_activate_pull (sinkpad, TRUE);
798 nuv->adapter = gst_adapter_new ();
799 res = gst_pad_activate_push (sinkpad, TRUE);
802 g_object_unref (nuv);
807 gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
809 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
812 gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
814 gst_pad_stop_task (sinkpad);
816 gst_object_unref (nuv);
822 gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
824 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
826 gst_adapter_push (nuv->adapter, buf);
828 return gst_nuv_demux_play (pad);
832 gst_nuv_demux_loop (GstPad * pad)
834 gst_nuv_demux_play (pad);
838 gst_nuv_demux_reset (GstNuvDemux * nuv)
840 nuv->state = GST_NUV_DEMUX_START;
843 nuv->video_offset = 0;
844 nuv->audio_offset = 0;
846 if (nuv->adapter != NULL)
847 gst_adapter_clear (nuv->adapter);
849 if (nuv->mpeg_buffer != NULL) {
850 gst_buffer_unref (nuv->mpeg_buffer);
851 nuv->mpeg_buffer = NULL;
865 gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv)
867 if (nuv->src_video_pad) {
868 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->src_video_pad);
869 nuv->src_video_pad = NULL;
872 if (nuv->src_audio_pad) {
873 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->src_audio_pad);
874 nuv->src_audio_pad = NULL;
878 static GstStateChangeReturn
879 gst_nuv_demux_change_state (GstElement * element, GstStateChange transition)
881 GstStateChangeReturn ret;
883 switch (transition) {
884 case GST_STATE_CHANGE_READY_TO_PAUSED:
890 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
891 if (ret == GST_STATE_CHANGE_FAILURE)
894 switch (transition) {
895 case GST_STATE_CHANGE_PAUSED_TO_READY:
896 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
897 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
908 plugin_init (GstPlugin * plugin)
911 setlocale (LC_ALL, "");
912 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
913 #endif /* ENABLE_NLS */
915 if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY,
916 GST_TYPE_NUV_DEMUX)) {
922 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
925 "Demuxes and muxes audio and video",
926 plugin_init, VERSION, "LGPL", "NuvDemux", "")