ADPCM Codecs
ADPCMCodec.h
1 #pragma once
2 #include "adpcm-ffmpeg/adpcm.h"
3 #include "adpcm-ffmpeg/bytestream.h"
4 #include "cstring"
5 #include "stddef.h"
6 #include "vector"
7 
8 #define ADAPCM_DEFAULT_BLOCK_SIZE 128
9 
10 #pragma GCC diagnostic ignored "-Wcomment"
11 #pragma GCC diagnostic ignored "-Wsign-compare"
12 
13 namespace adpcm_ffmpeg {
14 
21 class ADPCMCodec {
22  public:
23  ADPCMCodec() {
24  memset(&avctx, 0, sizeof(avctx));
25  memset(&enc_ctx, 0, sizeof(enc_ctx));
26  }
27 
28  AVCodecContext &ctx() { return avctx; }
29 
30  void setCodecID(AVCodecID id) { avctx.codec_id = id; }
31 
32  AVCodecID codecID() { return avctx.codec_id; }
33 
34  void setFrameSize(int fs) { avctx.frame_size = fs; }
35 
36  virtual void setBlockSize(int size) { enc_ctx.block_size = size; }
37 
38  int blockSize() { return enc_ctx.block_size; }
39 
40  int frameSize() { return avctx.frame_size; }
41 
42  int channels() { return avctx.nb_channels; }
43 
44  bool isPlanar() {
45  for (AVSampleFormat fmt: sample_formats){
46  if (fmt == AV_SAMPLE_FMT_S16P) return true;
47  }
48  return false;
49  }
50 
51  protected:
52  AVCodecContext avctx;
53  ADPCMEncodeContext enc_ctx;
54  std::vector<AVSampleFormat> sample_formats;
55 
56  int av_get_bits_per_sample() {
57  switch (avctx.codec_id) {
58  case AV_CODEC_ID_ADPCM_SBPRO_2:
59  return 2;
60  case AV_CODEC_ID_ADPCM_SBPRO_3:
61  return 3;
62  case AV_CODEC_ID_ADPCM_SBPRO_4:
63  case AV_CODEC_ID_ADPCM_IMA_WAV:
64  case AV_CODEC_ID_ADPCM_IMA_QT:
65  case AV_CODEC_ID_ADPCM_SWF:
66  case AV_CODEC_ID_ADPCM_MS:
67  case AV_CODEC_ID_ADPCM_ARGO:
68  case AV_CODEC_ID_ADPCM_CT:
69  case AV_CODEC_ID_ADPCM_IMA_ALP:
70  case AV_CODEC_ID_ADPCM_IMA_AMV:
71  case AV_CODEC_ID_ADPCM_IMA_APC:
72  case AV_CODEC_ID_ADPCM_IMA_APM:
73  case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
74  case AV_CODEC_ID_ADPCM_IMA_OKI:
75  case AV_CODEC_ID_ADPCM_IMA_WS:
76  case AV_CODEC_ID_ADPCM_IMA_SSI:
77  case AV_CODEC_ID_ADPCM_G722:
78  case AV_CODEC_ID_ADPCM_YAMAHA:
79  case AV_CODEC_ID_ADPCM_AICA:
80  return 4;
81  default:
82  return 0;
83  }
84  }
85 
86  int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size,
87  int flags) {
88  avpkt->size = size;
89  return 0;
90  }
91 
92  int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) {
93  return 0;
94  }
95 
96  //  error message about missing feature
97  void avpriv_request_sample(void *avc, const char *msg, ...) {
98  printf("%s", msg);
99  }
100 };
101 
102 } // namespace adpcm_ffmpeg
Common ADPCM Functionality.
Definition: ADPCMCodec.h:21
Definition: adpcm.h:221
C API context for encoder and decoder.
Definition: adpcm.h:236
int frame_size
Number of samples per channel in an audio frame.
Definition: adpcm.h:239
This structure provides the uncompressed PCM data.
Definition: adpcm.h:151
This structure stores compressed data. It is typically exported by demuxers and then passed as input ...
Definition: adpcm.h:143