Am Montag, 22. Oktober 2007 14:54 schrieb Michael Riepe:
> > The internal private arrays (byte_bookmarks, pic_bookmarks) are
> > self-terminated by a zero-bookmark. That's probabely not a problem for
> > the filepositions coming from topfield but maybe for frame numbers coming
> > from some other source which can become 0 for the very first frame.
> >
> > Should we use a -1 as terminator?
>
> Maybe. But it would be even better to use a std::vector or std::list
> instead of a bare pointer to int.

OK, mission accomplished... bit by bit I begin to love c++! ;)
But I'm not quiet sure if that's the best way passing the pointer of the 
bookmark vector... please have a look.

BTW, don't you miss a message box when Suggest/Import markers
does nothing at all? If so, try my patch... :)

ciao
Ralph
diff -Naur svn/src/dvbcut.cpp r92-list/src/dvbcut.cpp
--- svn/src/dvbcut.cpp	2007-10-22 12:05:55.000000000 +0200
+++ r92-list/src/dvbcut.cpp	2007-10-22 16:30:25.000000000 +0200
@@ -657,16 +657,26 @@
 
 void dvbcut::editSuggest()
 {
-  int pic = 0;
-  while ((pic = mpg->nextaspectdiscontinuity(pic)) >= 0)
+  int pic = 0, found=0;
+  while ((pic = mpg->nextaspectdiscontinuity(pic)) >= 0) {
     addEventListItem(pic, EventListItem::bookmark);
+    found++;
+  }
+  if(!found)  
+    critical("Markers not set - dvbcut","No aspect ratio changes detected!");
+    
 }
 
 void dvbcut::editImport()
 {
-  int *bookmark = mpg->getbookmarks();
-  while(bookmark && *bookmark)
-    addEventListItem(*bookmark++, EventListItem::bookmark);
+  int found=0;
+  if(std::vector<int> *bookmarks = mpg->getbookmarks())
+    for (std::vector<int>::iterator b = bookmarks->begin(); b != bookmarks->end(); ++b) {   
+      addEventListItem(*b, EventListItem::bookmark);
+      found++;
+    }
+  if(!found)  
+    critical("Markers not set - dvbcut","No valid bookmarks available/found!");   
 }
 
 void dvbcut::viewDifference()
diff -Naur svn/src/mpgfile.h r92-list/src/mpgfile.h
--- svn/src/mpgfile.h	2007-10-22 12:05:55.000000000 +0200
+++ r92-list/src/mpgfile.h	2007-10-22 15:51:02.000000000 +0200
@@ -65,7 +65,7 @@
     {
     return false;
     }
-  virtual int *getbookmarks()
+  virtual std::vector<int> *getbookmarks()
     {
     return NULL;
     }
diff -Naur svn/src/tsfile.cpp r92-list/src/tsfile.cpp
--- svn/src/tsfile.cpp	2007-10-22 12:05:55.000000000 +0200
+++ r92-list/src/tsfile.cpp	2007-10-22 16:05:58.000000000 +0200
@@ -258,8 +258,7 @@
   unsigned int frequency, symbolrate, modulation;
   int boff=len, off=0, type=0, hlen=0, verbose=0;
 
-  // initialize bookmark array! 
-  byte_bookmarks[0] = 0;
+  // this routine stores bookmarks as byte positions! 
   bytes = true;
   
   // just in case there's a corrupted TS packet at the beginning
@@ -324,22 +323,20 @@
   // OK,... we identified a receiver model!
   int bnum = 0; 
   //if(len>=hlen) // discard ALL (slightly) to small headers...? No, only require enough space for the bookmarks...
