[ANNOUNCE] vdr-pvrinput-0.0.1

Message ID 200506031147.43230.jareguero@telefonica.net
State New
Headers

Commit Message

Jose Alberto Reguero June 3, 2005, 9:47 a.m. UTC
  El Martes, 31 de Mayo de 2005 22:20, Andreas Regel escribió:
> Hello,
>
> here is a first release of the pvrinput plugin for VDR. It uses a
> Hauppauge PVR card (supported by ivtv drivers) as an input device for
> VDR. I am using it with driver version 0.2.0rc3j and encoder firmware
> 2.04.211.
>
> I have written this plugin because I was a bit unhappy about some things
> with analogtv. Motivated by a mail from Lars Altenhain on this list I
> tried an approach a bit different from the analogtv plugin. The reading
> of the PES data an the conversion to TS is done in a thread in the
> background without interrupting it on channel switch. The packets are
> then read out and delivered to VDR in the GetTSPacket function.
>
> Additionally the plugin reads the teletext data from the vbi device
> (/dev/vbi0 is hardcoded at the moment) and converts it to TS packets
> that the osdteletext plugin is able to receive. Sometimes one or two
> lines are wrong but its working quite good here.
>
> Compared to the analogtv plugin the following is better here with my
> configuration (Hauppauge PVR 250, Kernel 2.6, ivtv 0.2.0rc3j):
> - Faster channel switching
> - no video flickerung after channel switch
> - just minimal stuttering in sound after channel switch
> - and of course teletext support
>
> Expect problems to get it running in your environment, especially
> regardings device configuration :).
>
> You can find it here:
> http://home.arcor.de/andreas.regel/files/vdr-pvrinput-0.0.1.tgz
>
> Andreas
It works fine.
I make a patch to append radio support.
Perhaps you could integrate better way.
For radio channels video pid = 0 in channels.conf
The patch in ivtv.h is for amd64 vbi support.
Thanks.
Jose Alberto
  

Patch

diff -aur pvrinput-0.0.1/device.c pvrinput-0.0.1.radio/device.c
--- pvrinput-0.0.1/device.c	2005-05-31 21:04:31.000000000 +0200
+++ pvrinput-0.0.1.radio/device.c	2005-06-03 11:33:55.000000000 +0200
@@ -10,6 +10,7 @@ 
 
 extern "C" {
 #include <transform.h>
+#include <ctools.h>
 }
 
 #include "common.h"
@@ -96,21 +97,25 @@ 
 private:
 	bool active;
 	int video_fd;
+	int radio_fd;
 	cRingBufferLinear * tsBuffer;
 	cMutex * mutex;
 
 	static void WriteBuffer(unsigned char * buf, int count, void * p);
+	static void twrite_coque(uint8_t const *buf);
+	static void pes_filt_coque(p2p *p);
 protected:
 	virtual void Action(void);
 public:
-	cPvrVideoReadThread(int VideoDevice, cRingBufferLinear * TsBuffer, cMutex * Mutex);
+	cPvrVideoReadThread(int VideoDevice, int RadioDevice, cRingBufferLinear * TsBuffer, cMutex * Mutex);
 	virtual ~cPvrVideoReadThread(void);
 	int PutData(const unsigned char * Data, int Count);
 };
 
-cPvrVideoReadThread::cPvrVideoReadThread(int VideoDevice, cRingBufferLinear * TsBuffer, cMutex * Mutex)
+cPvrVideoReadThread::cPvrVideoReadThread(int VideoDevice, int RadioDevice, cRingBufferLinear * TsBuffer, cMutex * Mutex)
 :	active(false),
 	video_fd(VideoDevice),
+	radio_fd(RadioDevice),
 	tsBuffer(TsBuffer),
 	mutex(Mutex)
 {
@@ -138,6 +143,27 @@ 
 	thread->PutData(buf, count);
 }
 
+p2t_t p2t_coque;
+unsigned char buffer_coque[BUFFSIZE];
+int r_coque;
+
+void cPvrVideoReadThread::pes_filt_coque(p2p *p)
+{
+	int aux;
+
+	if ( p->cid == 0xc0)
+	{
+		aux = p->plength + 6;
+		memcpy(buffer_coque + r_coque, p->buf, aux);
+		r_coque += aux;
+	}
+}
+
+void cPvrVideoReadThread::twrite_coque(uint8_t const *buf)
+{
+	WriteBuffer((unsigned char *)buf, TS_SIZE, &p2t_coque);
+}
+
 void cPvrVideoReadThread::Action(void)
 {
 	active = true;
@@ -154,6 +180,7 @@ 
 	p2t.count1 = 0;
 	p2t.count0 = 0;
 	p2t.data = this;
+	init_p2t(&p2t_coque,twrite_coque);
 
 	while (active)
 	{
@@ -164,7 +191,17 @@ 
 			break;
 		}
 		if (r > 0)
-			kpes_to_ts(&p2t, buffer, r); // PES -> TS
+		{
+			if (radio_fd >= 0)
+			{
+				r_coque = 0;
+				get_pes(buffer, r, &p2t, pes_filt_coque); // SOLO AUDIO
+				if (r_coque > 0)
+					pes_to_ts(buffer_coque, r_coque, kAudioPid, &p2t_coque); // PES -> TS
+			}
+			else
+				kpes_to_ts(&p2t, buffer, r); // PES -> TS
+		}
 //		cCondWait::SleepMs(1);
 	}
 }
