ADPCM Codecs
Loading...
Searching...
No Matches
ADPCMCodec.h
1#pragma once
2#include "adpcm/adpcm.h"
3#include "adpcm/ByteReader.h"
4#include "adpcm/ByteWriter.h"
5#include "adpcm/config-adpcm.h"
6#include "string.h"
7#include "stddef.h"
8#include "stdarg.h"
9#include "adpcm/ADPCMVector.h"
10
11
12#pragma GCC diagnostic ignored "-Wcomment"
13#pragma GCC diagnostic ignored "-Wsign-compare"
14
15namespace adpcm_ffmpeg {
16
24 public:
25 ADPCMCodec() {
26 memset(&avctx, 0, sizeof(avctx));
27 memset(&enc_ctx, 0, sizeof(enc_ctx));
28 }
29
30 // derived encoders/decoders are deleted through this base pointer
31 virtual ~ADPCMCodec() {}
32
33 AVCodecContext &ctx() { return avctx; }
34
35 void setCodecID(AVCodecID id) { avctx.codec_id = id; }
36
37 AVCodecID codecID() { return avctx.codec_id; }
38
39 void setFrameSize(int fs) { avctx.frame_size = fs; }
40
41 virtual void setBlockSize(int size) { enc_ctx.block_size = size; }
42
43 int blockSize() { return enc_ctx.block_size; }
44
45 int frameSize() { return avctx.frame_size; }
46
47 int channels() { return avctx.nb_channels; }
48
49 bool isPlanar() {
50 for (AVSampleFormat fmt: sample_formats){
51 if (fmt == AV_SAMPLE_FMT_S16P) return true;
52 }
53 return false;
54 }
55
56 protected:
57 AVCodecContext avctx;
58 ADPCMEncodeContext enc_ctx;
59 ADPCMVector<AVSampleFormat> sample_formats{0};
60
61 int av_get_bits_per_sample() {
62 switch (avctx.codec_id) {
63 case AV_CODEC_ID_ADPCM_SBPRO_2:
64 return 2;
65 case AV_CODEC_ID_ADPCM_SBPRO_3:
66 return 3;
67 case AV_CODEC_ID_ADPCM_SBPRO_4:
68 case AV_CODEC_ID_ADPCM_IMA_WAV:
69 case AV_CODEC_ID_ADPCM_IMA_QT:
70 case AV_CODEC_ID_ADPCM_SWF:
71 case AV_CODEC_ID_ADPCM_MS:
72 case AV_CODEC_ID_ADPCM_ARGO:
73 case AV_CODEC_ID_ADPCM_CT:
74 case AV_CODEC_ID_ADPCM_IMA_ALP:
75 case AV_CODEC_ID_ADPCM_IMA_AMV:
76 case AV_CODEC_ID_ADPCM_IMA_APC:
77 case AV_CODEC_ID_ADPCM_IMA_APM:
78 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
79 case AV_CODEC_ID_ADPCM_IMA_OKI:
80 case AV_CODEC_ID_ADPCM_IMA_WS:
81 case AV_CODEC_ID_ADPCM_IMA_SSI:
82 case AV_CODEC_ID_ADPCM_G722:
83 case AV_CODEC_ID_ADPCM_YAMAHA:
84 case AV_CODEC_ID_ADPCM_AICA:
85 return 4;
86 default:
87 return 0;
88 }
89 }
90
91 int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size,
92 int flags) {
93 avpkt->size = size;
94 return 0;
95 }
96
97 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) {
98 return 0;
99 }
100
101 //  error message about missing feature
102 void avpriv_request_sample(void *avc, const char *msg, ...) {
103 va_list ap;
104 va_start(ap, msg);
105 vprintf(msg, ap);
106 va_end(ap);
107 }
108};
109
110} // namespace adpcm_ffmpeg
Common ADPCM Functionality.
Definition ADPCMCodec.h:23
Vector implementation which provides the most important methods as defined by std::vector....
Definition ADPCMVector.h:16
Definition adpcm.h:200
C API context for encoder and decoder.
Definition adpcm.h:215
int frame_size
Number of samples per channel in an audio frame.
Definition adpcm.h:218
This structure provides the uncompressed PCM data.
Definition adpcm.h:130
This structure stores compressed data. It is typically exported by demuxers and then passed as input ...
Definition adpcm.h:122