Commit 706fcffc authored by Nicolas Martyanoff's avatar Nicolas Martyanoff Committed by Michael Niedermayer

avformat/hlsenc: rename some identifers to make the code easier to read

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 53f10e03
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
typedef struct ListEntry { typedef struct HLSSegment {
char name[1024]; char filename[1024];
double duration; /* in seconds */ double duration; /* in seconds */
struct ListEntry *next; struct HLSSegment *next;
} ListEntry; } HLSSegment;
typedef struct HLSContext { typedef struct HLSContext {
const AVClass *class; // Class for private options. const AVClass *class; // Class for private options.
...@@ -45,7 +45,7 @@ typedef struct HLSContext { ...@@ -45,7 +45,7 @@ typedef struct HLSContext {
AVOutputFormat *oformat; AVOutputFormat *oformat;
AVFormatContext *avf; AVFormatContext *avf;
float time; // Set by a private option. float time; // Set by a private option.
int size; // Set by a private option. int max_nb_segments; // Set by a private option.
int wrap; // Set by a private option. int wrap; // Set by a private option.
int64_t recording_time; int64_t recording_time;
int has_video; int has_video;
...@@ -53,8 +53,8 @@ typedef struct HLSContext { ...@@ -53,8 +53,8 @@ typedef struct HLSContext {
int64_t end_pts; int64_t end_pts;
double duration; // last segment duration computed so far, in seconds double duration; // last segment duration computed so far, in seconds
int nb_entries; int nb_entries;
ListEntry *list; HLSSegment *segments;
ListEntry *end_list; HLSSegment *last_segment;
char *basename; char *basename;
char *baseurl; char *baseurl;
AVIOContext *pb; AVIOContext *pb;
...@@ -86,28 +86,28 @@ static int hls_mux_init(AVFormatContext *s) ...@@ -86,28 +86,28 @@ static int hls_mux_init(AVFormatContext *s)
} }
/* Create a new segment and append it to the segment list */ /* Create a new segment and append it to the segment list */
static int append_entry(HLSContext *hls, double duration) static int hls_append_segment(HLSContext *hls, double duration)
{ {
ListEntry *en = av_malloc(sizeof(*en)); HLSSegment *en = av_malloc(sizeof(*en));
if (!en) if (!en)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name)); av_strlcpy(en->filename, av_basename(hls->avf->filename), sizeof(en->filename));
en->duration = duration; en->duration = duration;
en->next = NULL; en->next = NULL;
if (!hls->list) if (!hls->segments)
hls->list = en; hls->segments = en;
else else
hls->end_list->next = en; hls->last_segment->next = en;
hls->end_list = en; hls->last_segment = en;
if (hls->size && hls->nb_entries >= hls->size) { if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
en = hls->list; en = hls->segments;
hls->list = en->next; hls->segments = en->next;
av_free(en); av_free(en);
} else } else
hls->nb_entries++; hls->nb_entries++;
...@@ -117,9 +117,9 @@ static int append_entry(HLSContext *hls, double duration) ...@@ -117,9 +117,9 @@ static int append_entry(HLSContext *hls, double duration)
return 0; return 0;
} }
static void free_entries(HLSContext *hls) static void hls_free_segments(HLSContext *hls)
{ {
ListEntry *p = hls->list, *en; HLSSegment *p = hls->segments, *en;
while(p) { while(p) {
en = p; en = p;
...@@ -131,7 +131,7 @@ static void free_entries(HLSContext *hls) ...@@ -131,7 +131,7 @@ static void free_entries(HLSContext *hls)
static int hls_window(AVFormatContext *s, int last) static int hls_window(AVFormatContext *s, int last)
{ {
HLSContext *hls = s->priv_data; HLSContext *hls = s->priv_data;
ListEntry *en; HLSSegment *en;
int target_duration = 0; int target_duration = 0;
int ret = 0; int ret = 0;
int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->nb_entries); int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->nb_entries);
...@@ -140,7 +140,7 @@ static int hls_window(AVFormatContext *s, int last) ...@@ -140,7 +140,7 @@ static int hls_window(AVFormatContext *s, int last)
&s->interrupt_callback, NULL)) < 0) &s->interrupt_callback, NULL)) < 0)
goto fail; goto fail;
for (en = hls->list; en; en = en->next) { for (en = hls->segments; en; en = en->next) {
if (target_duration < en->duration) if (target_duration < en->duration)
target_duration = ceil(en->duration); target_duration = ceil(en->duration);
} }
...@@ -153,11 +153,11 @@ static int hls_window(AVFormatContext *s, int last) ...@@ -153,11 +153,11 @@ static int hls_window(AVFormatContext *s, int last)
av_log(s, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", av_log(s, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n",
sequence); sequence);
for (en = hls->list; en; en = en->next) { for (en = hls->segments; en; en = en->next) {
avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration); avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration);
if (hls->baseurl) if (hls->baseurl)
avio_printf(hls->pb, "%s", hls->baseurl); avio_printf(hls->pb, "%s", hls->baseurl);
avio_printf(hls->pb, "%s\n", en->name); avio_printf(hls->pb, "%s\n", en->filename);
} }
if (last) if (last)
...@@ -282,7 +282,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -282,7 +282,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base, if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
end_pts, AV_TIME_BASE_Q) >= 0) { end_pts, AV_TIME_BASE_Q) >= 0) {
ret = append_entry(hls, hls->duration); ret = hls_append_segment(hls, hls->duration);
if (ret) if (ret)
return ret; return ret;
...@@ -317,10 +317,10 @@ static int hls_write_trailer(struct AVFormatContext *s) ...@@ -317,10 +317,10 @@ static int hls_write_trailer(struct AVFormatContext *s)
avio_closep(&oc->pb); avio_closep(&oc->pb);
avformat_free_context(oc); avformat_free_context(oc);
av_free(hls->basename); av_free(hls->basename);
append_entry(hls, hls->duration); hls_append_segment(hls, hls->duration);
hls_window(s, 1); hls_window(s, 1);
free_entries(hls); hls_free_segments(hls);
avio_close(hls->pb); avio_close(hls->pb);
return 0; return 0;
} }
...@@ -330,7 +330,7 @@ static int hls_write_trailer(struct AVFormatContext *s) ...@@ -330,7 +330,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
static const AVOption options[] = { static const AVOption options[] = {
{"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E}, {"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E},
{"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E}, {"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E},
{"hls_list_size", "set maximum number of playlist entries", OFFSET(size), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, {"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E},
{"hls_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E}, {"hls_wrap", "set number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E},
{"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{ NULL }, { NULL },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment