History

dca: Move ff_dca_convert_bitstream() to the DCA common code

This makes the DCA parser and decoder independent.

Diego Biurrun committed 13 years ago

Commit 1db6a081 parent b2472536 files · +44 −75Browse files

Unified · Split

6 files
  1. libavcodec/Makefile +1 −1
  2. libavcodec/dca.c +37 −0
  3. libavcodec/dca.h +6 −0
  4. libavcodec/dca_parser.c +0 −37
  5. libavcodec/dca_parser.h +0 −36
  6. libavcodec/dcadec.c +0 −1
libavcodec/Makefile+1−1
@@ -134,7 +134,7 @@ OBJS-$(CONFIG_COMFORTNOISE_ENCODER) += cngenc.o · 133 unmodified lines
134134 OBJS-$(CONFIG_CSCD_DECODER) += cscd.o
135135 OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
136136 OBJS-$(CONFIG_DCA_DECODER) += dcadec.o dca.o dcadsp.o \
137− dca_parser.o synth_filter.o
137+ synth_filter.o
138138 OBJS-$(CONFIG_DFA_DECODER) += dfa.o
139139 OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o
140140 OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o
libavcodec/dca.c+37−0
@@ -19,7 +19,9 @@ · 18 unmodified lines
1919 */
2020
2121 #include <stdint.h>
22+#include <string.h>
2223
24+#include "put_bits.h"
2325 #include "dca.h"
2426
2527 const uint32_t avpriv_dca_sample_rates[16] =
@@ -27,3 +29,38 @@ const uint32_t avpriv_dca_sample_rates[16] = · 1 unmodified line
2729 0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
2830 12000, 24000, 48000, 96000, 192000
2931 };
32+
33+int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
34+ int max_size)
35+{
36+ uint32_t mrk;
37+ int i, tmp;
38+ const uint16_t *ssrc = (const uint16_t *) src;
39+ uint16_t *sdst = (uint16_t *) dst;
40+ PutBitContext pb;
41+
42+ if ((unsigned) src_size > (unsigned) max_size)
43+ src_size = max_size;
44+
45+ mrk = AV_RB32(src);
46+ switch (mrk) {
47+ case DCA_MARKER_RAW_BE:
48+ memcpy(dst, src, src_size);
49+ return src_size;
50+ case DCA_MARKER_RAW_LE:
51+ for (i = 0; i < (src_size + 1) >> 1; i++)
52+ *sdst++ = av_bswap16(*ssrc++);
53+ return src_size;
54+ case DCA_MARKER_14B_BE:
55+ case DCA_MARKER_14B_LE:
56+ init_put_bits(&pb, dst, max_size);
57+ for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
58+ tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
59+ put_bits(&pb, 14, tmp);
60+ }
61+ flush_put_bits(&pb);
62+ return (put_bits_count(&pb) + 7) >> 3;
63+ default:
64+ return AVERROR_INVALIDDATA;
65+ }
66+}
libavcodec/dca.h+6−0
@@ -39,4 +39,10 @@ · 38 unmodified lines
3939
4040 extern av_export const uint32_t avpriv_dca_sample_rates[16];
4141
42+/**
43+ * Convert bitstream to one representation based on sync marker
44+ */
45+int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
46+ int max_size);
47+
4248 #endif /* AVCODEC_DCA_H */
libavcodec/dca_parser.c+0−37
@@ -24,9 +24,7 @@ · 23 unmodified lines
2424
2525 #include "parser.h"
2626 #include "dca.h"
27−#include "dca_parser.h"
2827 #include "get_bits.h"
29−#include "put_bits.h"
3028
3129 typedef struct DCAParseContext {
3230 ParseContext pc;
@@ -103,41 +101,6 @@ static av_cold int dca_parse_init(AVCodecParserContext * s) · 70 unmodified lines
103101 return 0;
104102 }
105103
106−int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
107− int max_size)
108−{
109− uint32_t mrk;
110− int i, tmp;
111− const uint16_t *ssrc = (const uint16_t *) src;
112− uint16_t *sdst = (uint16_t *) dst;
113− PutBitContext pb;
114−
115− if ((unsigned) src_size > (unsigned) max_size)
116− src_size = max_size;
117−
118− mrk = AV_RB32(src);
119− switch (mrk) {
120− case DCA_MARKER_RAW_BE:
121− memcpy(dst, src, src_size);
122− return src_size;
123− case DCA_MARKER_RAW_LE:
124− for (i = 0; i < (src_size + 1) >> 1; i++)
125− *sdst++ = av_bswap16(*ssrc++);
126− return src_size;
127− case DCA_MARKER_14B_BE:
128− case DCA_MARKER_14B_LE:
129− init_put_bits(&pb, dst, max_size);
130− for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
131− tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
132− put_bits(&pb, 14, tmp);
133− }
134− flush_put_bits(&pb);
135− return (put_bits_count(&pb) + 7) >> 3;
136− default:
137− return AVERROR_INVALIDDATA;
138− }
139−}
140−
141104 static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
142105 int *sample_rate)
143106 {
libavcodec/dca_parser.h+0−36
@@ -1,36 +0,0 @@
1−/*
2− * DCA parser
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 Libav.
9− *
10− * Libav 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− * Libav 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 Libav; if not, write to the Free Software
22− * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23− */
24−
25−#ifndef AVCODEC_DCA_PARSER_H
26−#define AVCODEC_DCA_PARSER_H
27−
28−#include <stdint.h>
29−
30−/**
31− * Convert bitstream to one representation based on sync marker
32− */
33−int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
34− int max_size);
35−
36−#endif /* AVCODEC_DCA_PARSER_H */
libavcodec/dcadec.c+0−1
@@ -40,7 +40,6 @@ · 39 unmodified lines
4040 #include "dcadata.h"
4141 #include "dcahuff.h"
4242 #include "dca.h"
43−#include "dca_parser.h"
4443 #include "mathops.h"
4544 #include "synth_filter.h"
4645 #include "dcadsp.h"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t