Libav
dca.c
Go to the documentation of this file.
1 /*
2  * DCA compatible decoder data
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 #include <string.h>
23 
24 #include "libavutil/error.h"
25 
26 #include "dca.h"
27 #include "put_bits.h"
28 
29 const uint32_t avpriv_dca_sample_rates[16] =
30 {
31  0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
32  12000, 24000, 48000, 96000, 192000
33 };
34 
35 int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
36  int max_size)
37 {
38  uint32_t mrk;
39  int i, tmp;
40  const uint16_t *ssrc = (const uint16_t *) src;
41  uint16_t *sdst = (uint16_t *) dst;
42  PutBitContext pb;
43 
44  if ((unsigned) src_size > (unsigned) max_size)
45  src_size = max_size;
46 
47  mrk = AV_RB32(src);
48  switch (mrk) {
49  case DCA_MARKER_RAW_BE:
50  memcpy(dst, src, src_size);
51  return src_size;
52  case DCA_MARKER_RAW_LE:
53  for (i = 0; i < (src_size + 1) >> 1; i++)
54  *sdst++ = av_bswap16(*ssrc++);
55  return src_size;
56  case DCA_MARKER_14B_BE:
57  case DCA_MARKER_14B_LE:
58  init_put_bits(&pb, dst, max_size);
59  for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
60  tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
61  put_bits(&pb, 14, tmp);
62  }
63  flush_put_bits(&pb);
64  return (put_bits_count(&pb) + 7) >> 3;
65  default:
66  return AVERROR_INVALIDDATA;
67  }
68 }
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define av_bswap16
Definition: bswap.h:31
int ff_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:35
#define AV_RL16
Definition: intreadwrite.h:42
uint8_t
#define AV_RB32
Definition: intreadwrite.h:130
error code definitions
#define AV_RB16
Definition: intreadwrite.h:53
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:134
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:67
#define DCA_MARKER_14B_LE
Definition: dca.h:35
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:29
#define DCA_MARKER_RAW_LE
Definition: dca.h:33
#define DCA_MARKER_14B_BE
Definition: dca.h:34
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:83
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
#define DCA_MARKER_RAW_BE
DCA syncwords, also used for bitstream type detection.
Definition: dca.h:32
bitstream writer API