Mercurial > libavcodec.hg
annotate dca_parser.c @ 7351:1502ba3beb72 libavcodec
The codebook generator algorithm involves picking three
different codebook centroids ("high utility", "low
utility" and "closest to the low utility one"). This
change avoid the corner case of choosing two times the
same centroid.
author | vitor |
---|---|
date | Wed, 23 Jul 2008 03:54:31 +0000 |
parents | 05987f234569 |
children | ee1b8c54a603 |
rev | line source |
---|---|
4599 | 1 /* |
4899 | 2 * DCA parser |
4599 | 3 * Copyright (C) 2004 Gildas Bazin |
4 * Copyright (C) 2004 Benjamin Zores | |
5 * Copyright (C) 2006 Benjamin Larsson | |
6 * Copyright (C) 2007 Konstantin Shishkov | |
7 * | |
8 * This file is part of FFmpeg. | |
9 * | |
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. | |
14 * | |
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. | |
19 * | |
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 | |
23 */ | |
24 | |
25 /** | |
4899 | 26 * @file dca_parser.c |
4599 | 27 */ |
28 | |
29 #include "parser.h" | |
4899 | 30 #include "dca.h" |
4599 | 31 |
32 typedef struct DCAParseContext { | |
33 ParseContext pc; | |
34 uint32_t lastmarker; | |
6598 | 35 int size; |
36 int framesize; | |
4599 | 37 } DCAParseContext; |
38 | |
39 #define IS_MARKER(state, i, buf, buf_size) \ | |
40 ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ | |
41 || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ | |
42 || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) | |
43 | |
44 /** | |
45 * finds the end of the current frame in the bitstream. | |
46 * @return the position of the first byte of the next frame, or -1 | |
47 */ | |
48 static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, | |
49 int buf_size) | |
50 { | |
51 int start_found, i; | |
52 uint32_t state; | |
53 ParseContext *pc = &pc1->pc; | |
54 | |
55 start_found = pc->frame_start_found; | |
56 state = pc->state; | |
57 | |
58 i = 0; | |
59 if (!start_found) { | |
60 for (i = 0; i < buf_size; i++) { | |
61 state = (state << 8) | buf[i]; | |
62 if (IS_MARKER(state, i, buf, buf_size)) { | |
63 if (pc1->lastmarker && state == pc1->lastmarker) { | |
64 start_found = 1; | |
65 break; | |
66 } else if (!pc1->lastmarker) { | |
67 start_found = 1; | |
68 pc1->lastmarker = state; | |
69 break; | |
70 } | |
71 } | |
72 } | |
73 } | |
74 if (start_found) { | |
75 for (; i < buf_size; i++) { | |
6598 | 76 pc1->size++; |
4599 | 77 state = (state << 8) | buf[i]; |
6598 | 78 if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size) && (!pc1->framesize || pc1->framesize == pc1->size)) { |
4599 | 79 pc->frame_start_found = 0; |
80 pc->state = -1; | |
6598 | 81 pc1->framesize = pc1->size; |
82 pc1->size = 0; | |
4599 | 83 return i - 3; |
84 } | |
85 } | |
86 } | |
87 pc->frame_start_found = start_found; | |
88 pc->state = state; | |
89 return END_NOT_FOUND; | |
90 } | |
91 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
4931
diff
changeset
|
92 static av_cold int dca_parse_init(AVCodecParserContext * s) |
4599 | 93 { |
94 DCAParseContext *pc1 = s->priv_data; | |
95 | |
96 pc1->lastmarker = 0; | |
97 return 0; | |
98 } | |
99 | |
100 static int dca_parse(AVCodecParserContext * s, | |
101 AVCodecContext * avctx, | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
102 const uint8_t ** poutbuf, int *poutbuf_size, |
4599 | 103 const uint8_t * buf, int buf_size) |
104 { | |
105 DCAParseContext *pc1 = s->priv_data; | |
106 ParseContext *pc = &pc1->pc; | |
107 int next; | |
108 | |
109 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | |
110 next = buf_size; | |
111 } else { | |
112 next = dca_find_frame_end(pc1, buf, buf_size); | |
113 | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
114 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
4599 | 115 *poutbuf = NULL; |
116 *poutbuf_size = 0; | |
117 return buf_size; | |
118 } | |
119 } | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
120 *poutbuf = buf; |
4599 | 121 *poutbuf_size = buf_size; |
122 return next; | |
123 } | |
124 | |
125 AVCodecParser dca_parser = { | |
126 {CODEC_ID_DTS}, | |
127 sizeof(DCAParseContext), | |
128 dca_parse_init, | |
129 dca_parse, | |
130 ff_parse_close, | |
131 }; |