mirror of https://github.com/mpv-player/mpv
function to read from a demuxer up to (and including) the specified
3-byte pattern. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17418 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
7fac067cae
commit
ab417b391a
|
@ -426,6 +426,41 @@ while(len>0){
|
|||
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;
|
||||
|
|
|
@ -256,6 +256,8 @@ inline static int ds_tell_pts(demux_stream_t *ds){
|
|||
|
||||
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] \
|
||||
|
|
Loading…
Reference in New Issue