15234
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <inttypes.h>
|
|
4 #include <string.h>
|
|
5 #include "m_option.h"
|
|
6 #include "../mp_msg.h"
|
|
7 #include "aviheader.h"
|
|
8 #include "../libaf/af_format.h"
|
|
9 #include "ms_hdr.h"
|
|
10 #include "muxer.h"
|
|
11 #include "ae_pcm.h"
|
|
12
|
|
13
|
|
14 static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
|
|
15 {
|
|
16 mux_a->h.dwScale=1;
|
|
17 mux_a->h.dwRate=encoder->params.sample_rate;
|
|
18 mux_a->wf=malloc(sizeof(WAVEFORMATEX));
|
|
19 mux_a->wf->wFormatTag=0x1; // PCM
|
|
20 mux_a->wf->nChannels=encoder->params.channels;
|
|
21 mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
|
|
22 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
|
|
23 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
|
|
24 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
|
|
25 mux_a->wf->wBitsPerSample=16;
|
|
26 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
|
|
27
|
|
28 encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
|
|
29 encoder->min_buffer_size = 16384;
|
|
30 encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
|
|
31
|
|
32 return 1;
|
|
33 }
|
|
34
|
|
35 static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
|
|
36 {
|
|
37 max_size = min(nsamples, max_size);
|
|
38 memcpy(dest, src, max_size);
|
|
39 return max_size;
|
|
40 }
|
|
41
|
|
42 static void set_decoded_len(audio_encoder_t *encoder, int len)
|
|
43 {
|
|
44 return;
|
|
45 }
|
|
46
|
|
47 static int close_pcm(audio_encoder_t *encoder)
|
|
48 {
|
|
49 return 1;
|
|
50 }
|
|
51
|
|
52 static int get_frame_size(audio_encoder_t *encoder)
|
|
53 {
|
|
54 return 0;
|
|
55 }
|
|
56
|
|
57 int mpae_init_pcm(audio_encoder_t *encoder)
|
|
58 {
|
|
59 encoder->params.samples_per_frame = encoder->params.sample_rate;
|
|
60 encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
|
|
61
|
|
62 encoder->decode_buffer_size = encoder->params.bitrate / 8;
|
|
63 encoder->bind = bind_pcm;
|
|
64 encoder->get_frame_size = get_frame_size;
|
|
65 encoder->set_decoded_len = set_decoded_len;
|
|
66 encoder->encode = encode_pcm;
|
|
67 encoder->close = close_pcm;
|
|
68
|
|
69 return 1;
|
|
70 }
|
|
71
|