4 * Copyright (c) 2007 Marco Gerards <marco@gnu.org>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * @file dirac_parser.c
26 * @author Marco Gerards <marco@gnu.org>
31 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
34 * Finds the end of the current frame in the bitstream.
35 * @return the position of the first byte of the next frame or -1
37 static int find_frame_end(ParseContext
*pc
, const uint8_t *buf
, int buf_size
)
39 uint32_t state
= pc
->state
;
42 for (i
= 0; i
< buf_size
; i
++) {
43 state
= (state
<< 8) | buf
[i
];
44 if (state
== DIRAC_PARSE_INFO_PREFIX
) {
45 pc
->frame_start_found
^= 1;
46 if (!pc
->frame_start_found
) {
58 static int dirac_parse(AVCodecParserContext
*s
, AVCodecContext
*avctx
,
59 const uint8_t **poutbuf
, int *poutbuf_size
,
60 const uint8_t *buf
, int buf_size
)
62 ParseContext
*pc
= s
->priv_data
;
65 if (s
->flags
& PARSER_FLAG_COMPLETE_FRAMES
) {
68 next
= find_frame_end(pc
, buf
, buf_size
);
70 if (ff_combine_frame(pc
, next
, &buf
, &buf_size
) < 0) {
78 *poutbuf_size
= buf_size
;
82 AVCodecParser dirac_parser
= {