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 {
static int replace_str_data_in_filename(char **s, const char *filename, char placeholder, const char *datastring)
{
const char *p;
- char *new_filename;
char c;
int addchar_count;
int found_count = 0;
AVBPrint buf;
+ int ret;
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
}
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;
- *s = new_filename;
+ if ((ret = av_bprint_finalize(&buf, s)) < 0)
+ return ret;
return found_count;
}
static int replace_int_data_in_filename(char **s, const char *filename, char placeholder, int64_t number)
{
const char *p;
- char *new_filename;
char c;
int nd, addchar_count;
int found_count = 0;
AVBPrint buf;
+ int ret;
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
}
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;
- *s = new_filename;
+ if ((ret = av_bprint_finalize(&buf, s)) < 0)
+ return ret;
return found_count;
}
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");
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");
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");
}
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);
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")) ||
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;
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);
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);
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];
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);
if (ret < 0) {
av_log(s, hls->ignore_io_errors ? AV_LOG_WARNING : AV_LOG_ERROR,
"Failed to open file '%s'\n", filename);
+ av_freep(&filename);
av_dict_free(&options);
return hls->ignore_io_errors ? 0 : ret;
}
}
ret = flush_dynbuf(vs, &range_length);
if (ret < 0) {
+ av_freep(&filename);
av_dict_free(&options);
return ret;
}
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);
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]) {
*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;