59 int nb_fragments, fragments_size, fragment_index;
97 if (whence != SEEK_SET)
118 if (offset >= frag->
start_pos && offset < frag->start_pos + frag->
size) {
159 for (i = 0; i <
size; i++)
194 int removed = 0, i,
start = 0;
205 if (!
final || removed)
216 char filename[1024], temp_filename[1024];
217 int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
221 snprintf(temp_filename,
sizeof(temp_filename),
"%s/Manifest.tmp", s->
filename);
227 avio_printf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
244 video_chunks = audio_chunks = 0;
250 avio_printf(out,
"<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" Duration=\"%"PRIu64
"\"", duration);
255 int last = -1,
index = 0;
256 avio_printf(out,
"<StreamIndex Type=\"video\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n", video_streams, video_chunks);
269 int last = -1,
index = 0;
270 avio_printf(out,
"<StreamIndex Type=\"audio\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n", audio_streams, audio_chunks);
285 rename(temp_filename, filename);
295 if (mkdir(s->
filename, 0777) == -1 && errno != EEXIST) {
325 if (mkdir(os->
dirname, 0777) == -1 && errno != EEXIST) {
414 if (*moof_size < 8 || *moof_size > size)
419 if (len > *moof_size)
431 if (len < 8 || len >= *moof_size)
433 if (tag ==
MKTAG(
'u',
'u',
'i',
'd')) {
434 static const uint8_t tfxd[] = {
435 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
436 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
440 if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
495 int n =
FFMIN(size,
sizeof(buf));
517 char filename[1024], target_filename[1024], header_filename[1024];
519 int64_t start_ts,
duration, moof_size;
541 copy_moof(s, filename, header_filename, moof_size);
542 rename(filename, target_filename);
543 add_fragment(os, target_filename, header_filename, start_ts, duration, start_pos,
size);
554 for (j = 0; j <
remove; j++) {
613 #define OFFSET(x) offsetof(SmoothStreamingContext, x)
614 #define E AV_OPT_FLAG_ENCODING_PARAM
616 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
617 {
"extra_window_size",
"number of fragments kept outside of the manifest before removing from disk",
OFFSET(extra_window_size),
AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX,
E },
618 {
"lookahead_count",
"number of lookahead fragments",
OFFSET(lookahead_count),
AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX,
E },
619 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
620 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
633 .
name =
"smoothstreaming",