vdr  1.7.27
transfer.c
Go to the documentation of this file.
00001 /*
00002  * transfer.c: Transfer mode
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: transfer.c 2.6 2012/02/29 14:16:23 kls Exp $
00008  */
00009 
00010 #include "transfer.h"
00011 
00012 // --- cTransfer -------------------------------------------------------------
00013 
00014 cTransfer::cTransfer(const cChannel *Channel)
00015 :cReceiver(Channel, TRANSFERPRIORITY)
00016 {
00017   patPmtGenerator.SetChannel(Channel);
00018 }
00019 
00020 cTransfer::~cTransfer()
00021 {
00022   cReceiver::Detach();
00023   cPlayer::Detach();
00024 }
00025 
00026 void cTransfer::Activate(bool On)
00027 {
00028   if (On) {
00029      PlayTs(patPmtGenerator.GetPat(), TS_SIZE);
00030      int Index = 0;
00031      while (uchar *pmt = patPmtGenerator.GetPmt(Index))
00032            PlayTs(pmt, TS_SIZE);
00033      }
00034   else
00035      cPlayer::Detach();
00036 }
00037 
00038 void cTransfer::Receive(uchar *Data, int Length)
00039 {
00040   if (cPlayer::IsAttached()) {
00041      // Transfer Mode means "live tv", so there's no point in doing any additional
00042      // buffering here. The TS packets *must* get through here! However, every
00043      // now and then there may be conditions where the packet just can't be
00044      // handled when offered the first time, so that's why we try several times:
00045      for (int i = 0; i < 100; i++) {
00046          if (PlayTs(Data, Length) > 0)
00047             return;
00048          cCondWait::SleepMs(10);
00049          }
00050      esyslog("ERROR: TS packet not accepted in Transfer Mode");
00051      }
00052 }
00053 
00054 // --- cTransferControl ------------------------------------------------------
00055 
00056 cDevice *cTransferControl::receiverDevice = NULL;
00057 
00058 cTransferControl::cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel)
00059 :cControl(transfer = new cTransfer(Channel), true)
00060 {
00061   ReceiverDevice->AttachReceiver(transfer);
00062   receiverDevice = ReceiverDevice;
00063 }
00064 
00065 cTransferControl::~cTransferControl()
00066 {
00067   receiverDevice = NULL;
00068   delete transfer;
00069 }