History

avcodec: add Gremlin DPCM decoder

Paul B Mahol committed 9 years ago

Commit 29bdcf51 parent 22a25ab6 files · +50 −8Browse files

Unified · Split

6 files
  1. libavcodec/Makefile +1 −0
  2. libavcodec/allcodecs.c +1 −0
  3. libavcodec/avcodec.h +1 −0
  4. libavcodec/codec_desc.c +7 −0
  5. libavcodec/dpcm.c +38 −6
  6. libavcodec/version.h +2 −2
libavcodec/Makefile+1−0
@@ -310,6 +310,7 @@ OBJS-$(CONFIG_G723_1_ENCODER) += g723_1enc.o g723_1.o \ · 309 unmodified lines
310OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o310OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
311OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o311OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o
312OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o312OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o
313OBJS-$(CONFIG_GREMLIN_DPCM_DECODER) += dpcm.o
313OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o314OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
314OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o315OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o
315OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261data.o h261.o316OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261data.o h261.o
libavcodec/allcodecs.c+1−0
@@ -520,6 +520,7 @@ static void register_all(void) · 519 unmodified lines
520 REGISTER_DECODER(PCM_ZORK, pcm_zork);520 REGISTER_DECODER(PCM_ZORK, pcm_zork);
521 521
522 /* DPCM codecs */522 /* DPCM codecs */
523 REGISTER_DECODER(GREMLIN_DPCM, gremlin_dpcm);
523 REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);524 REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm);
524 REGISTER_ENCDEC (ROQ_DPCM, roq_dpcm);525 REGISTER_ENCDEC (ROQ_DPCM, roq_dpcm);
525 REGISTER_DECODER(SOL_DPCM, sol_dpcm);526 REGISTER_DECODER(SOL_DPCM, sol_dpcm);
libavcodec/avcodec.h+1−0
@@ -548,6 +548,7 @@ enum AVCodecID { · 547 unmodified lines
548 AV_CODEC_ID_SOL_DPCM,548 AV_CODEC_ID_SOL_DPCM,
549 549
550 AV_CODEC_ID_SDX2_DPCM = 0x14800,550 AV_CODEC_ID_SDX2_DPCM = 0x14800,
551 AV_CODEC_ID_GREMLIN_DPCM,
551 552
552 /* audio codecs */553 /* audio codecs */
553 AV_CODEC_ID_MP2 = 0x15000,554 AV_CODEC_ID_MP2 = 0x15000,
libavcodec/codec_desc.c+7−0
@@ -2249,6 +2249,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 2248 unmodified lines
2249 .long_name = NULL_IF_CONFIG_SMALL("DPCM Squareroot-Delta-Exact"),2249 .long_name = NULL_IF_CONFIG_SMALL("DPCM Squareroot-Delta-Exact"),
2250 .props = AV_CODEC_PROP_LOSSY,2250 .props = AV_CODEC_PROP_LOSSY,
2251 },2251 },
2252 {
2253 .id = AV_CODEC_ID_GREMLIN_DPCM,
2254 .type = AVMEDIA_TYPE_AUDIO,
2255 .name = "gremlin_dpcm",
2256 .long_name = NULL_IF_CONFIG_SMALL("DPCM Gremlin"),
2257 .props = AV_CODEC_PROP_LOSSY,
2258 },
2252 2259
2253 /* audio codecs */2260 /* audio codecs */
2254 {2261 {
libavcodec/dpcm.c+38−6
@@ -44,7 +44,7 @@ · 43 unmodified lines
44#include "mathops.h"44#include "mathops.h"
45 45
46typedef struct DPCMContext {46typedef struct DPCMContext {
47 int16_t square_array[256];47 int16_t array[256];
48 int sample[2]; ///< previous sample (for SOL_DPCM)48 int sample[2]; ///< previous sample (for SOL_DPCM)
49 const int8_t *sol_table; ///< delta table for SOL_DPCM49 const int8_t *sol_table; ///< delta table for SOL_DPCM
50} DPCMContext;50} DPCMContext;
@@ -130,8 +130,8 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 79 unmodified lines
130 /* initialize square table */130 /* initialize square table */
131 for (i = 0; i < 128; i++) {131 for (i = 0; i < 128; i++) {
132 int16_t square = i * i;132 int16_t square = i * i;
133 s->square_array[i ] = square;133 s->array[i ] = square;
134 s->square_array[i + 128] = -square;134 s->array[i + 128] = -square;
135 }135 }
136 break;136 break;
137 137
@@ -156,7 +156,25 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) · 18 unmodified lines
156 case AV_CODEC_ID_SDX2_DPCM:156 case AV_CODEC_ID_SDX2_DPCM:
157 for (i = -128; i < 128; i++) {157 for (i = -128; i < 128; i++) {
158 int16_t square = i * i * 2;158 int16_t square = i * i * 2;
159 s->square_array[i+128] = i < 0 ? -square: square;159 s->array[i+128] = i < 0 ? -square: square;
160 }
161 break;
162
163 case AV_CODEC_ID_GREMLIN_DPCM: {
164 int delta = 0;
165 int code = 64;
166 int step = 45;
167
168 s->array[0] = 0;
169 for (i = 0; i < 127; i++) {
170 delta += (code >> 5);
171 code += step;
172 step += 2;
173
174 s->array[i*2 + 1] = delta;
175 s->array[i*2 + 2] = -delta;
176 }
177 s->array[255] = delta + (code >> 5);
160 }178 }
161 break;179 break;
162 180
@@ -207,6 +225,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 44 unmodified lines
207 else225 else
208 out = buf_size;226 out = buf_size;
209 break;227 break;
228 case AV_CODEC_ID_GREMLIN_DPCM:
210 case AV_CODEC_ID_SDX2_DPCM:229 case AV_CODEC_ID_SDX2_DPCM:
211 out = buf_size;230 out = buf_size;
212 break;231 break;
@@ -240,7 +259,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 27 unmodified lines
240 259
241 /* decode the samples */260 /* decode the samples */
242 while (output_samples < samples_end) {261 while (output_samples < samples_end) {
243 predictor[ch] += s->square_array[bytestream2_get_byteu(&gb)];262 predictor[ch] += s->array[bytestream2_get_byteu(&gb)];
244 predictor[ch] = av_clip_int16(predictor[ch]);263 predictor[ch] = av_clip_int16(predictor[ch]);
245 *output_samples++ = predictor[ch];264 *output_samples++ = predictor[ch];
246 265
@@ -335,12 +354,24 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, · 88 unmodified lines
335 354
336 if (!(n & 1))355 if (!(n & 1))
337 s->sample[ch] = 0;356 s->sample[ch] = 0;
338 s->sample[ch] += s->square_array[n + 128];357 s->sample[ch] += s->array[n + 128];
339 s->sample[ch] = av_clip_int16(s->sample[ch]);358 s->sample[ch] = av_clip_int16(s->sample[ch]);
340 *output_samples++ = s->sample[ch];359 *output_samples++ = s->sample[ch];
341 ch ^= stereo;360 ch ^= stereo;
342 }361 }
343 break;362 break;
363
364 case AV_CODEC_ID_GREMLIN_DPCM: {
365 int idx = 0;
366
367 while (output_samples < samples_end) {
368 uint8_t n = bytestream2_get_byteu(&gb);
369
370 *output_samples++ = s->sample[idx] += s->array[n];
371 idx ^= 1;
372 }
373 }
374 break;
344 }375 }
345 376
346 *got_frame_ptr = 1;377 *got_frame_ptr = 1;
@@ -360,6 +391,7 @@ AVCodec ff_ ## name_ ## _decoder = { \ · 13 unmodified lines
360 .capabilities = AV_CODEC_CAP_DR1, \391 .capabilities = AV_CODEC_CAP_DR1, \
361}392}
362 393
394DPCM_DECODER(AV_CODEC_ID_GREMLIN_DPCM, gremlin_dpcm, "DPCM Gremlin");
363DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay");395DPCM_DECODER(AV_CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay");
364DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ");396DPCM_DECODER(AV_CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ");
365DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact");397DPCM_DECODER(AV_CODEC_ID_SDX2_DPCM, sdx2_dpcm, "DPCM Squareroot-Delta-Exact");
libavcodec/version.h+2−2
@@ -28,8 +28,8 @@ · 27 unmodified lines
28#include "libavutil/version.h"28#include "libavutil/version.h"
29 29
30#define LIBAVCODEC_VERSION_MAJOR 5730#define LIBAVCODEC_VERSION_MAJOR 57
31#define LIBAVCODEC_VERSION_MINOR 9631#define LIBAVCODEC_VERSION_MINOR 97
32#define LIBAVCODEC_VERSION_MICRO 10132#define LIBAVCODEC_VERSION_MICRO 100
33 33
34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
35 LIBAVCODEC_VERSION_MINOR, \35 LIBAVCODEC_VERSION_MINOR, \

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