History

adx: convert to new channel layout API

Vittorio Giovara committed 9 years ago

Commit 44070541 parent 984612a3 files · +20 −13Browse files

Unified · Split

3 files
  1. libavcodec/adx.c +11 −5
  2. libavcodec/adxdec.c +3 −3
  3. libavcodec/adxenc.c +6 −5
libavcodec/adx.c+11−5
@@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff) · 37 unmodified lines
3838 int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
3939 int bufsize, int *header_size, int *coeff)
4040 {
41− int offset, cutoff;
41+ int offset, cutoff, channels;
4242
4343 if (bufsize < 24)
4444 return AVERROR_INVALIDDATA;
@@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, · 13 unmodified lines
5858 }
5959
6060 /* channels */
61− avctx->channels = buf[7];
62− if (avctx->channels <= 0 || avctx->channels > 2)
61+ channels = buf[7];
62+ if (channels <= 0 || channels > 2)
6363 return AVERROR_INVALIDDATA;
6464
65+ if (avctx->ch_layout.nb_channels != channels) {
66+ av_channel_layout_uninit(&avctx->ch_layout);
67+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
68+ avctx->ch_layout.nb_channels = channels;
69+ }
70+
6571 /* sample rate */
6672 avctx->sample_rate = AV_RB32(buf + 8);
6773 if (avctx->sample_rate < 1 ||
68− avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8))
74+ avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8))
6975 return AVERROR_INVALIDDATA;
7076
7177 /* bit rate */
72− avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
78+ avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
7379
7480 /* LPC coefficients */
7581 if (coeff) {
libavcodec/adxdec.c+3−3
@@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx) · 45 unmodified lines
4646 av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
4747 return AVERROR_INVALIDDATA;
4848 }
49− c->channels = avctx->channels;
49+ c->channels = avctx->ch_layout.nb_channels;
5050 c->header_parsed = 1;
5151 }
5252
@@ -132,7 +132,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, · 79 unmodified lines
132132 av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
133133 return AVERROR_INVALIDDATA;
134134 }
135− c->channels = avctx->channels;
135+ c->channels = avctx->ch_layout.nb_channels;
136136 c->header_parsed = 1;
137137 if (buf_size < header_size)
138138 return AVERROR_INVALIDDATA;
@@ -147,7 +147,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, · 8 unmodified lines
147147
148148 /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
149149 packet */
150− if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) {
150+ if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) {
151151 if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) {
152152 c->eof = 1;
153153 *got_frame_ptr = 0;
libavcodec/adxenc.c+6−5
@@ -107,7 +107,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize) · 106 unmodified lines
107107 bytestream_put_byte(&buf, 3); /* encoding */
108108 bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */
109109 bytestream_put_byte(&buf, 4); /* sample size */
110− bytestream_put_byte(&buf, avctx->channels); /* channels */
110+ bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */
111111 bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */
112112 bytestream_put_be32(&buf, 0); /* total sample count */
113113 bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */
@@ -125,7 +125,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx) · 11 unmodified lines
125125 {
126126 ADXContext *c = avctx->priv_data;
127127
128− if (avctx->channels > 2) {
128+ if (avctx->ch_layout.nb_channels > 2) {
129129 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
130130 return AVERROR(EINVAL);
131131 }
@@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 12 unmodified lines
144144 ADXContext *c = avctx->priv_data;
145145 const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
146146 uint8_t *dst;
147+ int channels = avctx->ch_layout.nb_channels;
147148 int ch, out_size, ret;
148149
149150 if (!samples) {
@@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 12 unmodified lines
162163 return 0;
163164 }
164165
165− out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE;
166+ out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE;
166167 if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0)
167168 return ret;
168169 dst = avpkt->data;
@@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 8 unmodified lines
177178 c->header_parsed = 1;
178179 }
179180
180− for (ch = 0; ch < avctx->channels; ch++) {
181− adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels);
181+ for (ch = 0; ch < channels; ch++) {
182+ adx_encode(c, dst, samples + ch, &c->prev[ch], channels);
182183 dst += BLOCK_SIZE;
183184 }
184185

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t