changeset 19137:d9656bb2ae0e

new vo driver for ivtv cards tv-out through internal h/w mpeg decoder
author ben
date Wed, 19 Jul 2006 22:02:09 +0000
parents 87f9eebbf712
children 0fb9a103800f
files configure libvo/video_out.c libvo/vo_ivtv.c
diffstat 3 files changed, 334 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Wed Jul 19 21:46:06 2006 +0000
+++ b/configure	Wed Jul 19 22:02:09 2006 +0000
@@ -318,6 +318,7 @@
   --enable-directx       build with DirectX support [autodetect]
   --enable-dxr2          build with DXR2 render support [autodetect]
   --enable-dxr3          build with DXR3/H+ render support [autodetect]
+  --enable-ivtv          build with IVTV TV-Out render support [autodetect]
   --enable-dvb           build with support for output via DVB-Card [autodetect]
   --enable-dvbhead       build with DVB support (HEAD version) [autodetect]
   --enable-mga           build with mga_vid (for Matrox G200/G4x0/G550) support
@@ -1597,6 +1598,7 @@
 _dvbhead=auto
 _dxr2=auto
 _dxr3=auto
+_ivtv=auto
 _iconv=auto
 _langinfo=auto
 _rtc=auto
@@ -1784,6 +1786,8 @@
   --disable-dxr2)	_dxr2=no	;;
   --enable-dxr3)	_dxr3=yes	;;
   --disable-dxr3)	_dxr3=no	;;
+  --enable-ivtv)        _ivtv=yes       ;;
+  --disable-ivtv)       _ivtv=no        ;;
   --enable-iconv)	_iconv=yes	;;
   --disable-iconv)	_iconv=no	;;
   --enable-langinfo)	_langinfo=yes	;;
@@ -4697,6 +4701,30 @@
 echores "$_dxr3"
 
 
+echocheck "IVTV TV-Out"
+if test "$_ivtv" = auto ; then
+  cat > $TMPC << EOF
+#include <stdlib.h>
+#include <inttypes.h>
+#include <linux/types.h>
+#include <linux/videodev2.h>
+#include <linux/ivtv.h>
+int main(void) { return 0; }
+EOF
+  _ivtv=no
+  cc_check && _ivtv=yes
+fi
+if test "$_ivtv" = yes ; then
+  _def_ivtv='#define HAVE_IVTV 1'
+  _vosrc="$_vosrc vo_ivtv.c"
+  _vomodules="ivtv $_vomodules"
+else
+  _def_ivtv='#undef HAVE_IVTV'
+  _novomodules="ivtv $_novomodules"
+fi
+echores "$_ivtv"
+
+
 echocheck "libfame"
 if test "$_libfame" = auto ; then
   _libfame=no
@@ -8207,6 +8235,7 @@
 $_def_fbdev
 $_def_dxr2
 $_def_dxr3
+$_def_ivtv
 $_def_dvb
 $_def_dvb_in
 $_def_svga
--- a/libvo/video_out.c	Wed Jul 19 21:46:06 2006 +0000
+++ b/libvo/video_out.c	Wed Jul 19 22:02:09 2006 +0000
@@ -99,6 +99,9 @@
 extern vo_functions_t video_out_dxr2;
 #endif
 extern vo_functions_t video_out_dxr3;
+#ifdef HAVE_IVTV
+extern vo_functions_t video_out_ivtv;
+#endif
 #ifdef HAVE_JPEG
 extern vo_functions_t video_out_jpeg;
 #endif
@@ -210,6 +213,9 @@
 #ifdef HAVE_DXR3
 	&video_out_dxr3,
 #endif
+#ifdef HAVE_IVTV
+        &video_out_ivtv,
+#endif
 #ifdef HAVE_ZR
 	&video_out_zr,
 	&video_out_zr2,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_ivtv.c	Wed Jul 19 22:02:09 2006 +0000
