resindvd: Initial partial port to 0.11

This commit is contained in:
Jan Schmidt 2012-06-09 22:36:06 +10:00
parent ea707c1764
commit 1218cff3dc
16 changed files with 2822 additions and 1409 deletions

View file

@ -321,7 +321,7 @@ GST_PLUGINS_NONPORTED=" aiff \
sdi siren speed subenc stereo tta videofilters \
videomeasure videosignal vmnc \
decklink fbdev linsys vcd \
apexsink cdaudio cog dc1394 dirac directfb resindvd \
apexsink cdaudio cog dc1394 dirac directfb \
gsettings jasper ladspa \
musepack musicbrainz nas neon ofa openal rsvg sdl sndfile spandsp spc timidity \
directsound directdraw direct3d9 acm wininet \

View file

@ -5,22 +5,21 @@ plugin_LTLIBRARIES = libgstresindvd.la
libgstresindvd_la_SOURCES = \
plugin.c \
resindvdbin.c \
rsnaudiomunge.c \
rsndec.c \
rsnstreamselector.c \
resindvdsrc.c \
rsndec.c \
gstmpegdesc.c \
gstmpegdemux.c \
gstpesfilter.c \
rsnparsetter.c \
rsnwrappedbuffer.c
rsninputselector.c \
# rsnparsetter.c \
# rsnwrappedbuffer.c \
# rsnaudiomunge.c
libgstresindvd_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) \
$(GST_CFLAGS) $(DVDNAV_CFLAGS)
libgstresindvd_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) \
-lgstinterfaces-$(GST_API_VERSION) -lgstvideo-$(GST_API_VERSION) \
-lgstpbutils-$(GST_API_VERSION) \
-lgstvideo-$(GST_API_VERSION) -lgstpbutils-$(GST_API_VERSION) \
$(GST_BASE_LIBS) $(GST_LIBS) $(DVDNAV_LIBS)
libgstresindvd_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstresindvd_la_LIBTOOLFLAGS = --tag=disable-static
@ -28,7 +27,7 @@ libgstresindvd_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = resindvdbin.h \
rsnaudiomunge.h \
rsndec.h \
rsnstreamselector.h \
rsninputselector.h \
resindvdsrc.h \
gstmpegdefs.h \
gstmpegdesc.h \

View file

