From kde-multimedia Wed Aug 30 19:55:32 2000 From: Martin Vogt Date: Wed, 30 Aug 2000 19:55:32 +0000 To: kde-multimedia Subject: [PATCH] mpeglib has less segfaults X-MARC-Message: https://marc.info/?l=kde-multimedia&m=96766537627017 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--YZ5djTAD1cGYuMQK" --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, I was wrong the memleak and segfault was caused by mpeglib not by artsd. Ok. This pacth (its huge) fixes this in many cases. But it still seems that the mp3 decoder produces segfaults on buggy mp3. For "good" mp3 I have tested 10.000 create/destroy cycles with mpeglibartsplay. I will commit the patch soon. Its big, but does not _change_ how mpeglib works. Its only a big bugfix. a.patch is against mpeglib b.patch for artspluggy Martin --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="a.patch" ? a.patch ? example/yaf/yafyuv/yaf-yuv Index: lib/decoder/decoderPlugin.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/decoder/decoderPlugin.cpp,v retrieving revision 1.4 diff -u -r1.4 decoderPlugin.cpp --- lib/decoder/decoderPlugin.cpp 2000/08/29 16:10:32 1.4 +++ lib/decoder/decoderPlugin.cpp 2000/08/30 19:49:52 @@ -419,13 +419,13 @@ break; case _COMMAND_SEEK: { if (streamState==_STREAM_STATE_FIRST_INIT) { - command->print("ignore command in _STREAM_STATE_FIRST_INIT"); + command->print("ignore command seek in _STREAM_STATE_FIRST_INIT"); } else { intArg=command->getIntArg(); cout << "_COMMAND_SEEK:"<name=name; bytePos=0; fillgrade=0; setUrl(name); lLock=false; abs_thread_mutex_init(&writeInMut); - abs_thread_mutex_init(&resizeMut); } BufferInputStream::~BufferInputStream() { delete ringBuffer; abs_thread_mutex_destroy(&writeInMut); - abs_thread_mutex_destroy(&resizeMut); } -int BufferInputStream::open(const char* name) { +int BufferInputStream::open(const char*) { leof=false; setBlocking(true); - setUrl(name); return true; } void BufferInputStream::close() { leof=true; setBlocking(false); - setUrl(NULL); } int BufferInputStream::eof() { @@ -81,7 +76,6 @@ int n=size; int canCopy=n; char* readPtr; - lockResizeBuffer(); // here we read even if leof is true // we make sure that we empty the whole buffer! while((eof()==false) && (n > 0)) { @@ -104,7 +98,6 @@ fillgrade-=canCopy; unlockBuffer(); } - unlockResizeBuffer(); return i; } @@ -199,7 +192,7 @@ } -int BufferInputStream::getFreeWrite() { +int BufferInputStream::getFreeSpace() { return ringBuffer->getFreeWrite(); } @@ -237,12 +230,10 @@ // remote read extension -int BufferInputStream::readRemote(char* &ptr,int size) { +int BufferInputStream::readRemote(char** ptr,int size) { int n=0; char* readPtr; - lockResizeBuffer(); while((eof()==false)) { - n=size; ringBuffer->getReadArea(readPtr,n); if (n < size){ @@ -254,7 +245,7 @@ } break; } - ptr=readPtr; + *ptr=readPtr; return n; } @@ -268,7 +259,6 @@ fillgrade-=bytes; unlockBuffer(); getTimeStamp(bytePos); - unlockResizeBuffer(); } @@ -286,23 +276,9 @@ abs_thread_mutex_unlock(&writeInMut); } -void BufferInputStream::lockResizeBuffer() { - abs_thread_mutex_lock(&resizeMut); -} - - -void BufferInputStream::unlockResizeBuffer() { - abs_thread_mutex_unlock(&resizeMut); -} int BufferInputStream::getSize() { return ringBuffer->getSize(); } -void BufferInputStream::resizeBuffer(int changeSize) { - lockResizeBuffer(); - lockBuffer(); - ringBuffer->resizeBuffer(changeSize); - unlockBuffer(); - unlockResizeBuffer(); -} + Index: lib/input/bufferInputStream.h =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/input/bufferInputStream.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 bufferInputStream.h --- lib/input/bufferInputStream.h 2000/07/04 19:22:13 1.1.1.1 +++ lib/input/bufferInputStream.h 2000/08/30 19:49:52 @@ -24,14 +24,11 @@ SimpleRingBuffer* ringBuffer; int leof; - const char* name; long bytePos; int fillgrade; int lLock; abs_thread_mutex_t writeInMut; - abs_thread_mutex_t resizeMut; - public: BufferInputStream(int size,int minlinSize,const char* name); ~BufferInputStream(); @@ -62,7 +59,7 @@ int getFillgrade(); int getSize(); int getFreeRead(); - int getFreeWrite(); + int getFreeSpace(); void clear(); @@ -70,7 +67,7 @@ // Note you _need_ to call always both methods // readRemote and forwardReadPtr even if bytes==0!!! // (we hold a resizeLock during this operation) - int readRemote(char* &ptr,int size); + int readRemote(char** ptr,int size); void forwardReadPtr(int bytes); void setCanWaitForData(int lBlock); @@ -86,10 +83,6 @@ private: void lockBuffer(); void unlockBuffer(); - - void lockResizeBuffer(); - void unlockResizeBuffer(); - }; #endif Index: lib/input/fileInputStream.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/input/fileInputStream.cpp,v retrieving revision 1.2 diff -u -r1.2 fileInputStream.cpp --- lib/input/fileInputStream.cpp 2000/08/29 16:10:32 1.2 +++ lib/input/fileInputStream.cpp 2000/08/30 19:49:53 @@ -18,12 +18,14 @@ FileInputStream::FileInputStream() { file=NULL; lopen=false; - name=NULL; + fileLen=0; + abs_thread_mutex_init(&fileMut); } FileInputStream::~FileInputStream() { close(); + abs_thread_mutex_destroy(&fileMut); } @@ -37,7 +39,9 @@ setUrl(dest); if (strlen(dest) == 1) { if (strncmp(dest,"-",1)==0) { + lockFile(); file=::fdopen(0,"r"); + unlockFile(); } } // load out of current dir if no full path is given @@ -53,30 +57,35 @@ } } cout << "open:"<> 6) == 0x01) { Index: lib/mpgplayer/mpegStreamPlayer.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/mpgplayer/mpegStreamPlayer.cpp,v retrieving revision 1.3 diff -u -r1.3 mpegStreamPlayer.cpp --- lib/mpgplayer/mpegStreamPlayer.cpp 2000/08/06 18:55:20 1.3 +++ lib/mpgplayer/mpegStreamPlayer.cpp 2000/08/30 19:49:55 @@ -44,9 +44,10 @@ here we set the plugins in autoPlay mode. because we handle all commands over the loopback buffer. */ + /* audioDecoder->config("-y","on",NULL); videoDecoder->config("-y","on",NULL); - + */ audioInput=new BufferInputStream(1024*_BUFFER_CHUNK_SIZE, 1024*200,"audioInput"); Index: lib/output/artsOutputStream.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/output/artsOutputStream.cpp,v retrieving revision 1.4 diff -u -r1.4 artsOutputStream.cpp --- lib/output/artsOutputStream.cpp 2000/08/29 16:10:32 1.4 +++ lib/output/artsOutputStream.cpp 2000/08/30 19:49:55 @@ -33,7 +33,7 @@ // from /dev/dsp + connected nodes // or arts need a video interface cout << "buffer"<isOpen()==false) { - audioTime->sleepWrite(size); - } // we call this for stream state handling OutputStream::audioPlay(startStamp,endStamp,buffer,size); @@ -106,13 +107,17 @@ // here we simulate our own blocking audio device - write=stream->write(buffer,size,startStamp); + if (stream->isOpen()==false) { + audioTime->sleepWrite(size); + } else { + write=stream->write(buffer,size,startStamp); + } return write; } -int ArtsOutputStream::read(char* &buffer,int bytes) { +int ArtsOutputStream::read(char** buffer,int bytes) { int back=stream->readRemote(buffer,bytes); return back; } Index: lib/output/artsOutputStream.h =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/output/artsOutputStream.h,v retrieving revision 1.2 diff -u -r1.2 artsOutputStream.h --- lib/output/artsOutputStream.h 2000/07/17 15:40:07 1.2 +++ lib/output/artsOutputStream.h 2000/08/30 19:49:56 @@ -104,7 +104,7 @@ // Remote read extension - int read(char* &buffer,int bytes); + int read(char** buffer,int bytes); void forwardReadPtr(int bytes); // buffer control Index: lib/output/audioData.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/output/audioData.cpp,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 audioData.cpp --- lib/output/audioData.cpp 2000/07/04 19:22:14 1.1.1.1 +++ lib/output/audioData.cpp 2000/08/30 19:49:56 @@ -30,6 +30,7 @@ delete audioTime; delete start; delete end; + delete writeStamp; } Index: lib/output/audioDataArray.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/output/audioDataArray.cpp,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 audioDataArray.cpp --- lib/output/audioDataArray.cpp 2000/07/04 19:22:15 1.1.1.1 +++ lib/output/audioDataArray.cpp 2000/08/30 19:49:56 @@ -24,6 +24,8 @@ readPos=0; writePos=0; pcmSum=0; + abs_thread_mutex_init(&writeInMut); + abs_thread_mutex_init(&changeMut); audioDataArray=new AudioData*[entries]; @@ -35,18 +37,19 @@ abs_thread_mutex_init(&writeInMut); abs_thread_mutex_init(&changeMut); - - } AudioDataArray::~AudioDataArray() { + int i; for(i=0;i= maxSize) { + cout << "size:"<read(getBuffer(),size); if (back!=size) { + perror("fillbuffer"); return false; } if(mpegHeaderInfo->getProtection()==false) { Index: lib/splay/mpeglayer3.cc =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/splay/mpeglayer3.cc,v retrieving revision 1.3 diff -u -r1.3 mpeglayer3.cc --- lib/splay/mpeglayer3.cc 2000/08/16 16:35:07 1.3 +++ lib/splay/mpeglayer3.cc 2000/08/30 19:50:00 @@ -241,6 +241,11 @@ gi->part2_3_length =getbits(12); gi->big_values =getbits(9); + if(gi->big_values > 288) { + fprintf(stderr,"big_values too large!\n"); + gi->big_values = 288; + } + gi->global_gain =getbits(8); gi->scalefac_compress =getbits(4); gi->window_switching_flag=getbit(); @@ -300,6 +305,11 @@ gi->part2_3_length =getbits(12); gi->big_values =getbits(9); + if(gi->big_values > 288) { + fprintf(stderr,"big_values too large!\n"); + gi->big_values = 288; + } + gi->global_gain =getbits(8); gi->scalefac_compress =getbits(9); gi->window_switching_flag=getbit(); @@ -773,10 +783,10 @@ if(h->treelen) { while(igetFreeWrite() < rawdataoffset*2) { + int freeWrite=bufferInputStream->getFreeSpace(); + + while(freeWrite < rawdataoffset*2) { + freeWrite=bufferInputStream->getFreeSpace(); dosleep(10000); } Index: lib/splay/splayPlugin.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib/lib/splay/splayPlugin.cpp,v retrieving revision 1.4 diff -u -r1.4 splayPlugin.cpp --- lib/splay/splayPlugin.cpp 2000/08/29 16:10:32 1.4 +++ lib/splay/splayPlugin.cpp 2000/08/30 19:50:00 @@ -82,7 +82,7 @@ cout << "_STREAM_STATE_FIRST_INIT"<firstInitialize(currentHeader)==false) { } else { - + cout << "splay has init"<setdownfrequency(downSampleFlag); server->setforcetomono(monoFlag); --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="b.patch" ? b.diff ? mvogt@aixd1.rhrk.uni-kl.de ? decoderBaseObject.h ? decoderBaseObject.cc ? b.patch Index: Makefile.am =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/Makefile.am,v retrieving revision 1.4 diff -u -r1.4 Makefile.am --- Makefile.am 2000/07/10 14:14:02 1.4 +++ Makefile.am 2000/08/30 19:53:25 @@ -51,11 +51,11 @@ libarts_mpeglib_la_SOURCES = $(BUILT_SOURCES) \ + decoderBaseObject_impl.cpp \ oggPlayObject_impl.cpp \ mpgPlayObject_impl.cpp \ wavPlayObject_impl.cpp \ - mp3PlayObject_impl.cpp \ - decoderBaseObject_impl.cpp + mp3PlayObject_impl.cpp libarts_mpeglib_la_LDFLAGS = $(all_libraries) \ @@ -81,6 +81,9 @@ -lkmedia2_idl \ -lartsflow_idl \ -lmcop + + + Index: decoderBaseObject_impl.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/decoderBaseObject_impl.cpp,v retrieving revision 1.11 diff -u -r1.11 decoderBaseObject_impl.cpp --- decoderBaseObject_impl.cpp 2000/08/29 17:12:42 1.11 +++ decoderBaseObject_impl.cpp 2000/08/30 19:53:26 @@ -12,6 +12,7 @@ #include "decoderBaseObject_impl.h" #include "../mpeglib/lib/decoder/decoderPlugin.h" +#include "../mpeglib/lib/splay/splayPlugin.h" // define this to run the playobject without the // arts backend. (usefull to check if a bug is in arts or mpeglib) @@ -40,26 +41,28 @@ DecoderBaseObject_impl::~DecoderBaseObject_impl() { cout << "~DecoderBaseObject_impl -s"<open((char*)filename.c_str()); setStreamState(_THREADSTATE_OPENED); + // we are still in posIdle here outputStream->audioOpen(); @@ -139,7 +143,6 @@ time.seconds=(long)(currentTime); time.ms=(long) (1000.0*(currentTime-(float)time.seconds)); cout << "currentTime :"<setAudioBufferSize(bufferSize); } if(_state == posPlaying) { - /* - * since the samplingrate of the MP3 and the samplingrate of the output - * device (soundcard) are not necessarily the same, it's a bit tricky - */ + // + // since the samplingrate of the MP3 and the samplingrate of the output + // device (soundcard) are not necessarily the same, it's a bit tricky + // // calculate "how fast" we consume input samples (2.0 means, we need 2 // input samples to generate one output sample) @@ -296,13 +299,8 @@ // convert that into bytes and try to read that many bytes wantBytes=(int) (wantWavSamples*byteMultiplikator); - hasBytes=outputStream->read(buffer,wantBytes); + hasBytes=outputStream->read(&buffer,wantBytes); - /* - if (flpos != 0.0) { - cout << "flpos:"<waitStreamState(_OUTPUT_WAIT_METHOD_POLL, @@ -425,14 +423,6 @@ // because of the asyncCommand above. if (decoderPlugin != NULL) { decoderPlugin->close(); - } - - // as long as the decoder is not delete - // we cannot close the Window!!!! - // this demonstrate that it even works _with_ closing the window - // (I hacked it for convinience) - if (outputStream != NULL) { - outputStream->closeWindow(); } Index: decoderBaseObject_impl.h =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/decoderBaseObject_impl.h,v retrieving revision 1.5 diff -u -r1.5 decoderBaseObject_impl.h --- decoderBaseObject_impl.h 2000/08/24 14:52:09 1.5 +++ decoderBaseObject_impl.h 2000/08/30 19:53:26 @@ -37,10 +37,11 @@ class InputStream; class ArtsOutputStream; + using namespace std; using namespace Arts; -class DecoderBaseObject_impl: +class DecoderBaseObject_impl : virtual public Arts::StdSynthModule, virtual public DecoderBaseObject_skel { @@ -61,7 +62,7 @@ virtual ~DecoderBaseObject_impl(); virtual DecoderPlugin* createPlugin(); - virtual InputStream* createInputStream(char* url); + virtual InputStream* createInputStream(const char* url); bool loadMedia(const string &filename); string description(); Index: mpeglibartsplay.cpp =================================================================== RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/mpeglibartsplay.cpp,v retrieving revision 1.5 diff -u -r1.5 mpeglibartsplay.cpp --- mpeglibartsplay.cpp 2000/08/29 17:12:42 1.5 +++ mpeglibartsplay.cpp 2000/08/30 19:53:26 @@ -165,7 +165,6 @@ *play3=server->createPlayObject(filename1); } play3->play(); - usleep(1000); Arts::poTime l_t_zero(0,0,0,"samples"); play3->seek(l_t_zero); --YZ5djTAD1cGYuMQK-- _______________________________________________ Kde-multimedia mailing list Kde-multimedia@master.kde.org http://master.kde.org/mailman/listinfo/kde-multimedia