annotate libmpcodecs/ae_toolame.c @ 13603:80fc8f48f14c

Do not loose commands while paused.
author reimar
date Sun, 10 Oct 2004 17:39:07 +0000
parents a87f1a948a24
children 17dd749b0554
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
1 #include "m_option.h"
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
2 #include "../mp_msg.h"
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
3 #include <inttypes.h>
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
4 #include "ae_toolame.h"
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
5
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
6
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
7 static int
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
8 param_bitrate = 192,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
9 param_srate = 48000,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
10 param_psy = 3,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
11 param_maxvbr = 192,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
12 param_errprot = 0,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
13 param_debug = 0;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
14
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
15 float param_vbr = 0;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
16 static char *param_mode = "stereo";
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
17
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
18 m_option_t toolameopts_conf[] = {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
19 {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
20 {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
21 {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
22 {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, 0, 50, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
23 {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
24 {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
25 {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
26 {NULL, NULL, 0, 0, 0, 0, NULL}
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
27 };
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
28
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
29
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
30 mpae_toolame_ctx *mpae_init_toolame(int channels, int srate)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
31 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
32 int mode;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
33 mpae_toolame_ctx *ctx = NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
34
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
35 if(channels == 1)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
36 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
37 mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
38 mode = MPG_MD_MONO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
39 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
40 else if(channels == 2)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
41 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
42 if(! strcasecmp(param_mode, "dual"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
43 mode = MPG_MD_DUAL_CHANNEL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
44 else if(! strcasecmp(param_mode, "jstereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
45 mode = MPG_MD_JOINT_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
46 else if(! strcasecmp(param_mode, "stereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
47 mode = MPG_MD_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
48 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
49 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
50 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
51 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
52 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
53 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
54 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
55
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
56 ctx = (mpae_toolame_ctx *) calloc(1, sizeof(mpae_toolame_ctx));
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
57 if(ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
58 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
59 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
60 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
61 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
62
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
63 ctx->toolame_ctx = toolame_init();
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
64 if(ctx->toolame_ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
65 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
66 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
67 free(ctx);
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
68 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
69 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
70 ctx->channels = channels;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
71 ctx->srate = srate;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
72
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
73 if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
74 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
75
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
76 if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
77 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
78
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
79 if(toolame_setSampleFreq(ctx->toolame_ctx, srate) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
80 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
81
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
82 if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
83 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
84
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
85 if(param_errprot)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
86 if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
87 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
88
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
89 if(param_vbr > 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
90 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
91 if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
92 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
93 if(toolame_setVBRLevel(ctx->toolame_ctx, param_maxvbr) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
94 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
95 if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
96 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
97 if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
98 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
99 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
100
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
101 if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
102 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
103
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
104 if(toolame_init_params(ctx->toolame_ctx) != 0)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
105 return NULL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
106
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
107 ctx->bitrate = param_bitrate;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
108
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
109 return ctx;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
110 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
111
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
112
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
113 int mpae_encode_toolame(mpae_toolame_ctx *ctx, uint8_t *dest, int nsamples, void *src, int max_size)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
114 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
115 int ret_size = 0, i;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
116 int16_t *buffer;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
117
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
118 buffer = (uint16_t *) src;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
119 for(i = 0; i < nsamples; i++)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
120 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
121 ctx->left_pcm[i] = buffer[2 * i];
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
122 ctx->right_pcm[i] = buffer[2 * i + (ctx->channels - 1)];
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
123 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
124
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
125 toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size);
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
126
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
127 return ret_size;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
128 }