X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fhlsenc.c;h=a34da2f515f4ce4539c8a4156e3a305cf4386ac0;hb=fdda832603c7f027b3d0541289182ad221c1439c;hp=0abf5402a8f6e0cd0c3aab372b656fbd142688df;hpb=76eaca43be161377a370228b1debb2617c8d379b;p=ffmpeg diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 0abf5402a8f..a34da2f515f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -173,18 +173,17 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ - char *language; /* audio lauguage name */ - char *agroup; /* audio group name */ - char *sgroup; /* subtitle group name */ - char *ccgroup; /* closed caption group name */ - char *baseurl; - char *varname; // variant name + const char *language; /* audio lauguage name */ + const char *agroup; /* audio group name */ + const char *sgroup; /* subtitle group name */ + const char *ccgroup; /* closed caption group name */ + const char *varname; /* variant name */ } VariantStream; typedef struct ClosedCaptionsStream { - char *ccgroup; /* closed caption group name */ - char *instreamid; /* closed captions INSTREAM-ID */ - char *language; /* closed captions langauge */ + const char *ccgroup; /* closed caption group name */ + const char *instreamid; /* closed captions INSTREAM-ID */ + const char *language; /* closed captions langauge */ } ClosedCaptionsStream; typedef struct HLSContext { @@ -371,6 +370,7 @@ static int replace_str_data_in_filename(char **s, const char *filename, char pla int addchar_count; int found_count = 0; AVBPrint buf; + int ret; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -396,10 +396,10 @@ static int replace_str_data_in_filename(char **s, const char *filename, char pla } if (!av_bprint_is_complete(&buf)) { av_bprint_finalize(&buf, NULL); - return -1; + return AVERROR(ENOMEM); } - if (av_bprint_finalize(&buf, &new_filename) < 0 || !new_filename) - return -1; + if ((ret = av_bprint_finalize(&buf, &new_filename)) < 0) + return ret; *s = new_filename; return found_count; } @@ -412,6 +412,7 @@ static int replace_int_data_in_filename(char **s, const char *filename, char pla int nd, addchar_count; int found_count = 0; AVBPrint buf; + int ret; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -445,10 +446,10 @@ static int replace_int_data_in_filename(char **s, const char *filename, char pla } if (!av_bprint_is_complete(&buf)) { av_bprint_finalize(&buf, NULL); - return -1; + return AVERROR(ENOMEM); } - if (av_bprint_finalize(&buf, &new_filename) < 0 || !new_filename) - return -1; + if ((ret = av_bprint_finalize(&buf, &new_filename)) < 0) + return ret; *s = new_filename; return found_count; } @@ -1291,8 +1292,8 @@ static int create_master_playlist(AVFormatContext *s, int ret, bandwidth; const char *m3u8_rel_name = NULL; const char *vtt_m3u8_rel_name = NULL; - char *ccgroup; - char *sgroup = NULL; + const char *ccgroup; + const char *sgroup = NULL; ClosedCaptionsStream *ccs; const char *proto = avio_find_protocol_name(hls->master_m3u8_url); int is_file_proto = proto && !strcmp(proto, "file"); @@ -1525,7 +1526,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode, en->duration, hls->flags & HLS_ROUND_DURATIONS, - en->size, en->pos, vs->baseurl, + en->size, en->pos, hls->baseurl, en->filename, prog_date_time_p, en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY); if (ret < 0) { av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); @@ -1547,7 +1548,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) for (en = vs->segments; en; en = en->next) { ret = ff_hls_write_file_entry(hls->sub_m3u8_out, 0, byterange_mode, en->duration, 0, en->size, en->pos, - vs->baseurl, en->sub_filename, NULL, 0, 0, 0); + hls->baseurl, en->sub_filename, NULL, 0, 0, 0); if (ret < 0) { av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); } @@ -1944,10 +1945,13 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) return AVERROR(EINVAL); q = varstr; - while (q < varstr + strlen(varstr)) { + while (1) { if (!av_strncasecmp(q, "a:", 2) || !av_strncasecmp(q, "v:", 2) || !av_strncasecmp(q, "s:", 2)) vs->nb_streams++; + q = strchr(q, ','); + if (!q) + break; q++; } vs->streams = av_mallocz(sizeof(AVStream *) * vs->nb_streams); @@ -1960,10 +1964,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) char *end; varstr = NULL; if (av_strstart(keyval, "language:", &val)) { - av_free(vs->language); - vs->language = av_strdup(val); - if (!vs->language) - return AVERROR(ENOMEM); + vs->language = val; continue; } else if (av_strstart(keyval, "default:", &val)) { vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) || @@ -1971,28 +1972,16 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) hls->has_default_key = 1; continue; } else if (av_strstart(keyval, "name:", &val)) { - av_free(vs->varname); - vs->varname = av_strdup(val); - if (!vs->varname) - return AVERROR(ENOMEM); + vs->varname = val; continue; } else if (av_strstart(keyval, "agroup:", &val)) { - av_free(vs->agroup); - vs->agroup = av_strdup(val); - if (!vs->agroup) - return AVERROR(ENOMEM); + vs->agroup = val; continue; } else if (av_strstart(keyval, "sgroup:", &val)) { - av_free(vs->sgroup); - vs->sgroup = av_strdup(val); - if (!vs->sgroup) - return AVERROR(ENOMEM); + vs->sgroup = val; continue; } else if (av_strstart(keyval, "ccgroup:", &val)) { - av_free(vs->ccgroup); - vs->ccgroup = av_strdup(val); - if (!vs->ccgroup) - return AVERROR(ENOMEM); + vs->ccgroup = val; continue; } else if (av_strstart(keyval, "v:", &val)) { codec_type = AVMEDIA_TYPE_VIDEO; @@ -2006,7 +1995,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) return AVERROR(EINVAL); } - num = strtoll(val, &end, 0); + num = strtoll(val, &end, 10); if (!av_isdigit(*val) || *end != '\0') { av_log(s, AV_LOG_ERROR, "Invalid stream number: '%s'\n", val); return AVERROR(EINVAL); @@ -2083,20 +2072,11 @@ static int parse_cc_stream_mapstring(AVFormatContext *s) ccstr = NULL; if (av_strstart(keyval, "ccgroup:", &val)) { - av_free(ccs->ccgroup); - ccs->ccgroup = av_strdup(val); - if (!ccs->ccgroup) - return AVERROR(ENOMEM); + ccs->ccgroup = val; } else if (av_strstart(keyval, "instreamid:", &val)) { - av_free(ccs->instreamid); - ccs->instreamid = av_strdup(val); - if (!ccs->instreamid) - return AVERROR(ENOMEM); + ccs->instreamid = val; } else if (av_strstart(keyval, "language:", &val)) { - av_free(ccs->language); - ccs->language = av_strdup(val); - if (!ccs->language) - return AVERROR(ENOMEM); + ccs->language = val; } else { av_log(s, AV_LOG_ERROR, "Invalid keyval %s\n", keyval); return AVERROR(EINVAL); @@ -2159,11 +2139,8 @@ static int update_variant_stream_info(AVFormatContext *s) return AVERROR(ENOMEM); //by default, the first available ccgroup is mapped to the variant stream - if (hls->nb_ccstreams) { - hls->var_streams[0].ccgroup = av_strdup(hls->cc_streams[0].ccgroup); - if (!hls->var_streams[0].ccgroup) - return AVERROR(ENOMEM); - } + if (hls->nb_ccstreams) + hls->var_streams[0].ccgroup = hls->cc_streams[0].ccgroup; for (i = 0; i < s->nb_streams; i++) hls->var_streams[0].streams[i] = s->streams[i]; @@ -2344,7 +2321,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) vs->start_pts_from_audio = 0; } - if (vs->has_video) { + if (vs->has_video) { can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME)); is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index); @@ -2574,20 +2551,6 @@ static void hls_deinit(AVFormatContext *s) hls_free_segments(vs->old_segments); av_freep(&vs->m3u8_name); av_freep(&vs->streams); - av_freep(&vs->agroup); - av_freep(&vs->sgroup); - av_freep(&vs->language); - av_freep(&vs->ccgroup); - av_freep(&vs->baseurl); - av_freep(&vs->varname); - } - - for (i = 0; i < hls->nb_ccstreams; i++) { - ClosedCaptionsStream *ccs = &hls->cc_streams[i]; - - av_freep(&ccs->ccgroup); - av_freep(&ccs->instreamid); - av_freep(&ccs->language); } ff_format_io_close(s, &hls->m3u8_out); @@ -2685,9 +2648,10 @@ static int hls_write_trailer(struct AVFormatContext *s) if (ret < 0) av_log(s, AV_LOG_WARNING, "Failed to upload file '%s' at the end.\n", oc->url); } - av_freep(&vs->temp_buffer); failed: + av_freep(&vs->temp_buffer); + av_dict_free(&options); av_freep(&filename); av_write_trailer(oc); if (oc->url[0]) { @@ -2952,12 +2916,6 @@ static int hls_init(AVFormatContext *s) *p = '.'; } - if (hls->baseurl) { - vs->baseurl = av_strdup(hls->baseurl); - if (!vs->baseurl) - return AVERROR(ENOMEM); - } - if ((ret = hls_mux_init(s, vs)) < 0) return ret;