11 #include "libaf/af_format.h"
12 #include "ad_internal.h"
14 #include "libmpdemux/mp3_hdr.h"
16 //based on ad_hwac3.c and ad_libmad.c
17 static int isdts
= -1;
19 static ad_info_t info
=
21 "MPEG audio pass-through (fake decoder)",
25 "For hardware decoders"
30 static int mpa_sync(sh_audio_t
*sh
, int no_frames
, int *n
, int *chans
, int *srate
, int *spf
, int *mpa_layer
, int *br
)
32 int cnt
= 0, x
= 0, len
, frames_count
;
37 while(cnt
+ 4 < sh
->a_in_buffer_len
)
39 if(((sh
->a_in_buffer
[cnt
] << 8) | sh
->a_in_buffer
[cnt
+1]) & 0xffe0 != 0xffe0)
41 x
= mp_get_mp3_header(&(sh
->a_in_buffer
[cnt
]), chans
, srate
, spf
, mpa_layer
, br
);
45 if(frames_count
== no_frames
)
53 len
= demux_read_data(sh
->ds
,&sh
->a_in_buffer
[sh
->a_in_buffer_len
],sh
->a_in_buffer_size
-sh
->a_in_buffer_len
);
55 sh
->a_in_buffer_len
+= len
;
57 mp_msg(MSGT_DECAUDIO
,MSGL_INFO
,"Cannot sync MPA frame: %d\r\n", len
);
61 static int preinit(sh_audio_t
*sh
)
63 sh
->audio_out_minsize
= 48;//check
64 sh
->audio_in_minsize
= 4608;//check
65 sh
->sample_format
= AF_FORMAT_MPEG2
;
69 static int init(sh_audio_t
*sh
)
71 int cnt
, chans
, srate
, spf
, mpa_layer
, br
, len
;
73 if((cnt
= mpa_sync(sh
, 1, &len
, &chans
, &srate
, &spf
, &mpa_layer
, &br
)) < 0)
77 sh
->samplerate
= srate
;
81 mp_msg(MSGT_DECAUDIO
,MSGL_V
,"AC_HWMPA initialized, bitrate: %d kb/s\r\n", len
);
85 static int decode_audio(sh_audio_t
*sh
,unsigned char *buf
,int minlen
,int maxlen
)
87 int len
, start
, cnt2
, tot
;
88 int chans
, srate
, spf
, mpa_layer
, br
;
91 while(tot
< minlen
&& tot
+4608<=maxlen
)
93 start
= mpa_sync(sh
, 1, &len
, &chans
, &srate
, &spf
, &mpa_layer
, &br
);
97 if(start
+ len
< sh
->a_in_buffer_len
&& start
+ len
>= maxlen
)
99 memcpy(&buf
[cnt2
], &(sh
->a_in_buffer
[start
]), len
);
101 sh
->a_in_buffer_len
-= start
+ len
;
102 memmove(sh
->a_in_buffer
, &(sh
->a_in_buffer
[start
+ len
]), sh
->a_in_buffer_len
);
110 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...)
116 case ADCTRL_RESYNC_STREAM
:
117 if(mpa_sync(sh
, 1, &len
, NULL
, NULL
, NULL
, NULL
, NULL
) >= 0)
120 return CONTROL_FALSE
;
121 case ADCTRL_SKIP_FRAME
:
122 start
= mpa_sync(sh
, 2, &len
, NULL
, NULL
, NULL
, NULL
, NULL
);
124 return CONTROL_FALSE
;
126 sh
->a_in_buffer_len
-= start
;
127 memmove(sh
->a_in_buffer
, &(sh
->a_in_buffer
[start
]), sh
->a_in_buffer_len
);
130 return CONTROL_UNKNOWN
;
134 static void uninit(sh_audio_t
*sh
)