[PATCH] Working PlayTsXXX to PlayXXX wrapper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi list,


Attached is a new version of cDevice::PlayTsVideo and cDevice::PlayTsAudio that properly handles partially accepted buffers of the PlayVideo and PlayAudio functions. The original functions would discard any partially written data.

These two functions are only used by devices that do not implement their own PlayTsXXX functions. The FF DVB devices don't use them any more, since TS is passed to (patched) DVB drivers. Other devices will soon play TS directly too.

However, it might still be useful for patches that restore support for older drivers. ;)


Cheers,

Udo

Index: device.c
===================================================================
--- device.c	(revision 1083)
+++ device.c	(working copy)
@@ -89,6 +89,10 @@
   liveSubtitle = NULL;
   dvbSubtitleConverter = NULL;
   autoSelectPreferredSubtitleLanguage = true;
+  tsToPesVideoBuffer = NULL;
+  tsToPesVideoLength = 0;
+  tsToPesAudioBuffer = NULL;
+  tsToPesAudioLength = 0;
 
   for (int i = 0; i < MAXRECEIVERS; i++)
       receiver[i] = NULL;
@@ -1270,14 +1274,33 @@
 
 int cDevice::PlayTsVideo(const uchar *Data, int Length)
 {
+  // Play remains of last buffer if not completely played:
+  while (tsToPesVideoBuffer && tsToPesVideoLength > 0) {
+        int w = PlayVideo(tsToPesVideoBuffer, tsToPesVideoLength);
+        if (w <= 0)
+           return w;
+        tsToPesVideoBuffer += w;
+        tsToPesVideoLength -= w;
+        if (tsToPesVideoLength > 0) {
+           errno = EAGAIN;
+           return -1;
+           }
+        tsToPesVideoBuffer = tsToPesVideo.GetPes(tsToPesVideoLength);
+        }
+
   // Video PES has no explicit length, so we can only determine the end of
   // a PES packet when the next TS packet that starts a payload comes in:
   if (TsPayloadStart(Data)) {
-     int l;
-     while (const uchar *p = tsToPesVideo.GetPes(l)) {
-           int w = PlayVideo(p, l);
+     while ((tsToPesVideoBuffer = tsToPesVideo.GetPes(tsToPesVideoLength))) {
+           int w = PlayVideo(tsToPesVideoBuffer, tsToPesVideoLength);
            if (w <= 0)
               return w;
+           tsToPesVideoBuffer += w;
+           tsToPesVideoLength -= w;
+           if (tsToPesVideoLength > 0) {
+              errno = EAGAIN;
+              return -1;
+              }
            }
      tsToPesVideo.Reset();
      }
@@ -1287,12 +1310,31 @@
 
 int cDevice::PlayTsAudio(const uchar *Data, int Length)
 {
+  // Play remains of last buffer if not completely played:
+  if (tsToPesAudioBuffer && tsToPesAudioLength > 0) {
+     int w = PlayAudio(tsToPesAudioBuffer, tsToPesAudioLength, 0);
+     if (w <= 0)
+        return w;
+     tsToPesAudioBuffer += w;
+     tsToPesAudioLength -= w;
+     if (tsToPesAudioLength > 0) {
+        errno = EAGAIN;
+        return -1;
+        }
+     tsToPesAudio.Reset();
+     }
+
   // Audio PES always has an explicit length and consists of single packets:
-  int l;
-  if (const uchar *p = tsToPesAudio.GetPes(l)) {
-     int w = PlayAudio(p, l, 0);
+  if ((tsToPesAudioBuffer = tsToPesAudio.GetPes(tsToPesAudioLength))) {
+     int w = PlayAudio(tsToPesAudioBuffer, tsToPesAudioLength, 0);
      if (w <= 0)
         return w;
+     tsToPesAudioBuffer += w;
+     tsToPesAudioLength -= w;
+     if (tsToPesAudioLength > 0) {
+        errno = EAGAIN;
+        return -1;
+        }
      tsToPesAudio.Reset();
      }
   tsToPesAudio.PutTs(Data, Length);
@@ -1347,7 +1389,11 @@
   else if (Data == NULL) {
      patPmtParser.Reset();
      tsToPesVideo.Reset();
+     tsToPesVideoBuffer = NULL;
+     tsToPesVideoLength = 0;
      tsToPesAudio.Reset();
+     tsToPesAudioBuffer = NULL;
+     tsToPesAudioLength = 0;
      tsToPesSubtitle.Reset();
      }
   return -1;
Index: device.h
===================================================================
--- device.h	(revision 1083)
+++ device.h	(working copy)
@@ -475,7 +475,11 @@
   cPlayer *player;
   cPatPmtParser patPmtParser;
   cTsToPes tsToPesVideo;
+  const uchar *tsToPesVideoBuffer;
+  int tsToPesVideoLength;
   cTsToPes tsToPesAudio;
+  const uchar *tsToPesAudioBuffer;
+  int tsToPesAudioLength;
   cTsToPes tsToPesSubtitle;
   bool isPlayingVideo;
 protected:
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux