2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2006-01-15 10:25:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
#include "libaf/af_format.h"
|
|
|
|
#include "ad_internal.h"
|
|
|
|
|
|
|
|
#include "libmpdemux/mp3_hdr.h"
|
|
|
|
|
|
|
|
//based on ad_hwac3.c and ad_libmad.c
|
|
|
|
|
2010-02-12 16:29:34 +00:00
|
|
|
static const ad_info_t info =
|
2006-01-15 10:25:14 +00:00
|
|
|
{
|
|
|
|
"MPEG audio pass-through (fake decoder)",
|
|
|
|
"hwmpa",
|
|
|
|
"NicoDVB",
|
|
|
|
"NicoDVB",
|
|
|
|
"For hardware decoders"
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAD_EXTERN(hwmpa)
|
|
|
|
|
|
|
|
static int mpa_sync(sh_audio_t *sh, int no_frames, int *n, int *chans, int *srate, int *spf, int *mpa_layer, int *br)
|
|
|
|
{
|
|
|
|
int cnt = 0, x = 0, len, frames_count;
|
|
|
|
|
|
|
|
frames_count = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
while(cnt + 4 < sh->a_in_buffer_len)
|
|
|
|
{
|
|
|
|
x = mp_get_mp3_header(&(sh->a_in_buffer[cnt]), chans, srate, spf, mpa_layer, br);
|
|
|
|
if(x > 0)
|
|
|
|
{
|
|
|
|
frames_count++;
|
|
|
|
if(frames_count == no_frames)
|
|
|
|
{
|
|
|
|
*n = x;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
if(len > 0)
|
|
|
|
sh->a_in_buffer_len += len;
|
|
|
|
} while(len > 0);
|
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Cannot sync MPA frame: %d\r\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int preinit(sh_audio_t *sh)
|
|
|
|
{
|
2006-07-22 22:14:14 +00:00
|
|
|
sh->audio_out_minsize = 4608;//check
|
2006-01-15 10:25:14 +00:00
|
|
|
sh->audio_in_minsize = 4608;//check
|
|
|
|
sh->sample_format = AF_FORMAT_MPEG2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(sh_audio_t *sh)
|
|
|
|
{
|
|
|
|
int cnt, chans, srate, spf, mpa_layer, br, len;
|
|
|
|
|
|
|
|
if((cnt = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br)) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sh->channels = chans;
|
|
|
|
sh->samplerate = srate;
|
|
|
|
sh->i_bps = br * 125;
|
|
|
|
sh->samplesize = 2;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2006-01-15 10:25:14 +00:00
|
|
|
mp_msg(MSGT_DECAUDIO,MSGL_V,"AC_HWMPA initialized, bitrate: %d kb/s\r\n", len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen)
|
|
|
|
{
|
2006-07-16 16:34:05 +00:00
|
|
|
int len, start, tot;
|
2006-01-15 10:25:14 +00:00
|
|
|
int chans, srate, spf, mpa_layer, br;
|
2006-07-22 22:14:14 +00:00
|
|
|
int tot2;
|
2006-01-15 10:25:14 +00:00
|
|
|
|
2006-07-22 22:14:14 +00:00
|
|
|
tot = tot2 = 0;
|
2006-07-16 16:34:05 +00:00
|
|
|
|
2006-07-22 22:14:14 +00:00
|
|
|
while(tot2 < maxlen)
|
2006-01-15 10:25:14 +00:00
|
|
|
{
|
|
|
|
start = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br);
|
2006-07-22 22:14:14 +00:00
|
|
|
if(start < 0 || tot2 + spf * 2 * chans > maxlen)
|
2006-01-15 10:25:14 +00:00
|
|
|
break;
|
|
|
|
|
2006-07-16 16:34:05 +00:00
|
|
|
if(start + len > sh->a_in_buffer_len)
|
|
|
|
{
|
|
|
|
int l;
|
2006-12-09 12:24:11 +00:00
|
|
|
l = FFMIN(sh->a_in_buffer_size - sh->a_in_buffer_len, start + len);
|
2006-07-16 16:34:05 +00:00
|
|
|
l = demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len], l);
|
|
|
|
if(! l)
|
2006-07-23 08:35:18 +00:00
|
|
|
break;
|
2006-07-16 16:34:05 +00:00
|
|
|
sh->a_in_buffer_len += l;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&buf[tot], &(sh->a_in_buffer[start]), len);
|
|
|
|
tot += len;
|
|
|
|
|
2006-01-15 10:25:14 +00:00
|
|
|
sh->a_in_buffer_len -= start + len;
|
|
|
|
memmove(sh->a_in_buffer, &(sh->a_in_buffer[start + len]), sh->a_in_buffer_len);
|
2006-07-22 22:14:14 +00:00
|
|
|
tot2 += spf * 2 * chans;
|
2006-08-01 18:44:31 +00:00
|
|
|
|
|
|
|
/* HACK: seems to fix most A/V sync issues */
|
|
|
|
break;
|
2006-01-15 10:25:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-23 08:35:18 +00:00
|
|
|
memset(&buf[tot], 0, tot2-tot);
|
2006-07-22 22:14:14 +00:00
|
|
|
return tot2;
|
2006-01-15 10:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int control(sh_audio_t *sh,int cmd,void* arg, ...)
|
|
|
|
{
|
2006-07-08 17:28:36 +00:00
|
|
|
int start, len;
|
2006-01-15 10:25:14 +00:00
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case ADCTRL_RESYNC_STREAM:
|
|
|
|
if(mpa_sync(sh, 1, &len, NULL, NULL, NULL, NULL, NULL) >= 0)
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
else
|
|
|
|
return CONTROL_FALSE;
|
|
|
|
case ADCTRL_SKIP_FRAME:
|
|
|
|
start = mpa_sync(sh, 2, &len, NULL, NULL, NULL, NULL, NULL);
|
2010-02-25 22:06:05 +00:00
|
|
|
if(start < 0)
|
2006-01-15 10:25:14 +00:00
|
|
|
return CONTROL_FALSE;
|
|
|
|
|
|
|
|
sh->a_in_buffer_len -= start;
|
|
|
|
memmove(sh->a_in_buffer, &(sh->a_in_buffer[start]), sh->a_in_buffer_len);
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void uninit(sh_audio_t *sh)
|
|
|
|
{
|
|
|
|
}
|