annotate alacenc.c @ 7598:60dd0089cdba libavcodec

alacenc: NULL_IF_CONFIG_SMALL long_name.
author ramiro
date Sun, 17 Aug 2008 12:25:01 +0000
parents 30af3a9775de
children 6250ff63990b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7595
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
1 /**
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
2 * ALAC audio encoder
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
4 *
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
5 * This file is part of FFmpeg.
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
6 *
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
11 *
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
15 * Lesser General Public License for more details.
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
16 *
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
20 */
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
21
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
22 #include "avcodec.h"
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
23 #include "bitstream.h"
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
24 #include "dsputil.h"
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
25 #include "lpc.h"
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
26
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
27 #define DEFAULT_FRAME_SIZE 4096
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
28 #define DEFAULT_SAMPLE_SIZE 16
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
29 #define MAX_CHANNELS 8
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
30 #define ALAC_EXTRADATA_SIZE 36
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
31 #define ALAC_FRAME_HEADER_SIZE 55
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
32 #define ALAC_FRAME_FOOTER_SIZE 3
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
33
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
34 #define ALAC_ESCAPE_CODE 0x1FF
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
35 #define ALAC_MAX_LPC_ORDER 30
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
36
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
37 int interlacing_shift;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
38 int interlacing_leftweight;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
39 PutBitContext pbctx;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
40 DSPContext dspctx;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
41 AVCodecContext *avctx;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
42 } AlacEncodeContext;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
43
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
44
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
45 static void encode_scalar(AlacEncodeContext *s, int x, int k, int write_sample_size)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
46 {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
47 int divisor, q, r;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
48
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
49 k = FFMIN(k, s->rc.k_modifier);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
50 divisor = (1<<k) - 1;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
51 q = x / divisor;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
52 r = x % divisor;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
53
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
54 if(q > 8) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
55 // write escape code and sample value directly
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
56 put_bits(&s->pbctx, 9, ALAC_ESCAPE_CODE);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
57 put_bits(&s->pbctx, write_sample_size, x);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
58 } else {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
59 if(q)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
60 put_bits(&s->pbctx, q, (1<<q) - 1);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
61 put_bits(&s->pbctx, 1, 0);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
62
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
63 if(k != 1) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
64 if(r > 0)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
65 put_bits(&s->pbctx, k, r+1);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
66 else
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
67 put_bits(&s->pbctx, k-1, 0);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
68 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
69 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
70 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
71
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
72 static void write_frame_header(AlacEncodeContext *s, int is_verbatim)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
73 {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
74 put_bits(&s->pbctx, 3, s->channels-1); // No. of channels -1
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
75 put_bits(&s->pbctx, 16, 0); // Seems to be zero
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
76 put_bits(&s->pbctx, 1, 1); // Sample count is in the header
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
77 put_bits(&s->pbctx, 2, 0); // FIXME: Wasted bytes field
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
78 put_bits(&s->pbctx, 1, is_verbatim); // Audio block is verbatim
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
79 put_bits(&s->pbctx, 32, s->avctx->frame_size); // No. of samples in the frame
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
80 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
81
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
82 static void write_compressed_frame(AlacEncodeContext *s)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
83 {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
84 int i, j;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
85
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
86 /* only simple mid/side decorrelation supported as of now */
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
87 alac_stereo_decorrelation(s);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
88 put_bits(&s->pbctx, 8, s->interlacing_shift);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
89 put_bits(&s->pbctx, 8, s->interlacing_leftweight);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
90
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
91 for(i=0;i<s->channels;i++) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
92
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
93 calc_predictor_params(s, i);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
94
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
95 put_bits(&s->pbctx, 4, 0); // prediction type : currently only type 0 has been RE'd
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
96 put_bits(&s->pbctx, 4, s->lpc[i].lpc_quant);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
97
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
98 put_bits(&s->pbctx, 3, s->rc.rice_modifier);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
99 put_bits(&s->pbctx, 5, s->lpc[i].lpc_order);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
100 // predictor coeff. table
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
101 for(j=0;j<s->lpc[i].lpc_order;j++) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
102 put_sbits(&s->pbctx, 16, s->lpc[i].lpc_coeff[j]);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
103 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
104 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
105
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
106 // apply lpc and entropy coding to audio samples
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
107
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
108 for(i=0;i<s->channels;i++) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
109 alac_linear_predictor(s, i);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
110 alac_entropy_coder(s);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
111 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
112 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
113
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
114 static av_cold int alac_encode_init(AVCodecContext *avctx)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
115 {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
116 AlacEncodeContext *s = avctx->priv_data;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
117 uint8_t *alac_extradata = av_mallocz(ALAC_EXTRADATA_SIZE+1);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
118
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
119 avctx->frame_size = DEFAULT_FRAME_SIZE;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
120 avctx->bits_per_sample = DEFAULT_SAMPLE_SIZE;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
121 s->channels = avctx->channels;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
122 s->samplerate = avctx->sample_rate;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
123
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
124 if(avctx->sample_fmt != SAMPLE_FMT_S16) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
125 av_log(avctx, AV_LOG_ERROR, "only pcm_s16 input samples are supported\n");
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
126 return -1;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
127 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
128
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
129 // Set default compression level
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
130 if(avctx->compression_level == FF_COMPRESSION_DEFAULT)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
131 s->compression_level = 1;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
132 else
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
133 s->compression_level = av_clip(avctx->compression_level, 0, 1);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
134
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
135 // Initialize default Rice parameters
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
136 s->rc.history_mult = 40;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
137 s->rc.initial_history = 10;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
138 s->rc.k_modifier = 14;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
139 s->rc.rice_modifier = 4;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
140
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
141 s->max_coded_frame_size = (ALAC_FRAME_HEADER_SIZE + ALAC_FRAME_FOOTER_SIZE +
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
142 avctx->frame_size*s->channels*avctx->bits_per_sample)>>3;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
143
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
144 s->write_sample_size = avctx->bits_per_sample + s->channels - 1; // FIXME: consider wasted_bytes
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
145
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
146 AV_WB32(alac_extradata, ALAC_EXTRADATA_SIZE);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
147 AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c'));
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
148 AV_WB32(alac_extradata+12, avctx->frame_size);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
149 AV_WB8 (alac_extradata+17, avctx->bits_per_sample);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
150 AV_WB8 (alac_extradata+21, s->channels);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
151 AV_WB32(alac_extradata+24, s->max_coded_frame_size);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
152 AV_WB32(alac_extradata+28, s->samplerate*s->channels*avctx->bits_per_sample); // average bitrate
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
153 AV_WB32(alac_extradata+32, s->samplerate);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
154
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
155 // Set relevant extradata fields
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
156 if(s->compression_level > 0) {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
157 AV_WB8(alac_extradata+18, s->rc.history_mult);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
158 AV_WB8(alac_extradata+19, s->rc.initial_history);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
159 AV_WB8(alac_extradata+20, s->rc.k_modifier);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
160 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
161
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
162 avctx->extradata = alac_extradata;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
163 avctx->extradata_size = ALAC_EXTRADATA_SIZE;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
164
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
165 avctx->coded_frame = avcodec_alloc_frame();
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
166 avctx->coded_frame->key_frame = 1;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
167
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
168 s->avctx = avctx;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
169 dsputil_init(&s->dspctx, avctx);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
170
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
171 allocate_sample_buffers(s);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
172
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
173 return 0;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
174 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
175
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
176 static av_cold int alac_encode_close(AVCodecContext *avctx)
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
177 {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
178 AlacEncodeContext *s = avctx->priv_data;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
179
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
180 av_freep(&avctx->extradata);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
181 avctx->extradata_size = 0;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
182 av_freep(&avctx->coded_frame);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
183 free_sample_buffers(s);
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
184 return 0;
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
185 }
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
186
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
187 AVCodec alac_encoder = {
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
188 "alac",
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
189 CODEC_TYPE_AUDIO,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
190 CODEC_ID_ALAC,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
191 sizeof(AlacEncodeContext),
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
192 alac_encode_init,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
193 alac_encode_frame,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
194 alac_encode_close,
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
195 .capabilities = CODEC_CAP_SMALL_LAST_FRAME,
7598
60dd0089cdba alacenc: NULL_IF_CONFIG_SMALL long_name.
ramiro
parents: 7595
diff changeset
196 .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
7595
30af3a9775de Import ok'd parts of ALAC encoder from GSoC repo.
ramiro
parents:
diff changeset
197 };