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.
|
|
|
|
*/
|
|
|
|
|
2005-04-22 06:59:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
2005-04-22 13:53:56 +00:00
|
|
|
#include <unistd.h>
|
2005-04-22 06:59:59 +00:00
|
|
|
#include <string.h>
|
2005-04-22 17:53:31 +00:00
|
|
|
#include <sys/types.h>
|
2005-04-22 06:59:59 +00:00
|
|
|
#include "m_option.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "mp_msg.h"
|
2007-03-15 17:51:32 +00:00
|
|
|
#include "libmpdemux/aviheader.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libaf/af_format.h"
|
2007-12-10 16:53:30 +00:00
|
|
|
#include "libaf/reorder_ch.h"
|
2007-03-15 17:51:32 +00:00
|
|
|
#include "libmpdemux/ms_hdr.h"
|
2007-03-15 17:30:55 +00:00
|
|
|
#include "stream/stream.h"
|
2007-03-15 17:51:32 +00:00
|
|
|
#include "libmpdemux/muxer.h"
|
2005-04-22 06:59:59 +00:00
|
|
|
#include "ae_pcm.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
|
|
|
|
{
|
|
|
|
mux_a->h.dwScale=1;
|
|
|
|
mux_a->h.dwRate=encoder->params.sample_rate;
|
|
|
|
mux_a->wf=malloc(sizeof(WAVEFORMATEX));
|
|
|
|
mux_a->wf->wFormatTag=0x1; // PCM
|
|
|
|
mux_a->wf->nChannels=encoder->params.channels;
|
|
|
|
mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
|
|
|
|
mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
|
|
|
|
mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
|
|
|
|
mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
|
|
|
|
mux_a->wf->wBitsPerSample=16;
|
|
|
|
mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-04-22 06:59:59 +00:00
|
|
|
encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
|
|
|
|
encoder->min_buffer_size = 16384;
|
|
|
|
encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-04-22 06:59:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
max_size = FFMIN(nsamples, max_size);
|
2009-11-10 00:45:19 +00:00
|
|
|
if (encoder->params.channels == 5 || encoder->params.channels == 6 ||
|
|
|
|
encoder->params.channels == 8) {
|
2007-12-10 16:53:30 +00:00
|
|
|
max_size -= max_size % (encoder->params.channels * 2);
|
|
|
|
reorder_channel_copy_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
|
|
|
|
dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
|
|
|
|
encoder->params.channels,
|
|
|
|
max_size / 2, 2);
|
|
|
|
}
|
|
|
|
else
|
2005-04-22 06:59:59 +00:00
|
|
|
memcpy(dest, src, max_size);
|
|
|
|
return max_size;
|
|
|
|
}
|
|
|
|
|
2005-04-25 06:46:30 +00:00
|
|
|
static int set_decoded_len(audio_encoder_t *encoder, int len)
|
2005-04-22 06:59:59 +00:00
|
|
|
{
|
2005-04-25 06:46:30 +00:00
|
|
|
return len;
|
2005-04-22 06:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int close_pcm(audio_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_frame_size(audio_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mpae_init_pcm(audio_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
encoder->params.samples_per_frame = encoder->params.sample_rate;
|
|
|
|
encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-04-22 06:59:59 +00:00
|
|
|
encoder->decode_buffer_size = encoder->params.bitrate / 8;
|
|
|
|
encoder->bind = bind_pcm;
|
|
|
|
encoder->get_frame_size = get_frame_size;
|
|
|
|
encoder->set_decoded_len = set_decoded_len;
|
|
|
|
encoder->encode = encode_pcm;
|
|
|
|
encoder->close = close_pcm;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-04-22 06:59:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|