Move #defines that are mostly used in h264.c out of h264data.h and into h264.h.
[FFMpeg-mirror/ffmpeg-vdpau.git] / libavcodec / dirac_parser.c
blob199354a9c65f7fd8bc19d575c8f43b7c6d833dfa
1 /*
2 * Dirac parser
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
23 /**
24 * @file dirac_parser.c
25 * Dirac Parser
26 * @author Marco Gerards <marco@gnu.org>
29 #include "parser.h"
31 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
33 /**
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;
40 int i;
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) {
47 pc->state = -1;
48 return i - 3;
53 pc->state = state;
55 return END_NOT_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;
63 int next;
65 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
66 next = buf_size;
67 }else{
68 next = find_frame_end(pc, buf, buf_size);
70 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
71 *poutbuf = NULL;
72 *poutbuf_size = 0;
73 return buf_size;
77 *poutbuf = buf;
78 *poutbuf_size = buf_size;
79 return next;
82 AVCodecParser dirac_parser = {
83 { CODEC_ID_DIRAC },
84 sizeof(ParseContext),
85 NULL,
86 dirac_parse,
87 ff_parse_close,