Lines Matching refs:pls

252 static int64_t get_segment_start_time_based_on_timeline(struct representation *pls, int64_t cur_seq_no)
259 if (pls->n_timelines) {
260 for (i = 0; i < pls->n_timelines; i++) {
261 if (pls->timelines[i]->starttime > 0) {
262 start_time = pls->timelines[i]->starttime;
267 start_time += pls->timelines[i]->duration;
269 if (pls->timelines[i]->repeat == -1) {
270 start_time = pls->timelines[i]->duration * cur_seq_no;
274 for (j = 0; j < pls->timelines[i]->repeat; j++) {
278 start_time += pls->timelines[i]->duration;
287 static int64_t calc_next_seg_no_from_timelines(struct representation *pls, int64_t cur_time)
294 for (i = 0; i < pls->n_timelines; i++) {
295 if (pls->timelines[i]->starttime > 0) {
296 start_time = pls->timelines[i]->starttime;
301 start_time += pls->timelines[i]->duration;
302 for (j = 0; j < pls->timelines[i]->repeat; j++) {
306 start_time += pls->timelines[i]->duration;
326 static void free_fragment_list(struct representation *pls)
330 for (i = 0; i < pls->n_fragments; i++) {
331 free_fragment(&pls->fragments[i]);
333 av_freep(&pls->fragments);
334 pls->n_fragments = 0;
337 static void free_timelines_list(struct representation *pls)
341 for (i = 0; i < pls->n_timelines; i++) {
342 av_freep(&pls->timelines[i]);
344 av_freep(&pls->timelines);
345 pls->n_timelines = 0;
348 static void free_representation(struct representation *pls)
350 free_fragment_list(pls);
351 free_timelines_list(pls);
352 free_fragment(&pls->cur_seg);
353 free_fragment(&pls->init_section);
354 av_freep(&pls->init_sec_buf);
355 av_freep(&pls->pb.pub.buffer);
356 ff_format_io_close(pls->parent, &pls->input);
357 if (pls->ctx) {
358 pls->ctx->pb = NULL;
359 avformat_close_input(&pls->ctx);
362 av_freep(&pls->url_template);
363 av_freep(&pls->lang);
364 av_freep(&pls->id);
365 av_freep(&pls);
372 struct representation *pls = c->videos[i];
373 free_representation(pls);
383 struct representation *pls = c->audios[i];
384 free_representation(pls);
394 struct representation *pls = c->subtitles[i];
395 free_representation(pls);
1373 static int64_t calc_cur_seg_no(AVFormatContext *s, struct representation *pls)
1380 if (pls->n_fragments) {
1382 num = pls->first_seq_no;
1383 } else if (pls->n_timelines) {
1385 start_time_offset = get_segment_start_time_based_on_timeline(pls, 0xFFFFFFFF) - 60 * pls->fragment_timescale; // 60 seconds before end
1386 num = calc_next_seg_no_from_timelines(pls, start_time_offset);
1388 num = pls->first_seq_no;
1390 num += pls->first_seq_no;
1391 } else if (pls->fragment_duration){
1392 av_log(s, AV_LOG_TRACE, "in fragment_duration mode fragment_timescale = %"PRId64", presentation_timeoffset = %"PRId64"\n", pls->fragment_timescale, pls->presentation_timeoffset);
1393 if (pls->presentation_timeoffset) {
1394 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) * pls->fragment_timescale)-pls->presentation_timeoffset) / pls->fragment_duration - c->min_buffer_time;
1397 num = pls->first_seq_no + (((c->publish_time + pls->fragment_duration) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration - c->min_buffer_time;
1399 num = pls->first_seq_no + (((c->publish_time - c->time_shift_buffer_depth + pls->fragment_duration) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
1402 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->suggested_presentation_delay) * pls->fragment_timescale) / pls->fragment_duration;
1406 num = pls->first_seq_no;
1411 static int64_t calc_min_seg_no(AVFormatContext *s, struct representation *pls)
1416 if (c->is_live && pls->fragment_duration) {
1418 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time) - c->time_shift_buffer_depth) * pls->fragment_timescale) / pls->fragment_duration;
1420 num = pls->first_seq_no;
1425 static int64_t calc_max_seg_no(struct representation *pls, DASHContext *c)
1429 if (pls->n_fragments) {
1430 num = pls->first_seq_no + pls->n_fragments - 1;
1431 } else if (pls->n_timelines) {
1433 num = pls->first_seq_no + pls->n_timelines - 1;
1434 for (i = 0; i < pls->n_timelines; i++) {
1435 if (pls->timelines[i]->repeat == -1) {
1436 int length_of_each_segment = pls->timelines[i]->duration / pls->fragment_timescale;
1439 num += pls->timelines[i]->repeat;
1442 } else if (c->is_live && pls->fragment_duration) {
1443 num = pls->first_seq_no + (((get_current_time_in_sec() - c->availability_start_time)) * pls->fragment_timescale) / pls->fragment_duration;
1444 } else if (pls->fragment_duration) {
1445 num = pls->first_seq_no + av_rescale_rnd(1, c->media_presentation_duration * pls->fragment_timescale, pls->fragment_duration, AV_ROUND_UP);
1582 static struct fragment *get_current_fragment(struct representation *pls)
1588 DASHContext *c = pls->parent->priv_data;
1590 while (( !ff_check_interrupt(c->interrupt_callback)&& pls->n_fragments > 0)) {
1591 if (pls->cur_seq_no < pls->n_fragments) {
1592 seg_ptr = pls->fragments[pls->cur_seq_no];
1606 refresh_manifest(pls->parent);
1612 min_seq_no = calc_min_seg_no(pls->parent, pls);
1613 max_seq_no = calc_max_seg_no(pls, c);
1615 if (pls->timelines || pls->fragments) {
1616 refresh_manifest(pls->parent);
1618 if (pls->cur_seq_no <= min_seq_no) {
1619 av_log(pls->parent, AV_LOG_VERBOSE, "old fragment: cur[%"PRId64"] min[%"PRId64"] max[%"PRId64"]\n", (int64_t)pls->cur_seq_no, min_seq_no, max_seq_no);
1620 pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls);
1621 } else if (pls->cur_seq_no > max_seq_no) {
1622 av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] max[%"PRId64"]\n", min_seq_no, max_seq_no);
1628 } else if (pls->cur_seq_no <= pls->last_seq_no) {
1636 if (!pls->url_template) {
1637 av_log(pls->parent, AV_LOG_ERROR, "Cannot get fragment, missing template URL\n");
1646 ff_dash_fill_tmpl_params(tmpfilename, c->max_url_size, pls->url_template, 0, pls->cur_seq_no, 0, get_segment_start_time_based_on_timeline(pls, pls->cur_seq_no));
1647 seg->url = av_strireplace(pls->url_template, pls->url_template, tmpfilename);
1649 av_log(pls->parent, AV_LOG_WARNING, "Unable to resolve template url '%s', try to use origin template\n", pls->url_template);
1650 seg->url = av_strdup(pls->url_template);
1652 av_log(pls->parent, AV_LOG_ERROR, "Cannot resolve template url '%s'\n", pls->url_template);
1665 static int read_from_url(struct representation *pls, struct fragment *seg,
1672 buf_size = FFMIN(buf_size, pls->cur_seg_size - pls->cur_seg_offset);
1674 ret = avio_read(pls->input, buf, buf_size);
1676 pls->cur_seg_offset += ret;
1681 static int open_input(DASHContext *c, struct representation *pls, struct fragment *seg)
1701 av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64"\n",
1703 ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL);
1708 pls->cur_seg_offset = 0;
1709 pls->cur_seg_size = seg->size;
1713 static int update_init_section(struct representation *pls)
1716 DASHContext *c = pls->parent->priv_data;
1721 if (!pls->init_section || pls->init_sec_buf)
1724 ret = open_input(c, pls, pls->init_section);
1726 av_log(pls->parent, AV_LOG_WARNING,
1731 if (pls->init_section->size >= 0)
1732 sec_size = pls->init_section->size;
1733 else if ((urlsize = avio_size(pls->input)) >= 0)
1738 av_log(pls->parent, AV_LOG_DEBUG,
1744 av_fast_malloc(&pls->init_sec_buf, &pls->init_sec_buf_size, sec_size);
1746 ret = read_from_url(pls, pls->init_section, pls->init_sec_buf,
1747 pls->init_sec_buf_size);
1748 ff_format_io_close(pls->parent, &pls->input);
1753 pls->init_sec_data_len = ret;
1754 pls->init_sec_buf_read_offset = 0;
1842 static void close_demux_for_component(struct representation *pls)
1845 av_freep(&pls->pb.pub.buffer);
1846 memset(&pls->pb, 0x00, sizeof(pls->pb));
1847 pls->ctx->pb = NULL;
1848 avformat_close_input(&pls->ctx);
1851 static int reopen_demux_for_component(AVFormatContext *s, struct representation *pls)
1859 if (pls->ctx) {
1860 close_demux_for_component(pls);
1868 if (!(pls->ctx = avformat_alloc_context())) {
1876 avformat_free_context(pls->ctx);
1877 pls->ctx = NULL;
1880 ffio_init_context(&pls->pb, avio_ctx_buffer, INITIAL_BUFFER_SIZE, 0,
1881 pls, read_data, NULL, c->is_live ? NULL : seek_data);
1882 pls->pb.pub.seekable = 0;
1884 if ((ret = ff_copy_whiteblacklists(pls->ctx, s)) < 0)
1887 pls->ctx->flags = AVFMT_FLAG_CUSTOM_IO;
1888 pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
1889 pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE;
1890 pls->ctx->interrupt_callback = s->interrupt_callback;
1891 ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, "", NULL, 0, 0);
1894 avformat_free_context(pls->ctx);
1895 pls->ctx = NULL;
1899 pls->ctx->pb = &pls->pb.pub;
1900 pls->ctx->io_open = nested_io_open;
1906 ret = avformat_open_input(&pls->ctx, "", in_fmt, &in_fmt_opts); //pls->init_section->url
1910 if (pls->n_fragments) {
1912 if (pls->framerate.den) {
1913 for (i = 0; i < pls->ctx->nb_streams; i++)
1914 pls->ctx->streams[i]->r_frame_rate = pls->framerate;
1917 ret = avformat_find_stream_info(pls->ctx, NULL);
1926 static int open_demux_for_component(AVFormatContext *s, struct representation *pls)
1931 pls->parent = s;
1932 pls->cur_seq_no = calc_cur_seg_no(s, pls);
1934 if (!pls->last_seq_no) {
1935 pls->last_seq_no = calc_max_seg_no(pls, s->priv_data);
1938 ret = reopen_demux_for_component(s, pls);
1942 for (i = 0; i < pls->ctx->nb_streams; i++) {
1944 AVStream *ist = pls->ctx->streams[i];
1973 static int is_common_init_section_exist(struct representation **pls, int n_pls)
1975 struct fragment *first_init_section = pls[0]->init_section;
1986 size = pls[0]->init_section->size;
1988 if (!pls[i]->init_section)
1991 if (av_strcasecmp(pls[i]->init_section->url, url) ||
1992 pls[i]->init_section->url_offset != url_offset ||
1993 pls[i]->init_section->size != size) {
2144 struct representation *pls = p[i];
2145 int needed = !pls->assoc_stream || pls->assoc_stream->discard < AVDISCARD_ALL;
2147 if (needed && !pls->ctx) {
2148 pls->cur_seg_offset = 0;
2149 pls->init_sec_buf_read_offset = 0;
2152 pls->cur_seq_no = FFMAX(pls->cur_seq_no, p[j]->cur_seq_no);
2154 reopen_demux_for_component(s, pls);
2155 av_log(s, AV_LOG_INFO, "Now receiving stream_index %d\n", pls->stream_index);
2156 } else if (!needed && pls->ctx) {
2157 close_demux_for_component(pls);
2158 ff_format_io_close(pls->parent, &pls->input);
2159 av_log(s, AV_LOG_INFO, "No longer receiving stream_index %d\n", pls->stream_index);
2238 static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
2245 av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms] %s\n",
2249 if (pls->n_fragments == 1) {
2250 pls->cur_timestamp = 0;
2251 pls->cur_seg_offset = 0;
2254 ff_read_frame_flush(pls->ctx);
2255 return av_seek_frame(pls->ctx, -1, seek_pos_msec * 1000, flags);
2258 ff_format_io_close(pls->parent, &pls->input);
2261 if (pls->n_timelines > 0 && pls->fragment_timescale > 0) {
2262 int64_t num = pls->first_seq_no;
2263 av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline start n_timelines[%d] "
2265 (int)pls->n_timelines, (int64_t)pls->last_seq_no);
2266 for (i = 0; i < pls->n_timelines; i++) {
2267 if (pls->timelines[i]->starttime > 0) {
2268 duration = pls->timelines[i]->starttime;
2270 duration += pls->timelines[i]->duration;
2271 if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2274 for (j = 0; j < pls->timelines[i]->repeat; j++) {
2275 duration += pls->timelines[i]->duration;
2277 if (seek_pos_msec < ((duration * 1000) / pls->fragment_timescale)) {
2285 pls->cur_seq_no = num > pls->last_seq_no ? pls->last_seq_no : num;
2286 av_log(pls->parent, AV_LOG_VERBOSE, "dash_seek with SegmentTimeline end cur_seq_no[%"PRId64"].\n",
2287 (int64_t)pls->cur_seq_no);
2288 } else if (pls->fragment_duration > 0) {
2289 pls->cur_seq_no = pls->first_seq_no + ((seek_pos_msec * pls->fragment_timescale) / pls->fragment_duration) / 1000;
2291 av_log(pls->parent, AV_LOG_ERROR, "dash_seek missing timeline or fragment_duration\n");
2292 pls->cur_seq_no = pls->first_seq_no;
2294 pls->cur_timestamp = 0;
2295 pls->cur_seg_offset = 0;
2296 pls->init_sec_buf_read_offset = 0;
2297 ret = dry_run ? 0 : reopen_demux_for_component(s, pls);