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 "put_bits.h"
29 #include "dca.h"
30 
31 const uint32_t avpriv_dca_sample_rates[16] =
32 {
33  0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
34  12000, 24000, 48000, 96000, 192000
35 };
36 
37 int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
38  int max_size)
39 {
40  uint32_t mrk;
41  int i, tmp;
42  const uint16_t *ssrc = (const uint16_t *) src;
43  uint16_t *sdst = (uint16_t *) dst;
44  PutBitContext pb;
45 
46  if ((unsigned) src_size > (unsigned) max_size)
47  src_size = max_size;
48 
49  mrk = AV_RB32(src);
50  switch (mrk) {
51  case DCA_MARKER_RAW_BE:
52  memcpy(dst, src, src_size);
53  return src_size;
54  case DCA_MARKER_RAW_LE:
55  for (i = 0; i < (src_size + 1) >> 1; i++)
56  *sdst++ = av_bswap16(*ssrc++);
57  return src_size;
58  case DCA_MARKER_14B_BE:
59  case DCA_MARKER_14B_LE:
60  init_put_bits(&pb, dst, max_size);
61  for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
62  tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
63  put_bits(&pb, 14, tmp);
64  }
65  flush_put_bits(&pb);
66  return (put_bits_count(&pb) + 7) >> 3;
67  default:
68  return AVERROR_INVALIDDATA;
69  }
70 }
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define av_bswap16
Definition: sh4/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:37
#define AV_RL16
uint8_t
#define AV_RB32
#define AV_RB16
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:73
#define DCA_MARKER_14B_LE
Definition: dca.h:35
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:31
#define DCA_MARKER_RAW_LE
Definition: dca.h:33
AVS_Value src
Definition: avisynth_c.h:523
synthesis window for stochastic i
#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:81
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:54
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
#define DCA_MARKER_RAW_BE
DCA syncwords, also used for bitstream type detection.
Definition: dca.h:32
bitstream writer API