Mercurial > audlegacy
annotate Plugins/Input/wma/libffwma/parser.c @ 255:ad1e65c6a854 trunk
[svn] Create some proper headers and include them. No more implicit declarations.
author | chainsaw |
---|---|
date | Sun, 04 Dec 2005 07:37:06 -0800 |
parents | 0bea7509d6ba |
children | f12d7e208b43 |
rev | line source |
---|---|
137 | 1 /* |
2 * Audio and Video frame extraction | |
3 * Copyright (c) 2003 Fabrice Bellard. | |
4 * Copyright (c) 2003 Michael Niedermayer. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 #include "avcodec.h" | |
255
ad1e65c6a854
[svn] Create some proper headers and include them. No more implicit declarations.
chainsaw
parents:
218
diff
changeset
|
21 #include "utils.h" |
137 | 22 |
23 AVCodecParser *av_first_parser = NULL; | |
24 | |
25 void av_register_codec_parser(AVCodecParser *parser) | |
26 { | |
27 parser->next = av_first_parser; | |
28 av_first_parser = parser; | |
29 } | |
30 | |
31 AVCodecParserContext *av_parser_init(int codec_id) | |
32 { | |
33 AVCodecParserContext *s; | |
34 AVCodecParser *parser; | |
35 int ret; | |
36 | |
37 for(parser = av_first_parser; parser != NULL; parser = parser->next) { | |
38 if (parser->codec_ids[0] == codec_id || | |
39 parser->codec_ids[1] == codec_id || | |
40 parser->codec_ids[2] == codec_id) | |
41 goto found; | |
42 } | |
43 return NULL; | |
44 found: | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
45 s = av_mallocz(sizeof(AVCodecParserContext)); |
137 | 46 if (!s) |
47 return NULL; | |
48 s->parser = parser; | |
210
12004b385a96
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
chainsaw
parents:
142
diff
changeset
|
49 s->priv_data = av_mallocz(parser->priv_data_size); |
137 | 50 if (!s->priv_data) { |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
51 free(s); |
137 | 52 return NULL; |
53 } | |
54 if (parser->parser_init) { | |
55 ret = parser->parser_init(s); | |
56 if (ret != 0) { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
57 free(s->priv_data); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
58 free(s); |
137 | 59 return NULL; |
60 } | |
61 } | |
62 return s; | |
63 } | |
64 | |
65 /* NOTE: buf_size == 0 is used to signal EOF so that the last frame | |
66 can be returned if necessary */ | |
67 int av_parser_parse(AVCodecParserContext *s, | |
68 AVCodecContext *avctx, | |
69 uint8_t **poutbuf, int *poutbuf_size, | |
70 const uint8_t *buf, int buf_size, | |
71 int64_t pts, int64_t dts) | |
72 { | |
73 int index, i, k; | |
74 uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; | |
75 | |
76 if (buf_size == 0) { | |
77 /* padding is always necessary even if EOF, so we add it here */ | |
78 memset(dummy_buf, 0, sizeof(dummy_buf)); | |
79 buf = dummy_buf; | |
80 } else { | |
81 /* add a new packet descriptor */ | |
82 k = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); | |
83 s->cur_frame_start_index = k; | |
84 s->cur_frame_offset[k] = s->cur_offset; | |
85 s->cur_frame_pts[k] = pts; | |
86 s->cur_frame_dts[k] = dts; | |
87 | |
88 /* fill first PTS/DTS */ | |
89 if (s->cur_offset == 0) { | |
90 s->last_pts = pts; | |
91 s->last_dts = dts; | |
92 } | |
93 } | |
94 | |
95 /* WARNING: the returned index can be negative */ | |
96 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); | |
97 /* update the file pointer */ | |
98 if (*poutbuf_size) { | |
99 /* fill the data for the current frame */ | |
100 s->frame_offset = s->last_frame_offset; | |
101 s->pts = s->last_pts; | |
102 s->dts = s->last_dts; | |
103 | |
104 /* offset of the next frame */ | |
105 s->last_frame_offset = s->cur_offset + index; | |
106 /* find the packet in which the new frame starts. It | |
107 is tricky because of MPEG video start codes | |
108 which can begin in one packet and finish in | |
109 another packet. In the worst case, an MPEG | |
110 video start code could be in 4 different | |
111 packets. */ | |
112 k = s->cur_frame_start_index; | |
113 for(i = 0; i < AV_PARSER_PTS_NB; i++) { | |
114 if (s->last_frame_offset >= s->cur_frame_offset[k]) | |
115 break; | |
116 k = (k - 1) & (AV_PARSER_PTS_NB - 1); | |
117 } | |
118 s->last_pts = s->cur_frame_pts[k]; | |
119 s->last_dts = s->cur_frame_dts[k]; | |
120 } | |
121 if (index < 0) | |
122 index = 0; | |
123 s->cur_offset += index; | |
124 return index; | |
125 } | |
126 | |
127 void av_parser_close(AVCodecParserContext *s) | |
128 { | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
129 if (s->parser->parser_close) |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
130 s->parser->parser_close(s); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
131 |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
132 free(s->priv_data); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
133 free(s); |
137 | 134 } |
135 |