Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mpeg2] Re: mpex experience



On Saturday 23 August 2003 01:07, greg wrote:
> Hi Andrew,
>
> If you need a test bunny then I'm your guy.
>
> I've also hacked together procfs support for getting at some of the
> status registers of the 7134 (if anyone is interested).

Hiya, here is my latest patch for the MPEX encoder. This is against the 
snapshot 20030822 on http://bytesex.org/. Sound is working fine now, as is 
video. 

There may be a remaining issue: sound can be out of sync when you first read 
from the encoder, but gets back in sync within about 20 seconds. I'm gonna 
try and fix this soon, but I thought you might like to test a nearly working 
version ASAP.


If you have a card *without* a tuner (as I do):

Unfortunately, BMK have used the same subsystem ID as the Philips reference 
board, so theres no good way to tell the BMK board versions apart.

When you load the module, you have to supply "chip=18" as a parameter. 

If you have more than one board (e.g. 3), you have as many 18's as boards 
(i.e. "chip=18,18,18" for 3 boards)

I've numbered the inputs starting from the one nearest the screw on the PCI 
connector as there is nothing actually stamped on the card.


For the version with the tuner:

Omit the "card=18", and it will be detected as a philips encoder reference 
board. I don't know if this will work correctly however, as I don't know how 
the inputs are wired up: I had to beep the inputs on my card out with a 
voltmeter to work out what was connected to what.

I'm not sure if sound is working for the tuner version. It is currently setup 
to read from LINE1. You may need to switch inputs using v4l to get sound from 
the tuner.
--- saa7134.orig/saa6752hs.c	2003-08-21 19:42:38.000000000 +0100
+++ saa7134/saa6752hs.c	2003-08-23 23:29:09.000000000 +0100
@@ -146,7 +146,7 @@
 {
 	unsigned char buf[3];
 	enum saa6752hs_mode _oldmode;
-	unsigned long timeout;
+	int startJiffies;
 
 	// determine the old mode
 	saa6752hs_get_mode(client, &_oldmode);
@@ -191,9 +191,12 @@
 		return -EINVAL;  
 	}
 	
+	// keep the old mode
+	if (oldmode) *oldmode = _oldmode;
+	
   	// set it and wait for it to be so
-	timeout = jiffies + HZ / 10;
 	i2c_master_send(client, buf, 1);
+	startJiffies = jiffies;
 	do {
 		// get the current status
 		buf[0] = 0x10;
@@ -203,10 +206,9 @@
 		// wait a bit
 		current->state = TASK_INTERRUPTIBLE;
 		schedule_timeout(1);
-	} while ((buf[0] & 0x20) && time_after(jiffies,timeout));
+	} while ((buf[0] & 0x20) && ((jiffies - startJiffies) < (2*HZ)));
 
-	// done
-	if (oldmode) *oldmode = _oldmode;
+	if ((jiffies - startJiffies) >= (2*HZ)) return -ETIMEDOUT;
   	return 0;
 }
 
@@ -223,15 +225,15 @@
 		break;
 	  
   	case SAA6752HS_MODE_ENCODING:
-  		command = SAA6752HS_COMMAND_RECONFIGURE_FORCE;
+  		command = SAA6752HS_COMMAND_START;
 		break;
 
   	case SAA6752HS_MODE_STOPPED:
-  		command = SAA6752HS_COMMAND_RECONFIGURE_FORCE;
+  		command = SAA6752HS_COMMAND_STOP;
 		break;
 	  
   	case SAA6752HS_MODE_PAUSED:
-  		command = SAA6752HS_COMMAND_RECONFIGURE_FORCE;
+  		command = SAA6752HS_COMMAND_PAUSE;
 		break;
 	
 	default:
@@ -250,6 +252,11 @@
 	// reset it
 	saa6752hs_chip_command(client, SAA6752HS_COMMAND_RESET, NULL);
   
+    	// Enable system timeout
+	buf[0] = 0x08;
+	buf[1] = 0x01;
+	i2c_master_send(client,buf,2);
+  
     	// Set GOP structure {3, 13}
 	buf[0] = 0x72;
 	buf[1] = 0x03;
