avformat/hlsenc: Simplify setting basename with av_asprintf()

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
pull/338/head
Andreas Rheinhardt 5 years ago
parent 6b44f6839d
commit 21553d2082
  1. 43
      libavformat/hlsenc.c

@ -2739,15 +2739,21 @@ static int hls_init(AVFormatContext *s)
int i = 0; int i = 0;
int j = 0; int j = 0;
HLSContext *hls = s->priv_data; HLSContext *hls = s->priv_data;
const char *pattern = "%d.ts"; const char *pattern;
VariantStream *vs = NULL; VariantStream *vs = NULL;
int basename_size = 0;
const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s);
const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt"; const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt";
char *p = NULL; char *p = NULL;
int http_base_proto = ff_is_http_proto(s->url); int http_base_proto = ff_is_http_proto(s->url);
int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1; int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
if (hls->use_localtime) {
pattern = get_default_pattern_localtime_fmt(s);
} else {
pattern = hls->segment_type == SEGMENT_TYPE_FMP4 ? "%d.m4s" : "%d.ts";
if (hls->flags & HLS_SINGLE_FILE)
pattern += 2;
}
hls->has_default_key = 0; hls->has_default_key = 0;
hls->has_video_m3u8 = 0; hls->has_video_m3u8 = 0;
ret = update_variant_stream_info(s); ret = update_variant_stream_info(s);
@ -2792,9 +2798,6 @@ static int hls_init(AVFormatContext *s)
} }
} }
if (hls->segment_type == SEGMENT_TYPE_FMP4) {
pattern = "%d.m4s";
}
if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) || if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) ||
(hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) || (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) ||
(hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) { (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) {
@ -2868,34 +2871,16 @@ static int hls_init(AVFormatContext *s)
if (ret < 0) if (ret < 0)
return ret; return ret;
} else { } else {
if (hls->flags & HLS_SINGLE_FILE) { p = strrchr(vs->m3u8_name, '.');
if (hls->segment_type == SEGMENT_TYPE_FMP4) { if (p)
pattern = ".m4s"; *p = '\0';
} else {
pattern = ".ts";
}
}
if (hls->use_localtime) {
basename_size = strlen(vs->m3u8_name) + strlen(pattern_localtime_fmt) + 1;
} else {
basename_size = strlen(vs->m3u8_name) + strlen(pattern) + 1;
}
vs->basename = av_malloc(basename_size); vs->basename = av_asprintf("%s%s", vs->m3u8_name, pattern);
if (!vs->basename) if (!vs->basename)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
av_strlcpy(vs->basename, vs->m3u8_name, basename_size);
p = strrchr(vs->basename, '.');
if (p) if (p)
*p = '\0'; *p = '.';
if (hls->use_localtime) {
av_strlcat(vs->basename, pattern_localtime_fmt, basename_size);
} else {
av_strlcat(vs->basename, pattern, basename_size);
}
} }
if (hls->segment_type == SEGMENT_TYPE_FMP4) { if (hls->segment_type == SEGMENT_TYPE_FMP4) {

Loading…
Cancel
Save