@@ -0,0 +1,299 @@
+/*
+ *  Copyright (C) 2006 Benjamin Zores
+ *   Video output for WinTV PVR-150/250/350 (a.k.a IVTV) cards.
+ *   TV-Out through hardware MPEG decoder.
+ *   Based on some old code from ivtv driver authors.
+ *   See http://ivtvdriver.org/index.php/Main_Page for more details on the
+ *    cards supported by the ivtv driver.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software Foundation,
+ *  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <linux/types.h>
+#include <linux/videodev2.h>
+#include <linux/ivtv.h>
+#include <linux/ioctl.h>
+
+#include "mp_msg.h"
+#include "subopt-helper.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+#include "libmpcodecs/mpeg_packetizer.h"
+
+#define DEFAULT_MPEG_DECODER "/dev/video16"
+#define IVTV_VO_HDR "VO: [ivtv]"
+
+/* ivtv private */
+int ivtv_fd = -1;
+static vo_mpegpes_t *pes;
+
+/* suboptions */
+static int output = -1;
+static char *device = NULL;
+
+static opt_t subopts[] = {
+  {"output",   OPT_ARG_INT,       &output,       (opt_test_f)int_non_neg},
+  {"device",   OPT_ARG_MSTRZ,     &device,       NULL},
+  {NULL}
+};
+
+static vo_info_t info = 
+{
+  "IVTV MPEG Video Decoder TV-Out",
+  "ivtv",
+  "Benjamin Zores",
+  ""
+};
+LIBVO_EXTERN (ivtv)
+
+/* ivtv internals */
+
+static uint32_t
+ivtv_reset (int blank_screen)
+{
+  struct ivtv_cfg_stop_decode sd;
+  struct ivtv_cfg_start_decode sd1;
+
+  sd.hide_last = blank_screen;
+  sd.pts_stop = 0;
+ 
+  if (ioctl (ivtv_fd, IVTV_IOC_S_STOP_DECODE, &sd) < 0)
+  {
+    mp_msg (MSGT_VO, MSGL_ERR,
+            "IVTV_IOC_STOP_DECODE: %s\n", strerror (errno));
+    return 1;
+  }
+  
+  sd1.gop_offset = 0;
+  sd1.muted_audio_frames = 0;
+  
+  if (ioctl (ivtv_fd, IVTV_IOC_S_START_DECODE, &sd1) < 0)
+  {
+    mp_msg (MSGT_VO, MSGL_ERR,
+            "IVTV_IOC_START_DECODE: %s\n", strerror (errno));
+    return 1;
+  }
+
+  return 0;
+}
+
+int
+ivtv_write (unsigned char *data, int len)
+{
+  if (ivtv_fd < 0)
+    return 0;
+  
+  return write (ivtv_fd, data, len);
+}
+
+/* video out functions */
+
+static int
+config (uint32_t width, uint32_t height,
+        uint32_t d_width, uint32_t d_height,
+        uint32_t fullscreen, char *title, uint32_t format)
+{
+  return 0;
+}
+
+static int
+preinit (const char *arg)
+{
+  struct v4l2_output vout;
+  int err;
+
+  if (subopt_parse (arg, subopts) != 0)
+  {
+    mp_msg (MSGT_VO, MSGL_FATAL,
+            "\n-vo ivtv command line help:\n"
+            "Example: mplayer -vo ivtv:device=/dev/video16:output=2\n"
+            "\nOptions:\n"
+            "  device=/dev/videoX\n"
+            "    Name of the MPEG decoder device file.\n"
+            "  output=<0-...>\n"
+            "    V4L2 id of the TV output.\n"
+            "\n" );
+    return -1;
+  }
+  
+  if (!device)
+    device = strdup (DEFAULT_MPEG_DECODER);    
+  
+  ivtv_fd = open (device, O_RDWR);
+  if (ivtv_fd < 0)
+  {  
+    free (device);
+    mp_msg (MSGT_VO, MSGL_FATAL, "%s %s\n", IVTV_VO_HDR, strerror (errno));
+    return -1;
+  }
+
+  /* list available outputs */
+  vout.index = 0;
+  err = 1;
+  mp_msg (MSGT_VO, MSGL_INFO, "%s Available video outputs: ", IVTV_VO_HDR);
+  while (ioctl (ivtv_fd, VIDIOC_ENUMOUTPUT, &vout) >= 0)
+  {
+    err = 0;
+    mp_msg (MSGT_VO, MSGL_INFO, "'#%d, %s' ", vout.index, vout.name);
+    vout.index++;
+  }
+  if (err)
+  {
+    mp_msg (MSGT_VO, MSGL_INFO, "none\n");
+    free (device);
+    return -1;
+  }
+  else
+    mp_msg (MSGT_VO, MSGL_INFO, "\n");
+
+  /* set user specified output */
+  if (output != -1)
+  {
+    if (ioctl (ivtv_fd, VIDIOC_S_OUTPUT, &output) < 0)
+    {
+      mp_msg (MSGT_VO, MSGL_ERR,
+              "%s can't set output (%s)\n", IVTV_VO_HDR, strerror (errno));
+      free (device);
+      return -1;
+    }
+  }
+
+  /* display device name */
+  mp_msg (MSGT_VO, MSGL_INFO, "%s using %s\n", IVTV_VO_HDR, device);
+  free (device);
+
+  /* display current video output */
+  if (ioctl (ivtv_fd, VIDIOC_G_OUTPUT, &output) == 0)
+  {
+    vout.index = output;
+    if (ioctl (ivtv_fd, VIDIOC_ENUMOUTPUT, &vout) < 0)
+    {
+      mp_msg (MSGT_VO, MSGL_ERR,
+              "%s can't get output (%s).\n", IVTV_VO_HDR, strerror (errno));
+      return -1;
+    }
+    else
+      mp_msg (MSGT_VO, MSGL_INFO,
+              "%s video output: %s\n", IVTV_VO_HDR, vout.name);
+  }
+  else
+  {
+    mp_msg (MSGT_VO, MSGL_ERR,
+            "%s can't get output (%s).\n", IVTV_VO_HDR, strerror (errno));
+    return -1;
+  }
+  
+  /* clear output */
+  ivtv_reset (1);
+
+  return 0;
+}
+
+static void
+draw_osd (void)
+{
+  /* do nothing */
+}
+
+static int
+draw_frame (uint8_t * src[])
+{
+  pes = (vo_mpegpes_t *) src[0];
+  return 0;
+}
+
+static void
+flip_page (void)
+{
+  if (ivtv_fd < 0)
+    return;
+
+  if (!pes)
+    return;
+
+  send_mpeg2_pes_packet (pes->data, pes->size, pes->id,
+                         pes->timestamp ? pes->timestamp : vo_pts,
+                         ivtv_write);
+
+  /* ensure flip_page() won't be called twice */
+  pes = NULL;
+}
+
+static int
+draw_slice (uint8_t *image[], int stride[], int w, int h, int x, int y)
+{
+  return 0;
+}
+
+static void
+uninit (void)
+{
+  if (ivtv_fd < 0)
+    return;
+
+  /* clear output */
+  ivtv_reset (1);
+
+  /* close device */
+  close (ivtv_fd);
+  ivtv_fd = -1;
+}
+
+static void
+check_events (void)
+{
+  /* do nothing */
+}
+
+static int
+query_format (uint32_t format)
+{
+  if (format != IMGFMT_MPEGPES)
+    return 0;
+    
+  return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER;
+}
+
+static int
+control (uint32_t request, void *data, ...)
+{
+  switch (request)
+  {
+  case VOCTRL_PAUSE: 
+  case VOCTRL_RESUME: 
+    return ivtv_reset (0);
+
+  case VOCTRL_RESET: 
+    return ivtv_reset (1);
+
+  case VOCTRL_QUERY_FORMAT:
+    return query_format (*((uint32_t*) data));
+  }
+  
+  return VO_NOTIMPL;
+}