@@ -309,8 +316,8 @@
 	buf[1] = 0x00;
 	i2c_master_send(client,buf,2);
   
-	// set the encoder into idle mode
- 	saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE_FORCE, NULL);
+	// set the encoder into stop mode
+ 	saa6752hs_chip_command(client, SAA6752HS_COMMAND_STOP, NULL);
   
 	return 0;
 }
@@ -365,7 +372,9 @@
 	if (bitrate->total_bitrate >= SAA6752HS_TOTAL_BITRATE_MAX) return -EINVAL;
 
   	// set the encoder into reconfigure mode
+	if (saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE, &oldmode)) {
 	saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE_FORCE, &oldmode);
+	}
 	  
 	// set the bitrate mode
 	buf[0] = 0x71;
@@ -410,7 +419,9 @@
 	if (*streamtype >= SAA6752HS_STREAMTYPE_MAX) return -EINVAL;
 
 	// set the encoder into reconfigure mode
+	if (saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE, &oldmode)) {
   	saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE_FORCE, &oldmode);
+	}
 
     	// Set video output stream format {TS}
 	buf[0] = 0xB0;
@@ -456,7 +467,6 @@
         if (NULL == (client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL)))
                 return -ENOMEM;
         memcpy(client,&client_template,sizeof(struct i2c_client));
-  
 	strlcpy(client->name, "saa6752hs", sizeof(client->name));
         i2c_attach_client(client);
 	saa6752hs_reset(client);
@@ -493,6 +503,24 @@
 	return 0;
 }
 
+static int saa6752hs_start_encoder(struct i2c_client* client)
+{
+	// start main MPEG encoder
+	saa6752hs_chip_command(client, SAA6752HS_COMMAND_START, NULL);
+
+	return 0;
+}
+
+static int saa6752hs_stop_encoder(struct i2c_client* client)
+{
+	// stop the encoder
+	if (saa6752hs_chip_command(client, SAA6752HS_COMMAND_STOP, NULL)) {
+		saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE_FORCE, NULL);
+	}
+  
+	return 0;
+}
+
 static int
 saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
 {
@@ -504,10 +532,10 @@
 		return saa6752hs_reset(client);
 	  
 	case MPEG_ENC_START:
-		return saa6752hs_chip_command(client, SAA6752HS_COMMAND_START, NULL);
+		return saa6752hs_start_encoder(client);
 
 	case MPEG_ENC_STOP:
-		return saa6752hs_chip_command(client, SAA6752HS_COMMAND_RECONFIGURE_FORCE, NULL);
+		return saa6752hs_stop_encoder(client);	  
 	  
 	case SAA6752HSIOC_SETBITRATE:
 		return saa6752hs_set_bitrate(client, bitrate_arg);
--- saa7134.orig/saa7134-ts.c	2003-08-21 16:54:24.000000000 +0100
+++ saa7134/saa7134-ts.c	2003-08-23 23:01:07.000000000 +0100
@@ -195,9 +195,6 @@
 	file->private_data = dev;
 	err = 0;
 
-	/* start the encoder */
-	saa7134_i2c_call_clients(dev, MPEG_ENC_START, 0);
-
  done:
 	up(&dev->ts.ts.lock);
 	return err;
@@ -215,6 +212,7 @@
 	dev->ts.users--;
 
 	/* stop the encoder */
+	dev->ts.started = 0;
 	saa7134_i2c_call_clients(dev, MPEG_ENC_STOP, 0);
   
 	up(&dev->ts.ts.lock);
@@ -226,6 +224,12 @@
 {
 	struct saa7134_dev *dev = file->private_data;
 
+	/* start the encoder */
+	if (!dev->ts.started) {
+		saa7134_i2c_call_clients(dev, MPEG_ENC_START, 0);
+		dev->ts.started = 1;
+	}
+  
 	return videobuf_read_stream(file, &dev->ts.ts, data, count, ppos, 0);
 }
 
--- saa7134.orig/saa7134.h	2003-08-20 11:21:00.000000000 +0100
+++ saa7134/saa7134.h	2003-08-23 22:58:01.000000000 +0100
@@ -48,6 +48,9 @@
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71)
 # define strlcpy(dest,src,len) strncpy(dest,src,(len)-1)
 #endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+# define pci_name(DEV) DEV->slot_name