@@ -295,6 +332,7 @@ 
 cPvrDevice::cPvrDevice(int DeviceNumber)
 :	video_fd(-1),
 	vbi_fd(-1),
+	radio_fd(-1),	
 	frequency(-1),
 	vpid(-1),
 	apid(-1),
@@ -317,7 +355,7 @@ 
 	}
 	tsBuffer = new cRingBufferLinear(MEGABYTE(3), TS_SIZE, false, "PVRTS");
 	tsBuffer->SetTimeouts(100, 100);
-	videoReadThread = new cPvrVideoReadThread(video_fd, tsBuffer, &mutex);
+	videoReadThread = new cPvrVideoReadThread(video_fd, radio_fd, tsBuffer, &mutex);
 	vbiReadThread = new cPvrVbiReadThread(vbi_fd, tsBuffer, &mutex);
 	SetVideoNorm(videoNormPAL);
 	SetCodec(aspect4by3, 6000, 256);
@@ -333,6 +371,8 @@ 
 	delete vbiReadThread;
 	delete tsBuffer;
 	close(vbi_fd);
+	if (radio_fd >= 0)
+		close (radio_fd);
 	close(video_fd);
 }
 
@@ -434,7 +474,23 @@ 
 	memset(&vf, 0, sizeof(vf));
 	vf.tuner = 0;
 	vf.type = V4L2_TUNER_ANALOG_TV;
-	vf.frequency = freq * 16 / 1000;
+	if (freq < 108000)
+	{
+		if (radio_fd == -1)
+		{
+			radio_fd = open ("/dev/radio",O_RDONLY);
+		}
+		vf.frequency = int((freq/1000.0f + .5/16) * 16);
+	}
+	else
+	{
+		if (radio_fd >=0)
+		{
+			close (radio_fd);
+			radio_fd = -1;
+		}
+		vf.frequency = freq * 16 / 1000;
+	}
 
 	if (IOCTL(video_fd, VIDIOC_S_FREQUENCY, &vf) != 0)
 	{
diff -aur pvrinput-0.0.1/device.h pvrinput-0.0.1.radio/device.h
--- pvrinput-0.0.1/device.h	2005-05-29 22:53:37.000000000 +0200
+++ pvrinput-0.0.1.radio/device.h	2005-06-02 20:06:06.000000000 +0200
@@ -15,6 +15,7 @@ 
 private:
 	int video_fd;
 	int vbi_fd;
+	int radio_fd;
 	int frequency;
 	int vpid;
 	int apid;
Sólo en pvrinput-0.0.1.radio: device.o
diff -aur pvrinput-0.0.1/ivtv.h pvrinput-0.0.1.radio/ivtv.h
--- pvrinput-0.0.1/ivtv.h	2005-05-29 12:05:33.000000000 +0200
+++ pvrinput-0.0.1.radio/ivtv.h	2005-06-02 22:55:11.000000000 +0200
@@ -43,17 +43,17 @@ 
 #define IVTV_SLICED_VPS		(1 << 4)
 
 struct ivtv_sliced_vbi_format {
-	unsigned long service_set;	/* one or more of the IVTV_SLICED_ defines */
-	unsigned long packet_size; 	/* the size in bytes of the ivtv_sliced_data packet */
-	unsigned long io_size;		/* maximum number of bytes passed by one read() call */
-	unsigned long reserved;
+	uint32_t service_set;	/* one or more of the IVTV_SLICED_ defines */
+	uint32_t packet_size; 	/* the size in bytes of the ivtv_sliced_data packet */
+	uint32_t io_size;		/* maximum number of bytes passed by one read() call */
+	uint32_t reserved;
 };
 
 /* This structure is the same as the proposed v4l2_sliced_data structure */
 /* id is one of the VBI_SLICED_ flags. */
 struct ivtv_sliced_data {
-	unsigned long id;
-	unsigned long line;
+	uint32_t id;
+	uint32_t line;
 	unsigned char data[0];
 };