-  if(len>=boff+4*MAX_BOOKMARKS) { 
+  if(len>=boff+4*TF_MAX_BOOKMARKS) { 
       // Seems to be a Topfield TF4000PVR/TF5xxxPVR TS-header with 576/3760bytes total length
       // and up to 64 bookmarks (BUT can be shorter/corrupted due to COPY/CUT-procedure on reveiver)
-      unsigned int bookmark;
-      do {
-          bookmark = (header[boff]<<24)|(header[boff+1]<<16)|(header[boff+2]<<8)|header[boff+3];
+      dvbcut_off_t bookmark;
+      while ((bookmark=(header[boff]<<24)|(header[boff+1]<<16)|(header[boff+2]<<8)|header[boff+3])
+              && bnum<TF_MAX_BOOKMARKS) {
           // bookmark is stored in 128 resp. 94kbyte units
-          byte_bookmarks[bnum] = bookmark*unit;
-          if(verbose && bookmark) fprintf(stderr,"BOOKMARK[%d] = %lld\n",bnum,byte_bookmarks[bnum]);
+          bookmark*=unit;
+          if(verbose) fprintf(stderr,"BOOKMARK[%d] = %lld\n",bnum,bookmark);
+          // fill bookmark vector with byte positions
+          byte_bookmarks.push_back(bookmark);
           bnum++;
           boff+=4;
       }  
-      while(bookmark && bnum<MAX_BOOKMARKS);
-      // add a terminating zero marker!   
-      if(bnum==MAX_BOOKMARKS) byte_bookmarks[bnum] = 0;
-      else bnum--;
   } else // receiver model identified but header to short!
       fprintf(stderr,"Header probabely corrupted (%dbytes to short), discarding bookmarks!\n",hlen-len);
 
diff -Naur svn/src/tsfile.h r92-list/src/tsfile.h
--- svn/src/tsfile.h	2007-10-22 12:05:55.000000000 +0200
+++ r92-list/src/tsfile.h	2007-10-22 16:30:33.000000000 +0200
@@ -36,7 +36,7 @@
 #define TF5010PVR_POS (1404)
 #define TF4000PVR_LEN (3*TSPACKETSIZE)
 #define TF4000PVR_POS (216)
-#define MAX_BOOKMARKS (64)
+#define TF_MAX_BOOKMARKS (64)
 
 /**
 @author Sven Over
@@ -103,12 +103,9 @@
   size_t get_si_table(uint8_t*, size_t,  size_t&, int, int);
 
   int isTOPFIELD(const uint8_t*, int);  
-  // indicates type of read bookmarks (frame numbers or byte positions)
-  bool bytes;
-  // to store the bookmarks in byte positions (terminated by a zero-bookmark)
-  dvbcut_off_t byte_bookmarks[MAX_BOOKMARKS+1];
-  // to store the bookmarks in frame numbers (terminated by a zero-bookmark)
-  int pic_bookmarks[MAX_BOOKMARKS+1];
+  bool bytes;                               // indicates type of read bookmarks 
+  std::vector<dvbcut_off_t> byte_bookmarks; // to store the bookmarks in byte positions 
+  std::vector<int> pic_bookmarks;           // to store the bookmarks in frame numbers 
 
 public:
   tsfile(inbuffer &b, int initial_offset);
@@ -122,16 +119,16 @@
   virtual bool istransportstream() {
     return true;
   }
-  virtual int *getbookmarks() {
+  virtual std::vector<int> *getbookmarks() {
     if(bytes) {
-      int pic, nbp=0,nbb=0;
-      while(byte_bookmarks[nbb])
-        if((pic = getpictureatposition(byte_bookmarks[nbb++])) >= 0) 
-          pic_bookmarks[nbp++] = pic;
-      pic_bookmarks[nbp] = 0;
+      // convert byte positions to frame numbers if not already done/stored
+      int pic;
+      for (std::vector<dvbcut_off_t>::iterator b = byte_bookmarks.begin(); b != byte_bookmarks.end(); ++b) 
+        if((pic = getpictureatposition(*b)) >= 0) 
+          pic_bookmarks.push_back(pic);
       bytes = false;
     } 
-    return pic_bookmarks;
+    return &pic_bookmarks;
   }
 
 };
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
DVBCUT-user mailing list
DVBCUT-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dvbcut-user

Reply via email to