[MPlayer-dev-eng] PATCH 5/5: vo_dxr2

Tobias Diedrich td at informatik.uni-hannover.de
Sun Dec 9 04:06:45 CET 2001


A first attempt at converting vo_dxr3 to work with dxr2 cards...
Does not work yet, though.
These beasts seem to want a system stream / program stream, just the
video stream does not work, so one would have to multiplex it...

-- 
Tobias								PGP: 0x9AC7E0BC
-------------- next part --------------
diff -urN main-current/libvo/dxr2ioctl.h main-multi/libvo/dxr2ioctl.h
--- main-current/libvo/dxr2ioctl.h	Thu Jan  1 01:00:00 1970
+++ main-multi/libvo/dxr2ioctl.h	Sat Dec  8 17:08:30 2001
@@ -0,0 +1,426 @@
+/*
+  **********************************************************************
+  *
+  *     Copyright 1999, 2000 Creative Labs, Inc.
+  *
+  **********************************************************************
+  *
+  *     Date                 Author               Summary of changes
+  *     ----                 ------               ------------------
+  *     October 20, 1999     Andrew de Quincey    Rewrote and extended
+  *                          Lucien Murray-Pitts  original incomplete 
+  *                                               driver.
+  *
+  *     April 18, 1999       Andrew Veliath       Original Driver
+  *                                               implementation
+  *
+  **********************************************************************
+  *
+  *     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., 675 Mass Ave, Cambridge, MA 02139,
+  *     USA.
+  *
+  **********************************************************************
+  */
+
+/**
+ *
+ * Driver for the Creative DXR2 Mpeg decoder card
+ *
+ */
+
+#include <linux/ioctl.h>
+#ifdef NEED_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <linux/cdrom.h>
+
+
+#ifndef __DXR2IOCTL_H__
+#define __DXR2IOCTL_H__
+
+
+// *******************************************************************
+// IOCTL codes (this is temporary)
+
+#define DXR2_IOC_MAGIC 'X'
+
+#define DXR2_IOC_GET_REGION_CODE		_IO(DXR2_IOC_MAGIC, 0)
+#define DXR2_IOC_SET_TV_OUTPUT_FORMAT		_IO(DXR2_IOC_MAGIC, 1)
+#define DXR2_IOC_SET_SOURCE_VIDEO_FORMAT 	_IO(DXR2_IOC_MAGIC, 2)
+#define DXR2_IOC_GET_CAPABILITIES		_IO(DXR2_IOC_MAGIC, 3)
+#define DXR2_IOC_CLEAR_VIDEO			_IO(DXR2_IOC_MAGIC, 4)
+#define DXR2_IOC_PAUSE				_IO(DXR2_IOC_MAGIC, 5)
+#define DXR2_IOC_SET_AUDIO_VOLUME		_IO(DXR2_IOC_MAGIC, 6)
+#define DXR2_IOC_SET_OUTPUT_ASPECT_RATIO	_IO(DXR2_IOC_MAGIC, 7)
+#define DXR2_IOC_ABORT				_IO(DXR2_IOC_MAGIC, 8)
+#define DXR2_IOC_STOP				_IO(DXR2_IOC_MAGIC, 9)
+#define DXR2_IOC_ENABLE_SUBPICTURE		_IO(DXR2_IOC_MAGIC, 10)
+#define DXR2_IOC_SLOW_FORWARDS			_IO(DXR2_IOC_MAGIC, 11)
+#define DXR2_IOC_SLOW_BACKWARDS			_IO(DXR2_IOC_MAGIC, 12)
+#define DXR2_IOC_SET_SOURCE_ASPECT_RATIO	_IO(DXR2_IOC_MAGIC, 13)
+#define DXR2_IOC_SET_ASPECT_RATIO_MODE		_IO(DXR2_IOC_MAGIC, 14)
+#define DXR2_IOC_SINGLE_STEP			_IO(DXR2_IOC_MAGIC, 15)
+#define DXR2_IOC_REVERSE_PLAY			_IO(DXR2_IOC_MAGIC, 16)
+#define DXR2_IOC_SET_SUBPICTURE_PALETTE		_IO(DXR2_IOC_MAGIC, 17)
+#define DXR2_IOC_GET_CHALLENGE_KEY		_IO(DXR2_IOC_MAGIC, 18)
+#define DXR2_IOC_SEND_CHALLENGE_KEY		_IO(DXR2_IOC_MAGIC, 19)
+#define DXR2_IOC_GET_RESPONSE_KEY		_IO(DXR2_IOC_MAGIC, 20)
+#define DXR2_IOC_SEND_RESPONSE_KEY		_IO(DXR2_IOC_MAGIC, 21)
+#define DXR2_IOC_SEND_DISC_KEY			_IO(DXR2_IOC_MAGIC, 22)
+#define DXR2_IOC_SEND_TITLE_KEY			_IO(DXR2_IOC_MAGIC, 23)
+#define DXR2_IOC_SET_DECRYPTION_MODE		_IO(DXR2_IOC_MAGIC, 24)
+#define DXR2_IOC_INIT_ZIVADS			_IO(DXR2_IOC_MAGIC, 25)
+#define DXR2_IOC_SET_TV_MACROVISION_MODE	_IO(DXR2_IOC_MAGIC, 27)
+#define DXR2_IOC_RESET 				_IO(DXR2_IOC_MAGIC, 28)
+#define DXR2_IOC_SET_BITSTREAM_TYPE 		_IO(DXR2_IOC_MAGIC, 29)
+#define DXR2_IOC_PLAY 				_IO(DXR2_IOC_MAGIC, 30)
+#define DXR2_IOC_GET_STC      			_IO(DXR2_IOC_MAGIC, 31)
+#define DXR2_IOC_SET_AUDIO_SAMPLE_FREQUENCY 	_IO(DXR2_IOC_MAGIC, 32)
+#define DXR2_IOC_SET_AUDIO_DATA_WIDTH		_IO(DXR2_IOC_MAGIC, 33)
+#define DXR2_IOC_IEC958_OUTPUT_MODE		_IO(DXR2_IOC_MAGIC, 34)
+#define DXR2_IOC_SET_AC3_MODE			_IO(DXR2_IOC_MAGIC, 35)
+#define DXR2_IOC_SELECT_AC3_VOICE		_IO(DXR2_IOC_MAGIC, 36)
+#define DXR2_IOC_AUDIO_MUTE			_IO(DXR2_IOC_MAGIC, 37)
+#define DXR2_IOC_SET_STEREO_MODE		_IO(DXR2_IOC_MAGIC, 38)
+#define DXR2_IOC_SELECT_STREAM			_IO(DXR2_IOC_MAGIC, 39)
+#define DXR2_IOC_HIGHLIGHT			_IO(DXR2_IOC_MAGIC, 40)
+#define DXR2_IOC_SET_TV_BLACKWHITE_MODE		_IO(DXR2_IOC_MAGIC, 41)
+#define DXR2_IOC_SET_TV_INTERLACED_MODE 	_IO(DXR2_IOC_MAGIC, 42)
+#define DXR2_IOC_SET_TV_75IRE_MODE      	_IO(DXR2_IOC_MAGIC, 43)
+#define DXR2_IOC_SET_TV_PIXEL_MODE      	_IO(DXR2_IOC_MAGIC, 44)
+#define DXR2_IOC_SET_OVERLAY_COLOUR    	        _IO(DXR2_IOC_MAGIC, 45)
+#define DXR2_IOC_SET_OVERLAY_GAIN	        _IO(DXR2_IOC_MAGIC, 46)
+#define DXR2_IOC_SET_OVERLAY_IN_DELAY           _IO(DXR2_IOC_MAGIC, 47)
+#define DXR2_IOC_SET_OVERLAY_MODE    	        _IO(DXR2_IOC_MAGIC, 48)
+#define DXR2_IOC_SET_OVERLAY_CROPPING	        _IO(DXR2_IOC_MAGIC, 49)
+#define DXR2_IOC_SET_OVERLAY_DIMENSION	        _IO(DXR2_IOC_MAGIC, 50)
+#define DXR2_IOC_SET_OVERLAY_POSITION	        _IO(DXR2_IOC_MAGIC, 51)
+#define DXR2_IOC_SET_OVERLAY_RATIO              _IO(DXR2_IOC_MAGIC, 52)
+#define DXR2_IOC_CALCULATE_VGA_PARAMETERS       _IO(DXR2_IOC_MAGIC, 53)
+#define DXR2_IOC_SET_VGA_PARAMETERS             _IO(DXR2_IOC_MAGIC, 54)
+#define DXR2_IOC_SET_OVERLAY_PICTURE_CONTROLS   _IO(DXR2_IOC_MAGIC, 55)
+#define DXR2_IOC_FAST_FORWARDS		        _IO(DXR2_IOC_MAGIC, 56)
+#define DXR2_IOC_FAST_BACKWARDS		        _IO(DXR2_IOC_MAGIC, 57)
+#define DXR2_IOC_BUFFERS_EMPTY		        _IO(DXR2_IOC_MAGIC, 58)
+
+
+// *******************************************************************
+// stuff for IOCTLS
+
+// video frequencies
+#define DXR2_SRC_VIDEO_FREQ_30 0
+#define DXR2_SRC_VIDEO_FREQ_25 1
+
+// aspect ratios
+#define DXR2_ASPECTRATIO_4_3 0
+#define DXR2_ASPECTRATIO_16_9 1
+
+// subpicture modes
+#define DXR2_SUBPICTURE_OFF 0
+#define DXR2_SUBPICTURE_ON  1
+
+// rates for slow forwards & backwards
+#define DXR2_PLAYRATE_2x 0
+#define DXR2_PLAYRATE_3x 1
+#define DXR2_PLAYRATE_4x 2
+#define DXR2_PLAYRATE_5x 3
+#define DXR2_PLAYRATE_6x 4
+
+// CSS decryption modes supported
+#define DXR2_CSSDECRMODE_OFF 0
+#define DXR2_CSSDECRMODE_ON  1
+
+// play modes
+#define DXR2_PLAYMODE_STOPPED         0
+#define DXR2_PLAYMODE_PAUSED          1
+#define DXR2_PLAYMODE_SLOWFORWARDS    2
+#define DXR2_PLAYMODE_SLOWBACKWARDS   3
+#define DXR2_PLAYMODE_SINGLESTEP      4
+#define DXR2_PLAYMODE_PLAY            5
+#define DXR2_PLAYMODE_REVERSEPLAY     6
+#define DXR2_PLAYMODE_FASTFORWARDS    7
+#define DXR2_PLAYMODE_FASTBACKWARDS   8
+
+// for operation queue
+#define DXR2_QUEUE_PAUSED             0
+#define DXR2_QUEUE_SETVOLUME          1
+#define DXR2_QUEUE_ENABLESUBPICTURE   2
+#define DXR2_QUEUE_FASTFORWARDS       3
+#define DXR2_QUEUE_FASTBACKWARDS      4
+#define DXR2_QUEUE_SELECTSTREAM       5
+#define DXR2_QUEUE_SETMUTESTATUS      6
+#define DXR2_QUEUE_HIGHLIGHT          7
+
+// aspect ratio modes
+#define DXR2_ASPECTRATIOMODE_NORMAL    0
+#define DXR2_ASPECTRATIOMODE_PAN_SCAN  1
+#define DXR2_ASPECTRATIOMODE_LETTERBOX 2
+
+// macrovision modes
+#define DXR2_MACROVISION_OFF                 0
+#define DXR2_MACROVISION_AGC                 1
+#define DXR2_MACROVISION_AGC_2COLOURSTRIPE   2
+#define DXR2_MACROVISION_AGC_4COLOURSTRIPE   3
+
+
+// TV output modes
+#define DXR2_OUTPUTFORMAT_NTSC      0
+#define DXR2_OUTPUTFORMAT_NTSC_60   1
+#define DXR2_OUTPUTFORMAT_PAL_M     2
+#define DXR2_OUTPUTFORMAT_PAL_M_60  3
+#define DXR2_OUTPUTFORMAT_PAL_BDGHI 4
+#define DXR2_OUTPUTFORMAT_PAL_N     5
+#define DXR2_OUTPUTFORMAT_PAL_Nc    6
+#define DXR2_OUTPUTFORMAT_PAL_60    7
+
+// black/white modes
+#define DXR2_BLACKWHITE_OFF   0
+#define DXR2_BLACKWHITE_ON    1
+
+// interlacing
+#define DXR2_INTERLACED_OFF   0
+#define DXR2_INTERLACED_ON    1
+
+// 7.5 IRE
+#define DXR2_75IRE_OFF        0
+#define DXR2_75IRE_ON         1
+
+// pixel modes
+#define DXR2_PIXEL_CCIR601    0
+#define DXR2_PIXEL_SQUARE     1
+
+// bitstreams possibly present in files
+#define DXR2_STREAM_VIDEO       0
+#define DXR2_STREAM_SUBPICTURE  1
+#define DXR2_STREAM_AUDIO_AC3   2
+#define DXR2_STREAM_AUDIO_MPEG  3
+#define DXR2_STREAM_AUDIO_LPCM  4
+#define DXR2_STREAM_AUDIO_5 5
+
+// bitstream types
+#define DXR2_BITSTREAM_TYPE_MPEG_VOB       0
+#define DXR2_BITSTREAM_TYPE_CDROM_VCD      1
+#define DXR2_BITSTREAM_TYPE_MPEG_VCD       2
+#define DXR2_BITSTREAM_TYPE_CDDA           3
+#define DXR2_BITSTREAM_TYPE_4              4
+
+// frequency of output audio data (to the pcm1723)
+#define DXR2_AUDIO_FREQ_441    0
+#define DXR2_AUDIO_FREQ_48     1
+#define DXR2_AUDIO_FREQ_96     2
+#define DXR2_AUDIO_FREQ_2205   3
+#define DXR2_AUDIO_FREQ_32     4
+
+// widths of output audio data (to the pcm1723)
+#define DXR2_AUDIO_WIDTH_16    0
+#define DXR2_AUDIO_WIDTH_20    1
+#define DXR2_AUDIO_WIDTH_24    2
+
+// play types
+#define DXR2_PLAYTYPE_NORMAL 0
+#define DXR2_PLAYTYPE_STILLSTOP 1
+
+// iec-958 output types
+#define DXR2_IEC958_DECODED    0
+#define DXR2_IEC958_ENCODED    1
+
+// AC3 modes
+#define DXR2_AC3MODE_LR_STEREO          0
+#define DXR2_AC3MODE_LR_STEREO_PROLOGIC 1
+#define DXR2_AC3MODE_LR_MONOR           2
+
+// AC3 voice configuration (for karaoke)
+#define DXR2_AC3VOICE_NONE        0
+#define DXR2_AC3VOICE_V1V2        1
+
+// highlight actions
+#define DXR2_BUTTONACTION_SELECT    0
+#define DXR2_BUTTONACTION_UNHIGHLIGHT 1
+#define DXR2_BUTTONACTION_ACTIVATE 2
+#define DXR2_BUTTONACTION_ACTIVATE_SELECTED 3
+#define DXR2_BUTTONACTION_4 4
+#define DXR2_BUTTONACTION_5 5
+#define DXR2_BUTTONACTION_6 6
+#define DXR2_BUTTONACTION_7 7
+#define DXR2_BUTTONACTION_8 8
+
+// special buttons
+#define DXR2_BUTTON_NONE    0
+#define DXR2_BUTTON_UP     64
+#define DXR2_BUTTON_DOWN   65
+#define DXR2_BUTTON_LEFT   66
+#define DXR2_BUTTON_RIGHT  67
+
+// mute modes
+#define DXR2_AUDIO_MUTE_ON     0
+#define DXR2_AUDIO_MUTE_OFF    1
+
+// stereo mode
+#define DXR2_AUDIO_STEREO_NORMAL  0
+#define DXR2_AUDIO_STEREO_MONOL   1
+#define DXR2_AUDIO_STEREO_MONOR   2
+#define DXR2_AUDIO_STEREO_REVERSE 3
+
+// overlay modes
+#define DXR2_OVERLAY_DISABLED           0
+#define DXR2_OVERLAY_WINDOW_KEY         1
+#define DXR2_OVERLAY_COLOUR_KEY         2
+#define DXR2_OVERLAY_WINDOW_COLOUR_KEY  3
+
+
+// portion of the sync signal to measure
+#define DXR2_MEASURE_PORTION_LOW       0
+#define DXR2_MEASURE_PORTION_HIGH      1
+#define DXR2_MEASURE_PORTION_ALL       2
+
+// which signal to measure
+#define DXR2_TIME_HSYNC                0
+#define DXR2_TIME_VSYNC                1
+#define DXR2_TIME_HCOLOURKEY           2
+#define DXR2_TIME_VCOLOURKEY           3
+
+
+
+// *******************************************************************
+// Structures
+
+
+typedef struct {
+
+  int arg;
+
+} dxr2_oneArg_t;
+
+
+typedef struct {
+
+  int arg1;
+  int arg2;
+
+} dxr2_twoArg_t;
+
+typedef struct {
+
+  int arg1;
+  int arg2;
+  int arg3;
+
+} dxr2_threeArg_t;
+
+typedef struct {
+
+  int arg1;
+  int arg2;
+  int arg3;
+  int arg4;
+
+} dxr2_fourArg_t;
+
+typedef struct {
+
+  int arg1;
+  int arg2;
+  int arg3;
+  int arg4;
+  int arg5;
+  int arg6;
+
+} dxr2_sixArg_t;
+
+
+typedef struct {
+
+  int arg1;
+  int arg2;
+  int arg3;
+  int arg4;
+  int arg5;
+  int arg6;
+  int arg7;
+  int arg8;
+  int arg9;
+
+} dxr2_nineArg_t;
+
+typedef struct {
+
+  int uCodeLength;
+  char uCode[0]; // allocate this structure to whatever length you need...
+
+} dxr2_uCode_t;
+
+typedef struct {
+
+  // offsets of window key being measured
+  int hOffWinKey;
+  int vOffWinKey;
+
+  // screen dimensions
+  int xScreen;
+  int yScreen;
+
+  // sync polarites
+  int hsyncPol;
+  int vsyncPol;
+
+  // video blanking 
+  int blankStart;
+  int blankWidth;
+  
+  // screen offsets
+  int hOffset;
+  int vOffset;
+  
+  // ratio
+  int ratio;
+  
+} dxr2_vgaParams_t;
+
+typedef struct {
+
+  int entries[16];
+
+} dxr2_palette_t;
+
+typedef struct {
+  
+  unsigned char key[10];
+
+} dxr2_challengeKey_t;
+
+
+typedef struct {
+  
+  unsigned char key[5];
+
+} dxr2_responseKey_t;
+
+
+typedef struct {
+  
+  unsigned char key[0x800];
+
+} dxr2_discKey_t;
+
+
+typedef struct {
+  
+  unsigned char cgmsFlags;
+  unsigned char key[5];
+
+} dxr2_titleKey_t;
+
+#endif
+
diff -urN main-current/libvo/video_out.c main-multi/libvo/video_out.c
--- main-current/libvo/video_out.c	Mon Dec  3 02:09:36 2001
+++ main-multi/libvo/video_out.c	Sat Dec  8 17:10:36 2001
@@ -74,6 +74,7 @@
 extern vo_functions_t video_out_aa;
 extern vo_functions_t video_out_mpegpes;
 extern vo_functions_t video_out_dxr3;
