FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dca.c
Go to the documentation of this file.
1 /*
2  * DCA compatible decoder data
3  * Copyright (C) 2004 Gildas Bazin
4  * Copyright (C) 2004 Benjamin Zores
5  * Copyright (C) 2006 Benjamin Larsson
6  * Copyright (C) 2007 Konstantin Shishkov
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include <stdint.h>
26 #include <string.h>
27 
28 #include "libavutil/error.h"
29 
30 #include "dca.h"
31 #include "dca_syncwords.h"
32 #include "put_bits.h"
33 
34 const uint32_t avpriv_dca_sample_rates[16] = {
35  0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
36  12000, 24000, 48000, 96000, 192000
37 };
38 
39 const uint32_t ff_dca_sampling_freqs[16] = {
40  8000, 16000, 32000, 64000, 128000, 22050, 44100, 88200,
41  176400, 352800, 12000, 24000, 48000, 96000, 192000, 384000,
42 };
43 
45  0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
46 };
47 
48 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
49  int max_size)
50 {
51  uint32_t mrk;
52  int i, tmp;
53  PutBitContext pb;
54 
55  if ((unsigned) src_size > (unsigned) max_size)
56  src_size = max_size;
57 
58  mrk = AV_RB32(src);
59  switch (mrk) {
62  memcpy(dst, src, src_size);
63  return src_size;
65  for (i = 0; i < (src_size + 1) >> 1; i++) {
66  AV_WB16(dst, AV_RL16(src));
67  src += 2;
68  dst += 2;
69  }
70  return src_size;
73  init_put_bits(&pb, dst, max_size);
74  for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
75  tmp = ((mrk == DCA_SYNCWORD_CORE_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
76  put_bits(&pb, 14, tmp);
77  }
78  flush_put_bits(&pb);
79  return (put_bits_count(&pb) + 7) >> 3;
80  default:
81  return AVERROR_INVALIDDATA;
82  }
83 }
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:206
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:87
#define src
Definition: vp8dsp.c:254
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
const uint8_t ff_dca_freq_ranges[16]
Definition: dca.c:44
uint8_t
#define DCA_SYNCWORD_CORE_14B_BE
Definition: dca_syncwords.h:24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:87
#define AV_WB16(p, v)
Definition: intreadwrite.h:410
#define DCA_SYNCWORD_CORE_BE
Definition: dca_syncwords.h:22
error code definitions
const uint32_t ff_dca_sampling_freqs[16]
Definition: dca.c:39
#define DCA_SYNCWORD_CORE_14B_LE
Definition: dca_syncwords.h:25
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
Convert bitstream to one representation based on sync marker.
Definition: dca.c:48
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:34
#define DCA_SYNCWORD_CORE_LE
Definition: dca_syncwords.h:23
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
#define DCA_SYNCWORD_SUBSTREAM
Definition: dca_syncwords.h:32
static uint8_t tmp[11]
Definition: aes_ctr.c:26
bitstream writer API