Allow factorization for the pending work on the audio movie source.
Stefano Sabatini authored on 2011/08/18 19:36:39... | ... |
@@ -39,6 +39,7 @@ |
39 | 39 |
#include "avfilter.h" |
40 | 40 |
|
41 | 41 |
typedef struct { |
42 |
+ /* common A/V fields */ |
|
42 | 43 |
const AVClass *class; |
43 | 44 |
int64_t seek_point; ///< seekpoint in microseconds |
44 | 45 |
double seek_point_d; |
... | ... |
@@ -51,6 +52,7 @@ typedef struct { |
51 | 51 |
int is_done; |
52 | 52 |
AVFrame *frame; ///< video frame to store the decoded images in |
53 | 53 |
|
54 |
+ /* video-only fields */ |
|
54 | 55 |
int w, h; |
55 | 56 |
AVFilterBufferRef *picref; |
56 | 57 |
} MovieContext; |
... | ... |
@@ -78,13 +80,31 @@ static const AVClass movie_class = { |
78 | 78 |
movie_options |
79 | 79 |
}; |
80 | 80 |
|
81 |
-static int movie_init(AVFilterContext *ctx) |
|
81 |
+static av_cold int movie_common_init(AVFilterContext *ctx, const char *args, void *opaque, |
|
82 |
+ enum AVMediaType type) |
|
82 | 83 |
{ |
83 | 84 |
MovieContext *movie = ctx->priv; |
84 | 85 |
AVInputFormat *iformat = NULL; |
85 | 86 |
AVCodec *codec; |
86 |
- int ret; |
|
87 | 87 |
int64_t timestamp; |
88 |
+ int ret; |
|
89 |
+ |
|
90 |
+ movie->class = &movie_class; |
|
91 |
+ av_opt_set_defaults2(movie, 0, 0); |
|
92 |
+ |
|
93 |
+ if (args) |
|
94 |
+ movie->file_name = av_get_token(&args, ":"); |
|
95 |
+ if (!movie->file_name || !*movie->file_name) { |
|
96 |
+ av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); |
|
97 |
+ return AVERROR(EINVAL); |
|
98 |
+ } |
|
99 |
+ |
|
100 |
+ if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) { |
|
101 |
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); |
|
102 |
+ return ret; |
|
103 |
+ } |
|
104 |
+ |
|
105 |
+ movie->seek_point = movie->seek_point_d * 1000000 + 0.5; |
|
88 | 106 |
|
89 | 107 |
av_register_all(); |
90 | 108 |
|
... | ... |
@@ -120,11 +140,11 @@ static int movie_init(AVFilterContext *ctx) |
120 | 120 |
} |
121 | 121 |
} |
122 | 122 |
|
123 |
- /* select the video stream */ |
|
124 |
- if ((ret = av_find_best_stream(movie->format_ctx, AVMEDIA_TYPE_VIDEO, |
|
123 |
+ /* select the media stream */ |
|
124 |
+ if ((ret = av_find_best_stream(movie->format_ctx, type, |
|
125 | 125 |
movie->stream_index, -1, NULL, 0)) < 0) { |
126 |
- av_log(ctx, AV_LOG_ERROR, "No video stream with index '%d' found\n", |
|
127 |
- movie->stream_index); |
|
126 |
+ av_log(ctx, AV_LOG_ERROR, "No %s stream with index '%d' found\n", |
|
127 |
+ av_get_media_type_string(type), movie->stream_index); |
|
128 | 128 |
return ret; |
129 | 129 |
} |
130 | 130 |
movie->stream_index = ret; |
... | ... |
@@ -145,14 +165,6 @@ static int movie_init(AVFilterContext *ctx) |
145 | 145 |
return ret; |
146 | 146 |
} |
147 | 147 |
|
148 |
- if (!(movie->frame = avcodec_alloc_frame()) ) { |
|
149 |
- av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n"); |
|
150 |
- return AVERROR(ENOMEM); |
|
151 |
- } |
|
152 |
- |
|
153 |
- movie->w = movie->codec_ctx->width; |
|
154 |
- movie->h = movie->codec_ctx->height; |
|
155 |
- |
|
156 | 148 |
av_log(ctx, AV_LOG_INFO, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n", |
157 | 149 |
movie->seek_point, movie->format_name, movie->file_name, |
158 | 150 |
movie->stream_index); |
... | ... |
@@ -160,31 +172,7 @@ static int movie_init(AVFilterContext *ctx) |
160 | 160 |
return 0; |
161 | 161 |
} |
162 | 162 |
|
163 |
-static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
|
164 |
-{ |
|
165 |
- MovieContext *movie = ctx->priv; |
|
166 |
- int ret; |
|
167 |
- movie->class = &movie_class; |
|
168 |
- av_opt_set_defaults2(movie, 0, 0); |
|
169 |
- |
|
170 |
- if (args) |
|
171 |
- movie->file_name = av_get_token(&args, ":"); |
|
172 |
- if (!movie->file_name || !*movie->file_name) { |
|
173 |
- av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); |
|
174 |
- return AVERROR(EINVAL); |
|
175 |
- } |
|
176 |
- |
|
177 |
- if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) { |
|
178 |
- av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); |
|
179 |
- return ret; |
|
180 |
- } |
|
181 |
- |
|
182 |
- movie->seek_point = movie->seek_point_d * 1000000 + 0.5; |
|
183 |
- |
|
184 |
- return movie_init(ctx); |
|
185 |
-} |
|
186 |
- |
|
187 |
-static av_cold void uninit(AVFilterContext *ctx) |
|
163 |
+static av_cold void movie_common_uninit(AVFilterContext *ctx) |
|
188 | 164 |
{ |
189 | 165 |
MovieContext *movie = ctx->priv; |
190 | 166 |
|
... | ... |
@@ -194,10 +182,30 @@ static av_cold void uninit(AVFilterContext *ctx) |
194 | 194 |
avcodec_close(movie->codec_ctx); |
195 | 195 |
if (movie->format_ctx) |
196 | 196 |
av_close_input_file(movie->format_ctx); |
197 |
+ |
|
197 | 198 |
avfilter_unref_buffer(movie->picref); |
198 | 199 |
av_freep(&movie->frame); |
199 | 200 |
} |
200 | 201 |
|
202 |
+static av_cold int movie_init(AVFilterContext *ctx, const char *args, void *opaque) |
|
203 |
+{ |
|
204 |
+ MovieContext *movie = ctx->priv; |
|
205 |
+ int ret; |
|
206 |
+ |
|
207 |
+ if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_VIDEO)) < 0) |
|
208 |
+ return ret; |
|
209 |
+ |
|
210 |
+ if (!(movie->frame = avcodec_alloc_frame()) ) { |
|
211 |
+ av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n"); |
|
212 |
+ return AVERROR(ENOMEM); |
|
213 |
+ } |
|
214 |
+ |
|
215 |
+ movie->w = movie->codec_ctx->width; |
|
216 |
+ movie->h = movie->codec_ctx->height; |
|
217 |
+ |
|
218 |
+ return 0; |
|
219 |
+} |
|
220 |
+ |
|
201 | 221 |
static int query_formats(AVFilterContext *ctx) |
202 | 222 |
{ |
203 | 223 |
MovieContext *movie = ctx->priv; |
... | ... |
@@ -298,8 +306,8 @@ AVFilter avfilter_vsrc_movie = { |
298 | 298 |
.name = "movie", |
299 | 299 |
.description = NULL_IF_CONFIG_SMALL("Read from a movie source."), |
300 | 300 |
.priv_size = sizeof(MovieContext), |
301 |
- .init = init, |
|
302 |
- .uninit = uninit, |
|
301 |
+ .init = movie_init, |
|
302 |
+ .uninit = movie_common_uninit, |
|
303 | 303 |
.query_formats = query_formats, |
304 | 304 |
|
305 | 305 |
.inputs = (AVFilterPad[]) {{ .name = NULL }}, |