[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdemultimedia/mpeglib/lib/input
From:       Martin Vogt <mvogt () rhrk ! uni-kl ! de>
Date:       2002-03-18 9:50:32
[Download RAW message or body]


kdemultimedia/mpeglib/lib/input fileInputStream.cpp,1.11,1.12
Author: mvogt
Mon Mar 18 10:50:32 CET 2002
In directory office:/tmp/cvs-serv26639/lib/input


Modified Files:
         fileInputStream.cpp
Log Message:
- not activated bugfix/workaround for vorbis bug.
- Vorbis does not work with KDE 3.0 and segfaults artsd.
- patch send to vorbis-dev.

Here's the patch:
- only touches vorbisPlugin.h|c
- removes cout's in fileInputStream

Index: lib/decoder/vorbisPlugin.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib/lib/decoder/vorbisPlugin.cpp,v
retrieving revision 1.5
diff -u -r1.5 vorbisPlugin.cpp
--- lib/decoder/vorbisPlugin.cpp	2002/02/28 18:37:37	1.5
+++ lib/decoder/vorbisPlugin.cpp	2002/03/18 09:35:58
@@ -16,39 +16,62 @@
 #ifdef OGG_VORBIS
 
 size_t fread_func(void *ptr, size_t size, size_t nmemb, void *stream) {
-  InputStream* input=(InputStream*) stream;
+  InputStream* input=((VorbisPlugin*)stream)->getInputStream();
   int bytes=input->read((char*)ptr,size*nmemb);
+  // workaround for RC3, report success during seek
+  /*
+  if (((VorbisPlugin*)stream)->vorbis_seek_bug_active == true) {
+    errno=0;
+    return 0;
+  }
+  */
+  // error on read and no "seek workaround"
   if (bytes == 0) {
     //
     // If different thread close the input we signal
     // a read error to vorbis
     //
     if (input->isOpen() == false) {
-      return (size_t)-1;
+      // note: errno is in this thread another variable, than in 
+      // the thread which closed the file.
+      // here we "fake" the errno var.
+      errno=EBADF;
+      return 0;
     }
   }
+  // successful read
   return bytes;
 }
 
 
 int fseek_func(void *stream, ogg_int64_t offset, int whence) {
-  int ret;
-  InputStream* input=(InputStream*) stream;
+  int ret=-1;
+  InputStream* input=((VorbisPlugin*)stream)->getInputStream();
 
-  if (whence==SEEK_SET) {
+  switch(whence) {
+  case SEEK_SET:
     ret=input->seek(offset);
-    return ret;
-  }
-  if (whence==SEEK_CUR) {
+    break;
+  case SEEK_CUR:
     ret=input->seek(input->getBytePosition()+offset);
-    return ret;
-  }  
-  if (whence==SEEK_END) {
+    break;
+  case SEEK_END:
     ret=input->seek(input->getByteLength());
-    return ret;
-  }   
-  cout << "hm, strange call"<<endl;
-  return -1;
+    break;
+  default:
+    cout << "fseek_func VorbisPlugn strange call"<<endl;
+  }
+
+  if (ret == false) {
+    // vorbis does not handle errors in seek at all
+    // and if they are handled vorbis segfaults. (RC3)
+    // here we always "success" but set an seek_error_mark
+    // 
+    ret=-1;
+  }
+
+  return ret;
+
 }
 
 
@@ -63,7 +86,7 @@
 
 
 long ftell_func  (void *stream) {
-  InputStream* input=(InputStream*) stream;
+  InputStream* input=((VorbisPlugin*)stream)->getInputStream();
   return input->getBytePosition();
 }
 
@@ -107,7 +130,7 @@
   // here is the hack to pass the pointer to
   // our streaming interface.
   
-  if(ov_open_callbacks(input, &vf, NULL, 0, callbacks) < 0) {
+  if(ov_open_callbacks(this, &vf, NULL, 0, callbacks) < 0) {
     return false;
   }
 
@@ -138,6 +161,7 @@
   case -1:
     /* error in the stream.  Not a problem, just reporting it in
        case we (the app) cares.  In this case, we don't. */
+    cout << "error found"<<endl;
     break;  
   default:
     if(current_section!=last_section){
@@ -183,6 +207,19 @@
   /********** Decode setup ************/
   // start decoding
   lshutdown=false;
+  /** 
+      Vorbis RC3 introducted a new bug:
+          seek on a closed stream segfaults vorbis.
+	  The bugfix in vorbis is (RC3) around line 1190 should be:
+                seek_error:
+		  // the caller of this goto may not set a return code 
+                  ret=OV_ENOSEEK;
+      The workaround is to check if we are in a seek operation
+      and always "fake" successfull reads.
+  */
+  vorbis_seek_bug_active=false;
+
+
   while(runCheck()) {
 
     switch(streamState) {
@@ -216,7 +253,9 @@
     default:
       cout << "unknown stream state vorbis decoder:"<<streamState<<endl;
     }
+
   }
+
   lshutdown=true;
   ov_clear(&vf); /* ov_clear closes the stream if its open.  Safe to
 		    call on an uninitialized structure as long as
@@ -228,7 +267,9 @@
 
 // vorbis can seek in streams
 int VorbisPlugin::seek_impl(int second) {
+  vorbis_seek_bug_active=true;
   ov_time_seek(&vf,(double) second);
+  vorbis_seek_bug_active=false;
   return true;
 }
 
Index: lib/decoder/vorbisPlugin.h
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib/lib/decoder/vorbisPlugin.h,v
retrieving revision 1.1
diff -u -r1.1 vorbisPlugin.h
--- lib/decoder/vorbisPlugin.h	2000/12/03 21:49:51	1.1
+++ lib/decoder/vorbisPlugin.h	2002/03/18 09:35:58
@@ -69,7 +69,12 @@
   void decoder_loop();
   int seek_impl(int second);
   void config(const char* key,const char* value,void* user_data);
- 
+
+  // vorbis bug workaround [START]
+  int vorbis_seek_bug_active;
+  InputStream* getInputStream() { return input; }
+  // vorbis bug workaround [END]
+
  private:
   int processVorbis(vorbis_info* vi,vorbis_comment* comment);
   int getTotalLength();
Index: lib/input/fileInputStream.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib/lib/input/fileInputStream.cpp,v
retrieving revision 1.11
diff -u -r1.11 fileInputStream.cpp
--- lib/input/fileInputStream.cpp	2001/11/30 08:31:16	1.11
+++ lib/input/fileInputStream.cpp	2002/03/18 09:35:59
@@ -100,9 +100,6 @@
     return 0;
   }
   if (bytesRead == 0){
-    cout << "size:"<<size<<endl;
-    cout << "eof:"<<eof()<<endl;
-    cout << "feof:"<<feof(file)<<endl;
     bytesRead=0;
   }
   return bytesRead;
@@ -120,7 +117,7 @@
   }
 
   if (pos < 0) {
-    //perror("seek in setBytePos");
+    cout <<"seek error in FileInputStream::seek"<<endl;
     back=false;
   }
   return back;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic