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
135135 return 1;
136136 }
137137
138−int avformat_write_header(AVFormatContext *s, AVDictionary **options)
138+
139+static int init_muxer(AVFormatContext *s, AVDictionary **options)
139140 {
140141 int ret = 0, i;
141142 AVStream *st;
@@ -248,12 +249,23 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 106 unmodified lines
248249 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
249250 }
250251
251− if (s->oformat->write_header) {
252− ret = s->oformat->write_header(s);
253− if (ret < 0)
254− goto fail;
252+ if (options) {
253+ av_dict_free(options);
254+ *options = tmp;
255255 }
256256
257+ return 0;
258+
259+fail:
260+ av_dict_free(&tmp);
261+ return ret;
262+}
263+
264+static int init_pts(AVFormatContext *s)
265+{
266+ int i;
267+ AVStream *st;
268+
257269 /* init PTS generation */
258270 for (i = 0; i < s->nb_streams; i++) {
259271 int64_t den = AV_NOPTS_VALUE;
@@ -270,22 +282,33 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 10 unmodified lines
270282 break;
271283 }
272284 if (den != AV_NOPTS_VALUE) {
273− if (den <= 0) {
274− ret = AVERROR_INVALIDDATA;
275− goto fail;
276− }
285+ if (den <= 0)
286+ return AVERROR_INVALIDDATA;
287+
277288 frac_init(&st->pts, 0, 0, den);
278289 }
279290 }
280291
281− if (options) {
282− av_dict_free(options);
283− *options = tmp;
292+ return 0;
293+}
294+
295+int 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;
284306 }
307+
308+ if ((ret = init_pts(s) < 0))
309+ return ret;
310+
285311 return 0;
286−fail:
287− av_dict_free(&tmp);
288− return ret;
289312 }
290313
291314 //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