@ -125,30 +125,56 @@
* 0x0F-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
* 0x80-0xFF User Private
*/
#define ST_RESERVED 0x00
#define ST_VIDEO_MPEG1 0x01
#define ST_VIDEO_MPEG2 0x02
#define ST_AUDIO_MPEG1 0x03
#define ST_AUDIO_MPEG2 0x04
#define ST_PRIVATE_SECTIONS 0x05
#define ST_PRIVATE_DATA 0x06
#define ST_MHEG 0x07
#define ST_DSMCC 0x08
#define ST_H222_1 0x09
#define ST_RESERVED 0x00
#define ST_VIDEO_MPEG1 0x01
#define ST_VIDEO_MPEG2 0x02
#define ST_AUDIO_MPEG1 0x03
#define ST_AUDIO_MPEG2 0x04
#define ST_PRIVATE_SECTIONS 0x05
#define ST_PRIVATE_DATA 0x06
#define ST_MHEG 0x07
#define ST_DSMCC 0x08
#define ST_H222_1 0x09
/* later extensions */
#define ST_AUDIO_AAC 0x0f
#define ST_VIDEO_MPEG4 0x10
#define ST_VIDEO_H264 0x1b
#define ST_AUDIO_AAC_ADTS 0x0f
/* LATM/LOAS AAC syntax */
#define ST_AUDIO_AAC_LOAS 0x11
#define ST_VIDEO_MPEG4 0x10
#define ST_VIDEO_H264 0x1b
/* Un-official Dirac extension */
#define ST_VIDEO_DIRAC 0xd1
#define ST_VIDEO_DIRAC 0xd1
/* private stream types */
#define ST_PS_AUDIO_AC3 0x81
#define ST_PS_AUDIO_DTS 0x8a
#define ST_PS_AUDIO_LPCM 0x8b
#define ST_PS_AUDIO_AC3 0x81
#define ST_PS_AUDIO_DTS 0x8a
#define ST_PS_AUDIO_LPCM 0x8b
#define ST_PS_DVD_SUBPICTURE 0xff
/* Blu-ray related */
#define ST_BD_AUDIO_LPCM 0x80
#define ST_BD_AUDIO_AC3 0x81
#define ST_BD_AUDIO_DTS 0x82
#define ST_BD_AUDIO_AC3_TRUE_HD 0x83
#define ST_BD_AUDIO_AC3_PLUS 0x84
#define ST_BD_AUDIO_DTS_HD 0x85
#define ST_BD_AUDIO_DTS_HD_MASTER_AUDIO 0x86
#define ST_BD_AUDIO_EAC3 0x87
#define ST_BD_PGS_SUBPICTURE 0x90
#define ST_BD_IGS 0x91
#define ST_BD_SUBTITLE 0x92
#define ST_BD_SECONDARY_AC3_PLUS 0xa1
#define ST_BD_SECONDARY_DTS_HD 0xa2
/* defined for VC1 extension in RP227 */
#define ST_PRIVATE_EA 0xea
/* HDV AUX stream mapping
* 0xA0 ISO/IEC 61834-11
* 0xA1 ISO/IEC 61834-11
*/
#define ST_HDV_AUX_A 0xa0
#define ST_HDV_AUX_V 0xa1
/* Un-official time-code stream */
#define ST_PS_TIMECODE 0xd2
@ -168,8 +194,19 @@
#define MPEG_MUX_RATE_MULT 50
/* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
#define READ_TS(data, target, lost_sync_label) \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target = ((guint64) (*data++ & 0x0E)) << 29; \
target |= ((guint64) (*data++ )) << 22; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) << 14; \
target |= ((guint64) (*data++ )) << 7; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) >> 1;
/* some extra GstFlowReturn values used internally */
#define GST_FLOW_NEED_MORE_DATA GST_FLOW_CUSTOM_SUCCESS
#define GST_FLOW_LOST_SYNC GST_FLOW_CUSTOM_SUCCESS_1
#define GST_FLOW_NEED_MORE_DATA GST_FLOW_CUSTOM_SUCCESS
#define GST_FLOW_LOST_SYNC GST_FLOW_CUSTOM_SUCCESS_1
#endif /* __GST_MPEG_DEFS_H__ */

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,10 @@
/*
/*
* This library is licensed under 2 different licenses and you
* can choose to use it under the terms of either one of them. The
* two licenses are the MPL 1.1 and the LGPL.
*
* MPL:
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
@ -9,6 +15,23 @@
* License for the specific language governing rights and limitations
* under the License.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* The Original Code is Fluendo MPEG Demuxer plugin.
*
* The Initial Developer of the Original Code is Fluendo, S.L.
@ -72,6 +95,9 @@ struct _GstFluPSDemux {
GstElement parent;
GstPad * sinkpad;
gboolean random_access; /* If we operate in pull mode */
gboolean flushing;
GstAdapter * adapter;
GstAdapter * rev_adapter;
@ -90,7 +116,7 @@ struct _GstFluPSDemux {
guint64 scr_rate_n;
guint64 scr_rate_d;
guint64 first_scr_offset;
guint64 last_scr_offset;
guint64 cur_scr_offset;
gint16 psm[GST_FLUPS_DEMUX_MAX_PSM];

View file

@ -1,23 +1,45 @@
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Fluendo MPEG Demuxer plugin.
*
* The Initial Developer of the Original Code is Fluendo, S.L.
* Portions created by Fluendo, S.L. are Copyright (C) 2005
* Fluendo, S.L. All Rights Reserved.
*
* Contributor(s): Wim Taymans <wim@fluendo.com>
* Jan Schmidt <thaytan@noraisin.net>
*/
/*
* This library is licensed under 2 different licenses and you
* can choose to use it under the terms of either one of them. The
* two licenses are the MPL 1.1 and the LGPL.
*
* MPL:
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* The Original Code is Fluendo MPEG Demuxer plugin.
*
* The Initial Developer of the Original Code is Fluendo, S.L.
* Portions created by Fluendo, S.L. are Copyright (C) 2005
* Fluendo, S.L. All Rights Reserved.
*
* Contributor(s): Wim Taymans <wim@fluendo.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -26,8 +48,8 @@
#include "gstmpegdefs.h"
#include "gstpesfilter.h"
GST_DEBUG_CATEGORY (gstflupesfilter_debug);
#define GST_CAT_DEFAULT (gstflupesfilter_debug)
GST_DEBUG_CATEGORY (mpegpspesfilter_debug);
#define GST_CAT_DEFAULT (mpegpspesfilter_debug)
static GstFlowReturn gst_pes_filter_data_push (GstPESFilter * filter,
gboolean first, GstBuffer * buffer);
@ -75,17 +97,6 @@ gst_pes_filter_set_callbacks (GstPESFilter * filter,
filter->user_data = user_data;
}
/* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
#define READ_TS(data, target, lost_sync_label) \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target = ((guint64) (*data++ & 0x0E)) << 29; \
target |= ((guint64) (*data++ )) << 22; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) << 14; \
target |= ((guint64) (*data++ )) << 7; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) >> 1;
static gboolean
gst_pes_filter_is_sync (guint32 sync)
{
@ -101,15 +112,21 @@ gst_pes_filter_parse (GstPESFilter * filter)
GstFlowReturn ret;
guint32 start_code;
gboolean STD_buffer_bound_scale G_GNUC_UNUSED;
guint16 STD_buffer_size_bound;
const guint8 *data;
gint avail, datalen;
gboolean have_size = FALSE;
/* read start code and length */
if (!(data = gst_adapter_peek (filter->adapter, 6)))
avail = gst_adapter_available (filter->adapter);
if (avail < 6)
goto need_more_data;
data = gst_adapter_map (filter->adapter, 6);
/* read start code and length */
/* get start code */
start_code = GST_READ_UINT32_BE (data);
if (!gst_pes_filter_is_sync (start_code))
@ -124,9 +141,6 @@ gst_pes_filter_parse (GstPESFilter * filter)
/* start parsing length */
filter->length = GST_READ_UINT16_BE (data);
/* see how much is available */
avail = gst_adapter_available (filter->adapter);
GST_DEBUG ("id 0x%02x length %d, avail %d start code 0x%02x", filter->id,
filter->length, avail, filter->start_code);
@ -139,6 +153,7 @@ gst_pes_filter_parse (GstPESFilter * filter)
* to set the allow_unbounded flag if they want */
if (filter->length == 0 &&
((filter->start_code & 0xFFFFFFF0) == PACKET_VIDEO_START_CODE ||
filter->start_code == ID_EXTENDED_STREAM_ID ||
filter->allow_unbounded)) {
GST_DEBUG ("id 0x%02x, unbounded length", filter->id);
filter->unbounded_packet = TRUE;
@ -155,10 +170,14 @@ gst_pes_filter_parse (GstPESFilter * filter)
avail = MIN (avail, filter->length + 6);
}
if (avail < 6)
goto need_more_data;
gst_adapter_unmap (filter->adapter);
/* read more data, either the whole packet if there is a length
* or whatever we have available if this in an unbounded packet. */
if (!(data = gst_adapter_peek (filter->adapter, avail)))
goto need_more_data;
data = gst_adapter_map (filter->adapter, avail);
/* This will make us flag LOST_SYNC if we run out of data from here onward */
have_size = TRUE;
@ -177,7 +196,8 @@ gst_pes_filter_parse (GstPESFilter * filter)
case ID_PROGRAM_STREAM_DIRECTORY:
case ID_DSMCC_STREAM:
case ID_ITU_TREC_H222_TYPE_E_STREAM:
goto skip;
/* Push directly out */
goto push_out;
case ID_PADDING_STREAM:
GST_DEBUG ("skipping padding stream");
goto skip;
@ -185,9 +205,8 @@ gst_pes_filter_parse (GstPESFilter * filter)
break;
}
if (datalen < 1)
if (datalen == 0)
goto need_more_data;
filter->pts = filter->dts = -1;
/* stuffing bits, first two bits are '10' for mpeg2 pes so this code is
@ -212,7 +231,7 @@ gst_pes_filter_parse (GstPESFilter * filter)
if (datalen < 3)
goto need_more_data;
/* STD_buffer_bound_scale = *data & 0x20; */
STD_buffer_bound_scale = *data & 0x20;
STD_buffer_size_bound = ((guint16) (*data++ & 0x1F)) << 8;
STD_buffer_size_bound |= *data++;
@ -264,7 +283,7 @@ gst_pes_filter_parse (GstPESFilter * filter)
/* check PES scrambling control */
if ((flags & 0x30) != 0)
goto encrypted;
GST_DEBUG ("PES scrambling control: %x", (flags >> 4) & 0x3);
/* 2: PTS_DTS_flags
* 1: ESCR_flag
@ -376,9 +395,53 @@ gst_pes_filter_parse (GstPESFilter * filter)
}
/* PES_extension_flag */
if ((flags & 0x01)) {
GST_DEBUG ("%x PES_extension", filter->id);
flags = *data++;
header_data_length -= 1;
datalen -= 1;
GST_DEBUG ("%x PES_extension, flags 0x%02x", filter->id, flags);
/* PES_private_data_flag */
if ((flags & 0x80)) {
GST_DEBUG ("%x PES_private_data_flag", filter->id);
data += 16;
header_data_length -= 16;
datalen -= 16;
}
/* pack_header_field_flag */
if ((flags & 0x40)) {
guint8 pack_field_length = *data;
GST_DEBUG ("%x pack_header_field_flag, pack_field_length %d",
filter->id, pack_field_length);
data += pack_field_length + 1;
header_data_length -= pack_field_length + 1;
datalen -= pack_field_length + 1;
}
/* program_packet_sequence_counter_flag */
if ((flags & 0x20)) {
GST_DEBUG ("%x program_packet_sequence_counter_flag", filter->id);
data += 2;
header_data_length -= 2;
datalen -= 2;
}
/* P-STD_buffer_flag */
if ((flags & 0x10)) {
GST_DEBUG ("%x P-STD_buffer_flag", filter->id);
data += 2;
header_data_length -= 2;
datalen -= 2;
}
/* PES_extension_flag_2 */
if ((flags & 0x01)) {
guint8 PES_extension_field_length = *data++;
GST_DEBUG ("%x PES_extension_flag_2, len %d",
filter->id, PES_extension_field_length & 0x7f);
if (PES_extension_field_length == 0x81) {
GST_DEBUG ("%x substream id 0x%02x", filter->id, *data);
}
data += PES_extension_field_length & 0x7f;
header_data_length -= (PES_extension_field_length & 0x7f) + 1;
datalen -= (PES_extension_field_length & 0x7f) + 1;
}
}
/* calculate the amount of real data in this PES packet */
data += header_data_length;
datalen -= header_data_length;
@ -392,6 +455,7 @@ gst_pes_filter_parse (GstPESFilter * filter)
goto lost_sync;
}
push_out:
{
GstBuffer *out;
guint16 consumed;
@ -408,11 +472,8 @@ gst_pes_filter_parse (GstPESFilter * filter)
}
if (datalen > 0) {
out = gst_buffer_new ();
GST_BUFFER_DATA (out) = g_memdup (data, datalen);
GST_BUFFER_SIZE (out) = datalen;
GST_BUFFER_MALLOCDATA (out) = GST_BUFFER_DATA (out);
out = gst_buffer_new_allocate (NULL, datalen, NULL);
gst_buffer_fill (out, 0, data, datalen);
ret = gst_pes_filter_data_push (filter, TRUE, out);
filter->first = FALSE;
} else {
@ -425,6 +486,7 @@ gst_pes_filter_parse (GstPESFilter * filter)
filter->state = STATE_DATA_PUSH;
}
gst_adapter_unmap (filter->adapter);
gst_adapter_flush (filter->adapter, avail);
ADAPTER_OFFSET_FLUSH (avail);
@ -434,36 +496,27 @@ need_more_data:
{
if (filter->unbounded_packet == FALSE) {
if (have_size == TRUE) {
GST_DEBUG ("bounded need more data %d, lost sync",
GST_DEBUG ("bounded need more data %" G_GSIZE_FORMAT " , lost sync",
gst_adapter_available (filter->adapter));
ret = GST_FLOW_LOST_SYNC;
} else {
GST_DEBUG ("bounded need more data %d, breaking for more",
gst_adapter_available (filter->adapter));
GST_DEBUG ("bounded need more data %" G_GSIZE_FORMAT
", breaking for more", gst_adapter_available (filter->adapter));
ret = GST_FLOW_NEED_MORE_DATA;
}
} else {
GST_DEBUG ("unbounded need more data %d",
GST_DEBUG ("unbounded need more data %" G_GSIZE_FORMAT,
gst_adapter_available (filter->adapter));
ret = GST_FLOW_NEED_MORE_DATA;
}
gst_adapter_unmap (filter->adapter);
return ret;
}
skip:
{
GST_DEBUG ("skipping 0x%02x", filter->id);
gst_adapter_flush (filter->adapter, avail);
ADAPTER_OFFSET_FLUSH (avail);
gst_adapter_unmap (filter->adapter);
filter->length -= avail - 6;
if (filter->length > 0 || filter->unbounded_packet)
filter->state = STATE_DATA_SKIP;
return GST_FLOW_OK;
}
encrypted:
{
GST_DEBUG ("skipping encrypted 0x%02x", filter->id);
GST_DEBUG ("skipping 0x%02x", filter->id);
gst_adapter_flush (filter->adapter, avail);
ADAPTER_OFFSET_FLUSH (avail);
@ -474,6 +527,7 @@ encrypted:
}
lost_sync:
{
gst_adapter_unmap (filter->adapter);
GST_DEBUG ("lost sync");
gst_adapter_flush (filter->adapter, 4);
ADAPTER_OFFSET_FLUSH (4);
@ -562,14 +616,8 @@ gst_pes_filter_process (GstPESFilter * filter)
ret = GST_FLOW_OK;
} else {
GstBuffer *out;
guint8 *data;
data = gst_adapter_take (filter->adapter, avail);
out = gst_buffer_new ();
GST_BUFFER_DATA (out) = data;
GST_BUFFER_SIZE (out) = avail;
GST_BUFFER_MALLOCDATA (out) = data;
out = gst_adapter_take_buffer (filter->adapter, avail);
ret = gst_pes_filter_data_push (filter, filter->first, out);
filter->first = FALSE;

View file

@ -1,4 +1,10 @@
/*
/*
* This library is licensed under 2 different licenses and you
* can choose to use it under the terms of either one of them. The
* two licenses are the MPL 1.1 and the LGPL.
*
* MPL:
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
@ -9,6 +15,23 @@
* License for the specific language governing rights and limitations
* under the License.
*
* LGPL:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* The Original Code is Fluendo MPEG Demuxer plugin.
*
* The Initial Developer of the Original Code is Fluendo, S.L.
@ -16,7 +39,6 @@
* Fluendo, S.L. All Rights Reserved.
*
* Contributor(s): Wim Taymans <wim@fluendo.com>
* Jan Schmidt <thaytan@noraisin.net>
*/
#ifndef __GST_PES_FILTER_H__
@ -62,8 +84,6 @@ struct _GstPESFilter {
gboolean unbounded_packet;
guint16 length;
guint8 type;
gint64 pts;
gint64 dts;
};

View file

@ -35,7 +35,7 @@ plugin_init (GstPlugin * plugin)
{
gboolean result = TRUE;
GST_DEBUG_CATEGORY_INIT (resindvd_debug, "resindvd elements",
GST_DEBUG_CATEGORY_INIT (resindvd_debug, "resindvd",
0, "DVD playback elements from resindvd");
#ifdef ENABLE_NLS

View file

@ -26,16 +26,20 @@
#include <gst/gst.h>
#include <gst/glib-compat-private.h>
#include <gst/pbutils/missing-plugins.h>
#include <gst/video/video.h>
#include <gst/audio/audio.h>
#include "resindvdbin.h"
#include "resindvdsrc.h"
#include "rsnstreamselector.h"
#include "rsnaudiomunge.h"
#include "rsninputselector.h"
// #include "rsnaudiomunge.h"
#include "rsndec.h"
#include "rsnparsetter.h"
// #include "rsnparsetter.h"
#include "gstmpegdemux.h"
#define RSN_TYPE_INPUT_SELECTOR GST_TYPE_INPUT_SELECTOR
GST_DEBUG_CATEGORY_EXTERN (resindvd_debug);
#define GST_CAT_DEFAULT resindvd_debug
@ -62,14 +66,14 @@ static GstStaticPadTemplate video_src_template =
GST_STATIC_PAD_TEMPLATE ("video",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS ("video/x-raw-yuv")
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
);
static GstStaticPadTemplate audio_src_template =
GST_STATIC_PAD_TEMPLATE ("audio",
GST_STATIC_PAD_TEMPLATE ("audio",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS ("audio/x-raw-int; audio/x-raw-float")
GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL))
);
static GstStaticPadTemplate subpicture_src_template =
@ -79,12 +83,12 @@ GST_STATIC_PAD_TEMPLATE ("subpicture",
GST_STATIC_CAPS ("subpicture/x-dvd")
);
static void rsn_dvdbin_do_init (GType rsn_dvdbin_type);
static void rsn_dvdbin_finalize (GObject * object);
static void rsn_dvdbin_uri_handler_init (gpointer g_iface, gpointer iface_data);
GST_BOILERPLATE_FULL (RsnDvdBin, rsn_dvdbin, GstBin,
GST_TYPE_BIN, rsn_dvdbin_do_init);
#define rsn_dvdbin_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (RsnDvdBin, rsn_dvdbin, GST_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, rsn_dvdbin_uri_handler_init));
static void demux_pad_added (GstElement * element, GstPad * pad,
RsnDvdBin * dvdbin);
@ -96,31 +100,14 @@ static void rsn_dvdbin_get_property (GObject * object, guint prop_id,
static GstStateChangeReturn rsn_dvdbin_change_state (GstElement * element,
GstStateChange transition);
static void
rsn_dvdbin_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&video_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&audio_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&subpicture_src_template));
gst_element_class_set_details_simple (element_class, "rsndvdbin",
"Generic/Bin/Player",
"DVD playback element", "Jan Schmidt <thaytan@noraisin.net>");
element_class->change_state = GST_DEBUG_FUNCPTR (rsn_dvdbin_change_state);
}
static void
rsn_dvdbin_class_init (RsnDvdBinClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *element_class;
gobject_class = (GObjectClass *) klass;
element_class = (GstElementClass *) klass;
gobject_class->finalize = rsn_dvdbin_finalize;
gobject_class->set_property = rsn_dvdbin_set_property;
@ -129,23 +116,23 @@ rsn_dvdbin_class_init (RsnDvdBinClass * klass)
g_object_class_install_property (gobject_class, ARG_DEVICE,
g_param_spec_string ("device", "Device", "DVD device location",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&video_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&audio_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&subpicture_src_template));
element_class->change_state = GST_DEBUG_FUNCPTR (rsn_dvdbin_change_state);
gst_element_class_set_details_simple (element_class, "rsndvdbin",
"Generic/Bin/Player",
"DVD playback element", "Jan Schmidt <thaytan@noraisin.net>");
}
static void
rsn_dvdbin_do_init (GType rsn_dvdbin_type)
{
static const GInterfaceInfo urihandler_info = {
rsn_dvdbin_uri_handler_init,
NULL,
NULL
};
g_type_add_interface_static (rsn_dvdbin_type, GST_TYPE_URI_HANDLER,
&urihandler_info);
}
static void
rsn_dvdbin_init (RsnDvdBin * dvdbin, RsnDvdBinClass * gclass)
rsn_dvdbin_init (RsnDvdBin * dvdbin)
{
dvdbin->dvd_lock = g_mutex_new ();
dvdbin->preroll_lock = g_mutex_new ();
@ -166,20 +153,20 @@ rsn_dvdbin_finalize (GObject * object)
/* URI interface */
static GstURIType
rsn_dvdbin_uri_get_type (void)
rsn_dvdbin_uri_get_type (GType type)
{
return GST_URI_SRC;
}
static const gchar *const *
rsn_dvdbin_uri_get_protocols (void)
rsn_dvdbin_uri_get_protocols (GType type)
{
static const gchar *protocols[] = { "dvd", NULL };
return protocols;
}
static const gchar *
static gchar *
rsn_dvdbin_uri_get_uri (GstURIHandler * handler)
{
RsnDvdBin *dvdbin = RESINDVDBIN (handler);
@ -192,11 +179,12 @@ rsn_dvdbin_uri_get_uri (GstURIHandler * handler)
dvdbin->last_uri = g_strdup ("dvd://");
DVDBIN_UNLOCK (dvdbin);
return dvdbin->last_uri;
return g_strdup (dvdbin->last_uri);
}
static gboolean
rsn_dvdbin_uri_set_uri (GstURIHandler * handler, const gchar * uri)
rsn_dvdbin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
RsnDvdBin *dvdbin = RESINDVDBIN (handler);
gboolean ret;
@ -335,10 +323,12 @@ typedef struct
{
RsnDvdBin *dvdbin;
GstPad *pad;
gulong pad_block_id;
} RsnDvdBinPadBlockCtx;
static void dvdbin_pad_blocked_cb (GstPad * pad, gboolean blocked,
RsnDvdBinPadBlockCtx * ctx);
static GstPadProbeReturn dvdbin_pad_blocked_cb (GstPad * pad,
GstPadProbeInfo * info, RsnDvdBinPadBlockCtx * ctx);
static void
_pad_block_destroy_notify (RsnDvdBinPadBlockCtx * ctx)
{
@ -366,6 +356,7 @@ create_elements (RsnDvdBin * dvdbin)
"device", dvdbin->device, NULL);
}
/* FIXME: Import and use local copy of mpeg PS demuxer */
if (!try_create_piece (dvdbin, DVD_ELEM_DEMUX,
NULL, GST_TYPE_FLUPS_DEMUX, "dvddemux", "DVD demuxer"))
return FALSE;
@ -394,7 +385,8 @@ create_elements (RsnDvdBin * dvdbin)
"viddec", "video decoder"))
return FALSE;
if (!try_create_piece (dvdbin, DVD_ELEM_PARSET, NULL, RSN_TYPE_RSNPARSETTER,
/* FIXME: Replace identity */
if (!try_create_piece (dvdbin, DVD_ELEM_PARSET, "identity", 0, //RSN_TYPE_RSNPARSETTER,
"rsnparsetter", "Aspect ratio adjustment"))
return FALSE;
@ -420,14 +412,16 @@ create_elements (RsnDvdBin * dvdbin)
bctx = g_slice_new (RsnDvdBinPadBlockCtx);
bctx->dvdbin = gst_object_ref (dvdbin);
bctx->pad = gst_object_ref (dvdbin->video_pad);
gst_pad_set_blocked_async_full (src, TRUE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
bctx->pad_block_id =
gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
(GstPadProbeCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
_pad_block_destroy_notify);
gst_object_unref (src);
src = NULL;
/* FIXME: Core input selector OK? */
if (!try_create_piece (dvdbin, DVD_ELEM_SPU_SELECT, NULL,
RSN_TYPE_STREAM_SELECTOR, "subpselect", "Subpicture stream selector"))
RSN_TYPE_INPUT_SELECTOR, "subpselect", "Subpicture stream selector"))
return FALSE;
/* Add a single standalone queue to hold a single buffer of SPU data */
@ -461,18 +455,20 @@ create_elements (RsnDvdBin * dvdbin)
bctx = g_slice_new (RsnDvdBinPadBlockCtx);
bctx->dvdbin = gst_object_ref (dvdbin);
bctx->pad = gst_object_ref (dvdbin->subpicture_pad);
gst_pad_set_blocked_async_full (src, TRUE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
bctx->pad_block_id =
gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
(GstPadProbeCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
_pad_block_destroy_notify);
gst_object_unref (src);
src = NULL;
if (!try_create_piece (dvdbin, DVD_ELEM_AUD_SELECT, NULL,
RSN_TYPE_STREAM_SELECTOR, "audioselect", "Audio stream selector"))
if (!try_create_piece (dvdbin, DVD_ELEM_AUD_SELECT, "input-selector",
RSN_TYPE_INPUT_SELECTOR, "audioselect", "Audio stream selector"))
return FALSE;
if (!try_create_piece (dvdbin, DVD_ELEM_AUD_MUNGE, NULL,
RSN_TYPE_AUDIOMUNGE, "audioearlymunge", "Audio output filter"))
if (!try_create_piece (dvdbin, DVD_ELEM_AUD_MUNGE, "identity",
0 /* RSN_TYPE_AUDIOMUNGE */ , "audioearlymunge",
"Audio output filter"))
return FALSE;
if (!try_create_piece (dvdbin, DVD_ELEM_AUDDEC, NULL,
@ -513,8 +509,9 @@ create_elements (RsnDvdBin * dvdbin)
bctx = g_slice_new (RsnDvdBinPadBlockCtx);
bctx->dvdbin = gst_object_ref (dvdbin);
bctx->pad = gst_object_ref (dvdbin->audio_pad);
gst_pad_set_blocked_async_full (src, TRUE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
bctx->pad_block_id =
gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
(GstPadProbeCallback) dvdbin_pad_blocked_cb, bctx, (GDestroyNotify)
_pad_block_destroy_notify);
gst_object_unref (src);
src = NULL;
@ -634,7 +631,7 @@ connect_thru_mq (RsnDvdBin * dvdbin, GstPad * pad)
return FALSE;
sinkname = gst_pad_get_name (mq_sink);
tmp = sinkname + 4;
tmp = sinkname + 5;
srcname = g_strdup_printf ("src_%s", tmp);
mq_src = gst_element_get_static_pad (dvdbin->pieces[DVD_ELEM_MQUEUE],
@ -653,9 +650,9 @@ can_sink_caps (GstElement * e, GstCaps * caps)
GstPad *sink = gst_element_get_static_pad (e, "sink");
if (sink) {
GstCaps *sink_caps = gst_pad_get_caps (sink);
GstCaps *sink_caps = gst_pad_query_caps (sink, caps);
if (sink_caps) {
res = gst_caps_can_intersect (sink_caps, caps);
res = !gst_caps_is_empty (sink_caps);
gst_caps_unref (sink_caps);
}
gst_object_unref (sink);
@ -675,7 +672,7 @@ demux_pad_added (GstElement * element, GstPad * pad, RsnDvdBin * dvdbin)
GST_DEBUG_OBJECT (dvdbin, "New pad: %" GST_PTR_FORMAT, pad);
caps = gst_pad_get_caps (pad);
caps = gst_pad_query_caps (pad, NULL);
if (caps == NULL) {
GST_WARNING_OBJECT (dvdbin, "NULL caps from pad %" GST_PTR_FORMAT, pad);
return;
@ -694,9 +691,12 @@ demux_pad_added (GstElement * element, GstPad * pad, RsnDvdBin * dvdbin)
g_return_if_fail (s != NULL);
if (can_sink_caps (dvdbin->pieces[DVD_ELEM_VIDDEC], caps)) {
GST_LOG_OBJECT (dvdbin, "Found video pad w/ caps %" GST_PTR_FORMAT, caps);
dest_pad =
gst_element_get_static_pad (dvdbin->pieces[DVD_ELEM_VIDDEC], "sink");
} else if (g_str_equal (gst_structure_get_name (s), "subpicture/x-dvd")) {
GST_LOG_OBJECT (dvdbin, "Found subpicture pad w/ caps %" GST_PTR_FORMAT,
caps);
dest_pad =
gst_element_get_request_pad (dvdbin->pieces[DVD_ELEM_SPU_SELECT],
"sink_%u");
@ -720,7 +720,7 @@ demux_pad_added (GstElement * element, GstPad * pad, RsnDvdBin * dvdbin)
("No MPEG video decoder found"));
} else {
GST_ELEMENT_WARNING (dvdbin, STREAM, CODEC_NOT_FOUND, (NULL),
("No MPEG audio decoder found"));
("No audio decoder found"));
}
}
@ -763,6 +763,7 @@ demux_no_more_pads (GstElement * element, RsnDvdBin * dvdbin)
gboolean no_more_pads = FALSE;
guint n_audio_pads = 0;
GST_DEBUG_OBJECT (dvdbin, "Received no more pads from demuxer");
DVDBIN_PREROLL_LOCK (dvdbin);
g_object_get (dvdbin->pieces[DVD_ELEM_AUD_SELECT], "n-pads", &n_audio_pads,
@ -781,21 +782,15 @@ demux_no_more_pads (GstElement * element, RsnDvdBin * dvdbin)
}
}
static void
dvdbin_pad_blocked_cb (GstPad * opad, gboolean blocked,
RsnDvdBinPadBlockCtx * ctx)
static GstPadProbeReturn
dvdbin_pad_blocked_cb (GstPad * opad,
GstPadProbeInfo * info, RsnDvdBinPadBlockCtx * ctx)
{
RsnDvdBin *dvdbin;
GstPad *pad;
gboolean added_last_pad = FALSE;
gboolean added = FALSE;
/* If not blocked ctx is NULL! */
if (!blocked) {
GST_DEBUG_OBJECT (opad, "Pad unblocked");
return;
}
dvdbin = ctx->dvdbin;
pad = ctx->pad;
@ -812,8 +807,8 @@ dvdbin_pad_blocked_cb (GstPad * opad, gboolean blocked,
}
DVDBIN_PREROLL_UNLOCK (dvdbin);
gst_pad_set_blocked_async (opad, FALSE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, NULL);
if (ctx->pad_block_id)
gst_pad_remove_probe (opad, ctx->pad_block_id);
} else if (pad == dvdbin->audio_pad) {
GST_DEBUG_OBJECT (opad, "Pad block -> audio pad");
DVDBIN_PREROLL_LOCK (dvdbin);
@ -826,8 +821,8 @@ dvdbin_pad_blocked_cb (GstPad * opad, gboolean blocked,
}
DVDBIN_PREROLL_UNLOCK (dvdbin);
gst_pad_set_blocked_async (opad, FALSE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, NULL);
if (ctx->pad_block_id)
gst_pad_remove_probe (opad, ctx->pad_block_id);
} else if (pad == dvdbin->video_pad) {
GST_DEBUG_OBJECT (opad, "Pad block -> video pad");
@ -842,14 +837,16 @@ dvdbin_pad_blocked_cb (GstPad * opad, gboolean blocked,
}
DVDBIN_PREROLL_UNLOCK (dvdbin);
gst_pad_set_blocked_async (opad, FALSE,
(GstPadBlockCallback) dvdbin_pad_blocked_cb, NULL);
if (ctx->pad_block_id)
gst_pad_remove_probe (opad, ctx->pad_block_id);
}
if (added_last_pad) {
GST_DEBUG_OBJECT (dvdbin, "Firing no more pads from pad-blocked cb");
gst_element_no_more_pads (GST_ELEMENT (dvdbin));
}
return GST_PAD_PROBE_OK;
}
static void

View file

@ -24,11 +24,12 @@
#include <stdio.h>
#include <string.h>
#include <gmodule.h>
#include <gst/gst.h>
#include <gst/glib-compat-private.h>
#include <gst/gst-i18n-plugin.h>
#include <gst/interfaces/navigation.h>
#include <gst/video/video.h>
#include <gst/video/navigation.h>
#include "resindvdsrc.h"
@ -89,6 +90,7 @@ typedef struct
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
// GST_STATIC_CAPS ("video/mpeg,mpegversion=2,systemstream=true")
GST_STATIC_CAPS ("application/x-resin-dvd")
);
@ -100,8 +102,9 @@ static GstFormat chapter_format;
static void rsn_dvdsrc_register_extra (GType rsn_dvdsrc_type);
GST_BOILERPLATE_FULL (resinDvdSrc, rsn_dvdsrc, GstBaseSrc,
GST_TYPE_BASE_SRC, rsn_dvdsrc_register_extra);
#define rsn_dvdsrc_parent_class parent_class
G_DEFINE_TYPE_EXTENDED (resinDvdSrc, rsn_dvdsrc, GST_TYPE_BASE_SRC,
0, rsn_dvdsrc_register_extra (g_define_type_id));
static gboolean read_vts_info (resinDvdSrc * src);
@ -118,11 +121,11 @@ static gboolean rsn_dvdsrc_unlock (GstBaseSrc * bsrc);
static gboolean rsn_dvdsrc_unlock_stop (GstBaseSrc * bsrc);
static gboolean rsn_dvdsrc_is_seekable (GstBaseSrc * bsrc);
static gboolean rsn_dvdsrc_prepare_seek (GstBaseSrc * bsrc, GstEvent * event,
GstSegment * segment);
static gboolean rsn_dvdsrc_prepare_seek (GstBaseSrc * bsrc,
GstEvent * event, GstSegment * segment);
static gboolean rsn_dvdsrc_do_seek (GstBaseSrc * bsrc, GstSegment * segment);
static GstStateChangeReturn
rsn_dvdsrc_change_state (GstElement * element, GstStateChange transition);
static GstStateChangeReturn rsn_dvdsrc_change_state (GstElement * element,
GstStateChange transition);
static void rsn_dvdsrc_prepare_spu_stream_event (resinDvdSrc * src,
guint8 logical_stream, guint8 phys_stream, gboolean forced_only);
@ -142,7 +145,6 @@ static void rsn_dvdsrc_check_nav_blocks (resinDvdSrc * src);
static void rsn_dvdsrc_schedule_nav_cb (resinDvdSrc * src,
RsnDvdPendingNav * next_nav);
static gboolean rsn_dvdsrc_check_get_range (GstBaseSrc * src);
static GstFlowReturn rsn_dvdsrc_create (GstBaseSrc * bsrc, guint64 offset,
guint length, GstBuffer ** buf);
static gboolean rsn_dvdsrc_src_event (GstBaseSrc * basesrc, GstEvent * event);
@ -188,18 +190,6 @@ rsn_dvdsrc_register_extra (GType rsn_dvdsrc_type)
chapter_format = gst_format_register ("chapter", "DVD chapter format");
}
static void
rsn_dvdsrc_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_set_details_simple (element_class, "Resin DVD Src",
"Source/DVD", "DVD source element", "Jan Schmidt <thaytan@noraisin.net>");
}
static void
rsn_dvdsrc_class_init (resinDvdSrcClass * klass)
{
@ -228,8 +218,6 @@ rsn_dvdsrc_class_init (resinDvdSrcClass * klass)
GST_DEBUG_FUNCPTR (rsn_dvdsrc_prepare_seek);
gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (rsn_dvdsrc_do_seek);
gstbasesrc_class->check_get_range =
GST_DEBUG_FUNCPTR (rsn_dvdsrc_check_get_range);
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (rsn_dvdsrc_create);
g_object_class_install_property (gobject_class, ARG_DEVICE,
@ -240,10 +228,15 @@ rsn_dvdsrc_class_init (resinDvdSrcClass * klass)
g_param_spec_boolean ("fast-start", "Fast start",
"Skip straight to the DVD menu on start", DEFAULT_FASTSTART,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_set_details_simple (gstelement_class, "Resin DVD Src",
"Source/DVD", "DVD source element", "Jan Schmidt <thaytan@noraisin.net>");
}
static void
rsn_dvdsrc_init (resinDvdSrc * rsndvdsrc, resinDvdSrcClass * gclass)
rsn_dvdsrc_init (resinDvdSrc * rsndvdsrc)
{
const gchar *envvar;
@ -637,11 +630,9 @@ rsn_dvdsrc_do_still (resinDvdSrc * src, int duration)
* event, then sleep */
still_event = gst_video_event_new_still_frame (TRUE);
gst_segment_set_last_stop (segment, GST_FORMAT_TIME, src->cur_end_ts);
segment->position = src->cur_end_ts;
seg_event = gst_event_new_new_segment_full (TRUE,
segment->rate, segment->applied_rate, segment->format,
segment->start, segment->last_stop, segment->time);
seg_event = gst_event_new_segment (segment);
/* Grab any pending highlight event to send too */
hl_event = src->highlight_event;
@ -757,9 +748,8 @@ rsn_dvdsrc_do_still (resinDvdSrc * src, int duration)
still_event = gst_video_event_new_still_frame (FALSE);
/* If the segment was too short in a timed still, it may need extending */
if (segment->last_stop < segment->start + GST_SECOND * duration)
gst_segment_set_last_stop (segment, GST_FORMAT_TIME,
segment->start + (GST_SECOND * duration));
if (segment->position < segment->start + GST_SECOND * duration)
segment->position = segment->start + (GST_SECOND * duration);
g_mutex_unlock (src->dvd_lock);
gst_pad_push_event (GST_BASE_SRC_PAD (src), still_event);
@ -875,9 +865,7 @@ update_title_info (resinDvdSrc * src, gboolean force)
}
}
if (title_str) {
GstTagList *tags = gst_tag_list_new ();
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE,
title_str, NULL);
GstTagList *tags = gst_tag_list_new (GST_TAG_TITLE, title_str, NULL);
g_free (title_str);
return tags;
}
@ -910,19 +898,18 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
{
GstFlowReturn ret = GST_FLOW_OK;
dvdnav_status_t dvdnav_ret;
guint8 *data;
gint event, len;
GstMapInfo mmap;
/* Allocate an output buffer if there isn't a pending one */
if (src->alloc_buf == NULL) {
src->alloc_buf = gst_buffer_new_and_alloc (DVD_VIDEO_LB_LEN);
gst_buffer_set_caps (src->alloc_buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));
}
if (src->alloc_buf == NULL)
src->alloc_buf = gst_buffer_new_allocate (NULL, DVD_VIDEO_LB_LEN, NULL);
gst_buffer_map (src->alloc_buf, &mmap, GST_MAP_WRITE);
data = GST_BUFFER_DATA (src->alloc_buf);
len = DVD_VIDEO_LB_LEN;
dvdnav_ret = dvdnav_get_next_block (src->dvdnav, data, &event, &len);
dvdnav_ret = dvdnav_get_next_block (src->dvdnav, mmap.data, &event, &len);
if (dvdnav_ret != DVDNAV_STATUS_OK)
goto read_error;
g_mutex_lock (src->branch_lock);
@ -933,10 +920,12 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
switch (event) {
case DVDNAV_BLOCK_OK:
/* Data block that needs outputting */
gst_buffer_unmap (src->alloc_buf, &mmap);
src->next_buf = src->alloc_buf;
src->alloc_buf = NULL;
src->next_is_nav_block = FALSE;
src->next_nav_ts = GST_CLOCK_TIME_NONE;
src->alloc_buf = NULL;
src->in_still_state = FALSE;
break;
case DVDNAV_NAV_PACKET:
@ -988,6 +977,7 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
src->cur_vobu_base_ts = new_base_time;
/* NAV packet is also a data block that needs sending */
gst_buffer_unmap (src->alloc_buf, &mmap);
src->next_buf = src->alloc_buf;
src->alloc_buf = NULL;
@ -1011,11 +1001,11 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
case DVDNAV_STOP:
/* End of the disc. EOS */
dvdnav_reset (src->dvdnav);
ret = GST_FLOW_UNEXPECTED;
ret = GST_FLOW_EOS;
break;
case DVDNAV_STILL_FRAME:
{
dvdnav_still_event_t *info = (dvdnav_still_event_t *) data;
dvdnav_still_event_t *info = (dvdnav_still_event_t *) mmap.data;
if (!have_dvd_lock) {
/* At a still frame but can't block, handle it later */
@ -1042,7 +1032,8 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
goto internal_error;
break;
case DVDNAV_CELL_CHANGE:{
dvdnav_cell_change_event_t *event = (dvdnav_cell_change_event_t *) data;
dvdnav_cell_change_event_t *event =
(dvdnav_cell_change_event_t *) mmap.data;
GstMessage *message;
src->pgc_duration = MPEGTIME_TO_GSTTIME (event->pgc_length);
@ -1067,10 +1058,11 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
break;
}
case DVDNAV_SPU_CLUT_CHANGE:
rsn_dvdsrc_prepare_clut_change_event (src, (const guint32 *) data);
rsn_dvdsrc_prepare_clut_change_event (src, (const guint32 *) mmap.data);
break;
case DVDNAV_VTS_CHANGE:{
dvdnav_vts_change_event_t *event = (dvdnav_vts_change_event_t *) data;
dvdnav_vts_change_event_t *event =
(dvdnav_vts_change_event_t *) mmap.data;
if (dvdnav_is_domain_vmgm (src->dvdnav)) {
src->vts_n = 0;
@ -1089,7 +1081,7 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
}
case DVDNAV_AUDIO_STREAM_CHANGE:{
dvdnav_audio_stream_change_event_t *event =
(dvdnav_audio_stream_change_event_t *) data;
(dvdnav_audio_stream_change_event_t *) mmap.data;
rsn_dvdsrc_prepare_audio_stream_event (src,
event->logical, event->physical);
@ -1100,7 +1092,7 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
}
case DVDNAV_SPU_STREAM_CHANGE:{
dvdnav_spu_stream_change_event_t *event =
(dvdnav_spu_stream_change_event_t *) data;
(dvdnav_spu_stream_change_event_t *) mmap.data;
gint phys_track = event->physical_wide & 0x1f;
gboolean forced_only = (event->physical_wide & 0x80) ? TRUE : FALSE;
@ -1117,7 +1109,7 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
}
case DVDNAV_HIGHLIGHT:{
GST_DEBUG_OBJECT (src, "highlight change event, button %d",
((dvdnav_highlight_event_t *) data)->buttonN);
((dvdnav_highlight_event_t *) mmap.data)->buttonN);
rsn_dvdsrc_update_highlight (src);
break;
}
@ -1131,6 +1123,9 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
GST_WARNING_OBJECT (src, "Unknown dvdnav event %d", event);
break;
}
if (src->alloc_buf) {
gst_buffer_unmap (src->alloc_buf, &mmap);
}
if (src->highlight_event && have_dvd_lock && src->in_playing) {
GstEvent *hl_event = src->highlight_event;
@ -1148,6 +1143,7 @@ rsn_dvdsrc_step (resinDvdSrc * src, gboolean have_dvd_lock)
/* ERRORS */
read_error:
{
gst_buffer_unmap (src->alloc_buf, &mmap);
if (!rsn_descrambler_available ()) {
GST_ELEMENT_ERROR (src, RESOURCE, READ,
(_("Could not read DVD. This may be because the DVD is encrypted "
@ -1163,6 +1159,7 @@ read_error:
}
internal_error:
{
gst_buffer_unmap (src->alloc_buf, &mmap);
GST_ELEMENT_ERROR (src, RESOURCE, READ, (_("Could not read DVD.")),
("Internal error processing DVD commands. Error: %s",
dvdnav_err_to_string (src->dvdnav)));
@ -1171,6 +1168,7 @@ internal_error:
branching:
{
g_mutex_unlock (src->branch_lock);
gst_buffer_unmap (src->alloc_buf, &mmap);
return GST_FLOW_FLUSHING;
}
}
@ -1288,14 +1286,6 @@ rsn_dvdsrc_prepare_next_block (resinDvdSrc * src, gboolean have_dvd_lock)
return ret;
}
static gboolean
rsn_dvdsrc_check_get_range (GstBaseSrc * src)
{
/* ResinDVD never operates in pull mode. There might be
* a reason to in the future though? */
return FALSE;
}
static GstFlowReturn
rsn_dvdsrc_create (GstBaseSrc * bsrc, guint64 offset,
guint length, GstBuffer ** outbuf)
@ -1396,11 +1386,11 @@ rsn_dvdsrc_create (GstBaseSrc * bsrc, guint64 offset,
}
if (src->cur_end_ts != GST_CLOCK_TIME_NONE)
gst_segment_set_last_stop (segment, GST_FORMAT_TIME, src->cur_end_ts);
segment->position = src->cur_end_ts;
if (tags) {
gst_element_found_tags_for_pad (GST_ELEMENT_CAST (src),
GST_BASE_SRC_PAD (src), tags);
GstEvent *tag_event = gst_event_new_tag (tags);
gst_pad_push_event (GST_BASE_SRC_PAD (src), tag_event);
tags = NULL;
}
g_mutex_lock (src->dvd_lock);
@ -2254,7 +2244,15 @@ rsn_dvdsrc_activate_nav_block (resinDvdSrc * src, GstBuffer * nav_buf)
{
int32_t forced_button;
navRead_PCI (&src->cur_pci, GST_BUFFER_DATA (nav_buf) + 0x2d);
{
GstMapInfo mmap;
gst_buffer_map (nav_buf, &mmap, GST_MAP_READ);
navRead_PCI (&src->cur_pci, mmap.data + 0x2d);
gst_buffer_unmap (nav_buf, &mmap);
}
src->have_pci = TRUE;
forced_button = src->cur_pci.hli.hl_gi.fosl_btnn & 0x3f;
@ -2374,7 +2372,8 @@ rsn_dvdsrc_schedule_nav_cb (resinDvdSrc * src, RsnDvdPendingNav * next_nav)
GST_TIME_ARGS (next_nav->running_ts));
g_mutex_unlock (src->dvd_lock);
gst_clock_id_wait_async (src->nav_clock_id, rsn_dvdsrc_nav_clock_cb, src);
gst_clock_id_wait_async (src->nav_clock_id, rsn_dvdsrc_nav_clock_cb, src,
NULL);
gst_object_unref (clock);
g_mutex_lock (src->dvd_lock);
}
@ -2615,6 +2614,16 @@ rsn_dvdsrc_src_query (GstBaseSrc * basesrc, GstQuery * query)
res = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
break;
}
case GST_QUERY_SCHEDULING:
{
/* Make sure we operate in pull mode */
gst_query_set_scheduling (query, GST_SCHEDULING_FLAG_SEQUENTIAL, 1, -1,
0);
gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH);
res = TRUE;
break;
}
default:
res = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
break;
@ -2653,7 +2662,7 @@ rsn_dvdsrc_prepare_seek (GstBaseSrc * bsrc, GstEvent * event,
/* Seeks in our internal formats are passed directly through to the do_seek
* method. */
gst_segment_init (segment, seek_format);
gst_segment_set_seek (segment, rate, seek_format, flags, cur_type, cur,
gst_segment_do_seek (segment, rate, seek_format, flags, cur_type, cur,
stop_type, stop, &update);
return TRUE;
@ -2898,7 +2907,7 @@ rsn_dvdsrc_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
segment->format = GST_FORMAT_TIME;
/* The first TS output: */
segment->last_stop = segment->start = src->cur_start_ts;
segment->position = segment->start = src->cur_start_ts;
/* time field = position is the 'logical' stream time here: */
segment->time = 0;

View file

@ -103,8 +103,6 @@ static void
rsn_audiomunge_init (RsnAudioMunge * munge)
{
munge->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
gst_pad_set_setcaps_function (munge->sinkpad,
GST_DEBUG_FUNCPTR (rsn_audiomunge_set_caps));
gst_pad_set_getcaps_function (munge->sinkpad,
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
gst_pad_set_chain_function (munge->sinkpad,
@ -156,7 +154,6 @@ rsn_audiomunge_set_caps (GstPad * pad, GstCaps * caps)
otherpad = (pad == munge->srcpad) ? munge->sinkpad : munge->srcpad;
ret = gst_pad_set_caps (otherpad, caps);
gst_object_unref (munge);
return ret;
}
@ -238,6 +235,14 @@ rsn_audiomunge_sink_event (GstPad * pad, GstEvent * event)
RsnAudioMunge *munge = RSN_AUDIOMUNGE (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS:
{
GstCaps *caps;
gst_event_parse_caps (event, &caps);
ret = gst_pad_set_caps (munge->src_pad, caps);
gst_event_unref (caps);
}
case GST_EVENT_FLUSH_STOP:
rsn_audiomunge_reset (munge);
ret = gst_pad_push_event (munge->srcpad, event);

View file

@ -23,6 +23,8 @@
#endif
#include <string.h>
#include <gst/video/video.h>
#include <gst/audio/audio.h>
#include "rsndec.h"
@ -53,9 +55,9 @@ rsn_dec_class_init (RsnDecClass * klass)
}
static gboolean
rsn_dec_sink_event (GstPad * pad, GstEvent * event)
rsn_dec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
RsnDec *self = RSN_DEC (gst_pad_get_parent (pad));
RsnDec *self = RSN_DEC (parent);
gboolean ret = TRUE;
const GstStructure *s = gst_event_get_structure (event);
const gchar *name = (s ? gst_structure_get_name (s) : NULL);
@ -63,9 +65,7 @@ rsn_dec_sink_event (GstPad * pad, GstEvent * event)
if (name && g_str_equal (name, "application/x-gst-dvd"))
ret = gst_pad_push_event (GST_PAD_CAST (self->srcpad), event);
else
ret = self->sink_event_func (pad, event);
gst_object_unref (self);
ret = self->sink_event_func (pad, parent, event);
return ret;
}
@ -246,10 +246,13 @@ _get_decoder_factories (gpointer arg)
RsnDecFactoryFilterCtx ctx = { NULL, };
GstCaps *raw;
gboolean raw_audio;
GstRegistry *registry = gst_registry_get ();
ctx.desired_caps = gst_pad_template_get_caps (templ);
raw = gst_caps_from_string ("audio/x-raw-float");
raw =
gst_caps_from_string
("audio/x-raw,format=(string){ F32LE, F32BE, F64LE, F64BE }");
raw_audio = gst_caps_can_intersect (raw, ctx.desired_caps);
if (raw_audio) {
GstCaps *sub = gst_caps_subtract (ctx.desired_caps, raw);
@ -263,7 +266,7 @@ _get_decoder_factories (gpointer arg)
ctx.decoder_caps = gst_caps_new_empty ();
GST_DEBUG ("Finding factories for caps: %" GST_PTR_FORMAT, ctx.desired_caps);
factories = gst_default_registry_feature_filter (
factories = gst_registry_feature_filter (registry,
(GstPluginFeatureFilter) rsndec_factory_filter, FALSE, &ctx);
/* If these are audio caps, we add audioconvert, which is not a decoder,
@ -274,7 +277,7 @@ _get_decoder_factories (gpointer arg)
GstPluginFeature *feature;
GST_DEBUG ("These are audio caps, adding audioconvert");
feature =
gst_default_registry_find_feature ("audioconvert",
gst_registry_find_feature (registry, "audioconvert",
GST_TYPE_ELEMENT_FACTORY);
if (feature) {
factories = g_list_append (factories, feature);
@ -372,23 +375,14 @@ static GstStaticPadTemplate audio_sink_template =
GST_STATIC_CAPS ("audio/mpeg,mpegversion=(int)1;"
"audio/x-private1-lpcm;"
"audio/x-private1-ac3;" "audio/ac3;" "audio/x-ac3;"
"audio/x-private1-dts; audio/x-raw-float")
"audio/x-private1-dts; audio/x-raw,format=(string)"
GST_AUDIO_FORMATS_ALL)
);
static GstStaticPadTemplate audio_src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-float, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) BYTE_ORDER, "
"width = (int) { 32, 64 }; "
"audio/x-raw-int, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) { 1234, 4321 },"
"width = (int) [ 1, 32 ], "
"depth = (int) [ 1, 32 ], " "signed = (boolean) { false, true }")
GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL))
);
G_DEFINE_TYPE (RsnAudioDec, rsn_audiodec, RSN_TYPE_DEC);
@ -438,7 +432,7 @@ GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate video_src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-yuv")
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
);
G_DEFINE_TYPE (RsnVideoDec, rsn_videodec, RSN_TYPE_DEC);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,91 @@
/* GStreamer
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __RSN_INPUT_SELECTOR_H__
#define __RSN_INPUT_SELECTOR_H__
#include <gst/gst.h>
G_BEGIN_DECLS
#define GST_TYPE_INPUT_SELECTOR \
(gst_input_selector_get_type())
#define GST_INPUT_SELECTOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INPUT_SELECTOR, RsnInputSelector))
#define GST_INPUT_SELECTOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INPUT_SELECTOR, RsnInputSelectorClass))
#define GST_IS_INPUT_SELECTOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INPUT_SELECTOR))
#define GST_IS_INPUT_SELECTOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INPUT_SELECTOR))
typedef struct _RsnInputSelector RsnInputSelector;
typedef struct _RsnInputSelectorClass RsnInputSelectorClass;
#define GST_INPUT_SELECTOR_GET_LOCK(sel) (&((RsnInputSelector*)(sel))->lock)
#define GST_INPUT_SELECTOR_GET_COND(sel) (&((RsnInputSelector*)(sel))->cond)
#define GST_INPUT_SELECTOR_LOCK(sel) (g_mutex_lock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
#define GST_INPUT_SELECTOR_UNLOCK(sel) (g_mutex_unlock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
#define GST_INPUT_SELECTOR_WAIT(sel) (g_cond_wait (GST_INPUT_SELECTOR_GET_COND(sel), \
GST_INPUT_SELECTOR_GET_LOCK(sel)))
#define GST_INPUT_SELECTOR_BROADCAST(sel) (g_cond_broadcast (GST_INPUT_SELECTOR_GET_COND(sel)))
/**
* RsnInputSelectorSyncMode:
* @GST_INPUT_SELECTOR_SYNC_MODE_ACTIVE_SEGMENT: Sync using the current active segment.
* @GST_INPUT_SELECTOR_SYNC_MODE_CLOCK: Sync using the clock.
*
* The different ways that input-selector can behave when in sync-streams mode.
*/
typedef enum {
GST_INPUT_SELECTOR_SYNC_MODE_ACTIVE_SEGMENT,
GST_INPUT_SELECTOR_SYNC_MODE_CLOCK
} RsnInputSelectorSyncMode;
struct _RsnInputSelector {
GstElement element;
GstPad *srcpad;
GstPad *active_sinkpad;
guint n_pads;
guint padcount;
gboolean sync_streams;
RsnInputSelectorSyncMode sync_mode;
gboolean cache_buffers;
GMutex lock;
GCond cond;
gboolean blocked;
gboolean flushing;
};
struct _RsnInputSelectorClass {
GstElementClass parent_class;
gint64 (*block) (RsnInputSelector *self);
};
G_GNUC_INTERNAL GType gst_input_selector_get_type (void);
G_END_DECLS
#endif /* __GST_INPUT_SELECTOR_H__ */

View file

@ -1,769 +0,0 @@
/* GStreamer
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
* Copyright (C) 2007 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include "rsnstreamselector.h"
GST_DEBUG_CATEGORY_STATIC (stream_selector_debug);
#define GST_CAT_DEFAULT stream_selector_debug
static GstStaticPadTemplate rsn_stream_selector_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
GST_STATIC_CAPS_ANY);
static GstStaticPadTemplate rsn_stream_selector_src_factory =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
enum
{
PROP_0,
PROP_N_PADS,
PROP_ACTIVE_PAD,
PROP_LAST
};
static gboolean rsn_stream_selector_is_active_sinkpad (RsnStreamSelector * sel,
GstPad * pad);
static GstPad *rsn_stream_selector_get_active (RsnStreamSelector * sel,
GstPad * pad);
static void rsn_stream_selector_set_active (RsnStreamSelector * sel,
GstPad * pad);
static GstPad *rsn_stream_selector_get_linked_pad (GstPad * pad,
gboolean strict);
#define RSN_TYPE_SELECTOR_PAD \
(gst_selector_pad_get_type())
#define GST_SELECTOR_PAD(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), RSN_TYPE_SELECTOR_PAD, RsnSelectorPad))
#define GST_SELECTOR_PAD_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), RSN_TYPE_SELECTOR_PAD, RsnSelectorPadClass))
#define RSN_IS_SELECTOR_PAD(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), RSN_TYPE_SELECTOR_PAD))
#define RSN_IS_SELECTOR_PAD_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), RSN_TYPE_SELECTOR_PAD))
#define GST_SELECTOR_PAD_CAST(obj) \
((RsnSelectorPad *)(obj))
typedef struct _RsnSelectorPad RsnSelectorPad;
typedef struct _RsnSelectorPadClass RsnSelectorPadClass;
struct _RsnSelectorPad
{
GstPad parent;
gboolean active;
gboolean eos;
GstSegment segment;
GstTagList *tags;
};
struct _RsnSelectorPadClass
{
GstPadClass parent;
};
static void gst_selector_pad_class_init (RsnSelectorPadClass * klass);
static void gst_selector_pad_init (RsnSelectorPad * pad);
static void gst_selector_pad_finalize (GObject * object);
static void gst_selector_pad_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static GstPadClass *selector_pad_parent_class = NULL;
static void gst_selector_pad_reset (RsnSelectorPad * pad);
static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
enum
{
PROP_PAD_0,
PROP_PAD_TAGS,
PROP_PAD_ACTIVE,
PROP_PAD_LAST
};
static GType
gst_selector_pad_get_type (void)
{
static GType selector_pad_type = 0;
if (!selector_pad_type) {
static const GTypeInfo selector_pad_info = {
sizeof (RsnSelectorPadClass),
NULL,
NULL,
(GClassInitFunc) gst_selector_pad_class_init,
NULL,
NULL,
sizeof (RsnSelectorPad),
0,
(GInstanceInitFunc) gst_selector_pad_init,
};
selector_pad_type =
g_type_register_static (GST_TYPE_PAD, "RsnSelectorPad",
&selector_pad_info, 0);
}
return selector_pad_type;
}
static void
gst_selector_pad_class_init (RsnSelectorPadClass * klass)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
selector_pad_parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = gst_selector_pad_finalize;
gobject_class->get_property =
GST_DEBUG_FUNCPTR (gst_selector_pad_get_property);
g_object_class_install_property (gobject_class, PROP_PAD_TAGS,
g_param_spec_boxed ("tags", "Tags",
"The currently active tags on the pad", GST_TYPE_TAG_LIST,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_PAD_ACTIVE,
g_param_spec_boolean ("active", "Active",
"If the pad is currently active", FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
gst_selector_pad_init (RsnSelectorPad * pad)
{
gst_selector_pad_reset (pad);
}
static void
gst_selector_pad_finalize (GObject * object)
{
RsnSelectorPad *pad;
pad = GST_SELECTOR_PAD_CAST (object);
if (pad->tags)
gst_tag_list_unref (pad->tags);
G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
}
static void
gst_selector_pad_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
{
RsnSelectorPad *pad;
pad = GST_SELECTOR_PAD (object);
switch (prop_id) {
case PROP_PAD_TAGS:
GST_OBJECT_LOCK (object);
g_value_set_boxed (value, pad->tags);
GST_OBJECT_UNLOCK (object);
break;
case PROP_PAD_ACTIVE:
{
RsnStreamSelector *sel;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
g_value_set_boolean (value, rsn_stream_selector_is_active_sinkpad (sel,
GST_PAD_CAST (pad)));
gst_object_unref (sel);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_selector_pad_reset (RsnSelectorPad * pad)
{
pad->active = FALSE;
pad->eos = FALSE;
gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
}
static gboolean
gst_selector_pad_event (GstPad * pad, GstEvent * event)
{
gboolean res = TRUE;
gboolean forward = TRUE;
RsnStreamSelector *sel;
RsnSelectorPad *selpad;
GstPad *active_sinkpad;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
selpad = GST_SELECTOR_PAD_CAST (pad);
/* only forward if we are dealing with the active sinkpad */
active_sinkpad = rsn_stream_selector_get_active (sel, pad);
forward = (active_sinkpad == pad);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_STOP:
gst_selector_pad_reset (selpad);
break;
case GST_EVENT_NEWSEGMENT:
{
gboolean update;
GstFormat format;
gdouble rate, arate;
gint64 start, stop, time;
gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
&start, &stop, &time);
GST_DEBUG_OBJECT (selpad,
"configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
"format %d, "
"%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
gst_segment_set_newsegment_full (&selpad->segment, update,
rate, arate, format, start, stop, time);
break;
}
case GST_EVENT_TAG:
{
GstTagList *tags;
GST_OBJECT_LOCK (selpad);
if (selpad->tags)
gst_tag_list_unref (selpad->tags);
gst_event_parse_tag (event, &tags);
if (tags)
tags = gst_tag_list_copy (tags);
selpad->tags = tags;
GST_DEBUG_OBJECT (sel, "received tags %" GST_PTR_FORMAT, selpad->tags);
GST_OBJECT_UNLOCK (selpad);
break;
}
case GST_EVENT_CUSTOM_DOWNSTREAM:
{
const GstStructure *structure = gst_event_get_structure (event);
if (structure != NULL &&
gst_structure_has_name (structure, "application/x-gst-dvd")) {
const char *type = gst_structure_get_string (structure, "event");
if (strcmp (type, "select-pad") == 0) {
rsn_stream_selector_set_active (sel, pad);
forward = FALSE;
}
}
}
case GST_EVENT_EOS:
selpad->eos = TRUE;
break;
default:
break;
}
if (forward)
res = gst_pad_push_event (sel->srcpad, event);
else
gst_event_unref (event);
gst_object_unref (sel);
return res;
}
static GstCaps *
gst_selector_pad_getcaps (GstPad * pad)
{
RsnStreamSelector *sel;
GstCaps *caps;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
caps = gst_pad_peer_get_caps (sel->srcpad);
if (caps == NULL)
caps = gst_caps_new_any ();
gst_object_unref (sel);
return caps;
}
static GstFlowReturn
gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
guint size, GstCaps * caps, GstBuffer ** buf)
{
RsnStreamSelector *sel;
GstFlowReturn result;
GstPad *active_sinkpad;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
active_sinkpad = rsn_stream_selector_get_active (sel, pad);
/* Fallback allocation for buffers from pads except the selected one */
if (pad != active_sinkpad) {
GST_DEBUG_OBJECT (sel,
"Pad %s:%s is not selected. Performing fallback allocation",
GST_DEBUG_PAD_NAME (pad));
*buf = NULL;
result = GST_FLOW_OK;
} else {
result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
/* FIXME: HACK. If buffer alloc returns not-linked, perform a fallback
* allocation. This should NOT be necessary, because playbin should
* properly block the source pad from running until it's finished hooking
* everything up, but playbin needs refactoring first. */
if (result == GST_FLOW_NOT_LINKED) {
GST_DEBUG_OBJECT (sel,
"No peer pad yet - performing fallback allocation for pad %s:%s",
GST_DEBUG_PAD_NAME (pad));
*buf = NULL;
result = GST_FLOW_OK;
}
}
gst_object_unref (sel);
return result;
}
static GstFlowReturn
gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
{
RsnStreamSelector *sel;
GstFlowReturn res;
GstPad *active_sinkpad;
RsnSelectorPad *selpad;
GstClockTime timestamp;
GstSegment *seg;
gboolean discont;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
selpad = GST_SELECTOR_PAD_CAST (pad);
seg = &selpad->segment;
active_sinkpad = rsn_stream_selector_get_active (sel, pad);
timestamp = GST_BUFFER_TIMESTAMP (buf);
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
GST_DEBUG_OBJECT (sel, "received timestamp %" GST_TIME_FORMAT,
GST_TIME_ARGS (timestamp));
gst_segment_set_last_stop (seg, seg->format, timestamp);
}
/* Ignore buffers from pads except the selected one */
if (pad != active_sinkpad)
goto ignore;
/* If we just switched pads, mark a discont buffer */
GST_OBJECT_LOCK (sel);
discont = sel->mark_discont;
sel->mark_discont = FALSE;
GST_OBJECT_UNLOCK (sel);
if (discont) {
GST_DEBUG_OBJECT (sel, "Marking buffer discont due to pad switch");
buf = gst_buffer_make_metadata_writable (buf);
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
}
/* forward */
GST_LOG_OBJECT (sel, "Forwarding buffer %p from pad %s:%s", buf,
GST_DEBUG_PAD_NAME (pad));
res = gst_pad_push (sel->srcpad, buf);
done:
gst_object_unref (sel);
return res;
/* dropped buffers */
ignore:
{
GST_DEBUG_OBJECT (sel, "Ignoring buffer %p from pad %s:%s",
buf, GST_DEBUG_PAD_NAME (pad));
gst_buffer_unref (buf);
res = GST_FLOW_NOT_LINKED;
goto done;
}
}
static void rsn_stream_selector_dispose (GObject * object);
static void rsn_stream_selector_init (RsnStreamSelector * sel);
static void rsn_stream_selector_base_init (RsnStreamSelectorClass * klass);
static void rsn_stream_selector_class_init (RsnStreamSelectorClass * klass);
static void rsn_stream_selector_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void rsn_stream_selector_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static GstPad *rsn_stream_selector_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * unused);
static void rsn_stream_selector_release_pad (GstElement * element,
GstPad * pad);
static GstIterator *rsn_stream_selector_iterate_linked_pads (GstPad * pad);
static GstCaps *rsn_stream_selector_getcaps (GstPad * pad);
static GstElementClass *parent_class = NULL;
GType
rsn_stream_selector_get_type (void)
{
static GType stream_selector_type = 0;
if (!stream_selector_type) {
static const GTypeInfo stream_selector_info = {
sizeof (RsnStreamSelectorClass),
(GBaseInitFunc) rsn_stream_selector_base_init,
NULL,
(GClassInitFunc) rsn_stream_selector_class_init,
NULL,
NULL,
sizeof (RsnStreamSelector),
0,
(GInstanceInitFunc) rsn_stream_selector_init,
};
stream_selector_type =
g_type_register_static (GST_TYPE_ELEMENT,
"RsnStreamSelector", &stream_selector_info, 0);
GST_DEBUG_CATEGORY_INIT (stream_selector_debug,
"streamselector", 0, "A stream-selector element");
}
return stream_selector_type;
}
static void
rsn_stream_selector_base_init (RsnStreamSelectorClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details_simple (element_class, "StreamSelector",
"Generic", "N-to-1 input stream_selectoring",
"Julien Moutte <julien@moutte.net>, "
"Ronald S. Bultje <rbultje@ronald.bitfreak.net>, "
"Jan Schmidt <thaytan@mad.scientist.com>, "
"Wim Taymans <wim.taymans@gmail.com>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&rsn_stream_selector_sink_factory));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&rsn_stream_selector_src_factory));
}
static void
rsn_stream_selector_class_init (RsnStreamSelectorClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
gobject_class->dispose = rsn_stream_selector_dispose;
gobject_class->set_property =
GST_DEBUG_FUNCPTR (rsn_stream_selector_set_property);
gobject_class->get_property =
GST_DEBUG_FUNCPTR (rsn_stream_selector_get_property);
g_object_class_install_property (gobject_class, PROP_N_PADS,
g_param_spec_uint ("n-pads", "Number of Pads",
"The number of sink pads", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
g_param_spec_object ("active-pad", "Active Pad",
"The currently active sink pad", GST_TYPE_PAD,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstelement_class->request_new_pad = rsn_stream_selector_request_new_pad;
gstelement_class->release_pad = rsn_stream_selector_release_pad;
}
static void
rsn_stream_selector_init (RsnStreamSelector * sel)
{
sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
gst_pad_set_iterate_internal_links_function (sel->srcpad,
GST_DEBUG_FUNCPTR (rsn_stream_selector_iterate_linked_pads));
gst_pad_set_getcaps_function (sel->srcpad,
GST_DEBUG_FUNCPTR (rsn_stream_selector_getcaps));
gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
/* sinkpad management */
sel->padcount = 0;
sel->active_sinkpad = NULL;
gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
}
static void
rsn_stream_selector_dispose (GObject * object)
{
RsnStreamSelector *sel = RSN_STREAM_SELECTOR (object);
if (sel->active_sinkpad) {
gst_object_unref (sel->active_sinkpad);
sel->active_sinkpad = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
rsn_stream_selector_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
RsnStreamSelector *sel = RSN_STREAM_SELECTOR (object);
switch (prop_id) {
case PROP_ACTIVE_PAD:
{
GstPad *pad = NULL;
pad = g_value_get_object (value);
rsn_stream_selector_set_active (sel, pad);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
rsn_stream_selector_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
RsnStreamSelector *sel = RSN_STREAM_SELECTOR (object);
switch (prop_id) {
case PROP_N_PADS:
GST_OBJECT_LOCK (object);
g_value_set_uint (value, sel->n_pads);
GST_OBJECT_UNLOCK (object);
break;
case PROP_ACTIVE_PAD:{
GST_OBJECT_LOCK (object);
g_value_set_object (value, sel->active_sinkpad);
GST_OBJECT_UNLOCK (object);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GstPad *
rsn_stream_selector_get_linked_pad (GstPad * pad, gboolean strict)
{
RsnStreamSelector *sel;
GstPad *otherpad = NULL;
sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
GST_OBJECT_LOCK (sel);
if (pad == sel->srcpad)
otherpad = sel->active_sinkpad;
else if (pad == sel->active_sinkpad || !strict)
otherpad = sel->srcpad;
if (otherpad)
gst_object_ref (otherpad);
GST_OBJECT_UNLOCK (sel);
gst_object_unref (sel);
return otherpad;
}
static GstCaps *
rsn_stream_selector_getcaps (GstPad * pad)
{
GstPad *otherpad;
GstObject *parent;
GstCaps *caps;
otherpad = rsn_stream_selector_get_linked_pad (pad, FALSE);
parent = gst_object_get_parent (GST_OBJECT (pad));
if (!otherpad) {
GST_DEBUG_OBJECT (parent,
"Pad %s:%s not linked, returning ANY", GST_DEBUG_PAD_NAME (pad));
caps = gst_caps_new_any ();
} else {
GST_DEBUG_OBJECT (parent,
"Pad %s:%s is linked (to %s:%s), returning peer caps",
GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (otherpad));
/* if the peer has caps, use those. If the pad is not linked, this function
* returns NULL and we return ANY */
if (!(caps = gst_pad_peer_get_caps (otherpad)))
caps = gst_caps_new_any ();
gst_object_unref (otherpad);
}
gst_object_unref (parent);
return caps;
}
/* check if the pad is the active sinkpad */
static gboolean
rsn_stream_selector_is_active_sinkpad (RsnStreamSelector * sel, GstPad * pad)
{
gboolean res;
GST_OBJECT_LOCK (sel);
res = (pad == sel->active_sinkpad);
GST_OBJECT_UNLOCK (sel);
return res;
}
/* Get or create the active sinkpad */
static GstPad *
rsn_stream_selector_get_active (RsnStreamSelector * sel, GstPad * pad)
{
GstPad *active_sinkpad;
RsnSelectorPad *selpad;
selpad = GST_SELECTOR_PAD_CAST (pad);
GST_OBJECT_LOCK (sel);
selpad->active = TRUE;
active_sinkpad = sel->active_sinkpad;
if (active_sinkpad == NULL) {
/* first pad we get an alloc on becomes the activated pad by default */
active_sinkpad = sel->active_sinkpad = gst_object_ref (pad);
GST_DEBUG_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
}
GST_OBJECT_UNLOCK (sel);
return active_sinkpad;
}
static void
rsn_stream_selector_set_active (RsnStreamSelector * sel, GstPad * pad)
{
GstPad **active_pad_p;
GST_OBJECT_LOCK (GST_OBJECT_CAST (sel));
if (pad != sel->active_sinkpad) {
RsnSelectorPad *selpad;
selpad = GST_SELECTOR_PAD_CAST (pad);
/* we can only activate pads that have data received */
if (selpad && !selpad->active) {
GST_DEBUG_OBJECT (sel, "No data received on pad %" GST_PTR_FORMAT, pad);
} else {
active_pad_p = &sel->active_sinkpad;
gst_object_replace ((GstObject **) active_pad_p, GST_OBJECT_CAST (pad));
GST_DEBUG_OBJECT (sel, "New active pad is %" GST_PTR_FORMAT,
sel->active_sinkpad);
}
/* Mark the next buffer as discontinuous */
sel->mark_discont = TRUE;
}
GST_OBJECT_UNLOCK (GST_OBJECT_CAST (sel));
}
static GstIterator *
rsn_stream_selector_iterate_linked_pads (GstPad * pad)
{
RsnStreamSelector *sel = RSN_STREAM_SELECTOR (gst_pad_get_parent (pad));
GstPad *otherpad = rsn_stream_selector_get_linked_pad (pad, TRUE);
GstIterator *it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
(GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
if (otherpad)
gst_object_unref (otherpad);
gst_object_unref (sel);
return it;
}
static GstPad *
rsn_stream_selector_request_new_pad (GstElement * element,
GstPadTemplate * templ, const gchar * unused)
{
RsnStreamSelector *sel;
gchar *name = NULL;
GstPad *sinkpad = NULL;
sel = RSN_STREAM_SELECTOR (element);
g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL);
GST_LOG_OBJECT (sel, "Creating new pad %d", sel->padcount);
GST_OBJECT_LOCK (sel);
name = g_strdup_printf ("sink_%u", sel->padcount++);
sinkpad = g_object_new (RSN_TYPE_SELECTOR_PAD,
"name", name, "direction", templ->direction, "template", templ, NULL);
g_free (name);
sel->n_pads++;
GST_OBJECT_UNLOCK (sel);
gst_pad_set_event_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_selector_pad_event));
gst_pad_set_getcaps_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
gst_pad_set_chain_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
gst_pad_set_iterate_internal_links_function (sinkpad,
GST_DEBUG_FUNCPTR (rsn_stream_selector_iterate_linked_pads));
gst_pad_set_bufferalloc_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
gst_pad_set_active (sinkpad, TRUE);
gst_element_add_pad (GST_ELEMENT (sel), sinkpad);
return sinkpad;
}
static void
rsn_stream_selector_release_pad (GstElement * element, GstPad * pad)
{
RsnStreamSelector *sel;
sel = RSN_STREAM_SELECTOR (element);
GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
GST_OBJECT_LOCK (sel);
/* if the pad was the active pad, makes us select a new one */
if (sel->active_sinkpad == pad) {
GST_DEBUG_OBJECT (sel, "Deactivating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
sel->active_sinkpad = NULL;
}
sel->n_pads--;
GST_OBJECT_UNLOCK (sel);
gst_pad_set_active (pad, FALSE);
gst_element_remove_pad (GST_ELEMENT (sel), pad);
}

View file

@ -1,63 +0,0 @@
/* GStreamer
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __RSN_STREAM_SELECTOR_H__
#define __RSN_STREAM_SELECTOR_H__
#include <gst/gst.h>
G_BEGIN_DECLS
#define RSN_TYPE_STREAM_SELECTOR \
(rsn_stream_selector_get_type())
#define RSN_STREAM_SELECTOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), RSN_TYPE_STREAM_SELECTOR, RsnStreamSelector))
#define RSN_STREAM_SELECTOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), RSN_TYPE_STREAM_SELECTOR, RsnStreamSelectorClass))
#define RSN_IS_STREAM_SELECTOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), RSN_TYPE_STREAM_SELECTOR))
#define RSN_IS_STREAM_SELECTOR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), RSN_TYPE_STREAM_SELECTOR))
typedef struct _RsnStreamSelector RsnStreamSelector;
typedef struct _RsnStreamSelectorClass RsnStreamSelectorClass;
struct _RsnStreamSelector {
GstElement element;
GstPad *srcpad;
GstPad *active_sinkpad;
guint n_pads;
guint padcount;
GstSegment segment;
gboolean mark_discont;
};
struct _RsnStreamSelectorClass {
GstElementClass parent_class;
};
GType rsn_stream_selector_get_type (void);
G_END_DECLS
#endif /* __RSN_STREAM_SELECTOR_H__ */