avformat/smoothstreaming: Add deinit function

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2019-12-20 19:57:34 +01:00
parent 76a413d961
commit 3129897c05
1 changed files with 16 additions and 27 deletions

View File

@ -286,21 +286,18 @@ static int ism_write_header(AVFormatContext *s)
ff_const59 AVOutputFormat *oformat; ff_const59 AVOutputFormat *oformat;
if (mkdir(s->url, 0777) == -1 && errno != EEXIST) { if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
ret = AVERROR(errno);
av_log(s, AV_LOG_ERROR, "mkdir failed\n"); av_log(s, AV_LOG_ERROR, "mkdir failed\n");
goto fail; return AVERROR(errno);
} }
oformat = av_guess_format("ismv", NULL, NULL); oformat = av_guess_format("ismv", NULL, NULL);
if (!oformat) { if (!oformat) {
ret = AVERROR_MUXER_NOT_FOUND; return AVERROR_MUXER_NOT_FOUND;
goto fail;
} }
c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams)); c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams));
if (!c->streams) { if (!c->streams) {
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
} }
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
@ -318,24 +315,21 @@ static int ism_write_header(AVFormatContext *s)
} }
if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) { if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
ret = AVERROR(errno);
av_log(s, AV_LOG_ERROR, "mkdir failed\n"); av_log(s, AV_LOG_ERROR, "mkdir failed\n");
goto fail; return AVERROR(errno);
} }
os->ctx = ctx = avformat_alloc_context(); os->ctx = ctx = avformat_alloc_context();
if (!ctx) { if (!ctx) {
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
} }
if ((ret = ff_copy_whiteblacklists(ctx, s)) < 0) if ((ret = ff_copy_whiteblacklists(ctx, s)) < 0)
goto fail; return ret;
ctx->oformat = oformat; ctx->oformat = oformat;
ctx->interrupt_callback = s->interrupt_callback; ctx->interrupt_callback = s->interrupt_callback;
if (!(st = avformat_new_stream(ctx, NULL))) { if (!(st = avformat_new_stream(ctx, NULL))) {
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
} }
avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
@ -343,8 +337,7 @@ static int ism_write_header(AVFormatContext *s)
ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek); ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek);
if (!ctx->pb) { if (!ctx->pb) {
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
} }
av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0); av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0);
@ -352,7 +345,7 @@ static int ism_write_header(AVFormatContext *s)
ret = avformat_write_header(ctx, &opts); ret = avformat_write_header(ctx, &opts);
av_dict_free(&opts); av_dict_free(&opts);
if (ret < 0) { if (ret < 0) {
goto fail; return ret;
} }
avio_flush(ctx->pb); avio_flush(ctx->pb);
s->streams[i]->time_base = st->time_base; s->streams[i]->time_base = st->time_base;
@ -365,8 +358,7 @@ static int ism_write_header(AVFormatContext *s)
os->fourcc = "WVC1"; os->fourcc = "WVC1";
} else { } else {
av_log(s, AV_LOG_ERROR, "Unsupported video codec\n"); av_log(s, AV_LOG_ERROR, "Unsupported video codec\n");
ret = AVERROR(EINVAL); return AVERROR(EINVAL);
goto fail;
} }
} else { } else {
c->has_audio = 1; c->has_audio = 1;
@ -379,8 +371,7 @@ static int ism_write_header(AVFormatContext *s)
os->audio_tag = 0x0162; os->audio_tag = 0x0162;
} else { } else {
av_log(s, AV_LOG_ERROR, "Unsupported audio codec\n"); av_log(s, AV_LOG_ERROR, "Unsupported audio codec\n");
ret = AVERROR(EINVAL); return AVERROR(EINVAL);
goto fail;
} }
os->packet_size = st->codecpar->block_align ? st->codecpar->block_align : 4; os->packet_size = st->codecpar->block_align ? st->codecpar->block_align : 4;
} }
@ -389,15 +380,13 @@ static int ism_write_header(AVFormatContext *s)
if (!c->has_video && c->min_frag_duration <= 0) { if (!c->has_video && c->min_frag_duration <= 0) {
av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration set\n"); av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration set\n");
ret = AVERROR(EINVAL); return AVERROR(EINVAL);
goto fail;
} }
ret = write_manifest(s, 0); ret = write_manifest(s, 0);
if (ret < 0)
return ret;
fail: return 0;
if (ret)
ism_free(s);
return ret;
} }
static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *start_ts, int64_t *duration, int64_t *moof_size, int64_t size) static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *start_ts, int64_t *duration, int64_t *moof_size, int64_t size)
@ -626,7 +615,6 @@ static int ism_write_trailer(AVFormatContext *s)
rmdir(s->url); rmdir(s->url);
} }
ism_free(s);
return 0; return 0;
} }
@ -659,5 +647,6 @@ AVOutputFormat ff_smoothstreaming_muxer = {
.write_header = ism_write_header, .write_header = ism_write_header,
.write_packet = ism_write_packet, .write_packet = ism_write_packet,
.write_trailer = ism_write_trailer, .write_trailer = ism_write_trailer,
.deinit = ism_free,
.priv_class = &ism_class, .priv_class = &ism_class,
}; };