mirror of https://github.com/mpv-player/mpv
cleanup of video packet writer, PTS sent only once
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4307 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
6601a894ac
commit
7f5bcb338f
|
@ -293,21 +293,23 @@ static void my_write(unsigned char* data,int len){
|
|||
static unsigned char pes_header[PES_MAX_SIZE];
|
||||
|
||||
void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
|
||||
int x;
|
||||
int ptslen=timestamp?5:1;
|
||||
|
||||
// startcode:
|
||||
pes_header[0]=pes_header[1]=0;
|
||||
pes_header[2]=id>>8; pes_header[3]=id&255;
|
||||
|
||||
while(1){
|
||||
int payload_size=len+5; // data + PTS
|
||||
if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
|
||||
while(len>0){
|
||||
int payload_size=len; // data + PTS
|
||||
if(6+ptslen+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-(6+ptslen);
|
||||
|
||||
// construct PES header: (code from ffmpeg's libav)
|
||||
// startcode:
|
||||
// packetsize:
|
||||
pes_header[4]=(payload_size)>>8;
|
||||
pes_header[5]=(payload_size)&255;
|
||||
// stuffing:
|
||||
pes_header[4]=(ptslen+payload_size)>>8;
|
||||
pes_header[5]=(ptslen+payload_size)&255;
|
||||
|
||||
if(ptslen==5){
|
||||
int x;
|
||||
// presentation time stamp:
|
||||
x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
|
||||
pes_header[6]=x;
|
||||
|
@ -315,13 +317,16 @@ void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
|
|||
pes_header[7]=x>>8; pes_header[8]=x&255;
|
||||
x=((((timestamp) & 0x7fff) << 1) | 1);
|
||||
pes_header[9]=x>>8; pes_header[10]=x&255;
|
||||
|
||||
payload_size-=5;
|
||||
memcpy(&pes_header[6+5],data,payload_size);
|
||||
my_write(pes_header,6+5+payload_size);
|
||||
} else {
|
||||
// stuffing and header bits:
|
||||
pes_header[6]=0x0f;
|
||||
}
|
||||
|
||||
memcpy(&pes_header[6+ptslen],data,payload_size);
|
||||
my_write(pes_header,6+ptslen+payload_size);
|
||||
|
||||
len-=payload_size; data+=payload_size;
|
||||
if(len<=0) break;
|
||||
ptslen=1; // store PTS only once, at first packet!
|
||||
}
|
||||
|
||||
// printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
|
||||
|
@ -332,6 +337,7 @@ void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,
|
|||
|
||||
int ptslen=timestamp?5:0;
|
||||
|
||||
// startcode:
|
||||
pes_header[0]=pes_header[1]=0;
|
||||
pes_header[2]=1; pes_header[3]=0xBD;
|
||||
|
||||
|
@ -398,7 +404,7 @@ void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,
|
|||
my_write(pes_header,6+3+ptslen+7+payload_size);
|
||||
|
||||
len-=payload_size; data+=payload_size;
|
||||
if(len<=0) break;
|
||||
ptslen=0; // store PTS only once, at first packet!
|
||||
}
|
||||
|
||||
// printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
|
||||
|
|
Loading…
Reference in New Issue