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 cMediamvpTransceiver::cMediamvpTransceiver(const cChannel *Channel, int Priority, int Socket, cDevice *Device) :
42 cReceiver(Channel->Ca(), Priority, 7, Channel->Vpid(), Channel->Ppid(),
43 Channel->Apid1(), Channel->Apid2(), Channel->Dpid1(), Channel->Dpid2(),
50 m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 2, true);
51 // m_RingBuffer = new cRingBufferLinear(VIDEOBUFSIZE, TS_SIZE * 20, true);
53 /* Select the correct Muxing depending on whether it's video or not */
54 if ( Channel->Vpid() == 0 || Channel->Vpid() == 1 || Channel->Vpid() == 0x1FFF ) {
55 m_Remux = new cTS2ESRemux(Channel->Apid1());
57 m_Remux = new cTS2PSRemux(Channel->Vpid(), Channel->Apid1(), 0, 0, 0, 0);
59 printf("Created transceiver at %p, remux @%p ringbuffer %p\n",this,m_Remux,m_RingBuffer);
61 /* Suggested by Peter Wagner to assist single DVB card systems */
63 m_Device->SwitchChannel(Channel, true);
65 m_Device->SwitchChannel(Channel, false);
72 pthread_mutex_init(&ringLock, NULL);
76 cMediamvpTransceiver::~cMediamvpTransceiver(void)
78 printf("Deleting transceiver at %p, remux @%p ringbuffer %p\n",this,m_Remux,m_RingBuffer);
89 void cMediamvpTransceiver::Activate(bool On)
97 void cMediamvpTransceiver::Stop(void)
106 void cMediamvpTransceiver::Receive(uchar *Data, int Length)
108 static time_t firsterr = 0;
109 static int errcnt = 0;
110 static bool showerr = true;
113 int p = m_RingBuffer->Put(Data, Length);
118 firsterr = time_ms();
119 else if (firsterr + BUFOVERTIME > time_ms() && errcnt > BUFOVERCOUNT) {
120 esyslog("ERROR: too many buffer overflows, logging stopped");
122 firsterr = time_ms();
124 } else if (firsterr + BUFOVERTIME < time_ms()) {
131 esyslog("ERROR: ring buffer overflow (%d bytes dropped)", Length - p);
133 firsterr = time_ms();
138 void cMediamvpTransceiver::Action(void)
143 printf("Mediamvp: Transceiver thread started (pid=%d)", getpid());
150 const uchar *block = m_RingBuffer->Get(recvd);
152 if (block && recvd > 0) {
153 const uchar *sendBlock;
157 sendBlock = m_Remux->Process(block, taken, bytes);
159 m_RingBuffer->Del(taken);
165 // write(m_Socket,sendBlock,bytes);
166 // printf("Written %i bytes\n", bytes);
169 pthread_mutex_lock(&ringLock);
170 rb.put((unsigned char*)sendBlock, bytes);
171 pthread_mutex_unlock(&ringLock);
172 //printf("Put %i into buffer\n", bytes);
180 printf("Mediamvp: Transceiver thread ended");
183 unsigned long cMediamvpTransceiver::getBlock(unsigned char* buffer, unsigned long amount)
185 pthread_mutex_lock(&ringLock);
187 while ((unsigned long)rb.getContent() < amount)
189 pthread_mutex_unlock(&ringLock);
191 pthread_mutex_lock(&ringLock);
194 unsigned long amountReceived = rb.get(buffer, amount);
195 pthread_mutex_unlock(&ringLock);
196 return amountReceived;