changeset 22775:f6dc5fd2b347

at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
author nicodvb
date Sat, 24 Mar 2007 10:37:05 +0000
parents 92e4f4b5828f
children 0d4052c65c0c
files stream/stream_vcd.c
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_vcd.c	Sat Mar 24 09:46:12 2007 +0000
+++ b/stream/stream_vcd.c	Sat Mar 24 10:37:05 2007 +0000
@@ -79,7 +79,7 @@
 
 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
   struct stream_priv_s* p = (struct stream_priv_s*)opts;
-  int ret,ret2,f;
+  int ret,ret2,f,sect,tmp;
   mp_vcd_priv_t* vcd;
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
   int bsize = VCD_SECTOR_SIZE;
@@ -143,6 +143,18 @@
     m_struct_free(&stream_opts,opts);
     return STREAM_ERROR;
   }
+  /* search forward up to at most 3 seconds to skip leading margin */
+  sect = ret / VCD_SECTOR_DATA;
+  for (tmp = sect; tmp < sect + 3 * 75; tmp++) {
+    char mem[VCD_SECTOR_DATA];
+    //since MPEG packs are block-aligned we stop discarding sectors if they are non-null
+    if (vcd_read(vcd, mem) != VCD_SECTOR_DATA || mem[2] || mem[3])
+      break;
+  }
+  mp_msg(MSGT_OPEN, MSGL_DBG2, "%d leading sectors skipped\n", tmp - sect);
+  vcd_set_msf(vcd, tmp);
+  ret = tmp * VCD_SECTOR_DATA;
+
   mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X  end: 0x%X\n",ret,ret2);
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)