I'm too lazy to comment this
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>
Thu, 29 May 2003 14:35:24 +0000 (14:35 +0000)
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>
Thu, 29 May 2003 14:35:24 +0000 (14:35 +0000)
Original commit message from CVS:
New dxr3 plugins from Martin Soto <soto@informatik.uni-kl.de>

16 files changed:
configure.ac
sys/dxr3/Makefile.am
sys/dxr3/ac3_padder.c [new file with mode: 0644]
sys/dxr3/ac3_padder.h [new file with mode: 0644]
sys/dxr3/dxr3audiosink.c [new file with mode: 0644]
sys/dxr3/dxr3audiosink.h [new file with mode: 0644]
sys/dxr3/dxr3common.h [new file with mode: 0644]
sys/dxr3/dxr3init.c [new file with mode: 0644]
sys/dxr3/dxr3marshal.list [new file with mode: 0644]
sys/dxr3/dxr3spusink.c [new file with mode: 0644]
sys/dxr3/dxr3spusink.h [new file with mode: 0644]
sys/dxr3/dxr3videosink.c [new file with mode: 0644]
sys/dxr3/dxr3videosink.h [new file with mode: 0644]
sys/dxr3/gstdxr3.c [deleted file]
sys/dxr3/gstdxr3videosink.c [deleted file]
sys/dxr3/gstdxr3videosink.h [deleted file]

index ba930d4..d1681d1 100644 (file)
@@ -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 ***
index 05e969a..b0309af 100644 (file)
@@ -1,11 +1,25 @@
-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
 
