changeset 4299:8e157167cee5

LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
author arpi
date Tue, 22 Jan 2002 02:14:40 +0000
parents 9eb7a02393a3
children 4ebab79785b7
files libvo/vo_mpegpes.c
diffstat 1 files changed, 44 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_mpegpes.c	Tue Jan 22 02:00:57 2002 +0000
+++ b/libvo/vo_mpegpes.c	Tue Jan 22 02:14:40 2002 +0000
@@ -163,7 +163,7 @@
     codec_context.frame_rate=25*FRAME_RATE_BASE; // !!!!!
     codec_context.gop_size=0; // I frames only
     codec_context.flags=CODEC_FLAG_QSCALE;
-    codec_context.quality=1; // quality!  1..31  (1=best,slowest)
+    codec_context.quality=3; // quality!  1..31  (1=best,slowest)
 
 #if 0
     codec_context.width=width;
@@ -328,8 +328,9 @@
 
 }
 
-void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp){
-    int x;
+void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
+
+    int ptslen=timestamp?5:0;
 
 	      pes_header[0]=pes_header[1]=0;
 	      pes_header[2]=1; pes_header[3]=0xBD;
@@ -341,19 +342,21 @@
 	    if(payload_size>len) payload_size=len;
 	    payload_size&=(~3); // align!
 
-	    payload_size+=20;  //  PTS+headers
-	    
 	    //if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
 	    
-    // construct PES header:  (code from ffmpeg's libav)
-	      // startcode:
 	      // packetsize:
-	      pes_header[4]=(payload_size)>>8;
-	      pes_header[5]=(payload_size)&255;
+	      pes_header[4]=(payload_size+3+ptslen+7)>>8;
+	      pes_header[5]=(payload_size+3+ptslen+7)&255;
+
 	      // stuffing:
 	      pes_header[6]=0x81;
 	      pes_header[7]=0x80;
-	      pes_header[8]=10; // hdrlen
+
+	      // hdrlen:
+	      pes_header[8]=ptslen;
+	      
+	  if(ptslen){
+	      int x;
 	      // presentation time stamp:
 	      x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
 	      pes_header[9]=x;
@@ -361,26 +364,38 @@
 	      pes_header[10]=x>>8; pes_header[11]=x&255;
 	      x=((((timestamp) & 0x7fff) << 1) | 1);
 	      pes_header[12]=x>>8; pes_header[13]=x&255;
-	      
-	      pes_header[14]=
-	      pes_header[15]=
-	      pes_header[16]=
-	      pes_header[17]=
-	      pes_header[18]=0xFF; // stuffing
-	      
-	      pes_header[19]=id;
+	  }
 	      
-	      pes_header[20]=0x07; // dunnowhat
-	      pes_header[21]=0x00;
-	      pes_header[22]=0x04;
-	      pes_header[23]=0x0C;
-	      
-	      pes_header[24]=0x01; // LPCM id
-	      pes_header[25]=0x80;
-	      
-	payload_size-=20;
-	memcpy(&pes_header[6+20],data,payload_size);
-	my_write(pes_header,6+20+payload_size);
+// ============ LPCM header: (7 bytes) =================
+// Info by mocm@convergence.de
+
+//	   ID:
+	      pes_header[ptslen+9]=id;
+
+//	   number of frames:
+	      pes_header[ptslen+10]=0x07;
+
+//	   first acces unit pointer, i.e. start of audio frame:
+	      pes_header[ptslen+11]=0x00;
+	      pes_header[ptslen+12]=0x04;
+
+//	   audio emphasis on-off                                  1 bit
+//	   audio mute on-off                                      1 bit
+//	   reserved                                               1 bit
+//	   audio frame number                                     5 bit
+	      pes_header[ptslen+13]=0x0C;
+
+//	   quantization word length                               2 bit
+//	   audio sampling frequency (48khz = 0, 96khz = 1)        2 bit
+//	   reserved                                               1 bit
+//	   number of audio channels - 1 (e.g. stereo = 1)         3 bit
+	      pes_header[ptslen+14]=1|(freq_id<<4);
+
+//	   dynamic range control (0x80 if off)
+	      pes_header[ptslen+15]=0x80;
+
+	memcpy(&pes_header[6+3+ptslen+7],data,payload_size);
+	my_write(pes_header,6+3+ptslen+7+payload_size);
 
 	len-=payload_size; data+=payload_size;
 	if(len<=0) break;