History

avformat: refactor avformat_write_header

Split away option settings, sanity checks and general setup.

Luca Barbato committed 14 years ago

Commit 1e46c631 parent 86bbdf81 file · +38 −15Browse files

Unified · Split

libavformat/mux.c+38−15
@@ -135,7 +135,8 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) · 134 unmodified lines
135 return 1;135 return 1;
136}136}
137 137
138int avformat_write_header(AVFormatContext *s, AVDictionary **options)138
139static int init_muxer(AVFormatContext *s, AVDictionary **options)
139{140{
140 int ret = 0, i;141 int ret = 0, i;
141 AVStream *st;142 AVStream *st;
@@ -248,12 +249,23 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 106 unmodified lines
248 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);249 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
249 }250 }
250 251
251 if (s->oformat->write_header) {252 if (options) {
252 ret = s->oformat->write_header(s);253 av_dict_free(options);
253 if (ret < 0)254 *options = tmp;
254 goto fail;
255 }255 }
256 256
257 return 0;
258
259fail:
260 av_dict_free(&tmp);
261 return ret;
262}
263
264static int init_pts(AVFormatContext *s)
265{
266 int i;
267 AVStream *st;
268
257 /* init PTS generation */269 /* init PTS generation */
258 for (i = 0; i < s->nb_streams; i++) {270 for (i = 0; i < s->nb_streams; i++) {
259 int64_t den = AV_NOPTS_VALUE;271 int64_t den = AV_NOPTS_VALUE;
@@ -270,22 +282,33 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 10 unmodified lines
270 break;282 break;
271 }283 }
272 if (den != AV_NOPTS_VALUE) {284 if (den != AV_NOPTS_VALUE) {
273 if (den <= 0) {285 if (den <= 0)
274 ret = AVERROR_INVALIDDATA;286 return AVERROR_INVALIDDATA;
275 goto fail;287
276 }
277 frac_init(&st->pts, 0, 0, den);288 frac_init(&st->pts, 0, 0, den);
278 }289 }
279 }290 }
280 291
281 if (options) {292 return 0;
282 av_dict_free(options);293}
283 *options = tmp;294
295int avformat_write_header(AVFormatContext *s, AVDictionary **options)
296{
297 int ret = 0;
298
299 if (ret = init_muxer(s, options))
300 return ret;
301
302 if (s->oformat->write_header) {
303 ret = s->oformat->write_header(s);
304 if (ret < 0)
305 return ret;
284 }306 }
307
308 if ((ret = init_pts(s) < 0))
309 return ret;
310
285 return 0;311 return 0;
286fail:
287 av_dict_free(&tmp);
288 return ret;
289}312}
290 313
291//FIXME merge with compute_pkt_fields314//FIXME merge with compute_pkt_fields

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t