| 1939 | } |
| 1940 | |
| 1941 | static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) |
| 1942 | { |
| 1943 | DASHContext *c = s->priv_data; |
| 1944 | AVStream *st = s->streams[pkt->stream_index]; |
| 1945 | OutputStream *os = &c->streams[pkt->stream_index]; |
| 1946 | AdaptationSet *as = &c->as[os->as_idx - 1]; |
| 1947 | int64_t seg_end_duration, elapsed_duration; |
| 1948 | int ret; |
| 1949 | |
| 1950 | ret = update_stream_extradata(s, os, pkt, &st->avg_frame_rate); |
| 1951 | if (ret < 0) |
| 1952 | return ret; |
| 1953 | |
| 1954 | // Fill in a heuristic guess of the packet duration, if none is available. |
| 1955 | // The mp4 muxer will do something similar (for the last packet in a fragment) |
| 1956 | // if nothing is set (setting it for the other packets doesn't hurt). |
| 1957 | // By setting a nonzero duration here, we can be sure that the mp4 muxer won't |
| 1958 | // invoke its heuristic (this doesn't have to be identical to that algorithm), |
| 1959 | // so that we know the exact timestamps of fragments. |
| 1960 | if (!pkt->duration && os->last_dts != AV_NOPTS_VALUE) |
| 1961 | pkt->duration = pkt->dts - os->last_dts; |
| 1962 | os->last_dts = pkt->dts; |
| 1963 | |
| 1964 | // If forcing the stream to start at 0, the mp4 muxer will set the start |
| 1965 | // timestamps to 0. Do the same here, to avoid mismatches in duration/timestamps. |
| 1966 | if (os->first_pts == AV_NOPTS_VALUE && |
| 1967 | s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) { |
| 1968 | pkt->pts -= pkt->dts; |
| 1969 | pkt->dts = 0; |
| 1970 | } |
| 1971 | |
| 1972 | if (c->write_prft) { |
| 1973 | ret = dash_parse_prft(c, pkt); |
| 1974 | if (ret < 0) |
| 1975 | return ret; |
| 1976 | } |
| 1977 | |
| 1978 | if (os->first_pts == AV_NOPTS_VALUE) { |
| 1979 | os->first_pts = pkt->pts; |
| 1980 | } |
| 1981 | os->last_pts = pkt->pts; |
| 1982 | |
| 1983 | if (!c->availability_start_time[0]) { |
| 1984 | int64_t start_time_us = av_gettime(); |
| 1985 | c->start_time_s = start_time_us / 1000000; |
| 1986 | format_date(c->availability_start_time, |
| 1987 | sizeof(c->availability_start_time), start_time_us); |
| 1988 | } |
| 1989 | |
| 1990 | if (!os->packets_written) |
| 1991 | os->availability_time_offset = 0; |
| 1992 | |
| 1993 | if (!os->availability_time_offset && |
| 1994 | ((os->frag_type == FRAG_TYPE_DURATION && os->seg_duration != os->frag_duration) || |
| 1995 | (os->frag_type == FRAG_TYPE_EVERY_FRAME && pkt->duration))) { |
| 1996 | AdaptationSet *as = &c->as[os->as_idx - 1]; |
| 1997 | int64_t frame_duration = 0; |
| 1998 |
nothing calls this directly
no test coverage detected