Hi!
This patch fixes some more bugs I've found:
* src/buffer.cpp:
Correct check for mmap() return value.
* src/mpegmuxer.cpp:
Drop zero-length packets.
This is a workaround that prevents dvbcut from crashing.
There will be a real fix once I found out why it happens.
Output files are still usable, though.
* src/mpgfile.cpp:
Fix broken initializer.
* src/tsfile.cpp:
Drop all packets that have the transport error indicator set.
This should improve dvbcut's ability to handle broken streams.
--
Michael "Tired" Riepe <[EMAIL PROTECTED]>
X-Tired: Each morning I get up I die a little
Index: dvbcut/src/buffer.cpp
===================================================================
RCS file: /var/cvs/sys/qt3/dvbcut/src/buffer.cpp,v
retrieving revision 1.1.1.3
retrieving revision 1.4
diff -u -r1.1.1.3 -r1.4
--- dvbcut/src/buffer.cpp 11 Dec 2005 20:27:04 -0000 1.1.1.3
+++ dvbcut/src/buffer.cpp 23 Jun 2006 12:13:30 -0000 1.4
@@ -28,6 +28,10 @@
#include <stdint.h>
#include "buffer.h"
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void*)-1)
+#endif
+
buffer::buffer(unsigned int _size):size(_size), readpos(0), writepos(0),
wrtot(0)
{
if (size > 0)
@@ -171,8 +175,8 @@
writepos=size;
if (pos+writepos>filesize)
writepos=filesize-pos;
- d=::mmap(0,writepos,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,pos);
- if (!d) {
+ d=::mmap(0,writepos,PROT_READ,MAP_SHARED,fd,pos);
+ if (d==MAP_FAILED) {
size=_size;
mmapped=false;
} else
@@ -248,8 +252,8 @@
size=mmapsize;
if (size>filesize)
size=filesize;
- d=::mmap(0,size,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
- if (!d) {
+ d=::mmap(0,size,PROT_READ,MAP_SHARED,fd,0);
+ if (d==MAP_FAILED) {
size=_size;
mmapped=false;
} else {
@@ -299,8 +303,8 @@
writepos=filesize-pos;
}
- d=::mmap(0,writepos,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,pos);
- if (!d) {
+ d=::mmap(0,writepos,PROT_READ,MAP_SHARED,fd,pos);
+ if (d==MAP_FAILED) {
readpos=writepos=0;
d=malloc(size);
mmapped=false;
Index: dvbcut/src/mpegmuxer.cpp
===================================================================
RCS file: /var/cvs/sys/qt3/dvbcut/src/mpegmuxer.cpp,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- dvbcut/src/mpegmuxer.cpp 16 Dec 2005 19:14:03 -0000 1.1.1.2
+++ dvbcut/src/mpegmuxer.cpp 5 Jul 2006 21:07:45 -0000 1.2
@@ -149,6 +149,11 @@
stream * const s=st[str];
if (!s)
return false;
+ if (len == 0) {
+ // I'm not sure why this happens, but it does. --mr
+ fprintf(stderr, "mpegmuxer::putpacket called with zero length,
str=%d\n", str);
+ return false;
+ }
pts+=ptsoffset;
dts+=ptsoffset;
au *newau=new au(data,len,pts,dts,flags);
Index: dvbcut/src/mpgfile.cpp
===================================================================
RCS file: /var/cvs/sys/qt3/dvbcut/src/mpgfile.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- dvbcut/src/mpgfile.cpp 22 Jun 2006 17:18:29 -0000 1.2
+++ dvbcut/src/mpgfile.cpp 23 Jun 2006 12:14:02 -0000 1.3
@@ -57,7 +57,7 @@
{
if (errormessage)
errormessage->clear();
- inbuffer buf(64 << 10, 128 << 10);
+ inbuffer buf(64 << 10, -1, false, 128 << 10);
int fd = buf.open(filename.c_str());
if (fd < 0) {
Index: dvbcut/src/tsfile.cpp
===================================================================
RCS file: /var/cvs/sys/qt3/dvbcut/src/tsfile.cpp,v
retrieving revision 1.1.1.4
retrieving revision 1.4
diff -u -r1.1.1.4 -r1.4
--- dvbcut/src/tsfile.cpp 14 Dec 2005 21:52:10 -0000 1.1.1.4
+++ dvbcut/src/tsfile.cpp 23 Jun 2006 12:16:46 -0000 1.4
@@ -38,6 +38,11 @@
std::list<std::pair<int,int> > audios;
for(int i=0;i<inpackets;++i) {
const tspacket &p=((const tspacket*)buf.data())[i];
+ if (p.transport_error_indicator())
+ continue; // drop invalid packet --mr
+ int pid=p.pid();
+ if (apid[pid])
+ continue; // already had this pid --mr
int sid=p.sid();
if (sid<0)
continue;
@@ -48,12 +53,11 @@
// sid=payload[9+payload[8]] | ((sid==0xbd)?0x100:0x200);
// }
- int pid=p.pid();
- if (((sid&0xe0) == 0xc0)&&(apid[pid]==false)) // mpeg audio stream
+ if ((sid&0xe0) == 0xc0) // mpeg audio stream
{
audios.push_back(std::pair<int,int>(sid,pid));
apid[pid]=true;
- } else if ((sid==0xbd) && (apid[pid]==false)) // private stream 1,
possibly AC3 audio stream
+ } else if (sid==0xbd) // private stream 1, possibly AC3 audio stream
{
const uint8_t *payload=(const uint8_t*) p.payload();
// if (p.payload_length()>9+payload[8])
@@ -154,6 +158,9 @@
s.fileposition+=TSPACKETSIZE;
+ // Abandon invalid packets --mr
+ if (p->transport_error_indicator())
+ continue;
// Abandon packets which have no payload or have invalid adaption field
length
if (p->payload_length()<=0)
continue;
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
DVBCUT-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dvbcut-user