Mercurial > mplayer.hg
changeset 4306:f11e25b77c1e
cleanup of video packet writer, PTS sent only once
author | arpi |
---|---|
date | Tue, 22 Jan 2002 18:12:00 +0000 |
parents | 624c73ec1c54 |
children | c494cc258eb8 |
files | libvo/vo_mpegpes.c |
diffstat | 1 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/vo_mpegpes.c Tue Jan 22 18:11:27 2002 +0000 +++ b/libvo/vo_mpegpes.c Tue Jan 22 18:12:00 2002 +0000 @@ -293,21 +293,23 @@ 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 @@ 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 @@ 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 @@ 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);