annotate dnxhd_parser.c @ 11225:5811a86f55f1 libavcodec

Use memset to set the runs partially coded superblocks Much faster for long runs (e.g. nearly uncoded frames), slightly faster for the general case.
author conrad
date Sun, 21 Feb 2010 00:10:47 +0000
parents e9d9d946f213
children 7dd2a45249a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8045
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
1 /*
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
2 * DNxHD/VC-3 parser
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
3 * Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
4 *
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
5 * This file is part of FFmpeg.
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
6 *
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
11 *
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
15 * Lesser General Public License for more details.
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
16 *
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
20 */
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
21
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8045
diff changeset
23 * @file libavcodec/dnxhd_parser.c
8045
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
24 * DNxHD/VC-3 parser
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
25 */
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
26
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
27 #include "parser.h"
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
28
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
29 #define DNXHD_HEADER_PREFIX 0x0000028001
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
30
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
31 static int dnxhd_find_frame_end(ParseContext *pc,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
32 const uint8_t *buf, int buf_size)
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
33 {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
34 uint64_t state = pc->state64;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
35 int pic_found = pc->frame_start_found;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
36 int i = 0;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
37
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
38 if (!pic_found) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
39 for (i = 0; i < buf_size; i++) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
40 state = (state<<8) | buf[i];
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
41 if ((state & 0xffffffffffLL) == DNXHD_HEADER_PREFIX) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
42 i++;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
43 pic_found = 1;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
44 break;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
45 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
46 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
47 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
48
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
49 if (pic_found) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
50 if (!buf_size) /* EOF considered as end of frame */
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
51 return 0;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
52 for (; i < buf_size; i++) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
53 state = (state<<8) | buf[i];
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
54 if ((state & 0xffffffffffLL) == DNXHD_HEADER_PREFIX) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
55 pc->frame_start_found = 0;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
56 pc->state64 = -1;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
57 return i-4;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
58 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
59 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
60 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
61 pc->frame_start_found = pic_found;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
62 pc->state64 = state;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
63 return END_NOT_FOUND;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
64 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
65
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
66 static int dnxhd_parse(AVCodecParserContext *s,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
67 AVCodecContext *avctx,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
68 const uint8_t **poutbuf, int *poutbuf_size,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
69 const uint8_t *buf, int buf_size)
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
70 {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
71 ParseContext *pc = s->priv_data;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
72 int next;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
73
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
74 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
75 next = buf_size;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
76 } else {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
77 next = dnxhd_find_frame_end(pc, buf, buf_size);
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
78 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
79 *poutbuf = NULL;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
80 *poutbuf_size = 0;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
81 return buf_size;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
82 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
83 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
84 *poutbuf = buf;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
85 *poutbuf_size = buf_size;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
86 return next;
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
87 }
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
88
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
89 AVCodecParser dnxhd_parser = {
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
90 { CODEC_ID_DNXHD },
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
91 sizeof(ParseContext),
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
92 NULL,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
93 dnxhd_parse,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
94 ff_parse_close,
444659c2b8a6 dnxhd parser
bcoudurier
parents:
diff changeset
95 };