diff --git a/sys/dxr3/ac3_padder.c b/sys/dxr3/ac3_padder.c
new file mode 100644 (file)
index 0000000..f6ff270
--- /dev/null
@@ -0,0 +1,255 @@
+/* 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;
+}
+
diff --git a/sys/dxr3/ac3_padder.h b/sys/dxr3/ac3_padder.h
new file mode 100644 (file)
index 0000000..c9a7447
--- /dev/null
@@ -0,0 +1,129 @@
+/* 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
diff --git a/sys/dxr3/dxr3audiosink.c b/sys/dxr3/dxr3audiosink.c
new file mode 100644 (file)
index 0000000..4101209
--- /dev/null
@@ -0,0 +1,810 @@
+/* GStreamer
+ * Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
+ *
+ * dxr3audiosink.c: 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.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <linux/soundcard.h>
+#include <linux/em8300.h>
+
+#include <gst/gst.h>
+
+#include "dxr3audiosink.h"
+#include "dxr3marshal.h"
+#include "dxr3common.h"
+
+/* Our only supported AC3 byte rate. */
+#define AC3_BYTE_RATE 48000
+
+/* Determines the amount of time to play the given number of bytes of
+   the original AC3 stream.  The result is expressed as MPEG2. */
+#define TIME_FOR_BYTES(bytes) (((bytes) * 90) / 48)
+
+
+/* ElementFactory information. */
+static GstElementDetails dxr3audiosink_details = {
+  "dxr3/Hollywood+ mpeg decoder board audio plugin",
+  "audio/raw|a52",
+  "GPL",
+  "Feeds audio to Sigma Designs em8300 based boards",
+  VERSION,
+  "Martin Soto <martinsoto@users.sourceforge.net>",
+  "(C) 2003",
+};
+
+
+/* Dxr3AudioSink signals and args */
+enum {
+  SIGNAL_FLUSHED,
+  LAST_SIGNAL
+};
+
+enum {
+  ARG_0,
+  ARG_DIGITAL_PCM
+};
+
+
+GST_PAD_TEMPLATE_FACTORY (dxr3audiosink_pcm_sink_factory,
+  "pcm_sink",
+  GST_PAD_SINK,
+  GST_PAD_ALWAYS,
+  GST_CAPS_NEW (
+    "dxr3audiosink_pcm_sink",
+    "audio/raw",
+      "format",            GST_PROPS_STRING ("int"),
+       "law",              GST_PROPS_INT (0),
+       "endianness",       GST_PROPS_INT (G_BYTE_ORDER),
+       "signed",           GST_PROPS_BOOLEAN (TRUE),
+       "width",            GST_PROPS_INT (16),
+       "depth",            GST_PROPS_INT (16),
+       "rate",             GST_PROPS_LIST (
+                            GST_PROPS_INT (32000),
+                            GST_PROPS_INT (44100),
+                            GST_PROPS_INT (48000),
+                            GST_PROPS_INT (66000)
+                           ),
+       "channels",         GST_PROPS_INT (2)
+  )
+)
+
+GST_PAD_TEMPLATE_FACTORY (dxr3audiosink_ac3_sink_factory,
+  "ac3_sink",
+  GST_PAD_SINK,
+  GST_PAD_ALWAYS,
+  GST_CAPS_NEW (
+    "dxr3audiosink_ac3_sink",
+    "audio/a52",
+    NULL
+  )
+)
+
+
+GST_PAD_EVENT_MASK_FUNCTION(dxr3audiosink_get_event_mask,
+  { GST_EVENT_FLUSH, 0 },
+  { GST_EVENT_DISCONTINUOUS, 0 },
+  { GST_EVENT_NEW_MEDIA, 0 },
+  { GST_EVENT_EOS, 0 }
+)
+
+
+static void    dxr3audiosink_class_init        (Dxr3AudioSinkClass *klass);
+static void    dxr3audiosink_init              (Dxr3AudioSink *sink);
+
+static void    dxr3audiosink_set_property      (GObject *object,
+                                                 guint prop_id, 
+                                                 const GValue *value,
+                                                 GParamSpec *pspec);
+static void    dxr3audiosink_get_property      (GObject *object,
+                                                 guint prop_id, 
+                                                GValue *value,
+                                                 GParamSpec *pspec);
+
+static gboolean dxr3audiosink_open             (Dxr3AudioSink *sink);
+static gboolean dxr3audiosink_set_mode_pcm     (Dxr3AudioSink *sink);
+static gboolean dxr3audiosink_set_mode_ac3     (Dxr3AudioSink *sink);
+static void    dxr3audiosink_close             (Dxr3AudioSink *sink);
+static void    dxr3audiosink_set_clock         (GstElement *element,
+                                                 GstClock *clock);
+
+static GstPadLinkReturn        dxr3audiosink_pcm_sinklink (GstPad *pad,
+                                                    GstCaps *caps);
+static void    dxr3audiosink_set_scr           (Dxr3AudioSink *sink,
+                                                 guint32 scr);
+
+static gboolean dxr3audiosink_handle_event      (GstPad *pad,
+                                                 GstEvent *event);
+static void    dxr3audiosink_chain_pcm         (GstPad *pad,GstBuffer *buf);
+static void    dxr3audiosink_chain_ac3         (GstPad *pad, GstBuffer *buf);
+
+/* static void dxr3audiosink_wait              (Dxr3AudioSink *sink, */
+/*                                                  GstClockTime time); */
+/* static int  dxr3audiosink_mvcommand         (Dxr3AudioSink *sink, */
+/*                                                  int command); */
+
+static GstElementStateReturn dxr3audiosink_change_state (GstElement *element);
+
+static void    dxr3audiosink_flushed           (Dxr3AudioSink *sink);
+
+static GstElementClass *parent_class = NULL;
+static guint dxr3audiosink_signals[LAST_SIGNAL] = { 0 };
+
+
+extern GType
+dxr3audiosink_get_type (void) 
+{
+  static GType dxr3audiosink_type = 0;
+
+  if (!dxr3audiosink_type) {
+    static const GTypeInfo dxr3audiosink_info = {
+      sizeof(Dxr3AudioSinkClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) dxr3audiosink_class_init,
+      NULL,
+      NULL,
+      sizeof (Dxr3AudioSink),
+      0,
+      (GInstanceInitFunc) dxr3audiosink_init,
+    };
+    dxr3audiosink_type = g_type_register_static (GST_TYPE_ELEMENT,
+                                                 "Dxr3AudioSink",
+                                                 &dxr3audiosink_info, 0);
+  }
+
+  return dxr3audiosink_type;
+}
+
+
+static void
+dxr3audiosink_class_init (Dxr3AudioSinkClass *klass) 
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+
+  gobject_class = (GObjectClass*)klass;
+  gstelement_class = (GstElementClass*)klass;
+
+  parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+
+  dxr3audiosink_signals[SIGNAL_FLUSHED] =
+    g_signal_new ("flushed", G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (Dxr3AudioSinkClass, flushed),
+                  NULL, NULL,
+                  dxr3_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+  klass->flushed = dxr3audiosink_flushed;
+
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DIGITAL_PCM,
+    g_param_spec_boolean ("digital-pcm", "Digital PCM",
+                          "Use the digital output for PCM sound",
+                          FALSE, G_PARAM_READWRITE)); 
+
+  gobject_class->set_property = dxr3audiosink_set_property;
+  gobject_class->get_property = dxr3audiosink_get_property;
+
+  gstelement_class->change_state = dxr3audiosink_change_state;
+  gstelement_class->set_clock = dxr3audiosink_set_clock;
+}
+
+
+static void 
+dxr3audiosink_init (Dxr3AudioSink *sink) 
+{
+  GstCaps *caps;
+  GstPadTemplate *temp;
+
+  /* Create the PCM pad. */
+  temp = GST_PAD_TEMPLATE_GET (dxr3audiosink_pcm_sink_factory);
+  sink->pcm_sinkpad = gst_pad_new_from_template (temp, "pcm_sink");
+  gst_pad_set_chain_function (sink->pcm_sinkpad, dxr3audiosink_chain_pcm);
+  gst_pad_set_link_function (sink->pcm_sinkpad, dxr3audiosink_pcm_sinklink);
+  gst_element_add_pad (GST_ELEMENT (sink), sink->pcm_sinkpad);
+
+  /* Create the AC3 pad. */
+  temp = GST_PAD_TEMPLATE_GET (dxr3audiosink_ac3_sink_factory);
+  sink->ac3_sinkpad = gst_pad_new_from_template (temp, "ac3_sink");
+  caps = gst_pad_template_get_caps (temp);
+  gst_pad_try_set_caps (sink->ac3_sinkpad, caps);
+  gst_caps_unref (caps);
+  gst_pad_set_chain_function (sink->ac3_sinkpad, dxr3audiosink_chain_ac3);
+  gst_element_add_pad (GST_ELEMENT (sink), sink->ac3_sinkpad);
+
+  GST_FLAG_SET (GST_ELEMENT(sink), GST_ELEMENT_EVENT_AWARE);
+  gst_pad_set_event_function (sink->pcm_sinkpad, dxr3audiosink_handle_event);
+  gst_pad_set_event_mask_function (sink->pcm_sinkpad,
+                                   dxr3audiosink_get_event_mask);
+  gst_pad_set_event_function (sink->ac3_sinkpad, dxr3audiosink_handle_event);
+  gst_pad_set_event_mask_function (sink->ac3_sinkpad,
+                                   dxr3audiosink_get_event_mask);
+
+  sink->card_number = 0;
+
+  sink->audio_filename = NULL;
+  sink->audio_fd = -1;
+
+  sink->control_filename = NULL;
+  sink->control_fd = -1;
+
+  /* Since we don't know any better, we set the initial scr to 0. */
+  sink->scr = 0;
+
+  /* Initially don't use digital output. */
+  sink->digital_pcm = FALSE;
+
+  /* Initially there's no padder.*/
+  sink->padder = NULL;
+
+  sink->mode = DXR3AUDIOSINK_MODE_NONE;
+}
+
+
+static void
+dxr3audiosink_set_property (GObject *object, guint prop_id,
+                           const GValue *value, GParamSpec *pspec)
+{
+  Dxr3AudioSink *sink;
+
+  /* it's not null if we got it, but it might not be ours */
+  sink = DXR3AUDIOSINK (object);
+
+  switch (prop_id) {
+  case ARG_DIGITAL_PCM:
+    sink->digital_pcm = g_value_get_boolean (value);
+    /* Refresh the setup of the device. */
+    if (sink->mode == DXR3AUDIOSINK_MODE_PCM) {
+      dxr3audiosink_set_mode_pcm (sink);
+    }
+    g_object_notify (G_OBJECT (sink), "digital-pcm");
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+
+static void   
+dxr3audiosink_get_property (GObject *object, guint prop_id,
+                            GValue *value, GParamSpec *pspec)
+{
+  Dxr3AudioSink *sink;
+  /* it's not null if we got it, but it might not be ours */
+  g_return_if_fail (GST_IS_DXR3AUDIOSINK (object));
+  sink = DXR3AUDIOSINK (object);
+  
+  switch (prop_id) {
+  case ARG_DIGITAL_PCM:
+    g_value_set_boolean (value, sink->digital_pcm);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+
+static gboolean
+dxr3audiosink_open (Dxr3AudioSink *sink)
+{
+  g_return_val_if_fail (!GST_FLAG_IS_SET (sink,
+                                          DXR3AUDIOSINK_OPEN), FALSE);
+
+  /* Compute the name of the audio device file. */
+  sink->audio_filename = g_strdup_printf ("/dev/em8300_ma-%d",
+                                          sink->card_number );
+
+  sink->audio_fd = open (sink->audio_filename, O_WRONLY);
+  if (sink->audio_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                      g_strconcat ("Error opening device file \"",
+                                  sink->audio_filename, "\": ",
+                                  g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Open the control device. */
+  sink->control_filename = g_strdup_printf ("/dev/em8300-%d",
+                                            sink->card_number );
+
+  sink->control_fd = open (sink->control_filename, O_WRONLY);
+  if (sink->control_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error opening device file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  GST_FLAG_SET (sink, DXR3AUDIOSINK_OPEN);
+
+  dxr3audiosink_set_mode_pcm (sink);
+
+  return TRUE;
+}
+
+
+/**
+ * dxr3audiosink_set_mode:
+ * @sink: The sink element to operate on.
+ *
+ * Set the operation mode of the element to PCM.
+ */
+static gboolean
+dxr3audiosink_set_mode_pcm (Dxr3AudioSink *sink)
+{
+  int tmp, oss_mode, audiomode;
+
+  if (sink->audio_fd == -1 || sink->control_fd == -1) {
+    return FALSE;
+  }
+
+  /* Set the audio device mode. */
+  oss_mode = (G_BYTE_ORDER == G_BIG_ENDIAN ? AFMT_S16_BE : AFMT_S16_LE);
+  tmp = oss_mode;
+  if (ioctl (sink->audio_fd, SNDCTL_DSP_SETFMT, &tmp) < 0 ||
+      tmp != oss_mode) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error configuring device mode for \"",
+                                    sink->audio_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Set the card's general audio output mode. */
+  audiomode = sink->digital_pcm ?
+    EM8300_AUDIOMODE_DIGITALPCM : EM8300_AUDIOMODE_ANALOG;
+  ioctl (sink->control_fd, EM8300_IOCTL_SET_AUDIOMODE, &audiomode);
+
+  /* Set the sampling rate. */
+  tmp = sink->rate;
+  if (ioctl (sink->audio_fd, SNDCTL_DSP_SPEED, &tmp) < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error configuring device "
+                                    "sampling rate for \"",
+                                    sink->audio_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Get rid of the padder, if any. */
+  if (sink->padder != NULL) {
+    g_free(sink->padder);
+    sink->padder = NULL;
+  }
+
+  sink->mode = DXR3AUDIOSINK_MODE_PCM;
+
+  return TRUE;
+}
+
+
+/**
+ * dxr3audiosink_set_mode:
+ * @sink: The sink element to operate on
+ *
+ * Set the operation mode of the element to AC3.
+ */
+static gboolean
+dxr3audiosink_set_mode_ac3 (Dxr3AudioSink *sink)
+{
+  int tmp, audiomode; 
+
+  if (sink->audio_fd == -1 || sink->control_fd == -1) {
+    return FALSE;
+  }
+
+  /* Set the sampling rate. */
+  tmp = AC3_BYTE_RATE;
+  if (ioctl (sink->audio_fd, SNDCTL_DSP_SPEED, &tmp) < 0 ||
+      tmp != AC3_BYTE_RATE) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error configuring device "
+                                    "sampling rate for \"",
+                                    sink->audio_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Set the card's general audio output mode to AC3. */
+  audiomode = EM8300_AUDIOMODE_DIGITALAC3;
+  ioctl (sink->control_fd, EM8300_IOCTL_SET_AUDIOMODE, &audiomode);
+
+  /* Create a padder if necessary, */
+  if (sink->padder == NULL) {
+      sink->padder = g_malloc (sizeof(ac3_padder));
+      ac3p_init(sink->padder);
+  }
+
+  sink->mode = DXR3AUDIOSINK_MODE_AC3;
+
+  return TRUE;
+}
+
+
+static void
+dxr3audiosink_close (Dxr3AudioSink *sink)
+{
+  g_return_if_fail (GST_FLAG_IS_SET (sink, DXR3AUDIOSINK_OPEN));
+
+  if (close (sink->audio_fd) != 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->audio_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  if (close (sink->control_fd) != 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  GST_FLAG_UNSET (sink, DXR3AUDIOSINK_OPEN);
+
+  g_free (sink->audio_filename);
+  sink->audio_filename = NULL;
+
+  g_free (sink->control_filename);
+  sink->control_filename = NULL;
+
+  /* Get rid of the padder, if any. */
+  if (sink->padder != NULL) {
+    g_free(sink->padder);
+    sink->padder = NULL;
+  }
+}
+
+
+static void
+dxr3audiosink_set_clock (GstElement *element, GstClock *clock)
+{
+  Dxr3AudioSink *src = DXR3AUDIOSINK (element);
+
+  src->clock = clock;
+}
+
+
+static GstPadLinkReturn
+dxr3audiosink_pcm_sinklink (GstPad *pad, GstCaps *caps)
+{
+  Dxr3AudioSink *sink = DXR3AUDIOSINK (gst_pad_get_parent (pad));
+  const gchar* mimetype;
+  gint rate;
+
+  if (!GST_CAPS_IS_FIXED(caps)) {
+    return GST_PAD_LINK_DELAYED;
+  }
+
+  mimetype = gst_caps_get_mime(caps);
+  if (strcmp (mimetype, "audio/raw") != 0) {
+    return GST_PAD_LINK_REFUSED;
+  }
+
+  if (!gst_caps_has_property (caps, "rate")) {
+    return GST_PAD_LINK_REFUSED;
+  }
+
+  gst_caps_get_int (caps, "rate", &rate);
+  if (rate != 32000 && rate != 44100 &&
+      rate != 48000 && rate != 66000) {
+    return GST_PAD_LINK_DELAYED;
+  }
+  sink->rate = rate;
+
+  return GST_PAD_LINK_OK;
+}
+
+
+static void
+dxr3audiosink_set_scr (Dxr3AudioSink *sink, guint32 scr)
+{
+  guint32 zero = 0;
+
+/*   fprintf (stderr, "====== Adjusting SCR\n"); */
+  ioctl (sink->control_fd, EM8300_IOCTL_SCR_SET, &zero);
+  ioctl (sink->control_fd, EM8300_IOCTL_SCR_SET, &scr);
+}
+
+
+static gboolean
+dxr3audiosink_handle_event (GstPad *pad, GstEvent *event)
+{
+  GstEventType type;
+  Dxr3AudioSink *sink = DXR3AUDIOSINK (gst_pad_get_parent (pad));
+
+  type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
+
+  switch (type) {
+  case GST_EVENT_FLUSH:
+    if (sink->control_fd >= 0) {
+      unsigned audiomode;
+
+      if (sink->mode == DXR3AUDIOSINK_MODE_AC3) {
+        audiomode = EM8300_AUDIOMODE_DIGITALPCM;
+        ioctl (sink->control_fd, EM8300_IOCTL_SET_AUDIOMODE, &audiomode);
+        audiomode = EM8300_AUDIOMODE_DIGITALAC3;
+        ioctl (sink->control_fd, EM8300_IOCTL_SET_AUDIOMODE, &audiomode);
+      }
+
+      /* Report the flush operation. */
+      g_signal_emit (G_OBJECT (sink),
+                     dxr3audiosink_signals[SIGNAL_FLUSHED], 0);
+    }
+    break;
+  default:
+    gst_pad_event_default (pad, event);
+    break;
+  }
+
+  return TRUE;
+}
+
+
+static void 
+dxr3audiosink_chain_pcm (GstPad *pad, GstBuffer *buf) 
+{
+  Dxr3AudioSink *sink;
+  gint bytes_written = 0;
+
+  g_return_if_fail (pad != NULL);
+  g_return_if_fail (GST_IS_PAD (pad));
+  g_return_if_fail (buf != NULL);
+
+  sink = DXR3AUDIOSINK (gst_pad_get_parent (pad));
+
+  if (GST_IS_EVENT (buf)) {
+    dxr3audiosink_handle_event (pad, GST_EVENT (buf));
+    return;
+  }
+
+  if (sink->mode != DXR3AUDIOSINK_MODE_PCM) {
+    /* Switch to PCM mode. */
+    dxr3audiosink_set_mode_pcm (sink);
+  }
+
+  if (GST_FLAG_IS_SET (sink, DXR3AUDIOSINK_OPEN)) {
+    if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
+      /* We have a new scr value. */
+      sink->scr = GSTTIME_TO_MPEGTIME (GST_BUFFER_TIMESTAMP (buf));
+    }
+
+    /* Update the system reference clock (SCR) in the card. */
+    {
+      unsigned in, out, odelay;
+      unsigned diff;
+
+      ioctl (sink->control_fd, EM8300_IOCTL_SCR_GET, &out);
+
+      ioctl (sink->audio_fd, SNDCTL_DSP_GETODELAY, &odelay);
+
+      in = MPEGTIME_TO_DXRTIME (sink->scr - (odelay * 90) / 192);
+      diff = in > out ? in - out : out - in;
+      if (diff > 1800) {
+        dxr3audiosink_set_scr (sink, in);
+      }
+    }
+
+    /* Update our SCR value. */
+    sink->scr += (unsigned) (GST_BUFFER_SIZE (buf) *
+                             (90000.0 / ((float)sink->rate * 4)));
+
+    /* Write the buffer to the sound device. */
+    bytes_written = write (sink->audio_fd, GST_BUFFER_DATA (buf),
+                           GST_BUFFER_SIZE (buf));
+    if (bytes_written < GST_BUFFER_SIZE (buf)) {
+      fprintf (stderr, "dxr3audiosink: Warning: %d bytes should be "
+               "written, only %d bytes written\n",
+               GST_BUFFER_SIZE (buf), bytes_written);
+    }
+  }
+
+  gst_buffer_unref (buf);
+}
+
+
+static void 
+dxr3audiosink_chain_ac3 (GstPad *pad, GstBuffer *buf) 
+{
+  Dxr3AudioSink *sink;
+  gint bytes_written = 0;
+
+  g_return_if_fail (pad != NULL);
+  g_return_if_fail (GST_IS_PAD (pad));
+  g_return_if_fail (buf != NULL);
+
+  sink = DXR3AUDIOSINK (gst_pad_get_parent (pad));
+
+  if (GST_IS_EVENT (buf)) {
+    dxr3audiosink_handle_event (pad, GST_EVENT (buf));
+    return;
+  }
+
+  if (sink->mode != DXR3AUDIOSINK_MODE_AC3) {
+    /* Switch to AC3 mode. */
+    dxr3audiosink_set_mode_ac3 (sink);
+  }
+
+  if (GST_FLAG_IS_SET (sink, DXR3AUDIOSINK_OPEN))
+  {
+    int event;
+
+    if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
+      /* We have a new scr value. */
+
+/*       fprintf (stderr, "------ Audio Time %.04f\n", */
+/*                (double) GST_BUFFER_TIMESTAMP (buf) / GST_SECOND); */
+
+      sink->scr = GSTTIME_TO_MPEGTIME (GST_BUFFER_TIMESTAMP (buf));
+    }
+
+    /* Push the new data into the padder. */
+    ac3p_push_data(sink->padder, GST_BUFFER_DATA (buf),
+                   GST_BUFFER_SIZE (buf));
+
+    /* Parse the data. */
+    event = ac3p_parse (sink->padder);
+    while (event != AC3P_EVENT_PUSH) {
+      switch (event) {
+      case AC3P_EVENT_FRAME:
+        /* We have a new frame: */
+
+        /* Update the system reference clock (SCR) in the card. */
+        {
+          unsigned in, out, odelay;
+          unsigned diff;
+
+          ioctl (sink->control_fd, EM8300_IOCTL_SCR_GET, &out);
+
+          ioctl (sink->audio_fd, SNDCTL_DSP_GETODELAY, &odelay);
+          /* 192000 bytes/sec */
+
+          in = MPEGTIME_TO_DXRTIME (sink->scr - (odelay * 90) / 192);
+          diff = in > out ? in - out : out - in;
+          if (diff > 1800) {
+            dxr3audiosink_set_scr (sink, in);
+          }
+        }
+
+        /* Update our SCR value. */
+        sink->scr += TIME_FOR_BYTES (ac3p_frame_size (sink->padder));
+
+        /* Write the frame to the sound device. */
+        bytes_written = write (sink->audio_fd, ac3p_frame (sink->padder),
+                               AC3P_IEC_FRAME_SIZE);
+
+        if (bytes_written < AC3P_IEC_FRAME_SIZE)
+        {
+          fprintf (stderr, "dxr3audiosink: Warning: %d bytes should be "
+                   "written, only %d bytes written\n",
+                   AC3P_IEC_FRAME_SIZE, bytes_written);
+        }
+
+        break;
+      }
+
+      event = ac3p_parse (sink->padder);
+    }
+  }
+
+  gst_buffer_unref(buf);
+}
+
+#if 0
+/**
+ * dxr3audiosink_wait:
+ * Make the sink wait the specified amount of time.
+ */
+static void
+dxr3audiosink_wait (Dxr3AudioSink *sink, GstClockTime time)
+{
+  GstClockID id;
+  GstClockTimeDiff jitter;
+  GstClockReturn ret;
+  GstClockTime current_time = gst_clock_get_time (sink->clock);
+
+  id = gst_clock_new_single_shot_id (sink->clock, current_time + time);
+  ret = gst_clock_id_wait (id, &jitter);
+  gst_clock_id_free (id);
+}
+
+
+static int
+dxr3audiosink_mvcommand (Dxr3AudioSink *sink, int command)
+{
+  em8300_register_t regs;
+  
+  regs.microcode_register = 1;
+  regs.reg = 0;
+  regs.val = command;
+  
+  return ioctl (sink->control_fd, EM8300_IOCTL_WRITEREG, &regs);
+}
+#endif
+
+static GstElementStateReturn
+dxr3audiosink_change_state (GstElement *element)
+{
+  g_return_val_if_fail (GST_IS_DXR3AUDIOSINK (element), GST_STATE_FAILURE);
+
+  if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
+    if (GST_FLAG_IS_SET (element, DXR3AUDIOSINK_OPEN)) {
+      dxr3audiosink_close (DXR3AUDIOSINK (element));
+    }
+  }
+  else {
+    if (!GST_FLAG_IS_SET (element, DXR3AUDIOSINK_OPEN)) {
+      if (!dxr3audiosink_open (DXR3AUDIOSINK (element))) {
+        return GST_STATE_FAILURE;
+      }
+    }
+  }
+
+  if (GST_ELEMENT_CLASS (parent_class)->change_state) {
+    return GST_ELEMENT_CLASS (parent_class)->change_state (element);
+  }
+
+  return GST_STATE_SUCCESS;
+}
+
+
+/**
+ * dxr3audiosink_flushed:
+ *
+ * Default do nothing implementation for the "flushed" signal.  The
+ * "flushed" signal will be fired right after flushing the hardware
+ * queues due to a received flush event 
+ */
+static void
+dxr3audiosink_flushed (Dxr3AudioSink *sink)
+{
+  /* Do nothing. */
+}
+
+
+extern gboolean 
+dxr3audiosink_factory_init (GstPlugin *plugin) 
+{ 
+  GstElementFactory *factory;
+
+  factory = gst_element_factory_new ("dxr3audiosink",
+                                     GST_TYPE_DXR3AUDIOSINK,
+                                     &dxr3audiosink_details);
+  g_return_val_if_fail (factory != NULL, FALSE);
+  gst_element_factory_add_pad_template (factory,
+                     GST_PAD_TEMPLATE_GET (dxr3audiosink_pcm_sink_factory));
+  gst_element_factory_add_pad_template (factory,
+                     GST_PAD_TEMPLATE_GET (dxr3audiosink_ac3_sink_factory));
+
+  gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
+
+  return TRUE;
+}
diff --git a/sys/dxr3/dxr3audiosink.h b/sys/dxr3/dxr3audiosink.h
new file mode 100644 (file)
index 0000000..28bb34e
--- /dev/null
@@ -0,0 +1,113 @@
+/* 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__ */
diff --git a/sys/dxr3/dxr3common.h b/sys/dxr3/dxr3common.h
new file mode 100644 (file)
index 0000000..06af09d
--- /dev/null
@@ -0,0 +1,39 @@
+/* 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__ */
diff --git a/sys/dxr3/dxr3init.c b/sys/dxr3/dxr3init.c
new file mode 100644 (file)
index 0000000..aa090b2
--- /dev/null
@@ -0,0 +1,51 @@
+/* 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
+ * 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 "dxr3videosink.h"
+#include "dxr3spusink.h"
+#include "dxr3audiosink.h"
+
+
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
+{
+  gboolean ret;
+
+  ret = dxr3videosink_factory_init (plugin);
+  g_return_val_if_fail (ret == TRUE, FALSE);
+
+  ret = dxr3spusink_factory_init (plugin);
+  g_return_val_if_fail (ret == TRUE, FALSE);
+
+  ret = dxr3audiosink_factory_init (plugin);
+  g_return_val_if_fail (ret == TRUE, FALSE);
+
+  return TRUE;
+}
+
+
+GstPluginDesc plugin_desc = {
+  GST_VERSION_MAJOR,
+  GST_VERSION_MINOR,
+  "dxr3",
+  plugin_init
+};
+
diff --git a/sys/dxr3/dxr3marshal.list b/sys/dxr3/dxr3marshal.list
new file mode 100644 (file)
index 0000000..7b99b1e
--- /dev/null
@@ -0,0 +1,5 @@
+VOID:VOID
+VOID:BOOLEAN
+VOID:POINTER
+VOID:UINT,UINT,UINT,UINT,UINT,UINT
+
diff --git a/sys/dxr3/dxr3spusink.c b/sys/dxr3/dxr3spusink.c
new file mode 100644 (file)
index 0000000..0d46b4c
--- /dev/null
@@ -0,0 +1,560 @@
+/* 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
+ * 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 <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <linux/em8300.h>
+
+#include <gst/gst.h>
+
+#include "dxr3spusink.h"
+#include "dxr3marshal.h"
+
+#include "dxr3common.h"
+
+
+/* ElementFactory information. */
+static GstElementDetails dxr3spusink_details = {
+  "dxr3/Hollywood+ mpeg decoder board subpicture element",
+  "video/mpeg",
+  "GPL",
+  "Feeds subpicture information to Sigma Designs em8300 based boards",
+  VERSION,
+  "Martin Soto <martinsoto@users.sourceforge.net>",
+  "(C) 2003",
+};
+
+
+/* Dxr3SpuSink signals and args */
+enum {
+  SET_CLUT_SIGNAL,
+  HIGHLIGHT_ON_SIGNAL,
+  HIGHLIGHT_OFF_SIGNAL,
+  SIGNAL_FLUSHED,
+  LAST_SIGNAL
+};
+
+enum {
+  ARG_0,
+};
+
+
+GST_PAD_TEMPLATE_FACTORY (dxr3spusink_sink_factory,
+  "sink",
+  GST_PAD_SINK,
+  GST_PAD_ALWAYS,
+  GST_CAPS_NEW (
+    "dxr3spusink_sink",
+    "video/mpeg",
+    NULL
+  )
+);
+
+
+GST_PAD_EVENT_MASK_FUNCTION (dxr3spusink_get_event_mask,
+  { GST_EVENT_FLUSH, 0 },
+  { GST_EVENT_DISCONTINUOUS, 0 },
+  { GST_EVENT_NEW_MEDIA, 0 },
+  { GST_EVENT_EOS, 0 }
+)
+
+
+static void    dxr3spusink_class_init          (Dxr3SpuSinkClass *klass);
+static void    dxr3spusink_init                (Dxr3SpuSink *dxr3spusink);
+
+static void    dxr3spusink_set_property        (GObject *object,
+                                                 guint prop_id, 
+                                                 const GValue *value,
+                                                 GParamSpec *pspec);
+static void    dxr3spusink_get_property        (GObject *object,
+                                                 guint prop_id, 
+                                                GValue *value,
+                                                 GParamSpec *pspec);
+
+static gboolean dxr3spusink_open               (Dxr3SpuSink *sink);
+static void    dxr3spusink_close               (Dxr3SpuSink *sink);
+static void    dxr3spusink_set_clock           (GstElement *element,
+                                                 GstClock *clock);
+
+static gboolean dxr3spusink_handle_event       (GstPad *pad, GstEvent *event);
+static void    dxr3spusink_chain               (GstPad *pad,GstBuffer *buf);
+
+static GstElementStateReturn dxr3spusink_change_state (GstElement *element);
+
+/* static void dxr3spusink_wait                (Dxr3SpuSink *sink, */
+/*                                                  GstClockTime time); */
+
+static void     dxr3spusink_set_clut           (Dxr3SpuSink *sink,
+                                                 const guint32 *clut);
+static void     dxr3spusink_highlight_on       (Dxr3SpuSink *sink,
+                                                 unsigned palette,
+                                                 unsigned sx, unsigned sy,
+                                                 unsigned ex, unsigned ey,
+                                                 unsigned pts);
+static void     dxr3spusink_highlight_off      (Dxr3SpuSink *sink);
+
+static void    dxr3spusink_flushed             (Dxr3SpuSink *sink);
+
+
+static GstElementClass *parent_class = NULL;
+static guint dxr3spusink_signals[LAST_SIGNAL] = { 0 };
+
+
+GType
+dxr3spusink_get_type (void) 
+{
+  static GType dxr3spusink_type = 0;
+
+  if (!dxr3spusink_type) {
+    static const GTypeInfo dxr3spusink_info = {
+      sizeof (Dxr3SpuSinkClass),
+      NULL,
+      NULL,
+      (GClassInitFunc)dxr3spusink_class_init,
+      NULL,
+      NULL,
+      sizeof (Dxr3SpuSink),
+      0,
+      (GInstanceInitFunc)dxr3spusink_init,
+    };
+    dxr3spusink_type = g_type_register_static (GST_TYPE_ELEMENT,
+                                               "Dxr3SpuSink",
+                                               &dxr3spusink_info, 0);
+  }
+  return dxr3spusink_type;
+}
+
+
+static void
+dxr3spusink_class_init (Dxr3SpuSinkClass *klass) 
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+
+  gobject_class = (GObjectClass*)klass;
+  gstelement_class = (GstElementClass*)klass;
+
+  parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+
+  dxr3spusink_signals[SET_CLUT_SIGNAL] =
+    g_signal_new ("set_clut",
+        G_TYPE_FROM_CLASS (klass),
+        G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+        G_STRUCT_OFFSET (Dxr3SpuSinkClass, set_clut),
+        NULL, NULL,
+        dxr3_marshal_VOID__POINTER,
+        G_TYPE_NONE, 1,
+        G_TYPE_POINTER);
+
+  dxr3spusink_signals[HIGHLIGHT_ON_SIGNAL] =
+    g_signal_new ("highlight_on",
+        G_TYPE_FROM_CLASS (klass),
+        G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+        G_STRUCT_OFFSET (Dxr3SpuSinkClass, highlight_on),
+        NULL, NULL,
+        dxr3_marshal_VOID__UINT_UINT_UINT_UINT_UINT_UINT,
+        G_TYPE_NONE, 6,
+        G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
+        G_TYPE_UINT, G_TYPE_UINT);
+
+  dxr3spusink_signals[HIGHLIGHT_OFF_SIGNAL] =
+    g_signal_new ("highlight_off",
+        G_TYPE_FROM_CLASS (klass),
+        G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+        G_STRUCT_OFFSET (Dxr3SpuSinkClass, highlight_off),
+        NULL, NULL,
+        dxr3_marshal_VOID__VOID,
+        G_TYPE_NONE, 0);
+
+  dxr3spusink_signals[SIGNAL_FLUSHED] =
+    g_signal_new ("flushed", G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (Dxr3SpuSinkClass, flushed),
+                  NULL, NULL,
+                  dxr3_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+  klass->set_clut = dxr3spusink_set_clut;
+  klass->highlight_on = dxr3spusink_highlight_on;
+  klass->highlight_off = dxr3spusink_highlight_off;
+  klass->flushed = dxr3spusink_flushed;
+
+  gobject_class->set_property = dxr3spusink_set_property;
+  gobject_class->get_property = dxr3spusink_get_property;
+
+  gstelement_class->change_state = dxr3spusink_change_state;
+  gstelement_class->set_clock = dxr3spusink_set_clock;
+}
+
+
+static void 
+dxr3spusink_init (Dxr3SpuSink *sink) 
+{
+  GstPad *pad;
+
+  pad = gst_pad_new_from_template (
+      GST_PAD_TEMPLATE_GET (dxr3spusink_sink_factory), "sink");
+  gst_element_add_pad (GST_ELEMENT (sink), pad);
+  gst_pad_set_chain_function (pad, dxr3spusink_chain);
+
+  GST_FLAG_SET (GST_ELEMENT (sink), GST_ELEMENT_EVENT_AWARE);
+  gst_pad_set_event_function (pad, dxr3spusink_handle_event);
+  gst_pad_set_event_mask_function (pad, dxr3spusink_get_event_mask);
+
+  sink->card_number = 0;
+
+  sink->spu_filename = NULL;
+  sink->spu_fd = -1;
+  sink->control_filename = NULL;
+  sink->control_fd = -1;
+
+  sink->clock = NULL;
+}
+
+
+static void
+dxr3spusink_set_property (GObject *object, guint prop_id,
+                                const GValue *value, GParamSpec *pspec)
+{
+  Dxr3SpuSink *sink;
+
+  /* it's not null if we got it, but it might not be ours */
+  sink = DXR3SPUSINK (object);
+
+  switch (prop_id) {
+    default:
+      break;
+  }
+}
+
+
+static void   
+dxr3spusink_get_property (GObject *object, guint prop_id,
+                          GValue *value, GParamSpec *pspec)
+{
+  Dxr3SpuSink *sink;
+  /* it's not null if we got it, but it might not be ours */
+  g_return_if_fail (GST_IS_DXR3SPUSINK (object));
+  sink = DXR3SPUSINK (object);
+  
+  switch (prop_id) {
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+
+static gboolean
+dxr3spusink_open (Dxr3SpuSink *sink)
+{
+  g_return_val_if_fail (!GST_FLAG_IS_SET (sink,
+                                          DXR3SPUSINK_OPEN), FALSE);
+
+  /* Compute the name of the spu device file. */
+  sink->spu_filename = g_strdup_printf ("/dev/em8300_sp-%d",
+                                        sink->card_number );
+
+  sink->spu_fd = open (sink->spu_filename, O_WRONLY);
+  if (sink->spu_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error opening device file \"",
+                                    sink->spu_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Open the control device. */
+  sink->control_filename = g_strdup_printf ("/dev/em8300-%d",
+                                            sink->card_number );
+
+  sink->control_fd = open (sink->control_filename, O_WRONLY);
+  if (sink->control_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error opening device file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  GST_FLAG_SET (sink, DXR3SPUSINK_OPEN);
+
+  return TRUE;
+}
+
+
+static void
+dxr3spusink_close (Dxr3SpuSink *sink)
+{
+  g_return_if_fail (GST_FLAG_IS_SET (sink, DXR3SPUSINK_OPEN));
+
+  if (close (sink->spu_fd) != 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->spu_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  if (close (sink->control_fd) != 0)
+  {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  GST_FLAG_UNSET (sink, DXR3SPUSINK_OPEN);
+
+  free (sink->spu_filename);
+  sink->spu_filename = NULL;
+}
+
+
+static void
+dxr3spusink_set_clock (GstElement *element, GstClock *clock)
+{
+  Dxr3SpuSink *src = DXR3SPUSINK (element);
+  
+  src->clock = clock;
+}
+
+
+static gboolean
+dxr3spusink_handle_event (GstPad *pad, GstEvent *event)
+{
+  GstEventType type;
+  Dxr3SpuSink *sink;
+
+  sink = DXR3SPUSINK (gst_pad_get_parent (pad));
+
+  type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
+
+  switch (type) {
+  case GST_EVENT_FLUSH:
+    if (sink->control_fd >= 0) {
+      int subdevice;
+      subdevice =  EM8300_SUBDEVICE_SUBPICTURE;
+      ioctl (sink->control_fd, EM8300_IOCTL_FLUSH, &subdevice);
+
+      /* FIXME: There should be a nicer way to do this, but I tried
+         everything and nothing else seems to really reset the video
+         fifo. */ 
+/*       dxr3spusink_close (sink); */
+/*       dxr3spusink_open (sink); */
+
+      /* Report the flush operation. */
+      g_signal_emit (G_OBJECT (sink),
+                     dxr3spusink_signals[SIGNAL_FLUSHED], 0);
+    }
+    break;
+  default:
+    gst_pad_event_default (pad, event);
+    break;
+  }
+
+  return TRUE;
+}
+
+
+static void 
+dxr3spusink_chain (GstPad *pad, GstBuffer *buf) 
+{
+  Dxr3SpuSink *sink;
+  gint bytes_written = 0;
+
+  g_return_if_fail (pad != NULL);
+  g_return_if_fail (GST_IS_PAD (pad));
+  g_return_if_fail (buf != NULL);
+
+  sink = DXR3SPUSINK (gst_pad_get_parent (pad));
+
+  if (GST_IS_EVENT (buf)) {
+    dxr3spusink_handle_event (pad, GST_EVENT (buf));
+    return;
+  }
+
+  if (GST_FLAG_IS_SET (sink, DXR3SPUSINK_OPEN)) {
+    /* If we have PTS information for the SPU unit, register it now.
+       The card needs the PTS to be written *before* the actual data. */
+    if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
+      guint pts = (guint) GSTTIME_TO_MPEGTIME (GST_BUFFER_TIMESTAMP (buf));
+      ioctl (sink->spu_fd, EM8300_IOCTL_SPU_SETPTS, &pts);
+    }
+
+    bytes_written = write (sink->spu_fd, GST_BUFFER_DATA (buf),
+                           GST_BUFFER_SIZE (buf));
+    if (bytes_written < GST_BUFFER_SIZE (buf)) {
+      fprintf (stderr, "dxr3spusink: Warning: %d bytes should be written,"
+               " only %d bytes written\n",
+               GST_BUFFER_SIZE (buf), bytes_written);
+    }
+  }
+
+  gst_buffer_unref (buf);
+}
+
+
+static GstElementStateReturn
+dxr3spusink_change_state (GstElement *element)
+{
+  g_return_val_if_fail (GST_IS_DXR3SPUSINK (element), GST_STATE_FAILURE);
+
+  switch (GST_STATE_TRANSITION (element)) {
+    case GST_STATE_NULL_TO_READY:
+      if (!GST_FLAG_IS_SET (element, DXR3SPUSINK_OPEN)) {
+        if (!dxr3spusink_open (DXR3SPUSINK (element))) {
+          return GST_STATE_FAILURE;
+        }
+      }
+      break;
+    case GST_STATE_READY_TO_PAUSED:
+      break;
+    case GST_STATE_PAUSED_TO_PLAYING:
+      break;
+    case GST_STATE_PLAYING_TO_PAUSED:
+      break;
+    case GST_STATE_PAUSED_TO_READY:
+      break;
+    case GST_STATE_READY_TO_NULL:
+      if (GST_FLAG_IS_SET (element, DXR3SPUSINK_OPEN)) {
+        dxr3spusink_close (DXR3SPUSINK (element));
+      }
+      break;
+  }
+
+  if (GST_ELEMENT_CLASS (parent_class)->change_state) {
+    return GST_ELEMENT_CLASS (parent_class)->change_state (element);
+  }
+
+  return GST_STATE_SUCCESS;
+}
+
+#if 0
+/**
+ * dxr3spusink_wait:
+ * Make the sink wait the specified amount of time.
+ */
+static void
+dxr3spusink_wait (Dxr3SpuSink *sink, GstClockTime time)
+{
+  GstClockID id;
+  GstClockTimeDiff jitter;
+  GstClockReturn ret;
+  GstClockTime current_time = gst_clock_get_time (sink->clock);
+
+  id = gst_clock_new_single_shot_id (sink->clock, current_time + time);
+  ret = gst_clock_id_wait (id, &jitter);
+  gst_clock_id_free (id);
+}
+#endif
+
+/**
+ * dxr3spusink_set_clut:
+ *
+ * Set a new SPU color lookup table (clut) in the dxr3 card.
+ */
+static void
+dxr3spusink_set_clut (Dxr3SpuSink *sink, const guint32 *clut)
+{
+  guint32 clut_fixed[16];
+  int i;
+
+  /* Fix the byte order of the table. */
+  for (i=0; i<16; i++) {
+    clut_fixed[i] = GUINT32_TO_LE (clut[i]);
+  }
+
+  if (ioctl (sink->spu_fd, EM8300_IOCTL_SPU_SETPALETTE, clut_fixed))
+    fprintf (stderr, "dxr3spusink: failed to set CLUT (%s)\n",
+             strerror (errno));
+}
+
+
+static void
+dxr3spusink_highlight_on (Dxr3SpuSink *sink, unsigned palette,
+                          unsigned sx, unsigned sy,
+                          unsigned ex, unsigned ey,
+                          unsigned pts)
+{
+  em8300_button_t btn;
+
+  btn.color = palette >> 16;
+  btn.contrast = palette;
+  btn.left = sx;
+  btn.top = sy;
+  btn.right = ex;
+  btn.bottom = ey;
+
+  if (ioctl (sink->spu_fd, EM8300_IOCTL_SPU_BUTTON, &btn)) {
+    fprintf (stderr, "dxr3spusink: failed to set spu button (%s)\n",
+             strerror (errno));
+  }
+}
+
+
+static void
+dxr3spusink_highlight_off (Dxr3SpuSink *sink)
+{
+  if (ioctl (sink->spu_fd, EM8300_IOCTL_SPU_BUTTON, NULL)) {
+    fprintf (stderr, "dxr3spusink: failed to set spu button (%s)\n",
+             strerror (errno));
+  }
+}
+
+
+/**
+ * dxr3spusink_flushed:
+ *
+ * Default do nothing implementation for the "flushed" signal.  The
+ * "flushed" signal will be fired right after flushing the hardware
+ * queues due to a received flush event 
+ */
+static void
+dxr3spusink_flushed (Dxr3SpuSink *sink)
+{
+  /* Do nothing. */
+}
+
+
+extern gboolean 
+dxr3spusink_factory_init (GstPlugin *plugin) 
+{ 
+  GstElementFactory *factory;
+
+  factory = gst_element_factory_new ("dxr3spusink",
+                                     GST_TYPE_DXR3SPUSINK,
+                                     &dxr3spusink_details);
+  g_return_val_if_fail (factory != NULL, FALSE);
+  gst_element_factory_add_pad_template (factory,
+                     GST_PAD_TEMPLATE_GET (dxr3spusink_sink_factory));
+
+  gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
+
+  return TRUE;
+}
diff --git a/sys/dxr3/dxr3spusink.h b/sys/dxr3/dxr3spusink.h
new file mode 100644 (file)
index 0000000..e255171
--- /dev/null
@@ -0,0 +1,87 @@
+/* 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
+ * 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 __DXR3SPUSINK_H__
+#define __DXR3SPUSINK_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+
+#define GST_TYPE_DXR3SPUSINK \
+  (dxr3spusink_get_type())
+#define DXR3SPUSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DXR3SPUSINK,Dxr3SpuSink))
+#define DXR3SPUSINK_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DXR3SPUSINK,Dxr3SpuSinkClass))
+#define GST_IS_DXR3SPUSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DXR3SPUSINK))
+#define GST_IS_DXR3SPUSINK_CLASS(obj) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DXR3SPUSINK))
+
+
+typedef struct _Dxr3SpuSink Dxr3SpuSink;
+typedef struct _Dxr3SpuSinkClass Dxr3SpuSinkClass;
+
+
+typedef enum {
+  DXR3SPUSINK_OPEN = GST_ELEMENT_FLAG_LAST,
+  DXR3SPUSINK_FLAG_LAST  = GST_ELEMENT_FLAG_LAST + 2,
+} Dxr3SpuSinkFlags;
+
+
+struct _Dxr3SpuSink {
+  GstElement element;
+
+  int card_number;                     /* The number of the card to open. */
+
+  gchar *spu_filename;                 /* File name for the spu device. */
+  int spu_fd;                          /* File descriptor for the spu device. */
+
+  gchar *control_filename;     /* File name for the control device. */
+  int control_fd;              /* File descriptor for the control
+                                   device. */
+
+  GstClock *clock;             /* The clock for this element. */
+};
+
+
+struct _Dxr3SpuSinkClass {
+  GstElementClass parent_class;
+
+  /* Signals */
+  void (*set_clut) (Dxr3SpuSink *sink, const guint32 *clut);
+  void (*highlight_on) (Dxr3SpuSink *sink, unsigned palette,
+                        unsigned sx, unsigned sy,
+                        unsigned ex, unsigned ey,
+                        unsigned pts);
+  void (*highlight_off) (Dxr3SpuSink *sink);
+  void (*flushed) (Dxr3SpuSink *sink);
+};
+
+
+extern GType   dxr3spusink_get_type            (void);
+extern gboolean        dxr3spusink_factory_init        (GstPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* __DXR3SPUSINK_H__ */
diff --git a/sys/dxr3/dxr3videosink.c b/sys/dxr3/dxr3videosink.c
new file mode 100644 (file)
index 0000000..ac858d8
--- /dev/null
@@ -0,0 +1,762 @@
+/* GStreamer
+ * Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
+ *
+ * dxr3videosink.c: Video 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
+ * 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 <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#include <linux/em8300.h>
+
+#include <gst/gst.h>
+
+#include "dxr3videosink.h"
+#include "dxr3marshal.h"
+
+#include "dxr3common.h"
+
+
+/* ElementFactory information. */
+static GstElementDetails dxr3videosink_details = {
+  "dxr3/Hollywood+ mpeg decoder board video element",
+  "video/mpeg",
+  "GPL",
+  "Feeds MPEG2 video to Sigma Designs em8300 based boards",
+  VERSION,
+  "Martin Soto <martinsoto@users.sourceforge.net>",
+  "(C) 2003",
+};
+
+
+/* Dxr3VideoSink signals and args */
+enum {
+  SIGNAL_FLUSHED,
+  LAST_SIGNAL
+};
+
+enum {
+  ARG_0,
+};
+
+/* Possible states for the MPEG start code scanner. */
+enum {
+  SCAN_STATE_WAITING,  /* Waiting for a code. */
+  SCAN_STATE_0,                /* 0 seen. */
+  SCAN_STATE_00,       /* 00 seen. */
+  SCAN_STATE_001       /* 001 seen. */
+};
+
+/* Possible states for the MPEG sequence parser. */
+enum {
+  PARSE_STATE_WAITING, /* Waiting for the start of a sequence. */
+  PARSE_STATE_START,   /* Start of sequence seen. */
+  PARSE_STATE_PICTURE, /* Picture start seen. */
+};
+
+
+/* Relevant mpeg start codes. */
+#define START_CODE_PICTURE 0x00
+#define START_CODE_SEQUENCE_HEADER 0xB3
+#define START_CODE_SEQUENCE_END 0xB7
+
+
+GST_PAD_TEMPLATE_FACTORY (dxr3videosink_sink_factory,
+  "sink",
+  GST_PAD_SINK,
+  GST_PAD_ALWAYS,
+  GST_CAPS_NEW (
+    "dxr3videosink_sink",
+    "video/mpeg",
+      "mpegversion",   GST_PROPS_LIST (
+                         GST_PROPS_INT (1),
+                         GST_PROPS_INT (2)
+                        ),
+      "systemstream",  GST_PROPS_BOOLEAN (FALSE)
+  )
+)
+
+
+GST_PAD_EVENT_MASK_FUNCTION (dxr3videosink_get_event_mask,
+  { GST_EVENT_FLUSH, 0 },
+  { GST_EVENT_DISCONTINUOUS, 0 },
+  { GST_EVENT_NEW_MEDIA, 0 },
+  { GST_EVENT_EOS, 0 }
+)
+
+
+static void    dxr3videosink_class_init        (Dxr3VideoSinkClass *klass);
+static void    dxr3videosink_init              (Dxr3VideoSink *dxr3videosink);
+
+static void    dxr3videosink_set_property      (GObject *object,
+                                                 guint prop_id, 
+                                                 const GValue *value,
+                                                 GParamSpec *pspec);
+static void    dxr3videosink_get_property      (GObject *object,
+                                                 guint prop_id, 
+                                                GValue *value,
+                                                 GParamSpec *pspec);
+
+static gboolean dxr3videosink_open             (Dxr3VideoSink *sink);
+static void    dxr3videosink_close             (Dxr3VideoSink *sink);
+static void    dxr3videosink_set_clock         (GstElement *element,
+                                                 GstClock *clock);
+
+static void    dxr3videosink_reset_parser      (Dxr3VideoSink *sink);
+static int     dxr3videosink_next_start_code   (Dxr3VideoSink *sink);
+static void    dxr3videosink_discard_data      (Dxr3VideoSink *sink,
+                                                 guint cut);
+static void    dxr3videosink_write_data        (Dxr3VideoSink *sink,
+                                                 guint cut);
+static void    dxr3videosink_parse_data        (Dxr3VideoSink *sink);
+
+static gboolean dxr3videosink_handle_event     (GstPad *pad, GstEvent *event);
+static void    dxr3videosink_chain             (GstPad *pad,GstBuffer *buf);
+
+static GstElementStateReturn dxr3videosink_change_state (GstElement *element);
+
+/* static void dxr3videosink_wait              (Dxr3VideoSink *sink, */
+/*                                                  GstClockTime time); */
+static int     dxr3videosink_mvcommand         (Dxr3VideoSink *sink,
+                                                 int command);
+
+static void    dxr3videosink_flushed           (Dxr3VideoSink *sink);
+
+static GstElementClass *parent_class = NULL;
+static guint dxr3videosink_signals[LAST_SIGNAL] = { 0 };
+
+
+extern GType
+dxr3videosink_get_type (void) 
+{
+  static GType dxr3videosink_type = 0;
+
+  if (!dxr3videosink_type) {
+    static const GTypeInfo dxr3videosink_info = {
+      sizeof (Dxr3VideoSinkClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) dxr3videosink_class_init,
+      NULL,
+      NULL,
+      sizeof (Dxr3VideoSink),
+      0,
+      (GInstanceInitFunc) dxr3videosink_init,
+    };
+    dxr3videosink_type = g_type_register_static (GST_TYPE_ELEMENT,
+                                                 "Dxr3VideoSink",
+                                                 &dxr3videosink_info, 0);
+  }
+
+  return dxr3videosink_type;
+}
+
+
+static void
+dxr3videosink_class_init (Dxr3VideoSinkClass *klass) 
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+
+  gobject_class = (GObjectClass*)klass;
+  gstelement_class = (GstElementClass*)klass;
+
+  parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+
+  dxr3videosink_signals[SIGNAL_FLUSHED] =
+    g_signal_new ("flushed", G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (Dxr3VideoSinkClass, flushed),
+                  NULL, NULL,
+                  dxr3_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
+  klass->flushed = dxr3videosink_flushed;
+
+  gobject_class->set_property = dxr3videosink_set_property;
+  gobject_class->get_property = dxr3videosink_get_property;
+
+  gstelement_class->change_state = dxr3videosink_change_state;
+  gstelement_class->set_clock = dxr3videosink_set_clock;
+}
+
+
+static void 
+dxr3videosink_init (Dxr3VideoSink *sink) 
+{
+  GstPad *pad;
+
+  pad = gst_pad_new_from_template (
+      GST_PAD_TEMPLATE_GET (dxr3videosink_sink_factory), "sink");
+  gst_element_add_pad (GST_ELEMENT (sink), pad);
+  gst_pad_set_chain_function (pad, dxr3videosink_chain);
+
+  GST_FLAG_SET (GST_ELEMENT (sink), GST_ELEMENT_EVENT_AWARE);
+  gst_pad_set_event_function (pad, dxr3videosink_handle_event);
+  gst_pad_set_event_mask_function (pad, dxr3videosink_get_event_mask);
+
+  sink->card_number = 0;
+
+  sink->video_filename = NULL;
+  sink->video_fd = -1;
+  sink->control_filename = NULL;
+  sink->control_fd = -1;
+
+  sink->clock = NULL;
+
+  sink->last_ts = GST_CLOCK_TIME_NONE;
+
+  sink->cur_buf = NULL;
+  dxr3videosink_reset_parser (sink);
+}
+
+
+static void
+dxr3videosink_set_property (GObject *object, guint prop_id,
+                            const GValue *value, GParamSpec *pspec)
+{
+  Dxr3VideoSink *sink;
+
+  /* it's not null if we got it, but it might not be ours */
+  sink = DXR3VIDEOSINK (object);
+
+  switch (prop_id) {
+    default:
+      break;
+  }
+}
+
+
+static void   
+dxr3videosink_get_property (GObject *object, guint prop_id,
+                            GValue *value, GParamSpec *pspec)
+{
+  Dxr3VideoSink *sink;
+  /* it's not null if we got it, but it might not be ours */
+  g_return_if_fail (GST_IS_DXR3VIDEOSINK (object));
+  sink = DXR3VIDEOSINK (object);
+  
+  switch (prop_id) {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+
+static gboolean
+dxr3videosink_open (Dxr3VideoSink *sink)
+{
+  g_return_val_if_fail (!GST_FLAG_IS_SET (sink,
+                                          DXR3VIDEOSINK_OPEN), FALSE);
+
+  /* Compute the name of the video device file. */
+  sink->video_filename = g_strdup_printf ("/dev/em8300_mv-%d",
+                                          sink->card_number );
+
+  sink->video_fd = open (sink->video_filename, O_WRONLY);
+  if (sink->video_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error opening device file \"",
+                                    sink->video_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  /* Open the control device. */
+  sink->control_filename = g_strdup_printf ("/dev/em8300-%d",
+                                            sink->card_number );
+
+  sink->control_fd = open (sink->control_filename, O_WRONLY);
+  if (sink->control_fd < 0) {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error opening device file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return FALSE;
+  }
+
+  GST_FLAG_SET (sink, DXR3VIDEOSINK_OPEN);
+
+  return TRUE;
+}
+
+
+static void
+dxr3videosink_close (Dxr3VideoSink *sink)
+{
+  g_return_if_fail (GST_FLAG_IS_SET (sink, DXR3VIDEOSINK_OPEN));
+
+  if (close (sink->video_fd) != 0)
+  {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->video_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  if (close (sink->control_fd) != 0)
+  {
+    gst_element_error (GST_ELEMENT (sink),
+                       g_strconcat ("Error closing file \"",
+                                    sink->control_filename, "\": ",
+                                    g_strerror (errno), NULL));
+    return;
+  }
+
+  GST_FLAG_UNSET (sink, DXR3VIDEOSINK_OPEN);
+
+  free (sink->video_filename);
+  sink->video_filename = NULL;
+}
+
+
+static void
+dxr3videosink_set_clock (GstElement *element, GstClock *clock)
+{
+  Dxr3VideoSink *src = DXR3VIDEOSINK (element);
+
+  src->clock = clock;
+}
+
+
+static void
+dxr3videosink_reset_parser (Dxr3VideoSink *sink)
+{
+  if (sink->cur_buf != NULL) {
+    gst_buffer_unref (sink->cur_buf);
+    sink->cur_buf = NULL;
+  }
+  sink->cur_ts = GST_CLOCK_TIME_NONE;
+
+  sink->scan_state = SCAN_STATE_WAITING;
+  sink->scan_pos = 0;
+
+  sink->parse_state = PARSE_STATE_WAITING;
+}
+
+
+static int
+dxr3videosink_next_start_code (Dxr3VideoSink *sink)
+{
+  guchar c;
+
+  g_return_val_if_fail (sink->cur_buf != NULL, -1);
+
+  while (sink->scan_pos < GST_BUFFER_SIZE (sink->cur_buf)) {
+    c = (GST_BUFFER_DATA (sink->cur_buf))[sink->scan_pos];
+
+    switch (sink->scan_state) {
+    case SCAN_STATE_WAITING:
+      if (c == 0x00) {
+        sink->scan_state = SCAN_STATE_0;
+      }
+      break;
+    case SCAN_STATE_0:
+      if (c == 0x00) {
+        sink->scan_state = SCAN_STATE_00;
+      }
+      else {
+        sink->scan_state = SCAN_STATE_WAITING;
+      }
+      break;
+    case SCAN_STATE_00:
+      if (c == 0x01) {
+        sink->scan_state = SCAN_STATE_001;
+      }
+      else if (c != 0x00) { 
+        sink->scan_state = SCAN_STATE_WAITING;
+      }
+      break;
+    case SCAN_STATE_001:
+      sink->scan_pos++;
+      sink->scan_state = SCAN_STATE_WAITING;
+      return c;
+    }
+
+    sink->scan_pos++;
+  }
+
+  return -1;
+}
+
+
+static void
+dxr3videosink_discard_data (Dxr3VideoSink *sink, guint cut)
+{
+  GstBuffer *sub;
+  guint size;
+
+  g_return_if_fail (sink->cur_buf != NULL);
+  g_assert (cut <= sink->scan_pos);
+
+  size = sink->scan_pos - cut;
+
+  g_return_if_fail (size <= GST_BUFFER_SIZE (sink->cur_buf));
+
+  if (GST_BUFFER_SIZE (sink->cur_buf) == size) {
+    gst_buffer_unref (sink->cur_buf);
+    sink->cur_buf = NULL;
+  }
+  else {
+    sub = gst_buffer_create_sub (sink->cur_buf, size,
+                                 GST_BUFFER_SIZE (sink->cur_buf)
+                                 - size);
+    gst_buffer_unref (sink->cur_buf);
+    sink->cur_buf = sub;
+  }
+
+  sink->scan_state = SCAN_STATE_WAITING;
+  sink->scan_pos = cut;
+
+  sink->cur_ts = GST_CLOCK_TIME_NONE;
+}
+
+
+static void
+dxr3videosink_write_data (Dxr3VideoSink *sink, guint cut)
+{
+  guint size, written;
+  guint8 *data;
+
+  g_return_if_fail (sink->cur_buf != NULL);
+
+  if (GST_FLAG_IS_SET (sink, DXR3VIDEOSINK_OPEN)) {
+    if (sink->cur_ts != GST_CLOCK_TIME_NONE) {
+      guint pts;
+
+/*       fprintf (stderr, "------ Video Time %.04f\n", */
+/*                (double) sink->cur_ts / GST_SECOND); */
+
+      pts = (guint) GSTTIME_TO_MPEGTIME (sink->cur_ts);
+      ioctl (sink->video_fd, EM8300_IOCTL_VIDEO_SETPTS, &pts);
+      sink->cur_ts = GST_CLOCK_TIME_NONE;
+    }
+
+    data = GST_BUFFER_DATA (sink->cur_buf);
+    size = sink->scan_pos - cut;
+
+    g_assert (size <= GST_BUFFER_SIZE (sink->cur_buf));
+
+    /* We should always write data that corresponds to whole MPEG
+       video sintactical elements.  They should always start with an
+       MPEG start code. */
+    g_assert (size >= 4 && data[0] == 0 && data[1] == 0 && data[2] == 1);
+
+    while (size > 0) {
+      written = write (sink->video_fd, data, size);
+      if (written < 0) {
+        gst_element_error (GST_ELEMENT (sink), "Writing to %s: %s",
+                           sink->video_filename, strerror (errno));
+        break;
+      }
+      size = size - written;
+      data = data + written;
+    };
+  }
+
+  dxr3videosink_discard_data (sink, cut);
+}
+
+
+static void
+dxr3videosink_parse_data (Dxr3VideoSink *sink)
+{
+  int code;
+
+  /* Timestamp handling assumes that timestamps are associated to
+     sequence starts.  This seems to be the case, at least for
+     DVDs. */
+
+  code = dxr3videosink_next_start_code (sink);
+  while (code >= 0) {
+    switch (sink->parse_state) {
+
+    case PARSE_STATE_WAITING:
+      if (code == START_CODE_SEQUENCE_HEADER) {
+        dxr3videosink_discard_data (sink, 4);
+        sink->parse_state = PARSE_STATE_START;
+        sink->cur_ts = sink->last_ts;
+      }
+      break;
+
+    case PARSE_STATE_START:
+      switch (code) {
+      case START_CODE_SEQUENCE_HEADER:
+        dxr3videosink_discard_data (sink, 4);
+        sink->cur_ts = sink->last_ts;
+        break;
+      case START_CODE_SEQUENCE_END:
+        dxr3videosink_discard_data (sink, 0);
+        sink->parse_state = PARSE_STATE_WAITING;
+        break;
+      case START_CODE_PICTURE:
+        sink->parse_state = PARSE_STATE_PICTURE;
+        break;
+      }
+      break;
+
+    case PARSE_STATE_PICTURE:
+      switch (code) {
+      case START_CODE_SEQUENCE_HEADER:
+        dxr3videosink_write_data (sink, 4);
+        sink->parse_state = PARSE_STATE_START;
+        sink->cur_ts = sink->last_ts;
+        break;
+      case START_CODE_SEQUENCE_END:
+        dxr3videosink_write_data (sink, 0);
+        sink->parse_state = PARSE_STATE_WAITING;
+        break;
+      case START_CODE_PICTURE:
+        dxr3videosink_write_data (sink, 4);
+        break;
+      }
+      break;
+
+    }
+
+    code = dxr3videosink_next_start_code (sink);
+  }
+
+  if (sink->parse_state == PARSE_STATE_WAITING) {
+    dxr3videosink_discard_data (sink, 0);
+  }
+}
+
+
+static gboolean
+dxr3videosink_handle_event (GstPad *pad, GstEvent *event)
+{
+  GstEventType type;
+  Dxr3VideoSink *sink;
+
+  sink = DXR3VIDEOSINK (gst_pad_get_parent (pad));
+
+  type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
+
+  switch (type) {
+  case GST_EVENT_EMPTY:
+    //fprintf (stderr, "++++++ Video empty event\n");
+    {
+      /* FIXME: Handle this with a discontinuity or something. */
+      /* Write an MPEG2 sequence end code, to ensure that the card
+         actually displays the last picture.  Apparently some DVDs are
+         encoded without proper sequence end codes. */
+      static guint8 sec[4] = { 0x00, 0x00, 0x01, 0xb7 };
+
+      if (sink->cur_buf != NULL) {
+        dxr3videosink_write_data (sink, 0);
+      }
+
+      write (sink->video_fd, &sec, 4);
+    }
+    break;
+
+  case GST_EVENT_DISCONTINUOUS:
+    //fprintf (stderr, "++++++ Video discont event\n");
+    {
+      gint64 time;
+      gboolean has_time;
+      unsigned cur_scr, mpeg_scr, diff;
+
+      has_time = gst_event_discont_get_value (event,
+                                              GST_FORMAT_TIME,
+                                              &time);
+      if (has_time) {
+/*         fprintf (stderr, "^^^^^^ Discontinuous event has time %.4f\n", */
+/*                  (double) time / GST_SECOND); */
+
+        /* If the SCR in the card is way off, fix it. */
+        ioctl (sink->control_fd, EM8300_IOCTL_SCR_GET, &cur_scr);
+        mpeg_scr = MPEGTIME_TO_DXRTIME (GSTTIME_TO_MPEGTIME (time));
+
+        diff = cur_scr > mpeg_scr ? cur_scr - mpeg_scr : mpeg_scr - cur_scr;
+        if (diff > 1800) {
+          unsigned zero = 0;
+/*           fprintf (stderr, "====== Adjusting SCR from video\n"); */
+
+          ioctl (sink->control_fd, EM8300_IOCTL_SCR_SET, &zero);
+          ioctl (sink->control_fd, EM8300_IOCTL_SCR_SET, &mpeg_scr);
+        }
+      }
+      else {
+/*         fprintf (stderr, "^^^^^^ Discontinuous event has no time\n"); */
+      }
+    }
+    break;
+
+  case GST_EVENT_FLUSH:
+    dxr3videosink_reset_parser (sink);
+    break;
+
+  default:
+    gst_pad_event_default (pad, event);
+    break;
+  }
+
+  return TRUE;
+}
+
+
+static void 
+dxr3videosink_chain (GstPad *pad, GstBuffer *buf) 
+{
+  Dxr3VideoSink *sink;
+  GstBuffer *merged;
+
+  g_return_if_fail (pad != NULL);
+  g_return_if_fail (GST_IS_PAD (pad));
+  g_return_if_fail (buf != NULL);
+
+  sink = DXR3VIDEOSINK (gst_pad_get_parent (pad));
+
+  if (GST_IS_EVENT (buf)) {
+    dxr3videosink_handle_event (pad, GST_EVENT (buf));
+    return;
+  }
+
+/*   fprintf (stderr, "^^^^^^ Video block\n"); */
+
+  if (sink->cur_buf == NULL) {
+    sink->cur_buf = buf;
+  }
+  else {
+    merged = gst_buffer_merge (sink->cur_buf, buf);
+    gst_buffer_unref (sink->cur_buf);
+    gst_buffer_unref (buf);
+    sink->cur_buf = merged;
+  }
+
+  sink->last_ts = GST_BUFFER_TIMESTAMP (buf);
+
+  dxr3videosink_parse_data (sink);
+}
+
+
+static GstElementStateReturn
+dxr3videosink_change_state (GstElement *element)
+{
+  g_return_val_if_fail (GST_IS_DXR3VIDEOSINK (element), GST_STATE_FAILURE);
+
+  switch (GST_STATE_TRANSITION (element)) {
+    case GST_STATE_NULL_TO_READY:
+      if (!GST_FLAG_IS_SET (element, DXR3VIDEOSINK_OPEN)) {
+        if (!dxr3videosink_open (DXR3VIDEOSINK (element))) {
+          return GST_STATE_FAILURE;
+        }
+      }
+      break;
+    case GST_STATE_READY_TO_PAUSED:
+      dxr3videosink_mvcommand (DXR3VIDEOSINK (element), MVCOMMAND_PAUSE);
+      break;
+    case GST_STATE_PAUSED_TO_PLAYING:
+      dxr3videosink_mvcommand (DXR3VIDEOSINK (element), MVCOMMAND_START);
+      break;
+    case GST_STATE_PLAYING_TO_PAUSED:
+      dxr3videosink_mvcommand (DXR3VIDEOSINK (element), MVCOMMAND_PAUSE);
+      break;
+    case GST_STATE_PAUSED_TO_READY:
+      dxr3videosink_mvcommand (DXR3VIDEOSINK (element), MVCOMMAND_STOP);
+      break;
+    case GST_STATE_READY_TO_NULL:
+      if (GST_FLAG_IS_SET (element, DXR3VIDEOSINK_OPEN)) {
+        dxr3videosink_close (DXR3VIDEOSINK (element));
+      }
+      break;
+  }
+
+  if (GST_ELEMENT_CLASS (parent_class)->change_state) {
+    return GST_ELEMENT_CLASS (parent_class)->change_state (element);
+  }
+
+  return GST_STATE_SUCCESS;
+}
+
+#if 0
+/**
+ * dxr3videosink_wait:
+ * Make the sink wait the specified amount of time.
+ */
+static void
+dxr3videosink_wait (Dxr3VideoSink *sink, GstClockTime time)
+{
+  GstClockID id;
+  GstClockTimeDiff jitter;
+  GstClockReturn ret;
+  GstClockTime current_time = gst_clock_get_time (sink->clock);
+
+  id = gst_clock_new_single_shot_id (sink->clock, current_time + time);
+  ret = gst_clock_id_wait (id, &jitter);
+  gst_clock_id_free (id);
+}
+#endif
+
+/**
+ * dxr3videosink_mvcommand
+ *
+ * Send an MVCOMMAND to the card.
+ */
+static int
+dxr3videosink_mvcommand (Dxr3VideoSink *sink, int command)
+{
+  em8300_register_t regs;
+  
+  regs.microcode_register = 1;
+  regs.reg = 0;
+  regs.val = command;
+  
+  return ioctl (sink->control_fd, EM8300_IOCTL_WRITEREG, &regs);
+}
+
+
+/**
+ * dxr3videosink_flushed:
+ *
+ * Default do nothing implementation for the "flushed" signal.  The
+ * "flushed" signal will be fired right after flushing the hardware
+ * queues due to a received flush event 
+ */
+static void
+dxr3videosink_flushed (Dxr3VideoSink *sink)
+{
+  /* Do nothing. */
+}
+
+
+extern gboolean 
+dxr3videosink_factory_init (GstPlugin *plugin) 
+{ 
+  GstElementFactory *factory;
+
+  factory = gst_element_factory_new ("dxr3videosink",
+                                     GST_TYPE_DXR3VIDEOSINK,
+                                     &dxr3videosink_details);
+  g_return_val_if_fail (factory != NULL, FALSE);
+  gst_element_factory_add_pad_template (factory,
+                     GST_PAD_TEMPLATE_GET (dxr3videosink_sink_factory));
+
+  gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
+
+  return TRUE;
+}
diff --git a/sys/dxr3/dxr3videosink.h b/sys/dxr3/dxr3videosink.h
new file mode 100644 (file)
index 0000000..b0e5cad
--- /dev/null
@@ -0,0 +1,97 @@
+/* GStreamer
+ * Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
+ *
+ * dxr3videosink.h: Video 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
+ * 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 __DXR3VIDEOSINK_H__
+#define __DXR3VIDEOSINK_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+
+#define GST_TYPE_DXR3VIDEOSINK \
+  (dxr3videosink_get_type())
+#define DXR3VIDEOSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DXR3VIDEOSINK,Dxr3VideoSink))
+#define DXR3VIDEOSINK_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DXR3VIDEOSINK,Dxr3VideoSinkClass))
+#define GST_IS_DXR3VIDEOSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DXR3VIDEOSINK))
+#define GST_IS_DXR3VIDEOSINK_CLASS(obj) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DXR3VIDEOSINK))
+
+
+typedef struct _Dxr3VideoSink Dxr3VideoSink;
+typedef struct _Dxr3VideoSinkClass Dxr3VideoSinkClass;
+
+
+typedef enum {
+  DXR3VIDEOSINK_OPEN = GST_ELEMENT_FLAG_LAST,
+  DXR3VIDEOSINK_FLAG_LAST  = GST_ELEMENT_FLAG_LAST + 2,
+} Dxr3VideoSinkFlags;
+
+
+struct _Dxr3VideoSink {
+  GstElement element;
+
+  int card_number;             /* The number of the card to open. */
+
+  gchar *video_filename;       /* File name for the video device. */
+  int video_fd;                        /* File descriptor for the video device. */
+
+  gchar *control_filename;     /* File name for the control device. */
+  int control_fd;              /* File descriptor for the control
+                                   device. */
+
+  GstClock *clock;             /* The clock for this element. */
+
+  GstClockTime last_ts;                /* Last timestamp received. */
+
+  GstBuffer *cur_buf;          /* The buffer we are currently
+                                   building. */
+  GstClockTime cur_ts;         /* Timestamp associated to the
+                                   current buffer. */
+
+  guchar scan_state;           /* The current state of the MPEG start
+                                   code scanner. */
+  guint scan_pos;              /* The current position of the MPEG
+                                   start code scanner (with respect to
+                                   the start of the current buffer. */
+
+  guchar parse_state;          /* The current state of the MPEG
+                                   sequence parser. */
+};
+
+
+struct _Dxr3VideoSinkClass {
+  GstElementClass parent_class;
+
+  /* signals */
+  void (*flushed) (Dxr3VideoSink *sink);
+};
+
+
+extern GType   dxr3videosink_get_type          (void);
+extern gboolean        dxr3videosink_factory_init      (GstPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* __DXR3VIDEOSINK_H__ */
diff --git a/sys/dxr3/gstdxr3.c b/sys/dxr3/gstdxr3.c
deleted file mode 100644 (file)
index 4d2cc00..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "gstdxr3videosink.h"
-
-/* elementfactory information */
-static GstElementDetails dxr3_video_sink_details = {
-  "dxr3/Hollywood+ mpeg decoder board plugin",
-  "video/mpeg",
-  "GPL",
-  "Outputs PAL/NTSC video via the dxr3/Hollywood+ mpeg decoder board",
-  VERSION,
-  "Rehan Khwaja <rehankhwaja@yahoo.com>",
-  "(C) 2002",
-};
-
-
-static gboolean
-plugin_init (GModule *module, GstPlugin *plugin)
-{
-  GstElementFactory *video_factory;
-
-  video_factory = gst_element_factory_new("dxr3videosink", GST_TYPE_DXR3_VIDEO_SINK, &dxr3_video_sink_details);
-  g_return_val_if_fail(video_factory != NULL, FALSE);
-
-  gst_element_factory_add_pad_template (video_factory, GST_PAD_TEMPLATE_GET (dxr3_video_sink_factory));
-
-  gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (video_factory));
-
-  return TRUE;
-}
-
-
-GstPluginDesc plugin_desc = {
-  GST_VERSION_MAJOR,
-  GST_VERSION_MINOR,
-  "dxr3",
-  plugin_init
-};
-
-       
diff --git a/sys/dxr3/gstdxr3videosink.c b/sys/dxr3/gstdxr3videosink.c
deleted file mode 100644 (file)
index 4d9a944..0000000
+++ /dev/null
@@ -1,383 +0,0 @@
-/* GStreamer DXR3 Hardware MPEG video decoder plugin
- * Copyright (C) <2002> Rehan Khwaja <rehankhwaja@yahoo.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.
- */
-
-
-#include <string.h>
-#include <fcntl.h>
-#include "gstdxr3videosink.h"
-#include <sys/ioctl.h>
-#include <linux/em8300.h>
-
-
-enum {
-  ARG_0,
-  ARG_TV_MODE,
-  ARG_DEVICE,
-  ARG_ASPECT_RATIO
-  /* TODO -
-   * DIGITAL/ANALOG AUDIO OUT
-   * OVERLAY MODE
-   * SET BCS??  what's that?
-   * OVERLAY ATTRIBUTES - where on the screen to put image
-   * OVERLAY WINDOW - as above
-   * OVERLAY KEYCOLOR
-   * OVERLAY SIGNAL MODE
-   * PLAYMODE - pausing, playing, slow forward etc
-   */
-};
-
-static void    gst_dxr3_video_sink_class_init  (GstDxr3VideoSinkClass *klass);
-static void    gst_dxr3_video_sink_init                (GstDxr3VideoSink *example);
-
-static void    gst_dxr3_video_sink_chain               (GstPad *pad, GstBuffer *buf);
-
-static void    gst_dxr3_video_sink_set_property        (GObject *object, guint prop_id,
-                                                const GValue *value, GParamSpec *pspec);
-static void    gst_dxr3_video_sink_get_property        (GObject *object, guint prop_id,
-                                                GValue *value, GParamSpec *pspec);
-static gboolean        gst_dxr3_video_sink_handle_event        (GstPad *pad, GstEvent *event);
-static void    gst_dxr3_video_sink_set_clock           (GstElement *element, GstClock *clock);
-
-
-static GstElementClass *parent_class = NULL;
-
-
-#define GST_TYPE_DXR3_VIDEO_SINK_ASPECT_RATIOS (gst_dxr3_video_sink_aspect_ratios_get_type())
-static GType
-gst_dxr3_video_sink_aspect_ratios_get_type(void) {
-  static GType dxr3_video_sink_aspect_ratio_type = 0;
-  static GEnumValue dxr3_video_sink_aspect_ratios[] = {
-    {0, "0", "4:3"},
-    {1, "1", "16:9"},
-    {0, NULL, NULL},
-  };
-  if (!dxr3_video_sink_aspect_ratio_type) {
-    dxr3_video_sink_aspect_ratio_type = g_enum_register_static("GstDxr3VideoSinkAspectRatios", dxr3_video_sink_aspect_ratios);
-  }
-  return dxr3_video_sink_aspect_ratio_type;
-}
-
-#define GST_TYPE_DXR3_VIDEO_SINK_TV_MODES (gst_dxr3_video_sink_tv_modes_get_type())
-static GType
-gst_dxr3_video_sink_tv_modes_get_type(void) {
-  static GType dxr3_video_sink_tv_mode_type = 0;
-  static GEnumValue dxr3_video_sink_tv_modes[] = {
-    {0, "0", "NTSC"},
-    {1, "1", "PAL"},
-    {0, NULL, NULL},
-  };
-  if (!dxr3_video_sink_tv_mode_type) {
-    dxr3_video_sink_tv_mode_type = g_enum_register_static("GstDxr3VideoSinkTvModes", dxr3_video_sink_tv_modes);
-  }
-  return dxr3_video_sink_tv_mode_type;
-}
-
-static void
-gst_dxr3_video_sink_set_clock(GstElement *element, GstClock *clock)
-{
-  GstDxr3VideoSink *dxr3_video_sink;
-
-  dxr3_video_sink = GST_DXR3_VIDEO_SINK(element);
-  dxr3_video_sink->clock = clock;
-}
-
-GType
-gst_dxr3_video_sink_get_type(void)
-{
-  static GType dxr3_video_sink_type = 0;
-
-  if (!dxr3_video_sink_type) {
-    static const GTypeInfo dxr3_video_sink_info = {
-      sizeof(GstDxr3VideoSinkClass),      NULL,
-      NULL,
-      (GClassInitFunc)gst_dxr3_video_sink_class_init,
-      NULL,
-      NULL,
-      sizeof(GstDxr3VideoSink),
-      0,
-      (GInstanceInitFunc)gst_dxr3_video_sink_init,
-    };
-    dxr3_video_sink_type = g_type_register_static(GST_TYPE_ELEMENT, "GstDxr3VideoSink", &dxr3_video_sink_info, 0);
-  }
-  return dxr3_video_sink_type;
-}
-
-static gchar *
-gst_dxr3_video_sink_get_control_device(GstDxr3VideoSink *dxr3_video_sink)
-{
-  return g_strdup_printf("/dev/em8300-%d", dxr3_video_sink->device_number);
-}
-
-static gchar *
-gst_dxr3_video_sink_get_video_device(GstDxr3VideoSink *dxr3_video_sink)
-{
-  return g_strdup_printf("/dev/em8300_mv-%d", dxr3_video_sink->device_number);
-}
-
-static void
-gst_dxr3_video_sink_class_init (GstDxr3VideoSinkClass *klass)
-{
-  GObjectClass *gobject_class;
-  GstElementClass *gstelement_class;
-
-  gobject_class = (GObjectClass*)klass;
-  gstelement_class = (GstElementClass*)klass;
-
-  parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
-
-  g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TV_MODE,
-    g_param_spec_enum("tv-mode","tv-mode","sets NTSC/PAL output format",
-                     GST_TYPE_DXR3_VIDEO_SINK_TV_MODES, 0, G_PARAM_READWRITE));
-
-  g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DEVICE,
-    g_param_spec_int("device","device","sets/returns board number",
-                     0,3,0,G_PARAM_READWRITE));
-
-  g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_ASPECT_RATIO,
-    g_param_spec_enum("aspect-ratio", "aspect-ratio", "sets/returns aspect ratio",
-                     GST_TYPE_DXR3_VIDEO_SINK_ASPECT_RATIOS, 0, G_PARAM_READWRITE));
-
-  gobject_class->set_property = gst_dxr3_video_sink_set_property;
-  gobject_class->get_property = gst_dxr3_video_sink_get_property;
-
-  gstelement_class->set_clock = gst_dxr3_video_sink_set_clock;
-}
-
-static void
-gst_dxr3_video_sink_open_device(GstDxr3VideoSink *dxr3_video_sink)
-{
-  gchar *video_device_path;
-
-  video_device_path = gst_dxr3_video_sink_get_video_device(dxr3_video_sink);
-  if (dxr3_video_sink->device){
-    fclose(dxr3_video_sink->device);
-  }
-  /* this is what disksink uses */
-  dxr3_video_sink->device = fopen(video_device_path, "w");
-
-  g_free(video_device_path);
-}
-
-static void
-gst_dxr3_video_sink_init(GstDxr3VideoSink *dxr3_video_sink)
-{
-  dxr3_video_sink->sinkpad = gst_pad_new_from_template (
-                 GST_PAD_TEMPLATE_GET (dxr3_video_sink_factory), "video_sink");
-  gst_pad_set_chain_function(dxr3_video_sink->sinkpad, gst_dxr3_video_sink_chain);
-  gst_element_add_pad(GST_ELEMENT(dxr3_video_sink),dxr3_video_sink->sinkpad);
-
-  dxr3_video_sink->device_number = 0;
-  dxr3_video_sink->device = 0;
-  /* FIXME - should only have device open when necessary
-   * which probably requires handling events?
-   * also, when is this device closed?
-   */
-  gst_dxr3_video_sink_open_device(dxr3_video_sink);
-
-  GST_FLAG_SET (GST_ELEMENT(dxr3_video_sink), GST_ELEMENT_EVENT_AWARE);
-  gst_pad_set_event_function(dxr3_video_sink->sinkpad, gst_dxr3_video_sink_handle_event);
-
-  dxr3_video_sink->clock = NULL;
-}
-
-static gboolean
-gst_dxr3_video_sink_handle_event(GstPad *pad, GstEvent *event)
-{
-  GstEventType type;
-
-  type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
-
-  switch (type) {
-    case GST_EVENT_SEEK:
-      g_print("seek event\n\n");
-      break;
-    case GST_EVENT_NEW_MEDIA:
-      g_print("new media event\n\n");
-      break;
-    case GST_EVENT_FLUSH:
-      g_print("flush event\n\n");
-      break;
-    default:
-      g_print("event\n\n");
-      gst_pad_event_default (pad, event);
-      break;
-  }
-
-  return TRUE;
-}
-
-static void
-gst_dxr3_video_sink_chain (GstPad *pad, GstBuffer *buf)
-{
-  GstDxr3VideoSink *dxr3_video_sink;
-  long pts;
-
-  /* Some of these checks are of dubious value, since if there were not
-   * already true, the chain function would never be called.
-   */
-  g_return_if_fail(pad != NULL);
-  g_return_if_fail(GST_IS_PAD(pad));
-  g_return_if_fail(buf != NULL);
-
-  dxr3_video_sink = GST_DXR3_VIDEO_SINK(gst_pad_get_parent (pad));
-
-  g_return_if_fail(dxr3_video_sink != NULL);
-  g_return_if_fail(GST_IS_DXR3_VIDEO_SINK(dxr3_video_sink));
-
-  /* Copy the data in the incoming buffer onto the device. */
-  fwrite(GST_BUFFER_DATA (buf), 1, GST_BUFFER_SIZE (buf), dxr3_video_sink->device);
-  pts = (long)GST_BUFFER_TIMESTAMP(buf);
-  if (-1 == ioctl((int)dxr3_video_sink->device, EM8300_IOCTL_VIDEO_SETPTS, &pts)){
-    GST_DEBUG(0, "FAILED call to EM8300_IOCTL_VIDEO_SETPTS\n");
-  }
-
-  gst_buffer_unref (buf);
-}
-
-static void
-gst_dxr3_video_sink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
-{
-  GstDxr3VideoSink *dxr3_video_sink;
-  int device;
-  gchar *device_path;
-  int tv_mode_ioctl, aspect_ratio_ioctl;
-
-  g_return_if_fail(GST_IS_DXR3_VIDEO_SINK(object));
-
-  dxr3_video_sink = GST_DXR3_VIDEO_SINK(object);
-
-  switch (prop_id) {
-    case ARG_TV_MODE:
-      device_path = gst_dxr3_video_sink_get_control_device(dxr3_video_sink);
-      device = open(device_path, O_WRONLY);
-      if (device == -1){
-        GST_DEBUG(0, "failed to open control device\n");
-       break;
-      }
-      switch(g_value_get_int(value)){
-      case 0:
-        tv_mode_ioctl = EM8300_VIDEOMODE_NTSC;
-       break;
-      case 1:
-        tv_mode_ioctl = EM8300_VIDEOMODE_PAL;
-       break;
-      case 2:
-        tv_mode_ioctl = EM8300_VIDEOMODE_PAL60;
-       break;
-      }
-      if (-1 == ioctl(device, EM8300_IOCTL_SET_VIDEOMODE, &tv_mode_ioctl)){
-        GST_DEBUG (0,"failed to set tv-mode\n");
-      }
-      close(device);
-      break;
-    case ARG_DEVICE:
-      dxr3_video_sink->device_number = g_value_get_int(value);
-      gst_dxr3_video_sink_open_device(dxr3_video_sink);
-      break;
-    case ARG_ASPECT_RATIO:
-      device_path = gst_dxr3_video_sink_get_control_device(dxr3_video_sink);
-      device = open(device_path, O_WRONLY);
-      if (device == -1){
-        GST_DEBUG(0, "failed to open control device\n");
-       break;
-      }
-      switch(g_value_get_enum(value)){
-      case 0:
-        aspect_ratio_ioctl = EM8300_ASPECTRATIO_4_3;
-       break;
-      case 1:
-        aspect_ratio_ioctl = EM8300_ASPECTRATIO_16_9;
-       break;
-      }
-      if (-1 == ioctl(device, EM8300_IOCTL_SET_ASPECTRATIO, &aspect_ratio_ioctl)){
-        GST_DEBUG(0, "failed to set aspect-ratio\n");
-      }
-      break;
-    default:
-      break;
-  }
-}
-
-static void
-gst_dxr3_video_sink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
-{
-  GstDxr3VideoSink *dxr3_video_sink;
-  gint device;
-  gchar *device_path;
-  int tv_mode_ioctl, aspect_ratio_ioctl;
-
-  g_return_if_fail(GST_IS_DXR3_VIDEO_SINK(object));
-  dxr3_video_sink = GST_DXR3_VIDEO_SINK(object);
-
-  switch (prop_id) {
-    case ARG_TV_MODE:
-      device_path = gst_dxr3_video_sink_get_control_device(dxr3_video_sink);
-      tv_mode_ioctl = 0;
-      device = open(device_path, O_WRONLY);
-      if (-1 == device){
-        GST_DEBUG(0, "failed to open control device\n");
-       break;
-      }
-      if (-1 == ioctl(device, EM8300_IOCTL_GET_VIDEOMODE, &tv_mode_ioctl)){
-        GST_DEBUG(0, "failed to get tv-mode\n");
-      }
-      close(device);
-
-      switch(tv_mode_ioctl){
-      case EM8300_VIDEOMODE_NTSC:
-        g_value_set_enum(value, 0);
-       break;
-      case EM8300_VIDEOMODE_PAL:
-        g_value_set_enum(value, 1);
-       break;
-      case EM8300_VIDEOMODE_PAL60:
-        g_value_set_enum(value, 2);
-       break;
-      }
-      break;
-    case ARG_DEVICE:
-      g_value_set_int(value, dxr3_video_sink->device_number);
-      break;
-    case ARG_ASPECT_RATIO:
-      device_path = gst_dxr3_video_sink_get_control_device(dxr3_video_sink);
-      aspect_ratio_ioctl = 0;
-      device = open(device_path, O_WRONLY);
-      if (-1 == device){
-        GST_DEBUG(0, "failed to open control device\n");
-       break;
-      }
-      if (-1 == ioctl(device, EM8300_IOCTL_GET_ASPECTRATIO, &aspect_ratio_ioctl)){
-        GST_DEBUG(0, "failed to get aspect ratio\n");
-      }
-      close(device);
-
-      switch(aspect_ratio_ioctl){
-      case EM8300_ASPECTRATIO_4_3:
-        g_value_set_enum(value, 0);
-       break;
-      case EM8300_ASPECTRATIO_16_9:
-        g_value_set_enum(value, 1);
-        break;
-      }
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-  }
-}
diff --git a/sys/dxr3/gstdxr3videosink.h b/sys/dxr3/gstdxr3videosink.h
deleted file mode 100644 (file)
index 3933329..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* GStreamer DXR3 Hardware MPEG video decoder plugin
- * Copyright (C) <2002> Rehan Khwaja <rehankhwaja@yahoo.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 __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;
-
-  /* board number */
-  gint device_number;
-
-  /* file handle for the video device */
-  FILE *device;
-
-  GstClock *clock;
-
-  /* our only pad */
-  GstPad *sinkpad;
-};
-
-
-typedef struct _GstDxr3VideoSinkClass GstDxr3VideoSinkClass;
-
-struct _GstDxr3VideoSinkClass {
-  GstElementClass parent_class;
-};
-
-
-#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__ */