[mythtv] [patch] dtvrecorder.cpp & hdtvrecorder.cpp assert removal

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Thu Jan 20 10:05:33 EST 2005


There were two asserts in dtvrecorder that did nothing at all.
i.e.
if (x==0)
   return;
assert(x!=0);

These were left behind from when I was working on this code.


There were also two asserts in hdtvrecorder.
One was in Open(), and I've replaced this with an errored return from 
Open() and an informative error message.

The other was in the WHACK_A_BUG_VIDEO code in WritePMT()
This one asserted that the rewritten pid was the video pid.
Instead I simply print an error message and don't rewrite
the pid if it doesn't correspond with the expected streamtype.

Both of these asserts are in debugging code, not enabled by default, but 
we might as well handle these properly if only for our own sake when 
debugging.

-- Daniel
-------------- next part --------------
Index: libs/libmythtv/dtvrecorder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dtvrecorder.cpp,v
retrieving revision 1.6
diff -u -r1.6 dtvrecorder.cpp
--- libs/libmythtv/dtvrecorder.cpp	8 Jan 2005 00:31:40 -0000	1.6
+++ libs/libmythtv/dtvrecorder.cpp	20 Jan 2005 15:01:57 -0000
@@ -5,8 +5,6 @@
  *  Distributed as part of MythTV under GPL v2 and later.
  */
 
-#include <cassert>
-
 using namespace std;
 
 #include "RingBuffer.h"
@@ -132,13 +130,11 @@
             _position_within_gop_header = (k == 0x00) ? 2 : 0;
         else 
         {
-            assert(2 == _position_within_gop_header);
             if (0x01 != k)
             {
                 _position_within_gop_header = (k) ? 0 : 2;
                 continue;
             }
-            assert(0x01 == k);
             const unsigned char k1 = buffer[i+1];
             if (0x00 == k1)
             {   //   00 00 01 00: picture_start_code
Index: libs/libmythtv/hdtvrecorder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/hdtvrecorder.cpp,v
retrieving revision 1.33
diff -u -r1.33 hdtvrecorder.cpp
--- libs/libmythtv/hdtvrecorder.cpp	8 Jan 2005 16:48:12 -0000	1.33
+++ libs/libmythtv/hdtvrecorder.cpp	20 Jan 2005 15:01:57 -0000
@@ -158,11 +158,14 @@
 
 #if FAKE_VIDEO
     // open file instead of device
-    if (_stream_fd >=0)
+    if (_stream_fd >= 0 && close(_stream_fd))
     {
-        int ret = close(_stream_fd);
-        assert(ret);
+        VERBOSE(VB_IMPORTANT,
+                QString("HDTVRecorder::Open(): Error, failed to close "
+                        "existing fd (%1)").arg(strerror(errno)));
+        return false;
     }
+
     _stream_fd = open(FAKE_VIDEO_FILES[fake_video_index], O_RDWR);
     VERBOSE(VB_IMPORTANT, QString("Opened fake video source %1").arg(FAKE_VIDEO_FILES[fake_video_index]));
     fake_video_index = (fake_video_index+1)%FAKE_VIDEO_NUM;
@@ -688,15 +691,23 @@
             WABV_started = true;
             WABV_wait_a_while = WABV_WAIT;
             WABV_base_pid = (((WABV_base_pid-0x100)+1)%32)+0x100;
-            VERBOSE(VB_IMPORTANT, QString("Whack a Bug: new video pid %1").arg(WABV_base_pid));
-            // rewrite video pid
-            assert(StreamID::MPEG2Video == StreamData()->PMT()->StreamType(0));
-            const uint old_video_pid=StreamData()->PMT()->StreamPID(0);
-            StreamData()->PMT()->SetStreamPID(0, WABV_base_pid);
-            if (StreamData()->PMT()->PCRPID() == old_video_pid)
-                StreamData()->PMT()->SetPCRPID(WABV_base_pid);
-            StreamData()->PMT()->SetCRC(StreamData()->PMT()->CalcCRC());
-            VERBOSE(VB_IMPORTANT, StreamData()->PMT()->toString());
+            if (StreamID::MPEG2Video != StreamData()->PMT()->StreamType(0))
+            {
+                VERBOSE(VB_IMPORTANT, "HDTVRecorder::WritePMT(): Error,"
+                        "Whack a Bug can not rewrite PMT, wrong stream type");
+            }
+            else
+            {
+                VERBOSE(VB_IMPORTANT, QString("Whack a Bug: new video pid %1").
+                        arg(WABV_base_pid));
+                // rewrite video pid
+                const uint old_video_pid=StreamData()->PMT()->StreamPID(0);
+                StreamData()->PMT()->SetStreamPID(0, WABV_base_pid);
+                if (StreamData()->PMT()->PCRPID() == old_video_pid)
+                    StreamData()->PMT()->SetPCRPID(WABV_base_pid);
+                StreamData()->PMT()->SetCRC(StreamData()->PMT()->CalcCRC());
+                VERBOSE(VB_IMPORTANT, StreamData()->PMT()->toString());
+            }
         }
 #endif
 #if WHACK_A_BUG_AUDIO


More information about the mythtv-dev mailing list