annotate libmpcodecs/ae_pcm.c @ 32006:3133252ce3fa

Actually set the destination address in the sockaddr_in struct for Windows as well...
author reimar
date Wed, 08 Sep 2010 18:37:55 +0000
parents 32725ca88fed
children c08363dc5320
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29826
diff changeset
18
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
19 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
20 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
21 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
22 #include <unistd.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
23 #include <string.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
24 #include <sys/types.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
25 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15258
diff changeset
26 #include "mp_msg.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
27 #include "libmpdemux/aviheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15258
diff changeset
28 #include "libaf/af_format.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
29 #include "libaf/reorder_ch.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
30 #include "libmpdemux/ms_hdr.h"
22600
3c2b4a866c6a Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
31 #include "stream/stream.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
32 #include "libmpdemux/muxer.h"
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
33 #include "ae_pcm.h"
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
34
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
35
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
36 static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
37 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
38 mux_a->h.dwScale=1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
39 mux_a->h.dwRate=encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
40 mux_a->wf=malloc(sizeof(WAVEFORMATEX));
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
41 mux_a->wf->wFormatTag=0x1; // PCM
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
42 mux_a->wf->nChannels=encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
43 mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
44 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
45 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
46 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
47 mux_a->wf->wBitsPerSample=16;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
48 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
49
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
50 encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
51 encoder->min_buffer_size = 16384;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
52 encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
53
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
54 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
55 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
56
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
57 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
58 {
21531
a90aa203186c Get rid of min/max macros from aviheader.h, they do not belong here.
reimar
parents: 17012
diff changeset
59 max_size = FFMIN(nsamples, max_size);
29826
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
60 if (encoder->params.channels == 5 || encoder->params.channels == 6 ||
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
61 encoder->params.channels == 8) {
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
62 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
63 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
64 dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
65 encoder->params.channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
66 max_size / 2, 2);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
67 }
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
68 else
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
69 memcpy(dest, src, max_size);
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
70 return max_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
71 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
72
15258
c2979462805a fixed wrong function pointers definitions
nicodvb
parents: 15240
diff changeset
73 static int set_decoded_len(audio_encoder_t *encoder, int len)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
74 {
15258
c2979462805a fixed wrong function pointers definitions
nicodvb
parents: 15240
diff changeset
75 return len;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
76 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
77
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
78 static int close_pcm(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
79 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
80 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
81 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
82
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
83 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
84 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
85 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
86 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
87
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
88 int mpae_init_pcm(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
89 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
90 encoder->params.samples_per_frame = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
91 encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
92
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
93 encoder->decode_buffer_size = encoder->params.bitrate / 8;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
94 encoder->bind = bind_pcm;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
95 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
96 encoder->set_decoded_len = set_decoded_len;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
97 encoder->encode = encode_pcm;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
98 encoder->close = close_pcm;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
99
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
100 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents:
diff changeset
101 }