[MPlayer-cvslog] CVS: main/libmpdemux demuxer.c, 1.213, 1.214 demuxer.h, 1.84, 1.85

Reimar Döffinger CVS syncmail at mplayerhq.hu
Tue Jan 17 21:04:51 CET 2006


CVS change done by Reimar Döffinger CVS

Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv5996/libmpdemux

Modified Files:
	demuxer.c demuxer.h 
Log Message:
function to read from a demuxer up to (and including) the specified
3-byte pattern.


Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -r1.213 -r1.214
--- demuxer.c	12 Jan 2006 20:04:34 -0000	1.213
+++ demuxer.c	17 Jan 2006 20:04:49 -0000	1.214
@@ -426,6 +426,41 @@
 return bytes;
 }
 
+/**
+ * \brief read data until the given 3-byte pattern is encountered, up to maxlen
+ * \param mem memory to read data into, may be NULL to discard data
+ * \param maxlen maximum number of bytes to read
+ * \param read number of bytes actually read
+ * \param pattern pattern to search for (lowest 8 bits are ignored)
+ * \return whether pattern was found
+ */
+int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
+                    int *read, uint32_t pattern) {
+  register uint32_t head = 0xffffff00;
+  register uint32_t pat = pattern & 0xffffff00;
+  int total_len = 0;
+  do {
+    register unsigned char *ds_buf = &ds->buffer[ds->buffer_size];
+    int len = ds->buffer_size - ds->buffer_pos;
+    register long pos = -len;
+    if (unlikely(pos >= 0)) { // buffer is empty
+      ds_fill_buffer(ds);
+      continue;
+    }
+    do {
+      head |= ds_buf[pos];
+      head <<= 8;
+    } while (++pos && head != pat);
+    len += pos;
+    if (total_len + len > maxlen)
+      len = maxlen - total_len;
+    len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len);
+    total_len += len;
+  } while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof);
+  if (read)
+    *read = total_len;
+  return total_len >= 3 && head == pat;
+}
 
 void ds_free_packs(demux_stream_t *ds){
   demux_packet_t *dp=ds->first;

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- demuxer.h	17 Sep 2005 18:05:55 -0000	1.84
+++ demuxer.h	17 Jan 2006 20:04:49 -0000	1.85
@@ -256,6 +256,8 @@
 
 int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);
 int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len);
+int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
+                    int *read, uint32_t pattern);
 
 #define demux_peekc(ds) (\
      (likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos] \




More information about the MPlayer-cvslog mailing list