2 Edited for VOMP by Chris Tallon
3 Edits Copyright 2004-2005 Chris Tallon
9 * (C) 2003 Dominic Morris
14 * Transceiver stuff - blatantly stolen from streamdev then changed
22 #include "transceiver.h"
27 #include <vdr/ringbuffer.h>
29 #include <sys/types.h>
33 #define VIDEOBUFSIZE MEGABYTE(1)
35 /* Disable logging if BUFCOUNT buffer overflows occur within BUFOVERTIME
36 milliseconds. Enable logging again if there is no error within BUFOVERTIME
38 #define BUFOVERTIME 5000
39 #define BUFOVERCOUNT 100
41 #if VDRVERSNUM < 10300
42 cMediamvpTransceiver::cMediamvpTransceiver(const cChannel *Channel, int Priority, int Socket, cDevice *Device) :
43 cReceiver(Channel->Ca(), Priority, 7, Channel->Vpid(), Channel->Ppid(),
44 Channel->Apid1(), Channel->Apid2(), Channel->Dpid1(), Channel->Dpid2(),
47 cMediamvpTransceiver::cMediamvpTransceiver(const cChannel *Channel, int Priority, int Socket, cDevice *Device) :
48 cReceiver(Channel->Ca(), Priority, Channel->Vpid(),
49 Channel->Apids(), Channel->Dpids(), Channel->Spids()) {
57 log = Log::getInstance();
59 m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true);
60 // m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 20, true);
62 /* Select the correct Muxing depending on whether it's video or not */
63 #if VDRVERSNUM < 10300
64 if ( Channel->Vpid() == 0 || Channel->Vpid() == 1 || Channel->Vpid() == 0x1FFF ) {
65 m_Remux = new cTS2ESRemux(Channel->Apid1());
67 m_Remux = new cTS2PSRemux(Channel->Vpid(), Channel->Apid1(), 0, 0, 0, 0);
70 if ( Channel->Vpid() == 0 || Channel->Vpid() == 1 || Channel->Vpid() == 0x1FFF ) {
71 m_Remux = new cTS2ESRemux(Channel->Apid(0));
73 m_Remux = new cTS2PSRemux(Channel->Vpid(), Channel->Apid(0), 0, 0, 0, 0);
76 log->log("Transciever", Log::DEBUG, "Created transceiver at %p, remux @%p ringbuffer %p",this,m_Remux,m_RingBuffer);
78 /* Suggested by Peter Wagner to assist single DVB card systems */
80 m_Device->SwitchChannel(Channel, true);
82 m_Device->SwitchChannel(Channel, false);
89 pthread_mutex_init(&ringLock, NULL);
93 cMediamvpTransceiver::~cMediamvpTransceiver(void)
95 log->log("Transciever", Log::DEBUG, "Deleting transceiver at %p, remux @%p ringbuffer %p",this,m_Remux,m_RingBuffer);
106 void cMediamvpTransceiver::Activate(bool On)
114 void cMediamvpTransceiver::Stop(void)
123 void cMediamvpTransceiver::Receive(uchar *Data, int Length)
125 static time_t firsterr = 0;
126 static int errcnt = 0;
127 static bool showerr = true;
130 int p = m_RingBuffer->Put(Data, Length);
133 #if VDRVERSNUM < 10300
136 firsterr = time_ms();
137 else if (firsterr + BUFOVERTIME > time_ms() && errcnt > BUFOVERCOUNT) {
138 esyslog("ERROR: too many buffer overflows, logging stopped");
140 firsterr = time_ms();
142 } else if (firsterr + BUFOVERTIME < time_ms()) {
149 esyslog("ERROR: ring buffer overflow (%d bytes dropped)", Length - p);
151 firsterr = time_ms();
158 else if (lastTime.Elapsed() > BUFOVERTIME && errcnt > BUFOVERCOUNT) {
159 esyslog("ERROR: too many buffer overflows, logging stopped");
162 } else if (lastTime.Elapsed() < BUFOVERTIME) {
169 esyslog("ERROR: ring buffer overflow (%d bytes dropped)", Length - p);
177 void cMediamvpTransceiver::Action(void)
182 log->log("Transciever", Log::DEBUG, "Mediamvp: Transceiver thread started (pid=%d)", getpid());
189 const uchar *block = m_RingBuffer->Get(recvd);
191 if (block && recvd > 0) {
192 const uchar *sendBlock;
196 sendBlock = m_Remux->Process(block, taken, bytes);
198 m_RingBuffer->Del(taken);
204 // write(m_Socket,sendBlock,bytes);
205 // printf("Written %i bytes\n", bytes);
208 pthread_mutex_lock(&ringLock);
209 rb.put((unsigned char*)sendBlock, bytes);
210 pthread_mutex_unlock(&ringLock);
211 //printf("Put %i into buffer\n", bytes);
219 log->log("Transciever", Log::DEBUG, "Mediamvp: Transceiver thread ended");
222 unsigned long cMediamvpTransceiver::getBlock(unsigned char* buffer, unsigned long amount)
224 pthread_mutex_lock(&ringLock);
226 while ((unsigned long)rb.getContent() < amount)
228 pthread_mutex_unlock(&ringLock);
230 pthread_mutex_lock(&ringLock);
233 unsigned long amountReceived = rb.get(buffer, amount);
234 pthread_mutex_unlock(&ringLock);
235 return amountReceived;