changeset 3829:30b4f0c45b6e

hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
author arpi
date Fri, 28 Dec 2001 12:03:52 +0000
parents 063e5b0065a4
children fc1db33734e7
files ac3-iec958.c ac3-iec958.h dec_audio.c
diffstat 3 files changed, 38 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ac3-iec958.c	Fri Dec 28 10:21:05 2001 +0000
+++ b/ac3-iec958.c	Fri Dec 28 12:03:52 2001 +0000
@@ -83,23 +83,23 @@
   } bsi;
 }; 
 
-void ac3_iec958_build_burst(int length, int data_type, int big_endian, unsigned char * data, unsigned char * out)
+int ac3_iec958_build_burst(int length, int data_type, int big_endian, unsigned char * data, unsigned char * out)
 {
-	const char sync[4] = { 0x72, 0xF8, 0x1F, 0x4E };
+	const char sync[6] = { 0x72, 0xF8, 0x1F, 0x4E, 0x00, 0x00 };
 
-	memcpy(out, sync, 4);
+	memcpy(out, sync, 6);
 	if (length)
 		out[4] = data_type; /* & 0x1F; */
 	else
 		out[4] = 0;
-	out[5] = 0x00;
-	out[6] = (length*8) & 0xFF;
-	out[7] = ((length*8) >> 8) & 0xFF;
+	out[6] = (length << 3) & 0xFF;
+	out[7] = (length >> 5) & 0xFF;
 	if (big_endian)
 		swab(data, out + 8, length);
 	else
-		memcpy(data, out + 8, length);
+		memcpy(out + 8, data, length);
 	memset(out + 8 + length, 0, 6144 - 8 - length);
+	return 6144;
 }
 
 int ac3_iec958_parse_syncinfo(unsigned char *buf, int size, struct hwac3info *ai, int *skipped)
--- a/ac3-iec958.h	Fri Dec 28 10:21:05 2001 +0000
+++ b/ac3-iec958.h	Fri Dec 28 12:03:52 2001 +0000
@@ -7,7 +7,7 @@
   int bitrate, framesize, samplerate, bsmod;
 };
 
-void ac3_iec958_build_burst(int length, int data_type, int big_endian, unsigned char * data, unsigned char * out);
+int ac3_iec958_build_burst(int length, int data_type, int big_endian, unsigned char * data, unsigned char * out);
 int ac3_iec958_parse_syncinfo(unsigned char *buf, int size, struct hwac3info *ai, int *skipped);
 
 #endif
--- a/dec_audio.c	Fri Dec 28 10:21:05 2001 +0000
+++ b/dec_audio.c	Fri Dec 28 12:03:52 2001 +0000
@@ -273,6 +273,7 @@
   // Dolby AC3 audio:
   sh_audio->audio_out_minsize=4*256*6;
   sh_audio->sample_format = AFMT_AC3;
+  sh_audio->channels=1;
   break;
 case AFM_GSM:
   // MS-GSM audio codec:
@@ -425,27 +426,32 @@
   break;
 }
 case AFM_HWAC3: {
-  unsigned char *buffer;		    
-  struct hwac3info ai;
-  int len, skipped;
-  len = ds_get_packet(sh_audio->ds, &buffer); // maybe 1 packet is not enough,
-    // at least for mpeg, PS packets contain about max. 2000 bytes of data.
-  if(ac3_iec958_parse_syncinfo(buffer, len, &ai, &skipped) < 0) {
-      mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_AC3notvalid);
-      driver = 0;
-      break;
+  // Dolby AC3 passthrough:
+  int accel=0; // should contain mmx/sse/etc flags
+  a52_samples=a52_init (accel);
+  if (a52_samples == NULL) {
+       mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
+       driver=0;break;
   }
-  if(ai.samplerate != 48000) {
-      mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AC3only48k);
-      driver = 0;
-      break;
+  sh_audio->a_in_buffer_size=3840;
+  sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
+  sh_audio->a_in_buffer_len=0;
+  if(a52_fillbuff(sh_audio)<0) {
+       mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
+       driver=0;break;
   }
-  sh_audio->samplerate=ai.samplerate;
-  sh_audio->samplesize=ai.framesize;
+  
+  //sh_audio->samplerate=ai.samplerate;   // SET by a52_fillbuff()
+  //sh_audio->samplesize=ai.framesize;
+  //sh_audio->i_bps=ai.bitrate*(1000/8);  // SET by a52_fillbuff()
+  //sh_audio->ac3_frame=malloc(6144);
+  //sh_audio->o_bps=sh_audio->i_bps;  // XXX FIXME!!! XXX
+
+  // o_bps is calculated from samplesize*channels*samplerate
+  // a single ac3 frame is always translated to 6144 byte packet. (zero padding)
   sh_audio->channels=1;
-  sh_audio->i_bps=ai.bitrate*(1000/8);
-  sh_audio->ac3_frame=malloc(6144);
-  sh_audio->o_bps=sh_audio->i_bps;  // XXX FIXME!!! XXX
+  sh_audio->samplesize=4;   // 1*4*(6*256) = 6144 (very TRICKY!)
+
   break;
 }
 case AFM_ALAW: {
@@ -1000,10 +1006,11 @@
 	break;
       }
       case AFM_HWAC3: // AC3 through SPDIF
-	if(demux_read_data(sh_audio->ds,sh_audio->ac3_frame, 6144) != 6144) 
-	    break; //EOF 
-	ac3_iec958_build_burst(1536, 0x1F, 1, buf, sh_audio->ac3_frame);
-	len = 6144;
+        if(!sh_audio->a_in_buffer_len)
+	    if((len=a52_fillbuff(sh_audio))<0) break; //EOF
+	sh_audio->a_in_buffer_len=0;
+	len = ac3_iec958_build_burst(len, 0x01, 1, sh_audio->a_in_buffer, buf);
+	// len = 6144 = 4*(6*256)
 	break;
 #ifdef USE_WIN32DLL
       case AFM_ACM:
@@ -1122,6 +1129,7 @@
               switch(sh_audio->codec->driver){
                 case AFM_MPEG: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
                 case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame
+		case AFM_HWAC3:
                 case AFM_A52: a52_fillbuff(sh_audio);break; // skip AC3 frame
 		case AFM_ACM:
 		case AFM_DSHOW: {