annotate dirac_parser.c @ 8019:dea517f771aa libavcodec

nellymoserenc: flush PutBitContext after use.
author ramiro
date Sat, 11 Oct 2008 14:52:00 +0000
parents cebe9c3422a8
children e623323d409f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6733
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
1 /*
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
2 * Dirac parser
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
3 *
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
4 * Copyright (c) 2007 Marco Gerards <marco@gnu.org>
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
5 *
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
6 * This file is part of FFmpeg.
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
7 *
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
12 *
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
16 * Lesser General Public License for more details.
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
17 *
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
21 */
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
22
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
23 /**
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
24 * @file dirac_parser.c
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
25 * Dirac Parser
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
26 * @author Marco Gerards <marco@gnu.org>
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
27 */
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
28
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
29 #include "parser.h"
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
30
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
31 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
32
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
33 /**
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
34 * Finds the end of the current frame in the bitstream.
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
35 * @return the position of the first byte of the next frame or -1
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
36 */
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
37 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
38 {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
39 uint32_t state = pc->state;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
40 int i;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
41
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
42 for (i = 0; i < buf_size; i++) {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
43 state = (state << 8) | buf[i];
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
44 if (state == DIRAC_PARSE_INFO_PREFIX) {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
45 pc->frame_start_found ^= 1;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
46 if (!pc->frame_start_found) {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
47 pc->state = -1;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
48 return i - 3;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
49 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
50 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
51 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
52
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
53 pc->state = state;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
54
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
55 return END_NOT_FOUND;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
56 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
57
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
58 static int dirac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
59 const uint8_t **poutbuf, int *poutbuf_size,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
60 const uint8_t *buf, int buf_size)
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
61 {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
62 ParseContext *pc = s->priv_data;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
63 int next;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
64
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
65 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
66 next = buf_size;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
67 }else{
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
68 next = find_frame_end(pc, buf, buf_size);
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
69
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
70 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
71 *poutbuf = NULL;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
72 *poutbuf_size = 0;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
73 return buf_size;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
74 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
75 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
76
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
77 *poutbuf = buf;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
78 *poutbuf_size = buf_size;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
79 return next;
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
80 }
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
81
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
82 AVCodecParser dirac_parser = {
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
83 { CODEC_ID_DIRAC },
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
84 sizeof(ParseContext),
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
85 NULL,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
86 dirac_parse,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
87 ff_parse_close,
cebe9c3422a8 Add Dirac parser from SoC; written by Marco Gerards;
diego
parents:
diff changeset
88 };