annotate libmpcodecs/ae_pcm.c @ 26236:34cbcf7b4c80

better wording
author ptt
date Fri, 21 Mar 2008 19:16:44 +0000
parents dfa8a510c81c
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
1 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
2 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
3 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
4 #include <unistd.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
5 #include <string.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
6 #include <sys/types.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
7 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15258
diff changeset
8 #include "mp_msg.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
9 #include "libmpdemux/aviheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15258
diff changeset
10 #include "libaf/af_format.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
11 #include "libaf/reorder_ch.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
12 #include "libmpdemux/ms_hdr.h"
22600
3c2b4a866c6a Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
13 #include "stream/stream.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
14 #include "libmpdemux/muxer.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
15 #include "ae_pcm.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
16
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
17
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
18 static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
19 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
20 mux_a->h.dwScale=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
21 mux_a->h.dwRate=encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
22 mux_a->wf=malloc(sizeof(WAVEFORMATEX));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
23 mux_a->wf->wFormatTag=0x1; // PCM
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
24 mux_a->wf->nChannels=encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
25 mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
26 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
27 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
28 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
29 mux_a->wf->wBitsPerSample=16;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
30 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
31
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
32 encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
33 encoder->min_buffer_size = 16384;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
34 encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
35
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
36 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
37 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
38
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
39 static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
40 {
21531
a90aa203186c Get rid of min/max macros from aviheader.h, they do not belong here.
reimar
parents: 17012
diff changeset
41 max_size = FFMIN(nsamples, max_size);
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
42 if (encoder->params.channels == 6 || encoder->params.channels == 5) {
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
43 max_size -= max_size % (encoder->params.channels * 2);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
44 reorder_channel_copy_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
45 dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
46 encoder->params.channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
47 max_size / 2, 2);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
48 }
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
49 else
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
50 memcpy(dest, src, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
51 return max_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
52 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
53
15258
c2979462805a fixed wrong function pointers definitions
nicodvb
parents: 15240
diff changeset
54 static int set_decoded_len(audio_encoder_t *encoder, int len)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
55 {
15258
c2979462805a fixed wrong function pointers definitions
nicodvb
parents: 15240
diff changeset
56 return len;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
57 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
58
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
59 static int close_pcm(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
60 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
61 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
62 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
63
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
64 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
65 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
66 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
67 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
68
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
69 int mpae_init_pcm(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
70 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
71 encoder->params.samples_per_frame = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
72 encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
73
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
74 encoder->decode_buffer_size = encoder->params.bitrate / 8;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
75 encoder->bind = bind_pcm;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
76 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
77 encoder->set_decoded_len = set_decoded_len;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
78 encoder->encode = encode_pcm;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
79 encoder->close = close_pcm;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
80
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
81 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
82 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
83