3 * Copyright (C) 2004 Gildas Bazin
4 * Copyright (C) 2004 Benjamin Zores
5 * Copyright (C) 2006 Benjamin Larsson
6 * Copyright (C) 2007 Konstantin Shishkov
8 * This file is part of FFmpeg.
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.
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.
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
28 typedef struct DCAParseContext {
36 #define IS_MARKER(state, i, buf, buf_size) \
37 ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
38 || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
39 || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE)
42 * finds the end of the current frame in the bitstream.
43 * @return the position of the first byte of the next frame, or -1
45 static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf,
50 ParseContext *pc = &pc1->pc;
52 start_found = pc->frame_start_found;
57 for (i = 0; i < buf_size; i++) {
58 state = (state << 8) | buf[i];
59 if (IS_MARKER(state, i, buf, buf_size)) {
60 if (pc1->lastmarker && state == pc1->lastmarker) {
63 } else if (!pc1->lastmarker) {
65 pc1->lastmarker = state;
72 for (; i < buf_size; i++) {
74 state = (state << 8) | buf[i];
75 if (state == DCA_HD_MARKER && !pc1->hd_pos)
76 pc1->hd_pos = pc1->size;
77 if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
78 if(pc1->framesize > pc1->size)
81 pc1->framesize = pc1->hd_pos ? pc1->hd_pos : pc1->size;
83 pc->frame_start_found = 0;
90 pc->frame_start_found = start_found;
95 static av_cold int dca_parse_init(AVCodecParserContext * s)
97 DCAParseContext *pc1 = s->priv_data;
103 static int dca_parse(AVCodecParserContext * s,
104 AVCodecContext * avctx,
105 const uint8_t ** poutbuf, int *poutbuf_size,
106 const uint8_t * buf, int buf_size)
108 DCAParseContext *pc1 = s->priv_data;
109 ParseContext *pc = &pc1->pc;
112 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
115 next = dca_find_frame_end(pc1, buf, buf_size);
117 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
124 *poutbuf_size = buf_size;
128 AVCodecParser ff_dca_parser = {
130 sizeof(DCAParseContext),