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);
326 if (mkdir(os->
dirname, 0777) < 0) {
416 if (*moof_size < 8 || *moof_size > size)
421 if (len > *moof_size)
433 if (len < 8 || len >= *moof_size)
435 if (tag ==
MKTAG(
'u',
'u',
'i',
'd')) {
436 static const uint8_t tfxd[] = {
437 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
438 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
442 if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
497 int n =
FFMIN(size,
sizeof(buf));
519 char filename[1024], target_filename[1024], header_filename[1024];
521 int64_t start_ts,
duration, moof_size;
543 copy_moof(s, filename, header_filename, moof_size);
544 rename(filename, target_filename);
545 add_fragment(os, target_filename, header_filename, start_ts, duration, start_pos,
size);
556 for (j = 0; j <
remove; j++) {
615 #define OFFSET(x) offsetof(SmoothStreamingContext, x)
616 #define E AV_OPT_FLAG_ENCODING_PARAM
618 {
"window_size",
"number of fragments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
619 {
"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 },
620 {
"lookahead_count",
"number of lookahead fragments",
OFFSET(lookahead_count),
AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX,
E },
621 {
"min_frag_duration",
"minimum fragment duration (in microseconds)",
OFFSET(min_frag_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
622 {
"remove_at_exit",
"remove all fragments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
635 .
name =
"smoothstreaming",