1 /* GStreamer NUV demuxer
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
24 * @see_also: mythtvsrc
26 * Demuxes MythTVs NuppelVideo .nuv file into raw or compressed audio and/or
29 * This element currently only supports pull-based scheduling.
32 * <title>Example launch line</title>
34 * gst-launch filesrc test.nuv ! nuvdemux name=demux demux.audio_00 ! decodebin ! audioconvert ! audioresample ! autoaudiosink demux.video_00 ! queue ! decodebin ! ffmpegcolorspace ! videoscale ! autovideosink
35 * ]| Play (parse and decode) an .nuv file and try to output it to
36 * an automatically detected soundcard and videosink. If the NUV file contains
37 * compressed audio or video data, this will only work if you have the
38 * right decoder elements/plugins installed.
48 #include <gst/gsterror.h>
49 #include <gst/gstplugin.h>
52 #include "gst/gst-i18n-plugin.h"
53 #include "gstnuvdemux.h"
55 GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug);
56 #define GST_CAT_DEFAULT nuvdemux_debug
59 #define GST_FLOW_ERROR_NO_DATA -101
61 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_EVENT);
63 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
66 GST_STATIC_CAPS ("video/x-nuv"));
68 static GstStaticPadTemplate audio_src_template =
69 GST_STATIC_PAD_TEMPLATE ("audio_src",
74 static GstStaticPadTemplate video_src_template =
75 GST_STATIC_PAD_TEMPLATE ("video_src",
80 /* NUV Demux indexes init/dispose callers */
81 static void gst_nuv_demux_finalize (GObject * object);
82 static GstStateChangeReturn gst_nuv_demux_change_state (GstElement * element,
83 GstStateChange transition);
84 static void gst_nuv_demux_loop (GstPad * pad);
85 static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf);
86 static GstFlowReturn gst_nuv_demux_play (GstPad * pad);
87 static gboolean gst_nuv_demux_sink_activate_pull (GstPad * sinkpad,
89 static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad);
90 static GstFlowReturn gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size,
91 gboolean move, GstBuffer ** buffer);
92 static void gst_nuv_demux_reset (GstNuvDemux * nuv);
93 static gboolean gst_nuv_demux_handle_sink_event (GstPad * sinkpad,
95 static void gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv);
96 static void gst_nuv_demux_send_eos (GstNuvDemux * nuv);
99 GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT);
101 #if G_BYTE_ORDER == G_BIG_ENDIAN
102 static inline gdouble
103 _gdouble_swap_le_be (gdouble * d)
112 u.i = GUINT64_SWAP_LE_BE (u.i);
116 #define READ_DOUBLE_FROM_LE(d) (_gdouble_swap_le_be((gdouble* ) d))
117 #else /* G_BYTE_ORDER != G_BIG_ENDIAN */
118 #define READ_DOUBLE_FROM_LE(d) *((gdouble* ) (d))
119 #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */
123 gst_nuv_demux_base_init (gpointer klass)
125 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
127 gst_element_class_add_static_pad_template (element_class,
128 &audio_src_template);
130 gst_element_class_add_static_pad_template (element_class,
131 &video_src_template);
133 gst_element_class_add_static_pad_template (element_class,
135 gst_element_class_set_details_simple (element_class, "Nuv demuxer",
137 "Demultiplex a MythTV NuppleVideo .nuv file into audio and video",
138 "Renato Araujo Oliveira Filho <renato.filho@indt.org.br>,"
139 "Rosfran Borges <rosfran.borges@indt.org.br>");
143 gst_nuv_demux_class_init (GstNuvDemuxClass * klass)
145 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
146 GObjectClass *gobject_class = (GObjectClass *) klass;
148 gobject_class->finalize = gst_nuv_demux_finalize;
150 gstelement_class->change_state =
151 GST_DEBUG_FUNCPTR (gst_nuv_demux_change_state);
155 gst_nuv_demux_init (GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class)
157 nuv->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
159 gst_pad_set_activate_function (nuv->sinkpad, gst_nuv_demux_sink_activate);
161 gst_pad_set_activatepull_function (nuv->sinkpad,
162 gst_nuv_demux_sink_activate_pull);
164 gst_pad_set_chain_function (nuv->sinkpad,
165 GST_DEBUG_FUNCPTR (gst_nuv_demux_chain));
167 gst_pad_set_event_function (nuv->sinkpad, gst_nuv_demux_handle_sink_event);
169 gst_element_add_pad (GST_ELEMENT (nuv), nuv->sinkpad);
172 nuv->mpeg_buffer = NULL;
176 gst_nuv_demux_reset (nuv);
180 gst_nuv_demux_finalize (GObject * object)
182 GstNuvDemux *nuv = GST_NUV_DEMUX (object);
184 if (nuv->mpeg_buffer != NULL) {
185 gst_buffer_unref (nuv->mpeg_buffer);
188 gst_nuv_demux_destoy_src_pad (nuv);
189 gst_nuv_demux_reset (nuv);
190 if (nuv->adapter != NULL) {
191 g_object_unref (nuv->adapter);
194 G_OBJECT_CLASS (parent_class)->finalize (object);
197 /*****************************************************************************
199 *****************************************************************************/
202 gst_nuv_demux_handle_sink_event (GstPad * sinkpad, GstEvent * event)
204 gboolean res = FALSE;
206 switch (GST_EVENT_TYPE (event)) {
207 case GST_EVENT_NEWSEGMENT:
211 return gst_pad_event_default (sinkpad, event);
215 gst_event_unref (event);
223 gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header ** h_ret)
225 GstBuffer *buffer = NULL;
229 res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer);
230 if (res != GST_FLOW_OK)
233 h = g_new0 (nuv_header, 1);
235 memcpy (h->id, buffer->data, 12);
236 memcpy (h->version, buffer->data + 12, 5);
237 h->i_width = GST_READ_UINT32_LE (&buffer->data[20]);
238 h->i_height = GST_READ_UINT32_LE (&buffer->data[24]);
239 h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]);
240 h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]);
241 h->i_mode = buffer->data[36];
242 h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]);
243 h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]);
244 h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]);
245 h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]);
246 h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]);
247 h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]);
249 GST_DEBUG_OBJECT (nuv,
250 "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id,
251 h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps,
252 h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks,
253 h->i_keyframe_distance);
256 gst_buffer_unref (buffer);
261 gst_nuv_demux_stream_header_data (GstNuvDemux * nuv)
263 GstFlowReturn res = gst_nuv_demux_header_load (nuv, &nuv->h);
265 if (res == GST_FLOW_OK)
266 nuv->state = GST_NUV_DEMUX_EXTRA_DATA;
274 gst_nuv_demux_stream_file_header (GstNuvDemux * nuv)
276 GstFlowReturn res = GST_FLOW_OK;
277 GstBuffer *file_header = NULL;
279 res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header);
280 if (res != GST_FLOW_OK) {
283 if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) ||
284 strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) {
285 nuv->state = GST_NUV_DEMUX_HEADER_DATA;
287 GST_DEBUG_OBJECT (nuv, "error parsing file header");
288 nuv->state = GST_NUV_DEMUX_INVALID_DATA;
289 res = GST_FLOW_ERROR;
292 if (file_header != NULL) {
293 gst_buffer_unref (file_header);
301 gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header ** h_ret)
305 GstBuffer *buf = NULL;
307 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf);
309 if (res != GST_FLOW_OK) {
311 gst_buffer_unref (buf);
316 h = g_new0 (nuv_frame_header, 1);
320 h->i_compression = data[1];
321 h->i_keyframe = data[2];
322 h->i_filters = data[3];
324 h->i_timecode = GST_READ_UINT32_LE (&data[4]);
325 h->i_length = GST_READ_UINT32_LE (&data[8]);
326 GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d",
328 h->i_compression ? h->i_compression : ' ',
329 h->i_keyframe ? h->i_keyframe : ' ',
330 h->i_filters, h->i_timecode, h->i_length);
333 gst_buffer_unref (buf);
338 gst_nuv_demux_extended_header_load (GstNuvDemux * nuv,
339 nuv_extended_header ** h_ret)
342 GstBuffer *buff = NULL;
343 nuv_extended_header *h;
346 GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff);
348 if (res != GST_FLOW_OK) {
350 gst_buffer_unref (buff);
355 h = g_new0 (nuv_extended_header, 1);
357 h->i_version = GST_READ_UINT32_LE (&data[0]);
358 h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]);
359 h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]);
360 h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]);
361 h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]);
362 h->i_audio_channels = GST_READ_UINT32_LE (&data[20]);
363 h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]);
364 h->i_audio_quality = GST_READ_UINT32_LE (&data[28]);
365 h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]);
366 h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]);
367 h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]);
368 h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]);
369 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]);
370 h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]);
371 h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]);
372 h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]);
373 h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]);
375 GST_DEBUG_OBJECT (nuv,
376 "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d"
377 "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%"
378 G_GINT64_FORMAT " keyfao=%" G_GINT64_FORMAT, h->i_version,
379 (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc,
380 h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels,
381 h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality,
382 h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate,
383 h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset,
384 h->i_keyframe_adjust_offset);
387 gst_buffer_unref (buff);
392 gst_nuv_demux_handle_src_event (GstPad * pad, GstEvent * event)
394 gst_event_unref (event);
400 gst_nuv_demux_create_pads (GstNuvDemux * nuv)
402 if (nuv->h->i_video_blocks != 0) {
403 GstCaps *video_caps = NULL;
406 gst_pad_new_from_static_template (&video_src_template, "video_src");
408 video_caps = gst_caps_new_simple ("video/x-divx",
409 "divxversion", G_TYPE_INT, 4,
410 "width", G_TYPE_INT, nuv->h->i_width,
411 "height", G_TYPE_INT, nuv->h->i_height,
412 "framerate", GST_TYPE_FRACTION, (gint) (nuv->h->d_fps * 1000.0f), 1000,
413 "pixel-aspect-ratio", GST_TYPE_FRACTION,
414 (gint) (nuv->h->d_aspect * 1000.0f), 1000, NULL);
416 gst_pad_use_fixed_caps (nuv->src_video_pad);
417 gst_pad_set_active (nuv->src_video_pad, TRUE);
418 gst_pad_set_caps (nuv->src_video_pad, video_caps);
420 gst_pad_set_event_function (nuv->src_video_pad,
421 gst_nuv_demux_handle_src_event);
422 gst_pad_set_active (nuv->src_video_pad, TRUE);
423 gst_element_add_pad (GST_ELEMENT (nuv), nuv->src_video_pad);
425 gst_caps_unref (video_caps);
428 if (nuv->h->i_audio_blocks != 0) {
429 GstCaps *audio_caps = NULL;
432 gst_pad_new_from_static_template (&audio_src_template, "audio_src");
434 audio_caps = gst_caps_new_simple ("audio/mpeg",
435 "rate", G_TYPE_INT, nuv->eh->i_audio_sample_rate,
436 "format", GST_TYPE_FOURCC, nuv->eh->i_audio_fcc,
437 "channels", G_TYPE_INT, nuv->eh->i_audio_channels,
438 "mpegversion", G_TYPE_INT, nuv->eh->i_version, NULL);
440 gst_pad_use_fixed_caps (nuv->src_audio_pad);
441 gst_pad_set_active (nuv->src_audio_pad, TRUE);
442 gst_pad_set_caps (nuv->src_audio_pad, audio_caps);
443 gst_pad_set_active (nuv->src_audio_pad, TRUE);
444 gst_element_add_pad (GST_ELEMENT (nuv), nuv->src_audio_pad);
446 gst_pad_set_event_function (nuv->src_audio_pad,
447 gst_nuv_demux_handle_src_event);
449 gst_caps_unref (audio_caps);
452 gst_element_no_more_pads (GST_ELEMENT (nuv));
456 gst_nuv_demux_read_head_frame (GstNuvDemux * nuv)
458 GstFlowReturn ret = GST_FLOW_OK;
460 ret = gst_nuv_demux_frame_header_load (nuv, &nuv->fh);
461 if (ret != GST_FLOW_OK)
464 nuv->state = GST_NUV_DEMUX_MOVI;
469 gst_nuv_demux_stream_data (GstNuvDemux * nuv)
471 GstFlowReturn ret = GST_FLOW_OK;
472 GstBuffer *buf = NULL;
473 nuv_frame_header *h = nuv->fh;
475 if (h->i_type == 'R')
478 if (h->i_length > 0) {
479 ret = gst_nuv_demux_read_bytes (nuv, h->i_length, TRUE, &buf);
480 if (ret != GST_FLOW_OK)
483 if (h->i_timecode > 0)
484 GST_BUFFER_TIMESTAMP (buf) = h->i_timecode * GST_MSECOND;
494 GST_BUFFER_OFFSET (buf) = nuv->video_offset;
495 gst_buffer_set_caps (buf, GST_PAD_CAPS (nuv->src_video_pad));
496 ret = gst_pad_push (nuv->src_video_pad, buf);
505 GST_BUFFER_OFFSET (buf) = nuv->audio_offset;
506 gst_buffer_set_caps (buf, GST_PAD_CAPS (nuv->src_audio_pad));
507 ret = gst_pad_push (nuv->src_audio_pad, buf);
513 switch (h->i_compression) {
515 gst_pad_push_event (nuv->src_video_pad,
516 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1,
520 gst_pad_push_event (nuv->src_audio_pad,
521 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
529 gst_buffer_unref (buf);
535 nuv->state = GST_NUV_DEMUX_FRAME_HEADER;
542 gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv)
544 GstFlowReturn ret = GST_FLOW_OK;
546 /* ffmpeg extra data */
548 gst_nuv_demux_read_bytes (nuv, nuv->mpeg_data_size, TRUE,
550 if (ret != GST_FLOW_OK) {
551 return GST_FLOW_ERROR;
553 GST_BUFFER_SIZE (nuv->mpeg_buffer) = nuv->mpeg_data_size;
554 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER;
559 gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv)
561 GstFlowReturn ret = GST_FLOW_OK;
566 ret = gst_nuv_demux_frame_header_load (nuv, &h);
567 if (ret != GST_FLOW_OK)
570 if (h->i_type != 'D') {
572 return GST_FLOW_ERROR;
575 if (h->i_length > 0) {
576 if (h->i_compression == 'F') {
577 nuv->state = GST_NUV_DEMUX_MPEG_DATA;
580 return GST_FLOW_ERROR;
583 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER;
592 gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv)
594 GstFlowReturn ret = GST_FLOW_OK;
596 ret = gst_nuv_demux_extended_header_load (nuv, &nuv->eh);
597 if (ret != GST_FLOW_OK)
600 gst_nuv_demux_create_pads (nuv);
601 nuv->state = GST_NUV_DEMUX_FRAME_HEADER;
606 gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv)
608 GstBuffer *buf = NULL;
609 GstFlowReturn res = GST_FLOW_OK;
611 res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf);
612 if (res != GST_FLOW_OK) {
614 gst_buffer_unref (buf);
619 if (buf->data[0] == 'X') {
620 nuv_frame_header *h = NULL;
622 gst_buffer_unref (buf);
625 res = gst_nuv_demux_frame_header_load (nuv, &h);
626 if (res != GST_FLOW_OK)
629 if (h->i_length != 512) {
631 return GST_FLOW_ERROR;
635 nuv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA;
637 nuv->state = GST_NUV_DEMUX_INVALID_DATA;
638 GST_ELEMENT_ERROR (nuv, STREAM, DEMUX, (NULL),
639 ("Unsupported extended header (0x%02x)", buf->data[0]));
640 gst_buffer_unref (buf);
641 return GST_FLOW_ERROR;
647 gst_nuv_demux_play (GstPad * pad)
649 GstFlowReturn res = GST_FLOW_OK;
650 GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad));
652 switch (nuv->state) {
653 case GST_NUV_DEMUX_START:
654 res = gst_nuv_demux_stream_file_header (nuv);
655 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
658 if (nuv->state != GST_NUV_DEMUX_HEADER_DATA)
661 case GST_NUV_DEMUX_HEADER_DATA:
662 res = gst_nuv_demux_stream_header_data (nuv);
663 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
666 if (nuv->state != GST_NUV_DEMUX_EXTRA_DATA)
669 case GST_NUV_DEMUX_EXTRA_DATA:
670 res = gst_nuv_demux_stream_extra_data (nuv);
671 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
674 if (nuv->state != GST_NUV_DEMUX_MPEG_DATA)
677 case GST_NUV_DEMUX_MPEG_DATA:
678 res = gst_nuv_demux_stream_mpeg_data (nuv);
679 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
683 if (nuv->state != GST_NUV_DEMUX_EXTEND_HEADER)
686 case GST_NUV_DEMUX_EXTEND_HEADER:
687 res = gst_nuv_demux_stream_extend_header (nuv);
688 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
691 if (nuv->state != GST_NUV_DEMUX_EXTEND_HEADER_DATA)
694 case GST_NUV_DEMUX_EXTEND_HEADER_DATA:
695 res = gst_nuv_demux_stream_extend_header_data (nuv);
696 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
700 if (nuv->state != GST_NUV_DEMUX_FRAME_HEADER)
703 case GST_NUV_DEMUX_FRAME_HEADER:
704 res = gst_nuv_demux_read_head_frame (nuv);
705 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
708 if (nuv->state != GST_NUV_DEMUX_MOVI)
711 case GST_NUV_DEMUX_MOVI:
712 res = gst_nuv_demux_stream_data (nuv);
713 if ((res != GST_FLOW_OK) && (res != GST_FLOW_CUSTOM_ERROR)) {
717 case GST_NUV_DEMUX_INVALID_DATA:
721 g_assert_not_reached ();
724 GST_DEBUG_OBJECT (nuv, "state: %d res:%s", nuv->state,
725 gst_flow_get_name (res));
730 GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res));
731 gst_pad_pause_task (nuv->sinkpad);
732 if (res == GST_FLOW_UNEXPECTED) {
733 gst_nuv_demux_send_eos (nuv);
734 } else if (res == GST_FLOW_NOT_LINKED || res < GST_FLOW_UNEXPECTED) {
735 GST_ELEMENT_ERROR (nuv, STREAM, FAILED,
736 (_("Internal data stream error.")),
737 ("streaming stopped, reason %s", gst_flow_get_name (res)));
739 gst_nuv_demux_send_eos (nuv);
745 gst_nuv_demux_send_eos (GstNuvDemux * nuv)
747 gst_element_post_message (GST_ELEMENT (nuv),
748 gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1));
750 if (nuv->src_video_pad)
751 gst_pad_push_event (nuv->src_video_pad, gst_event_new_eos ());
752 if (nuv->src_audio_pad)
753 gst_pad_push_event (nuv->src_audio_pad, gst_event_new_eos ());
757 gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move,
760 GstFlowReturn ret = GST_FLOW_OK;
763 *buffer = gst_buffer_new ();
767 if (nuv->mode == 0) {
768 ret = gst_pad_pull_range (nuv->sinkpad, nuv->offset, size, buffer);
769 if (ret == GST_FLOW_OK) {
774 } else if (ret == GST_FLOW_UNEXPECTED) {
775 gst_nuv_demux_send_eos (nuv);
776 return GST_FLOW_WRONG_STATE;
779 if (gst_adapter_available (nuv->adapter) < size)
780 return GST_FLOW_ERROR_NO_DATA;
783 *buffer = gst_adapter_take_buffer (nuv->adapter, size);
787 data = (guint8 *) gst_adapter_peek (nuv->adapter, size);
788 *buffer = gst_buffer_new ();
789 gst_buffer_set_data (*buffer, data, size);
796 gst_nuv_demux_sink_activate (GstPad * sinkpad)
799 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
801 if (gst_pad_check_pull_range (sinkpad)) {
803 if (nuv->adapter != NULL) {
804 g_object_unref (nuv->adapter);
807 res = gst_pad_activate_pull (sinkpad, TRUE);
811 nuv->adapter = gst_adapter_new ();
813 res = gst_pad_activate_push (sinkpad, TRUE);
816 g_object_unref (nuv);
821 gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
823 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad));
826 gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad);
828 gst_pad_stop_task (sinkpad);
830 gst_object_unref (nuv);
836 gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf)
838 GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad));
840 gst_adapter_push (nuv->adapter, buf);
842 return gst_nuv_demux_play (pad);
846 gst_nuv_demux_loop (GstPad * pad)
848 gst_nuv_demux_play (pad);
852 gst_nuv_demux_reset (GstNuvDemux * nuv)
854 nuv->state = GST_NUV_DEMUX_START;
857 nuv->video_offset = 0;
858 nuv->audio_offset = 0;
860 if (nuv->adapter != NULL)
861 gst_adapter_clear (nuv->adapter);
863 if (nuv->mpeg_buffer != NULL) {
864 gst_buffer_unref (nuv->mpeg_buffer);
865 nuv->mpeg_buffer = NULL;
879 gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv)
881 if (nuv->src_video_pad) {
882 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->src_video_pad);
883 nuv->src_video_pad = NULL;
886 if (nuv->src_audio_pad) {
887 gst_element_remove_pad (GST_ELEMENT (nuv), nuv->src_audio_pad);
888 nuv->src_audio_pad = NULL;
892 static GstStateChangeReturn
893 gst_nuv_demux_change_state (GstElement * element, GstStateChange transition)
895 GstStateChangeReturn ret;
897 switch (transition) {
898 case GST_STATE_CHANGE_READY_TO_PAUSED:
904 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
905 if (ret == GST_STATE_CHANGE_FAILURE)
908 switch (transition) {
909 case GST_STATE_CHANGE_PAUSED_TO_READY:
910 gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element));
911 gst_nuv_demux_reset (GST_NUV_DEMUX (element));
922 plugin_init (GstPlugin * plugin)
924 GST_DEBUG_CATEGORY_INIT (nuvdemux_debug, "nuvdemux",
925 0, "Demuxer for NUV streams");
928 GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
930 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
931 #endif /* ENABLE_NLS */
933 if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY,
934 GST_TYPE_NUV_DEMUX)) {
940 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
943 "Demuxes MythTV NuppelVideo files",
944 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)