[MPlayer-dev-eng] [PATCH] add support for AC3 endianness

Ulion ulion2002 at gmail.com
Wed Sep 19 17:19:12 CEST 2007


2007/9/17, Ulion <ulion2002 at gmail.com>:
> 2007/9/17, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> > Hello,
> > On Mon, Sep 17, 2007 at 06:00:27AM +0800, Ulion wrote:
> > > Should the AF_FORMAT_AC3_LE and AF_FORMAT_AC3_BE format need a 16 bits
> > > flag with AF_FORMAT_16BIT?
> >
> > They are not needed so far, so I'd prefer to not add them. But if you
> > see anything in the patch that would make it non-trivial to add it later
> > please say so.
> >
>
>    case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
>      // Check for errors in configuraton
> -    if(AF_OK != check_format(*(int*)arg))
> +    if(!AF_FORMAT_IS_AC3(*(int*)arg) && AF_OK != check_format(*(int*)arg))
>        return AF_ERROR;
>
>      af->data->format = *(int*)arg;
>      af->data->bps = af_fmt2bits(af->data->format)/8;
>
> Here af->data->bps got by af_fmt2bits, although I don't known what's
> the usage of the 'bps', but af_fmt2bits not support AC3 format will
> always return 8. Since ac3 stream is always 16bits format (does it?),
> I prefer to make it return 16 instead, although I don't known whether
> it make any different.
>

After some real test, I found the data->bps is very important for
endian conversions!
With bps=1, no endian conversion will be done, target buffer always be
empty. Check the function endian(...). We need a manual fix in
af_fmt2bits for AC3 format or add 16bits flag into AC3 format, maybe a
special fix is better for current usage of AC3 format type.

Index: libaf/format.c
===================================================================
--- libaf/format.c      (revision 24572)
+++ libaf/format.c      (working copy)
@@ -64,6 +64,8 @@

 inline int af_fmt2bits(int format)
 {
+    if (AF_FORMAT_IS_AC3(format))
+        return 16;
     return (format & AF_FORMAT_BITS_MASK)+8;
 //    return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8;
 #if 0


And also, in ao_alsa.c need more fix here to make ao alsa work
correctly when input format is either AC3_LE or AC3_BE.

> +         if (ao_data.format == AF_FORMAT_AC3_BE)
> +           ao_data.format = AF_FORMAT_AC3_LE;
> +         else if (ao_data.format == AF_FORMAT_AC3_LE) {
> +           ao_data.format = AF_FORMAT_AC3_BE;
> +           alsa_format = SND_PCM_FORMAT_S16_BE;
> +         }
> +         else ao_data.format = AF_FORMAT_S16_LE;

The ao oss part of patch also has problem, here's part of a working
patch fixed and tested by me.

Index: libao2/ao_oss.c
===================================================================
@@ -294,14 +294,17 @@
 #if defined(FD_CLOEXEC) && defined(F_SETFD)
   fcntl(audio_fd, F_SETFD, FD_CLOEXEC);
 #endif
-
-  if(format == AF_FORMAT_AC3) {
+
+  if (AF_FORMAT_IS_AC3(format)) {
+    format = AF_FORMAT_AC3_NE;
+    ao_data.format=format;
     ao_data.samplerate=rate;
     ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
   }

 ac3_retry:
-  ao_data.format=format;
+  if (!AF_FORMAT_IS_AC3(ao_data.format))
+    ao_data.format=format;
   oss_format=format2oss(format);
   if (oss_format == -1) {
 #ifdef WORDS_BIGENDIAN
@@ -323,14 +326,15 @@
        mp_msg(MSGT_AO,MSGL_WARN,"WARNING! Your soundcard does NOT
support %s sample format! Broken audio or bad playback speed are
possible! Try with '-af format'\n",audio_out_format_name(format));
 #endif

-  ao_data.format = oss2format(oss_format);
+  if (!AF_FORMAT_IS_AC3(ao_data.format))
+    ao_data.format = oss2format(oss_format);
   if (ao_data.format == -1) return 0;

   mp_msg(MSGT_AO,MSGL_V,"audio_setup: sample format: %s (requested: %s)\n",



-- 
Ulion



More information about the MPlayer-dev-eng mailing list