+extern vo_functions_t video_out_dxr2;
 #ifdef TARGET_LINUX
 extern vo_functions_t video_out_vesa;
 #endif
@@ -126,6 +127,9 @@
 #endif
 #ifdef HAVE_DXR3
 	&video_out_dxr3,
+#endif
+#ifdef HAVE_DXR2
+	&video_out_dxr2,
 #endif
 
 #ifdef HAVE_PNG
diff -urN main-current/libvo/vo_dxr2.c main-multi/libvo/vo_dxr2.c
--- main-current/libvo/vo_dxr2.c	Thu Jan  1 01:00:00 1970
+++ main-multi/libvo/vo_dxr2.c	Sat Dec  8 18:08:51 2001
@@ -0,0 +1,445 @@
+/* 
+ * vo_dxr3.c - DXR3/H+ video out
+ *
+ * Copyright (C) 2001 David Holm <dholm at iname.com>
+ *
+ */
+
+#include "fastmemcpy.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+
+#include "dxr2ioctl.h"
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+#include "../libmp1e/libmp1e.h"
+
+#include "../postproc/rgb2rgb.h"
+#ifdef HAVE_MMX
+#include "mmx.h"
+#endif
+
+LIBVO_EXTERN (dxr2)
+
+rte_context *mp1e_context = NULL;
+rte_codec *mp1e_codec = NULL;
+rte_buffer mp1e_buffer;
+struct { uint16_t Y,U,V; } YUV_s;
+#define RGBTOY(R,G,B) (uint16_t)( (0.257 * R) + (0.504 * G) + (0.098 * B) + 16 )
+#define RGBTOU(R,G,B) (uint16_t)( -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128 )
+#define RGBTOV(R,G,B) (uint16_t)( (0.439 * R) - (0.368 * G) - (0.071 * B) + 128 )
+#define RGBTOYUV(R,G,B) YUV_s.Y = RGBTOY(R,G,B); \
+			YUV_s.U = RGBTOU(R,G,B); \
+			YUV_s.V = RGBTOV(R,G,B);
+
+static unsigned char *picture_data[3];
+static unsigned int picture_linesize[3];
+
+static int v_width,v_height;
+static int s_width,s_height;
+static int c_width,c_height;
+static int s_pos_x,s_pos_y;
+static int d_pos_x,d_pos_y;
+static int osd_w,osd_h;
+
+static int img_format = 0;
+
+static int dxr2fd = -1;
+static int outfd = -1;
+static int fd_spu = -1;
+static int ioval = 0;
+
+static vo_info_t vo_info = 
+{
+	"DXR2 video out",
+	"dxr2",
+	"David Holm <dholm at iname.com>",
+	""
+};
+
+void write_dxr2( rte_context* context, void* data, size_t size, void* user_data )
+{
+/*    if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts ) < 0 )
+	printf( "VO: [dxr3] Unable to set video PTS\n" );*/
+    write( outfd, data, size );
+}
+
+static uint32_t init(uint32_t scr_width, uint32_t scr_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format)
+{
+    int uCodeFD;
+    int uCodeSize;
+    int stream_type;
+    dxr2_uCode_t* uCode;
+    dxr2_threeArg_t video_freq;
+
+    dxr2fd = open( "/dev/dxr2", O_WRONLY );
+    outfd = open( "foo.mpg", O_WRONLY | O_CREAT);
+//    outfd = dxr2fd;
+    if( dxr2fd < 1 )
+    {
+	printf( "VO: [dxr2] Error opening /dev/dxr2 for writing!\n" );
+	return -1;
+    }
+
+    if ((uCodeFD = open("/usr/src/dvd12.ux", O_RDONLY)) < 0) {
+
+	printf("VO: [dxr2] Could not open uCode (%s): %s\n", "/usr/src/dvd12.ux", strerror(errno));
+	return -1;
+    }
+
+    uCodeSize = lseek(uCodeFD, 0, SEEK_END);
+    if ((uCode = malloc(uCodeSize + 4)) == NULL) {
+
+	printf("VO: [dxr2] Could not allocate memory for uCode: %s\n", strerror(errno));
+	return -1;
+    }
+    lseek(uCodeFD, 0, SEEK_SET);
+    if (read(uCodeFD, uCode+4, uCodeSize) != uCodeSize) {
+
+	printf("VO: [dxr2] Could not read uCode uCode: %s\n", strerror(errno));
+	return -1;
+    }
+    close(uCodeFD);
+    uCode->uCodeLength = uCodeSize;
+
+    // upload ucode
+    ioctl(dxr2fd, DXR2_IOC_INIT_ZIVADS, uCode);
+
+    // start playing
+    stream_type = DXR2_BITSTREAM_TYPE_MPEG_VCD;
+    ioctl(dxr2fd, DXR2_IOC_SET_BITSTREAM_TYPE, &stream_type);
+    video_freq.arg1 = DXR2_SRC_VIDEO_FREQ_30;
+    video_freq.arg2 = 0x2d0;
+    video_freq.arg3 = 0x1e0;
+    ioctl(dxr2fd, DXR2_IOC_SET_SOURCE_VIDEO_FORMAT, &video_freq);
+    ioctl(dxr2fd, DXR2_IOC_PLAY, NULL);
+
+    img_format = format;
+    v_width = width;
+    v_height = height;
+    s_width = scr_width;
+    s_height = scr_height;
+
+    if( format == IMGFMT_YV12 || format == IMGFMT_YUY2 || format == IMGFMT_BGR24 )
+    {
+	int size;
+	enum rte_frame_rate frame_rate;
+
+	if( !rte_init() )
+	{
+	    printf( "VO: [dxr3] Unable to initialize MP1E!\n" );
+	    return -1;
+	}
+	
+        if(width<=352 && height<=288){
+          c_width=352;
+          c_height=288;
+        } else
+        if(width<=352 && height<=576){
+          c_width=352;
+          c_height=576;
+        } else
+        if(width<=480 && height<=576){
+          c_width=480;
+          c_height=576;
+        } else
+        if(width<=544 && height<=576){
+          c_width=544;
+          c_height=576;
+        } else {
+          c_width=704;
+          c_height=576;
+        }
+	
+	mp1e_context = rte_context_new( c_width, c_height, NULL );
+	rte_set_verbosity( mp1e_context, 0 );
+	
+	printf( "VO: [dxr3] %dx%d => %dx%d\n", v_width, v_height, c_width, c_height );
+
+	if( !mp1e_context )
+	{
+	    printf( "VO: [dxr3] Unable to create context!\n" );
+	    return -1;
+	}
+	
+	if( !rte_set_format( mp1e_context, "mpeg1" ) )
+	{
+	    printf( "VO: [dxr3] Unable to set format\n" );
+	    return -1;
+	}
+
+	rte_set_mode( mp1e_context, RTE_VIDEO );
+	mp1e_codec = rte_codec_set( mp1e_context, RTE_STREAM_VIDEO, 0, "mpeg1-video" );
+
+	if( vo_fps < 24.0 ) frame_rate = RTE_RATE_1;
+	else if( vo_fps < 25.0 ) frame_rate = RTE_RATE_2;
+	else if( vo_fps < 29.97 ) frame_rate = RTE_RATE_3;
+	else if( vo_fps < 30.0 ) frame_rate = RTE_RATE_4;
+	else if( vo_fps < 50.0 ) frame_rate = RTE_RATE_5;
+	else if( vo_fps < 59.97 ) frame_rate = RTE_RATE_6;
+	else if( vo_fps < 60.0 ) frame_rate = RTE_RATE_7;
+	else if( vo_fps > 60.0 ) frame_rate = RTE_RATE_8;
+	else frame_rate = RTE_RATE_NORATE;
+
+        if( !rte_set_video_parameters( mp1e_context, RTE_YUV420, mp1e_context->width,
+					mp1e_context->height, frame_rate,
+					3e6, "I" ) )
+        {
+            printf( "VO: [dxr3] Unable to set mp1e context!\n" );
+	    rte_context_destroy( mp1e_context );
+	    return -1;
+	}
+	
+	rte_set_input( mp1e_context, RTE_VIDEO, RTE_PUSH, TRUE, NULL, NULL, NULL );
+	rte_set_output( mp1e_context, (void*)write_dxr2, NULL, NULL );
+	
+	if( !rte_init_context( mp1e_context ) )
+	{
+	    printf( "VO: [dxr3] Unable to init mp1e context!\n" );
+	    rte_context_delete( mp1e_context );
+	    return -1;
+	}
+
+        osd_w=scr_width;
+        d_pos_x=(c_width-(int)scr_width)/2;
+        if(d_pos_x<0)
+	{
+    	    s_pos_x=-d_pos_x;d_pos_x=0;
+    	    osd_w=c_width;
+        } else s_pos_x=0;
+    
+        osd_h=scr_height;
+        d_pos_y=(c_height-(int)scr_height)/2;
+        if(d_pos_y<0)
+	{
+    	    s_pos_y=-d_pos_y;d_pos_y=0;
+    	    osd_h=c_height;
+        } else s_pos_y=0;
+    
+        printf("VO: [dxr3] Position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
+                
+        size = c_width*c_height;
+
+        picture_data[0] = malloc((size * 3)/2);
+	picture_data[1] = picture_data[0] + size;
+	picture_data[2] = picture_data[1] + size / 4;
+	picture_linesize[0] = c_width;
+	picture_linesize[1] = c_width / 2;
+	picture_linesize[2] = c_width / 2;
+
+	// Set the border colorwou
+	RGBTOYUV(0,0,0)
+        memset( picture_data[0], YUV_s.Y, picture_linesize[0]*c_height );
+        memset( picture_data[1], YUV_s.U, picture_linesize[1]*(c_height/2) );
+        memset( picture_data[2], YUV_s.V, picture_linesize[2]*(c_height/2) );
+	
+	if( !rte_start_encoding( mp1e_context ) )
+	{
+	    printf( "VO: [dxr3] Unable to start mp1e encoding!\n" );
+	    uninit();
+	    return -1;
+	}
+
+	return 0;
+    }
+    else if(format==IMGFMT_MPEGPES)
+    {
+	printf( "VO: [dxr3] Format: MPEG-PES (no conversion needed)\n" );
+	return 0;
+    }
+
+    printf( "VO: [dxr3] Format: Unsuppomp1ed\n" );
+    return -1;
+}
+
+static const vo_info_t* get_info(void)
+{
+    return &vo_info;
+}
+
+static void draw_alpha(int x0, int y0, int w, int h, unsigned char* src, unsigned char *srca, int srcstride)
+{
+}
+
+static void draw_osd(void)
+{
+}
+
+static uint32_t draw_frame(uint8_t * src[])
+{
+    if( img_format == IMGFMT_MPEGPES )
+    {
+        int data_left;
+	vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
+
+/*	if( ioctl( fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts ) < 0 )
+	    printf( "VO: [dxr3] Unable to set video PTS\n" ); */
+
+	data_left = p->size;
+	while( data_left )
+	    data_left -= write( outfd, &((unsigned char*)p->data)[p->size-data_left], data_left );
+
+	return 0;
+    }
+    else if( img_format == IMGFMT_YUY2 )
+    {
+	int w=v_width,h=v_height;
+	unsigned char *s,*dY,*dU,*dV;
+	
+        if(d_pos_x+w>picture_linesize[0]) w=picture_linesize[0]-d_pos_x;
+        if(d_pos_y+h>c_height) h=c_height-d_pos_y;
+
+	s = src[0]+s_pos_x+s_pos_y*(w*2);
+	dY = picture_data[0]+d_pos_x+d_pos_y*picture_linesize[0];
+	dU = picture_data[1]+(d_pos_x/2)+(d_pos_y/2)*picture_linesize[1];
+	dV = picture_data[2]+(d_pos_x/2)+(d_pos_y/2)*picture_linesize[2];
+	
+	yuy2toyv12( s, dY, dU, dV, w, h, picture_linesize[0], picture_linesize[1], w*2 );
+	
+	mp1e_buffer.data = picture_data[0];
+	mp1e_buffer.time = vo_pts/90000.0;
+	mp1e_buffer.user_data = NULL;
+	rte_push_video_buffer( mp1e_context, &mp1e_buffer );
+	return 0;
+    }
+    else if( img_format == IMGFMT_BGR24 )
+    {
+	int x,y,w=v_width,h=v_height;
+	unsigned char *s,*dY,*dU,*dV;
+	
+        if(d_pos_x+w>picture_linesize[0]) w=picture_linesize[0]-d_pos_x;
+        if(d_pos_y+h>c_height) h=c_height-d_pos_y;
+
+	s = src[0]+s_pos_y*(w*3);
+
+	dY = picture_data[0]+d_pos_y*picture_linesize[0];
+	dU = picture_data[1]+(d_pos_y/2)*picture_linesize[1];
+	dV = picture_data[2]+(d_pos_y/2)*picture_linesize[2];
+	
+	for(y=0;y<h;y++)
+	{
+	    dY+=d_pos_x;
+	    dU+=d_pos_x/4;
+	    dV+=d_pos_x/4;
+	    s+=s_pos_x;
+	    for(x=0;x<w;x+=4)
+	    {
+		RGBTOYUV(s[2],s[1],s[0]);
+		s+=3;
+		*dY = YUV_s.Y;dY++;
+//	The chrominance is shifted, ppl will have to settle with b&w for now ;)
+//		*dU = YUV_s.U;dU++;
+//		*dV = YUV_s.V;dV++;
+		
+		*dY = RGBTOY(s[2],s[1],s[0]);dY++;
+		s+=3;
+		*dY = RGBTOY(s[2],s[1],s[0]);dY++;
+		s+=3;
+		*dY = RGBTOY(s[2],s[1],s[0]);dY++;
+		s+=3;
+	    }
+	    dY+=d_pos_x;
+	    dU+=d_pos_x/4;
+	    dV+=d_pos_x/4;
+	    s+=s_pos_x;
+	}
+	
+	mp1e_buffer.data = picture_data[0];
+	mp1e_buffer.time = vo_pts/90000.0;
+	mp1e_buffer.user_data = NULL;
+	rte_push_video_buffer( mp1e_context, &mp1e_buffer );
+	
+	return 0;
+    }
+
+    return -1;
+}
+
+static void flip_page (void)
+{
+    if( img_format == IMGFMT_YV12 )
+    {
+	mp1e_buffer.data = picture_data[0];
+	mp1e_buffer.time = vo_pts/90000.0;
+	mp1e_buffer.user_data = NULL;
+	rte_push_video_buffer( mp1e_context, &mp1e_buffer );
+    }
+}
+
+static uint32_t draw_slice( uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0 )
+{
+    if( img_format == IMGFMT_YV12 )
+    {
+	int y;
+	unsigned char *s,*s1;
+	unsigned char *d,*d1;
+
+	x0+=d_pos_x;
+	y0+=d_pos_y;
+
+        if(x0+w>picture_linesize[0]) w=picture_linesize[0]-x0;
+        if(y0+h>c_height) h=c_height-y0;
+
+        s=srcimg[0]+s_pos_x+s_pos_y*stride[0];
+        d=picture_data[0]+x0+y0*picture_linesize[0];
+	for(y=0;y<h;y++)
+	{
+	    memcpy(d,s,w);
+	    s+=stride[0];
+	    d+=picture_linesize[0];
+	}
+
+	w/=2;h/=2;x0/=2;y0/=2;
+	
+	s=srcimg[1]+s_pos_x+s_pos_y*stride[1];
+	d=picture_data[1]+x0+y0*picture_linesize[1];
+	s1=srcimg[2]+s_pos_x+s_pos_y*stride[2];
+	d1=picture_data[2]+x0+y0*picture_linesize[2];
+	for(y=0;y<h;y++)
+	{
+	    memcpy(d,s,w);
+	    memcpy(d1,s1,w);
+	    s+=stride[1];s1+=stride[2];
+	    d+=picture_linesize[1];d1+=picture_linesize[2];
+	}
+
+	return 0;
+    }
+
+    return -1;
+}
+
+
+static uint32_t
+query_format(uint32_t format)
+{
+    if(format==IMGFMT_MPEGPES) return 0x2;0x4;
+    if(format==IMGFMT_YV12) return 0x1|0x4;
+    if(format==IMGFMT_YUY2) return 0x1|0x4;
+    if(format==IMGFMT_BGR24) { printf( "VO: [dxr3] WARNING\tExperimental output, black&white only and very slow\n\t(will be inproved later, this format is rarely used)\n" ); return 0x1|0x4; }
+    else printf( "VO: [dxr3] Format unsupported, mail dholm at iname.com\n" );
+    return 0;
+}
+
+static void uninit(void)
+{
+    printf( "VO: [dxr3] Uninitializing\n" );
+    if( picture_data[0] ) free(picture_data[0]);
+    if( fd_spu ) close(fd_spu);
+}
+
+
+static void check_events(void)
+{
+}
+


More information about the MPlayer-dev-eng mailing list