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 "put_bits.h"
32 
33 const uint32_t avpriv_dca_sample_rates[16] = {
34  0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
35  12000, 24000, 48000, 96000, 192000
36 };
37 
38 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
39  int max_size)
40 {
41  uint32_t mrk;
42  int i, tmp;
43  const uint16_t *ssrc = (const uint16_t *) src;
44  uint16_t *sdst = (uint16_t *) dst;
45  PutBitContext pb;
46 
47  if ((unsigned) src_size > (unsigned) max_size)
48  src_size = max_size;
49 
50  mrk = AV_RB32(src);
51  switch (mrk) {
52  case DCA_MARKER_RAW_BE:
53  memcpy(dst, src, src_size);
54  return src_size;
55  case DCA_MARKER_RAW_LE:
56  for (i = 0; i < (src_size + 1) >> 1; i++)
57  *sdst++ = av_bswap16(*ssrc++);
58  return src_size;
59  case DCA_MARKER_14B_BE:
60  case DCA_MARKER_14B_LE:
61  init_put_bits(&pb, dst, max_size);
62  for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
63  tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
64  put_bits(&pb, 14, tmp);
65  }
66  flush_put_bits(&pb);
67  return (put_bits_count(&pb) + 7) >> 3;
68  default:
69  return AVERROR_INVALIDDATA;
70  }
71 }