summaryrefslogtreecommitdiff
path: root/pes2es.cpp
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2009-10-02 17:36:58 +0200
committerJochen Dolze <vdr@dolze.de>2009-10-02 17:36:58 +0200
commit52cd041405849817c72d272bee0e6798f57b66c4 (patch)
tree994709d9e41ae0a367ba4b0bf5254911a4f38558 /pes2es.cpp
parenta21c3bf58621446068b054326eec83dae1e744a0 (diff)
downloadvdr-plugin-markad-52cd041405849817c72d272bee0e6798f57b66c4.tar.gz
vdr-plugin-markad-52cd041405849817c72d272bee0e6798f57b66c4.tar.bz2
Rewrote packet handling code, now it uses queues
Diffstat (limited to 'pes2es.cpp')
-rw-r--r--pes2es.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/pes2es.cpp b/pes2es.cpp
new file mode 100644
index 0000000..8d09e45
--- /dev/null
+++ b/pes2es.cpp
@@ -0,0 +1,95 @@
+/*
+ * pes2es.cpp: A plugin for the Video Disk Recorder
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id$
+ */
+
+#include "pes2es.h"
+
+cMarkAdPES2ES::cMarkAdPES2ES(int RecvNumber, const char *QueueName, int QueueSize)
+{
+ queue = new cMarkAdPaketQueue(RecvNumber,QueueName,QueueSize);
+ type=0;
+}
+
+cMarkAdPES2ES::~cMarkAdPES2ES()
+{
+ if (queue) delete queue;
+}
+
+void cMarkAdPES2ES::Reset()
+{
+ queue->Clear();
+}
+
+void cMarkAdPES2ES::Process(MarkAdPid Pid, uchar *PESData, int PESSize, uchar **ESData, int *ESSize)
+{
+ if ((!ESData) || (!ESSize) || (!queue)) return;
+ *ESData=NULL;
+ *ESSize=0;
+
+ if (PESData)
+ {
+ struct PESHDR *peshdr=(struct PESHDR *) PESData;
+
+ // first check some simple things
+ if ((peshdr->Sync1!=0) && (peshdr->Sync2!=0) && (peshdr->Sync3!=1))
+ {
+ Reset();
+ return;
+ }
+
+ int Length=(peshdr->LenH<<8)+peshdr->LenL+sizeof(PESHDR);
+ if (Length!=PESSize)
+ {
+ Reset();
+ return;
+ }
+
+ switch (Pid.Type)
+ {
+ case MARKAD_PIDTYPE_VIDEO_H262:
+ case MARKAD_PIDTYPE_VIDEO_H264:
+ if ((peshdr->StreamID & 0xF0)!=0xE0) return;
+ type=MA_PACKET_PKT;
+ break;
+ case MARKAD_PIDTYPE_AUDIO_AC3:
+ if (peshdr->StreamID!=0xBD) return;
+ type=MA_PACKET_AC3;
+ break;
+ case MARKAD_PIDTYPE_AUDIO_MP2:
+ if ((peshdr->StreamID<0xC0) || (peshdr->StreamID>0xDF)) return;
+ type=MA_PACKET_MP2;
+ break;
+ default:
+ Reset();
+ return;
+ }
+
+ struct PESHDROPT *peshdropt=(struct PESHDROPT *) &PESData[sizeof(struct PESHDR)];
+
+ uchar *buf;
+ int buflen;
+
+ if (peshdropt->MarkerBits==0x2)
+ {
+ // we have an optional PES header
+ int bpos=sizeof(struct PESHDR)+sizeof(struct PESHDROPT)+
+ peshdropt->Length;
+ buf=&PESData[bpos];
+ buflen=PESSize-bpos;
+ }
+ else
+ {
+ int bpos=sizeof(struct PESHDR);
+ buf=&PESData[bpos];
+ buflen=PESSize-bpos;
+ }
+
+ queue->Put(buf,buflen);
+ }
+ if (type) *ESData=queue->GetPacket(ESSize,type);
+ return;
+}