2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
27 #include "libmpdemux/aviheader.h"
28 #include "libaf/af_format.h"
29 #include "libaf/reorder_ch.h"
30 #include "libmpdemux/ms_hdr.h"
31 #include "stream/stream.h"
32 #include "libmpdemux/muxer.h"
36 static int bind_pcm(audio_encoder_t
*encoder
, muxer_stream_t
*mux_a
)
39 mux_a
->h
.dwRate
=encoder
->params
.sample_rate
;
40 mux_a
->wf
=malloc(sizeof(WAVEFORMATEX
));
41 mux_a
->wf
->wFormatTag
=0x1; // PCM
42 mux_a
->wf
->nChannels
=encoder
->params
.channels
;
43 mux_a
->h
.dwSampleSize
=2*mux_a
->wf
->nChannels
;
44 mux_a
->wf
->nBlockAlign
=mux_a
->h
.dwSampleSize
;
45 mux_a
->wf
->nSamplesPerSec
=mux_a
->h
.dwRate
;
46 mux_a
->wf
->nAvgBytesPerSec
=mux_a
->h
.dwSampleSize
*mux_a
->wf
->nSamplesPerSec
;
47 mux_a
->wf
->wBitsPerSample
=16;
48 mux_a
->wf
->cbSize
=0; // FIXME for l3codeca.acm
50 encoder
->input_format
= (mux_a
->wf
->wBitsPerSample
==8) ? AF_FORMAT_U8
: AF_FORMAT_S16_LE
;
51 encoder
->min_buffer_size
= 16384;
52 encoder
->max_buffer_size
= mux_a
->wf
->nAvgBytesPerSec
;
57 static int encode_pcm(audio_encoder_t
*encoder
, uint8_t *dest
, void *src
, int nsamples
, int max_size
)
59 max_size
= FFMIN(nsamples
, max_size
);
60 if (encoder
->params
.channels
== 5 || encoder
->params
.channels
== 6 ||
61 encoder
->params
.channels
== 8) {
62 max_size
-= max_size
% (encoder
->params
.channels
* 2);
63 reorder_channel_copy_nch(src
, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT
,
64 dest
, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT
,
65 encoder
->params
.channels
,
69 memcpy(dest
, src
, max_size
);
73 static int set_decoded_len(audio_encoder_t
*encoder
, int len
)
78 static int close_pcm(audio_encoder_t
*encoder
)
83 static int get_frame_size(audio_encoder_t
*encoder
)
88 int mpae_init_pcm(audio_encoder_t
*encoder
)
90 encoder
->params
.samples_per_frame
= encoder
->params
.sample_rate
;
91 encoder
->params
.bitrate
= encoder
->params
.sample_rate
* encoder
->params
.channels
* 2 * 8;
93 encoder
->decode_buffer_size
= encoder
->params
.bitrate
/ 8;
94 encoder
->bind
= bind_pcm
;
95 encoder
->get_frame_size
= get_frame_size
;
96 encoder
->set_decoded_len
= set_decoded_len
;
97 encoder
->encode
= encode_pcm
;
98 encoder
->close
= close_pcm
;