Use MSGT_DECVIDEO in a video decoder.
[mplayer/glamo.git] / libmpcodecs / ae_pcm.c
blobcbae42dc87b2319026130176369a96cf55cd524d
1 /*
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <inttypes.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include <sys/types.h>
25 #include "m_option.h"
26 #include "mp_msg.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"
33 #include "ae_pcm.h"
36 static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
38 mux_a->h.dwScale=1;
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;
54 return 1;
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,
66 max_size / 2, 2);
68 else
69 memcpy(dest, src, max_size);
70 return max_size;
73 static int set_decoded_len(audio_encoder_t *encoder, int len)
75 return len;
78 static int close_pcm(audio_encoder_t *encoder)
80 return 1;
83 static int get_frame_size(audio_encoder_t *encoder)
85 return 0;
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;
100 return 1;