+#endif
 
 
 #ifndef TRUE
@@ -161,6 +164,7 @@
 #define SAA7134_BOARD_ELSA_500TV       15
 #define SAA7134_BOARD_ASUSTeK_TVFM7134 16
 #define SAA7134_BOARD_VA1000POWER      17
+#define SAA7134_BOARD_BMK_MPEX_NOTUNER 18
 
 #define SAA7134_INPUT_MAX 8
 
@@ -284,6 +288,7 @@
 	/* TS capture */
 	struct videobuf_queue      ts;
 	struct saa7134_pgtable     pt_ts;
+	int			   started;
 };
 
 /* oss dsp status */
--- saa7134.orig/saa7134-cards.c	2003-08-20 11:31:00.000000000 +0100
+++ saa7134/saa7134-cards.c	2003-08-23 22:55:29.000000000 +0100
@@ -32,6 +32,8 @@
 static char name_tv_mono[] = "TV (mono only)";
 static char name_comp1[]   = "Composite1";
 static char name_comp2[]   = "Composite2";
+static char name_comp3[]   = "Composite3";
+static char name_comp4[]   = "Composite4";
 static char name_svideo[]  = "S-Video";
 
 /* ------------------------------------------------------------------ */
@@ -503,6 +505,40 @@
                         .tv   = 1,
                 }},
        },
+	[SAA7134_BOARD_BMK_MPEX_NOTUNER] = {
+		/* "Andrew de Quincey" <adq@lidskialf.net> */
+		.name		= "BMK MPEX No Tuner",
+		.audio_clock	= 0x200000, // 0x00187de7,
+		.tuner_type	= TUNER_ABSENT,
+		.inputs         = {{
+			.name = name_comp1,
+			.vmux = 4,
+			.amux = LINE1,
+		},{
+			.name = name_comp2,
+			.vmux = 3,
+			.amux = LINE1,
+		},{
+			.name = name_comp3,
+			.vmux = 0,
+			.amux = LINE1,
+		},{
+			.name = name_comp4,
+			.vmux = 1,
+			.amux = LINE1,
+		},{
+			.name = name_svideo,
+			.vmux = 8,
+			.amux = LINE1,
+		}},
+		.radio = {
+			.name = name_radio,
+			.amux = LINE2,
+		}, 
+		.i2s_rate  = 48000,
+		.has_ts    = 1,
+		.video_out = CCIR656,
+	},
 };
 const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
 
--- saa7134.orig/saa7134-tvaudio.c	2003-08-11 14:03:26.000000000 +0100
+++ saa7134/saa7134-tvaudio.c	2003-08-23 23:04:32.000000000 +0100
@@ -204,7 +204,11 @@
 	case LINE1: reg = 0x00; break;
 	case LINE2: reg = 0x01; break;
 	}
+	if (card_has_ts(dev)) {
+		saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x0f, reg);
+	} else {
 	saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x07, reg);
+	}
 
 	/* switch gpio-connected external audio mux */
 	if (0 == card(dev).gpiomask)
@@ -880,6 +884,16 @@
 		saa_writeb(SAA7134_I2S_AUDIO_OUTPUT,   0x01);
 	}
 
+	/* setup audio for MPEG encoder LINE1 */
+	if (card_has_ts(dev)) {
+		switch(dev->pci->device) {
+		case PCI_DEVICE_ID_PHILIPS_SAA7134:
+			saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10, 0x10);
+			saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, 0x0);
+			break;
+		}
+	}
+		  
 	switch (dev->pci->device) {
 	case PCI_DEVICE_ID_PHILIPS_SAA7134:
 		my_thread = tvaudio_thread;

Home | Main Index | Thread Index