mirror of https://github.com/mpv-player/mpv
faster and (IMHO) cleaner code.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17419 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
ab417b391a
commit
dcb489559e
|
@ -15,43 +15,37 @@
|
||||||
//static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
|
//static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
|
||||||
unsigned char* videobuffer=NULL;
|
unsigned char* videobuffer=NULL;
|
||||||
int videobuf_len=0;
|
int videobuf_len=0;
|
||||||
unsigned char videobuf_code[4];
|
int next_nal = -1;
|
||||||
|
///! legacy variable, 4 if stream is synced, 0 if not
|
||||||
int videobuf_code_len=0;
|
int videobuf_code_len=0;
|
||||||
|
|
||||||
|
#define MAX_SYNCLEN (10 * 1024 * 1024)
|
||||||
// sync video stream, and returns next packet code
|
// sync video stream, and returns next packet code
|
||||||
int sync_video_packet(demux_stream_t *ds){
|
int sync_video_packet(demux_stream_t *ds){
|
||||||
|
if (!videobuf_code_len) {
|
||||||
int skipped=0;
|
int skipped=0;
|
||||||
// we need enough bytes in the buffer:
|
if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) {
|
||||||
while(videobuf_code_len<4){
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n", skipped);
|
||||||
#if 0
|
goto eof_out;
|
||||||
int c;
|
}
|
||||||
c=demux_getc(ds);if(c<0){ return 0;} // EOF
|
next_nal = demux_getc(ds);
|
||||||
videobuf_code[videobuf_code_len++]=c;
|
if (next_nal < 0)
|
||||||
#else
|
goto eof_out;
|
||||||
videobuf_code[videobuf_code_len++]=demux_getc(ds);
|
videobuf_code_len = 4;
|
||||||
#endif
|
if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,next_nal);
|
||||||
}
|
}
|
||||||
// sync packet:
|
return 0x100|next_nal;
|
||||||
while(1){
|
|
||||||
int c;
|
eof_out:
|
||||||
if(videobuf_code[0]==0 &&
|
next_nal = -1;
|
||||||
videobuf_code[1]==0 &&
|
videobuf_code_len = 0;
|
||||||
videobuf_code[2]==1) break; // synced
|
return 0;
|
||||||
// shift buffer, drop first byte
|
|
||||||
++skipped;
|
|
||||||
videobuf_code[0]=videobuf_code[1];
|
|
||||||
videobuf_code[1]=videobuf_code[2];
|
|
||||||
videobuf_code[2]=videobuf_code[3];
|
|
||||||
c=demux_getc(ds);if(c<0){ return 0;} // EOF
|
|
||||||
videobuf_code[3]=c;
|
|
||||||
}
|
|
||||||
if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,videobuf_code[3]);
|
|
||||||
return 0x100|videobuf_code[3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return: packet length
|
// return: packet length
|
||||||
int read_video_packet(demux_stream_t *ds){
|
int read_video_packet(demux_stream_t *ds){
|
||||||
int packet_start;
|
int packet_start;
|
||||||
|
int res, read;
|
||||||
|
|
||||||
if (VIDEOBUFFER_SIZE - videobuf_len < 5)
|
if (VIDEOBUFFER_SIZE - videobuf_len < 5)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -60,46 +54,35 @@ int packet_start;
|
||||||
|
|
||||||
// COPY STARTCODE:
|
// COPY STARTCODE:
|
||||||
packet_start=videobuf_len;
|
packet_start=videobuf_len;
|
||||||
videobuffer[videobuf_len+0]=videobuf_code[0];
|
videobuffer[videobuf_len+0]=0;
|
||||||
videobuffer[videobuf_len+1]=videobuf_code[1];
|
videobuffer[videobuf_len+1]=0;
|
||||||
videobuffer[videobuf_len+2]=videobuf_code[2];
|
videobuffer[videobuf_len+2]=1;
|
||||||
videobuffer[videobuf_len+3]=videobuf_code[3];
|
videobuffer[videobuf_len+3]=next_nal;
|
||||||
videobuf_len+=4;
|
videobuf_len+=4;
|
||||||
|
|
||||||
// READ PACKET:
|
// READ PACKET:
|
||||||
{
|
res = demux_pattern_3(ds, &videobuffer[videobuf_len],
|
||||||
register uint32_t head = 0xffffffff;
|
VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100);
|
||||||
register unsigned char *buf = &videobuffer[VIDEOBUFFER_SIZE];
|
videobuf_len += read;
|
||||||
register int pos = videobuf_len - VIDEOBUFFER_SIZE;
|
if (!res)
|
||||||
do {
|
goto eof_out;
|
||||||
int c=demux_getc(ds);
|
|
||||||
if(c<0) break; // EOF
|
|
||||||
buf[pos]=c;
|
|
||||||
head<<=8;
|
|
||||||
if(head==0x100) break; // synced
|
|
||||||
head|=c;
|
|
||||||
} while (++pos);
|
|
||||||
if (pos) pos++; // increment missed because of break
|
|
||||||
videobuf_len = &buf[pos] - videobuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ds->eof){
|
videobuf_len-=3;
|
||||||
videobuf_code_len=0; // EOF, no next code
|
|
||||||
return videobuf_len-packet_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
videobuf_len-=4;
|
|
||||||
|
|
||||||
mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len);
|
mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len);
|
||||||
|
|
||||||
// Save next packet code:
|
// Save next packet code:
|
||||||
videobuf_code[0]=videobuffer[videobuf_len];
|
next_nal = demux_getc(ds);
|
||||||
videobuf_code[1]=videobuffer[videobuf_len+1];
|
if (next_nal < 0)
|
||||||
videobuf_code[2]=videobuffer[videobuf_len+2];
|
goto eof_out;
|
||||||
videobuf_code[3]=videobuffer[videobuf_len+3];
|
|
||||||
videobuf_code_len=4;
|
videobuf_code_len=4;
|
||||||
|
|
||||||
return videobuf_len-packet_start;
|
return videobuf_len-packet_start;
|
||||||
|
|
||||||
|
eof_out:
|
||||||
|
next_nal = -1;
|
||||||
|
videobuf_code_len = 0;
|
||||||
|
return videobuf_len - packet_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return: next packet code
|
// return: next packet code
|
||||||
|
|
Loading…
Reference in New Issue