Commit 2c98438c authored by Ronald S. Bultje's avatar Ronald S. Bultje

I'm too lazy to comment this

Original commit message from CVS:
New dxr3 plugins from Martin Soto <soto@informatik.uni-kl.de>
parent bbd6f980
......@@ -292,8 +292,15 @@ dnl ==========================================================================
dnl *** DXR3 card ***
translit(dnm, m, l) AM_CONDITIONAL(USE_DXR3, true)
GST_CHECK_FEATURE(DXR3, [DXR3 hardware mpeg video decoder], dxr3videosink, [
AC_CHECK_HEADER(linux/em8300.h, HAVE_DXR3="yes", HAVE_DXR3="no")
GST_CHECK_FEATURE(DXR3, [DXR3 hardware MPEG DVD decoder],
dxr3videosink dxr3audiosink dxr3spusink, [
HAVE_DXR3=yes
AC_CHECK_HEADER(linux/em8300.h, ,
[ AC_MSG_WARN([DXR3/em8300 header file not found]) &&
HAVE_DXR3=no ] )
AC_CHECK_HEADER(linux/soundcard.h, ,
[ AC_MSG_WARN([Generic sound header file not found]) &&
HAVE_DXR3=no ] )
])
dnl *** OSS audio ***
......
plugindir = $(libdir)/gstreamer-@GST_MAJORMINOR@
plugindir= $(libdir)/gstreamer-@GST_MAJORMINOR@
plugin_LTLIBRARIES = libgstdxr3.la
libgstdxr3_la_SOURCES = gstdxr3videosink.c gstdxr3.c
libgstdxr3_la_SOURCES = dxr3videosink.c dxr3audiosink.c dxr3spusink.c \
dxr3init.c ac3_padder.c dxr3marshal.c
libgstdxr3_la_CFLAGS = $(GST_CFLAGS)
libgstdxr3_la_LIBADD =
libgstdxr3_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstdxr3videosink.h
BUILT_SOURCES = dxr3marshal.c dxr3marshal.h
built_headers = dxr3marshal.h
noinst_HEADERS = dxr3videosink.h dxr3audiosink.h dxr3spusink.h \
dxr3common.h ac3_padder.h
dxr3marshal.h: dxr3marshal.list
glib-genmarshal --header --prefix=dxr3_marshal $^ > dxr3marshal.h.tmp
mv dxr3marshal.h.tmp dxr3marshal.h
dxr3marshal.c: dxr3marshal.list
echo "#include \"dxr3marshal.h\"" >> dxr3marshal.c.tmp
glib-genmarshal --body --prefix=dxr3_marshal $^ >> dxr3marshal.c.tmp
mv dxr3marshal.c.tmp dxr3marshal.c
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* ac3_padder.c: Pad AC3 frames for use with an SPDIF interface.
*
* 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.
*/
#include <stdio.h>
#include <string.h>
#include "ac3_padder.h"
#define IEC61937_DATA_TYPE_AC3 1
struct frmsize_s
{
unsigned short bit_rate;
unsigned short frm_size[3];
};
static const struct frmsize_s frmsizecod_tbl[64] =
{
{ 32 ,{64 ,69 ,96 } },
{ 32 ,{64 ,70 ,96 } },
{ 40 ,{80 ,87 ,120 } },
{ 40 ,{80 ,88 ,120 } },
{ 48 ,{96 ,104 ,144 } },
{ 48 ,{96 ,105 ,144 } },
{ 56 ,{112 ,121 ,168 } },
{ 56 ,{112 ,122 ,168 } },
{ 64 ,{128 ,139 ,192 } },
{ 64 ,{128 ,140 ,192 } },
{ 80 ,{160 ,174 ,240 } },
{ 80 ,{160 ,175 ,240 } },
{ 96 ,{192 ,208 ,288 } },
{ 96 ,{192 ,209 ,288 } },
{ 112 ,{224 ,243 ,336 } },
{ 112 ,{224 ,244 ,336 } },
{ 128 ,{256 ,278 ,384 } },
{ 128 ,{256 ,279 ,384 } },
{ 160 ,{320 ,348 ,480 } },
{ 160 ,{320 ,349 ,480 } },
{ 192 ,{384 ,417 ,576 } },
{ 192 ,{384 ,418 ,576 } },
{ 224 ,{448 ,487 ,672 } },
{ 224 ,{448 ,488 ,672 } },
{ 256 ,{512 ,557 ,768 } },
{ 256 ,{512 ,558 ,768 } },
{ 320 ,{640 ,696 ,960 } },
{ 320 ,{640 ,697 ,960 } },
{ 384 ,{768 ,835 ,1152 } },
{ 384 ,{768 ,836 ,1152 } },
{ 448 ,{896 ,975 ,1344 } },
{ 448 ,{896 ,976 ,1344 } },
{ 512 ,{1024 ,1114 ,1536 } },
{ 512 ,{1024 ,1115 ,1536 } },
{ 576 ,{1152 ,1253 ,1728 } },
{ 576 ,{1152 ,1254 ,1728 } },
{ 640 ,{1280 ,1393 ,1920 } },
{ 640 ,{1280 ,1394 ,1920 } }
};
/* Go one byte forward in the input buffer. */
#define ac3p_in_fw(padder) ((padder)->in_ptr++, (padder)->remaining--)
/* Go one byte forward in the output buffer. */
#define ac3p_out_fw(padder) ((padder)->out_ptr++, (padder)->bytes_to_copy--)
/**
* ac3p_init
* @padder: The padder structure to initialize.
*
* Initializes an AC3 stream padder. This structure can be
* subsequently used to parse an AC3 stream and convert it to IEC958
* (S/PDIF) padded packets.
*/
extern void
ac3p_init(ac3_padder *padder)
{
const char sync[4] = { 0x72, 0xF8, 0x1F, 0x4E };
padder->state = AC3P_STATE_SYNC1;
/* No material to read yet. */
padder->remaining = 0;
/* Initialize the sync bytes in the frame. */
memcpy(padder->frame.header, sync, 4);
}
/**
* ac3_push_data
* @padder The padder structure.
* @data A pointer to a buffer with new data to parse. This should
* correspond to a new piece of a stream containing raw AC3 data.
* @size The number of available bytes in the buffer.
*
* Pushes a new buffer of data to be parsed by the ac3 padder. The
* ac3_parse() function will actually parse the data and report when
* new frames are found. This funcion should only be called once at
* the beginning of the parsing process, or when the ac3_parse()
* function returns the %AC3P_EVENT_PUSH event.
*/
extern void
ac3p_push_data(ac3_padder *padder, guchar *data, guint size)
{
padder->in_ptr = data;
padder->remaining = size;
}
/**
* ac3p_parse
* @padder The padder structure.
*
* Parses the bytes already pushed into the padder structure (see
* ac3p_push_data()) and returns an event value depending on the
* results of the parsing.
*
* Returns: %AC3P_EVENT_FRAME to indicate that a new AC3 was found and
* padded for IEC958 transmission. This frame can be read inmediatly
* with ac3p_frame(). %AC3P_EVENT_PUSH to indicate that new data from
* the input stream must be pushed into the padder using
* ac3p_push_data(). This function should be called again after
* pushing the data.
*/
extern int
ac3p_parse(ac3_padder *padder)
{
while (padder->remaining > 0) {
switch (padder->state) {
case AC3P_STATE_SYNC1:
if (*(padder->in_ptr) == 0x0b) {
/* The first sync byte was found. Go to the next state. */
padder->frame.sync_byte1 = 0x0b;
padder->state = AC3P_STATE_SYNC2;
}
ac3p_in_fw(padder);
break;
case AC3P_STATE_SYNC2:
if (*(padder->in_ptr) == 0x77) {
/* The second sync byte was seen right after the first. Go to
the next state. */
padder->frame.sync_byte2 = 0x77;
padder->state = AC3P_STATE_HEADER;
/* Skip one byte. */
ac3p_in_fw(padder);
/* Prepare for reading the header. */
padder->out_ptr = (guchar *) &(padder->frame.crc1);
/* Discount the 2 sync bytes from the header size. */
padder->bytes_to_copy = AC3P_AC3_HEADER_SIZE - 2;
}
else {
/* The second sync byte was not seen. Go back to the
first state. */
padder->state = AC3P_STATE_SYNC1;
}
break;
case AC3P_STATE_HEADER:
if (padder->bytes_to_copy > 0) {
/* Copy one byte. */
*(padder->out_ptr) = *(padder->in_ptr);
ac3p_in_fw(padder);
ac3p_out_fw(padder);
}
else {
int fscod;
/* The header is ready: */
fscod = (padder->frame.code >> 6) & 0x03;
/* Calculate the frame size. */
padder->ac3_frame_size =
2 * frmsizecod_tbl[padder->frame.code & 0x3f].frm_size[fscod];
/* Set up the IEC header. */
if (padder->ac3_frame_size > 0) {
padder->frame.header[4] = IEC61937_DATA_TYPE_AC3;
}
else {
/* Don't know what it is, better be careful. */
padder->state = AC3P_STATE_SYNC1;
break;
}
padder->frame.header[5] = 0x00;
padder->frame.header[6] = (padder->ac3_frame_size*8) & 0xFF;
padder->frame.header[7] = ((padder->ac3_frame_size*8) >> 8) & 0xFF;
/* Prepare for reading the body. */
padder->bytes_to_copy = padder->ac3_frame_size - AC3P_AC3_HEADER_SIZE;
padder->state = AC3P_STATE_CONTENT;
}
break;
case AC3P_STATE_CONTENT:
if (padder->bytes_to_copy > 0) {
/* Copy one byte. */
*(padder->out_ptr) = *(padder->in_ptr);
ac3p_in_fw(padder);
ac3p_out_fw(padder);
}
else {
guint16 *ptr, i;
/* Frame ready. Prepare for output: */
/* Zero the non AC3 portion of the padded frame. */
memset(&(padder->frame.sync_byte1) + padder->ac3_frame_size, 0,
AC3P_IEC_FRAME_SIZE - AC3P_IEC_HEADER_SIZE - padder->ac3_frame_size);
/* Fix the byte order in the AC3 portion: */
ptr = (guint16 *) &(padder->frame.sync_byte1);
i = padder->ac3_frame_size / 2;
while (i > 0) {
*ptr = GUINT16_TO_BE(*ptr);
ptr++;
i--;
}
/* Start over again. */
padder->state = AC3P_STATE_SYNC1;
return AC3P_EVENT_FRAME;
}
break;
}
}
return AC3P_EVENT_PUSH;
}
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* ac3_padder.h: Pad AC3 frames for use with an SPDIF interface.
*
* 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 AC3_PADDER_INC
#define AC3_PADDER_INC
#include <glib.h>
/* Size of an IEC958 padded AC3 frame. */
#define AC3P_IEC_FRAME_SIZE 6144
/* Size of the IEC958 header. */
#define AC3P_IEC_HEADER_SIZE 8
/* Size of the AC3 header. */
#define AC3P_AC3_HEADER_SIZE 7
/* An IEC958 padded AC3 frame. */
typedef struct {
/* IEC header. */
guchar header[AC3P_IEC_HEADER_SIZE];
/* Begin of AC3 header. */
guchar sync_byte1;
guchar sync_byte2;
guchar crc1[2];
guchar code;
guchar bsidmod;
guchar acmod;
/* End of AC3 header. */
unsigned char data[AC3P_IEC_FRAME_SIZE - AC3P_IEC_HEADER_SIZE
- AC3P_AC3_HEADER_SIZE];
} ac3p_iec958_burst_frame;
/* Possible states for the reading automaton: */
/* Searching for sync byte 1. */
#define AC3P_STATE_SYNC1 1
/* Searching for sync byte 2. */
#define AC3P_STATE_SYNC2 2
/* Reading AC3 header. */
#define AC3P_STATE_HEADER 3
/* Reading packet contents.*/
#define AC3P_STATE_CONTENT 4
/* Events generated by the parse function: */
/* The parser needs new data to be pushed. */
#define AC3P_EVENT_PUSH 1
/* There is a new padded frame ready to read from the padder structure. */
#define AC3P_EVENT_FRAME 2
/* The internal state for the padder. */
typedef struct {
guint state; /* State of the reading automaton. */
guchar *in_ptr; /* Input pointer, marking the current
postion in the input buffer. */
guint remaining; /* The number of bytes remaining in the current
reading buffer. */
guchar *out_ptr; /* Output pointer, marking the current
position in the output frame. */
guint bytes_to_copy;
/* Number of bytes that still must be copied
to the output frame *during this reading
stage*. */
guint ac3_frame_size;
/* The size in bytes of the pure AC3 portion
of the current frame. */
ac3p_iec958_burst_frame frame;
/* The current output frame. */
} ac3_padder;
extern void
ac3p_init(ac3_padder *padder);
extern void
ac3p_push_data(ac3_padder *padder, guchar *data, guint size);
extern int
ac3p_parse(ac3_padder *padder);
/**
* ac3p_frame
* @padder The padder structure.
*
* Returns a pointer to the padded frame contained in the padder.
*/
#define ac3p_frame(padder) ((guint *) &((padder)->frame))
/**
* ac3p_frame_size
* @padder The padder structure.
*
* Returns the length in bytes of the last read raw AC3 frame.
*/
#define ac3p_frame_size(padder) ((padder)->ac3_frame_size)
#endif
This diff is collapsed.
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* dxr3audiosink.h: Audio sink for em8300 based DVD cards.
*
* 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 __DXR3AUDIOSINK_H__
#define __DXR3AUDIOSINK_H__
#include <gst/gst.h>
#include "ac3_padder.h"
G_BEGIN_DECLS
#define GST_TYPE_DXR3AUDIOSINK \
(dxr3audiosink_get_type())
#define DXR3AUDIOSINK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DXR3AUDIOSINK,Dxr3AudioSink))
#define DXR3AUDIOSINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DXR3AUDIOSINK,Dxr3AudioSinkClass))
#define GST_IS_DXR3AUDIOSINK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DXR3AUDIOSINK))
#define GST_IS_DXR3AUDIOSINK_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DXR3AUDIOSINK))
typedef struct _Dxr3AudioSink Dxr3AudioSink;
typedef struct _Dxr3AudioSinkClass Dxr3AudioSinkClass;
typedef enum {
DXR3AUDIOSINK_OPEN = GST_ELEMENT_FLAG_LAST,
DXR3AUDIOSINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2,
} Dxr3AudioSinkFlags;
/* PCM or AC3? */
typedef enum {
DXR3AUDIOSINK_MODE_NONE, /* No mode set. */
DXR3AUDIOSINK_MODE_AC3, /* AC3 out. */
DXR3AUDIOSINK_MODE_PCM, /* PCM out. */
} Dxr3AudioSinkMode;
/* Information for a delayed SCR set operation. */
typedef struct {
struct _Dxr3AudioSink *sink;
guint32 scr;
} Dxr3AudioSinkDelayedSCR;
struct _Dxr3AudioSink {
GstElement element;
GstPad *pcm_sinkpad; /* The AC3 audio sink pad. */
GstPad *ac3_sinkpad; /* The PCM audio sink pad. */
int card_number; /* The number of the card to open. */
gchar *audio_filename; /* File name for the audio device. */
int audio_fd; /* File descriptor for the audio device. */
gchar *control_filename; /* File name for the control device. */
int control_fd; /* File descriptor for the control
device. */
guint64 scr; /* The current System Reference Clock value
for the audio stream. */
gboolean digital_pcm; /* Should PCM use the digital or the
analog output? */
Dxr3AudioSinkMode mode; /* The current sound output mode. */
gint rate; /* The sampling rate for PCM sound. */
ac3_padder *padder; /* AC3 to SPDIF padder object. */
GstClock *clock; /* The clock for this element. */
};
struct _Dxr3AudioSinkClass {
GstElementClass parent_class;
/* signals */
void (*flushed) (Dxr3AudioSink *sink);
};
extern GType dxr3audiosink_get_type (void);
extern gboolean dxr3audiosink_factory_init (GstPlugin *plugin);
G_END_DECLS
#endif /* __DXR3AUDIOINK_H__ */
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* dxr3videosink.h: Common declarations for the DXR3 plugin.
*
* 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 __DXR3COMMON_H__
#define __DXR3COMMON_H__
/* Convert from GStreamer time to MPEG time. */
#define GSTTIME_TO_MPEGTIME(time) (((time) * 9) / (GST_MSECOND/10))
/* The em8300 driver expresses time in units of 1/45000 of second. */
/* Convert from MPEG time to em8300 time. */
#define MPEGTIME_TO_DXRTIME(time) ((guint32) ((time) >> 1))
/* Convert from em8300 time to GStreamer time. */
#define DXRTIME_TO_GSTTIME(time) \
((GstClockTime) ((double) (time) * (((double) GST_MSECOND) / 45.0)))
#endif /* __DXR3COMMON_H__ */
/* GStreamer DXR3 Hardware MPEG video decoder plugin
* Copyright (C) <2002> Rehan Khwaja <rehankhwaja@yahoo.com>
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* dxr3init.c: DXR3 plugin initialization.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -17,69 +19,33 @@
* Boston, MA 02111-1307, USA.
*/
#include "dxr3videosink.h"
#include "dxr3spusink.h"
#include "dxr3audiosink.h"
#ifndef __GST_DXR3_VIDEO_SINK_H__
#define __GST_DXR3_VIDEO_SINK_H__
#include <gst/gst.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _GstDxr3VideoSink GstDxr3VideoSink;
struct _GstDxr3VideoSink;
struct _GstDxr3VideoSink {
GstElement element;
static gboolean
plugin_init (GModule *module, GstPlugin *plugin)
{
gboolean ret;
/* board number */
gint device_number;
ret = dxr3videosink_factory_init (plugin);
g_return_val_if_fail (ret == TRUE, FALSE);
/* file handle for the video device */
FILE *device;
ret = dxr3spusink_factory_init (plugin);
g_return_val_if_fail (ret == TRUE, FALSE);
GstClock *clock;
/* our only pad */
GstPad *sinkpad;
};
ret = dxr3audiosink_factory_init (plugin);
g_return_val_if_fail (ret == TRUE, FALSE);
return TRUE;
}
typedef struct _GstDxr3VideoSinkClass GstDxr3VideoSinkClass;
struct _GstDxr3VideoSinkClass {
GstElementClass parent_class;
GstPluginDesc plugin_desc = {
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"dxr3",
plugin_init
};
#define GST_TYPE_DXR3_VIDEO_SINK \
(gst_dxr3_video_sink_get_type())
#define GST_DXR3_VIDEO_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DXR3_VIDEO_SINK,GstDxr3VideoSink))
#define GST_DXR3_VIDEO_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DXR3_VIDEO_SINK,GstDxr3VideoSink))
#define GST_IS_DXR3_VIDEO_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DXR3_VIDEO_SINK))
#define GST_IS_DXR3_VIDEO_SINK_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DXR3_VIDEO_SINK))
GType gst_dxr3_video_sink_get_type(void);
GST_PAD_TEMPLATE_FACTORY (dxr3_video_sink_factory,
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
gst_caps_new ("video_sink", "video/mpeg", NULL)
);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GST_DXR3_VIDEO_SINK_H__ */
VOID:VOID
VOID:BOOLEAN
VOID:POINTER
VOID:UINT,UINT,UINT,UINT,UINT,UINT
This diff is collapsed.
/* GStreamer
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
*
* dxr3spusink.h: Subpicture sink for em8300 based cards.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public