Skip to content

Commit

Permalink
avformat: move AVStream.{first,cur}_dts to AVStreamInternal
Browse files Browse the repository at this point in the history
They are private fields, no reason to have them exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
  • Loading branch information
jamrial committed Jun 9, 2021
1 parent 39affa5 commit 591b88e
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 83 deletions.
11 changes: 0 additions & 11 deletions libavformat/avformat.h
Expand Up @@ -992,17 +992,6 @@ typedef struct AVStream {

int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */

// Timestamp generation support:
/**
* Timestamp corresponding to the last dts sync point.
*
* Initialized when AVCodecParserContext.dts_sync_point >= 0 and
* a DTS is received from the underlying container. Otherwise set to
* AV_NOPTS_VALUE by default.
*/
int64_t first_dts;
int64_t cur_dts;

/**
* An opaque field for libavformat internal usage.
* Must not be accessed in any way by callers.
Expand Down
4 changes: 2 additions & 2 deletions libavformat/concatdec.c
Expand Up @@ -638,8 +638,8 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
}
}

if (cat->cur_file->duration == AV_NOPTS_VALUE && st->cur_dts != AV_NOPTS_VALUE) {
int64_t next_dts = av_rescale_q(st->cur_dts, st->time_base, AV_TIME_BASE_Q);
if (cat->cur_file->duration == AV_NOPTS_VALUE && st->internal->cur_dts != AV_NOPTS_VALUE) {
int64_t next_dts = av_rescale_q(st->internal->cur_dts, st->time_base, AV_TIME_BASE_Q);
if (cat->cur_file->next_dts == AV_NOPTS_VALUE || next_dts > cat->cur_file->next_dts) {
cat->cur_file->next_dts = next_dts;
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/fifo.c
Expand Up @@ -139,7 +139,7 @@ static int fifo_thread_write_header(FifoThreadContext *ctx)
}

for (i = 0;i < avf2->nb_streams; i++)
avf2->streams[i]->cur_dts = 0;
avf2->streams[i]->internal->cur_dts = 0;

ret = avformat_write_header(avf2, &format_options);
if (!ret)
Expand Down
6 changes: 3 additions & 3 deletions libavformat/hdsenc.c
Expand Up @@ -504,11 +504,11 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t end_dts = os->fragment_index * (int64_t)c->min_frag_duration;
int ret;

if (st->first_dts == AV_NOPTS_VALUE)
st->first_dts = pkt->dts;
if (st->internal->first_dts == AV_NOPTS_VALUE)
st->internal->first_dts = pkt->dts;

if ((!os->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
av_compare_ts(pkt->dts - st->first_dts, st->time_base,
av_compare_ts(pkt->dts - st->internal->first_dts, st->time_base,
end_dts, AV_TIME_BASE_Q) >= 0 &&
pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {

Expand Down
11 changes: 11 additions & 0 deletions libavformat/internal.h
Expand Up @@ -389,6 +389,17 @@ struct AVStreamInternal {
* 0 means unknown
*/
int stream_identifier;

// Timestamp generation support:
/**
* Timestamp corresponding to the last dts sync point.
*
* Initialized when AVCodecParserContext.dts_sync_point >= 0 and
* a DTS is received from the underlying container. Otherwise set to
* AV_NOPTS_VALUE by default.
*/
int64_t first_dts;
int64_t cur_dts;
};

void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type);
Expand Down
18 changes: 9 additions & 9 deletions libavformat/mux.c
Expand Up @@ -525,7 +525,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *

if (s->debug & FF_FDEBUG_TS)
av_log(s, AV_LOG_DEBUG, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->internal->cur_dts), delay, pkt->size, pkt->stream_index);

if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
pkt->pts = pkt->dts;
Expand Down Expand Up @@ -553,14 +553,14 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *
pkt->dts = st->internal->pts_buffer[0];
}

if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
if (st->internal->cur_dts && st->internal->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE &&
st->codecpar->codec_type != AVMEDIA_TYPE_DATA &&
st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
st->internal->cur_dts >= pkt->dts) || st->internal->cur_dts > pkt->dts)) {
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
st->index, av_ts2str(st->cur_dts), av_ts2str(pkt->dts));
st->index, av_ts2str(st->internal->cur_dts), av_ts2str(pkt->dts));
return AVERROR(EINVAL);
}
if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
Expand All @@ -575,7 +575,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *
av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%s dts2:%s\n",
av_ts2str(pkt->pts), av_ts2str(pkt->dts));

st->cur_dts = pkt->dts;
st->internal->cur_dts = pkt->dts;
st->internal->priv_pts->val = pkt->dts;

/* update pts */
Expand Down Expand Up @@ -763,13 +763,13 @@ static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)

/* check that the dts are increasing (or at least non-decreasing,
* if the format allows it */
if (st->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) ||
st->cur_dts > pkt->dts)) {
if (st->internal->cur_dts != AV_NOPTS_VALUE &&
((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->internal->cur_dts >= pkt->dts) ||
st->internal->cur_dts > pkt->dts)) {
av_log(s, AV_LOG_ERROR,
"Application provided invalid, non monotonically increasing "
"dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
st->index, st->cur_dts, pkt->dts);
st->index, st->internal->cur_dts, pkt->dts);
return AVERROR(EINVAL);
}

Expand Down
2 changes: 1 addition & 1 deletion libavformat/mxfdec.c
Expand Up @@ -1766,7 +1766,7 @@ static int mxf_compute_ptses_fake_index(MXFContext *mxf, MXFIndexTable *index_ta
* 6: 5 5
*
* We do this by bucket sorting x by x+TemporalOffset[x] into mxf->ptses,
* then settings mxf->first_dts = -max(TemporalOffset[x]).
* then settings mxf->internal->first_dts = -max(TemporalOffset[x]).
* The latter makes DTS <= PTS.
*/
for (i = x = 0; i < index_table->nb_segments; i++) {
Expand Down
2 changes: 1 addition & 1 deletion libavformat/pcm.c
Expand Up @@ -79,7 +79,7 @@ int ff_pcm_read_seek(AVFormatContext *s,
pos *= block_align;

/* recompute exact position */
st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
st->internal->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
if ((ret = avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET)) < 0)
return ret;
return 0;
Expand Down
4 changes: 2 additions & 2 deletions libavformat/rdt.c
Expand Up @@ -415,7 +415,7 @@ rdt_parse_sdp_line (AVFormatContext *s, int st_index,
if (av_strstart(p, "OpaqueData:buffer;", &p)) {
rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p);
} else if (av_strstart(p, "StartTime:integer;", &p))
stream->first_dts = atoi(p);
stream->internal->first_dts = atoi(p);
else if (av_strstart(p, "ASMRuleBook:string;", &p)) {
int n, first = -1;

Expand Down Expand Up @@ -465,7 +465,7 @@ add_dstream(AVFormatContext *s, AVStream *orig_st)
return NULL;
st->id = orig_st->id;
st->codecpar->codec_type = orig_st->codecpar->codec_type;
st->first_dts = orig_st->first_dts;
st->internal->first_dts = orig_st->internal->first_dts;

return st;
}
Expand Down
6 changes: 3 additions & 3 deletions libavformat/sbgdec.c
Expand Up @@ -1444,7 +1444,7 @@ static av_cold int sbg_read_header(AVFormatContext *avf)
st->duration = script.end_ts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE :
av_rescale(script.end_ts - script.start_ts,
sbg->sample_rate, AV_TIME_BASE);
st->cur_dts = st->start_time;
st->internal->cur_dts = st->start_time;
r = encode_intervals(&script, st->codecpar, &inter);
if (r < 0)
goto fail;
Expand All @@ -1465,7 +1465,7 @@ static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
int64_t ts, end_ts;
int ret;

ts = avf->streams[0]->cur_dts;
ts = avf->streams[0]->internal->cur_dts;
end_ts = ts + avf->streams[0]->codecpar->frame_size;
if (avf->streams[0]->duration != AV_NOPTS_VALUE)
end_ts = FFMIN(avf->streams[0]->start_time + avf->streams[0]->duration,
Expand All @@ -1488,7 +1488,7 @@ static int sbg_read_seek2(AVFormatContext *avf, int stream_index,
return AVERROR(EINVAL);
if (stream_index < 0)
ts = av_rescale_q(ts, AV_TIME_BASE_Q, avf->streams[0]->time_base);
avf->streams[0]->cur_dts = ts;
avf->streams[0]->internal->cur_dts = ts;
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions libavformat/smoothstreamingenc.c
Expand Up @@ -586,11 +586,11 @@ static int ism_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t end_dts = (c->nb_fragments + 1) * (int64_t) c->min_frag_duration;
int ret;

if (st->first_dts == AV_NOPTS_VALUE)
st->first_dts = pkt->dts;
if (st->internal->first_dts == AV_NOPTS_VALUE)
st->internal->first_dts = pkt->dts;

if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
av_compare_ts(pkt->dts - st->first_dts, st->time_base,
av_compare_ts(pkt->dts - st->internal->first_dts, st->time_base,
end_dts, AV_TIME_BASE_Q) >= 0 &&
pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {

Expand Down
2 changes: 1 addition & 1 deletion libavformat/tedcaptionsdec.c
Expand Up @@ -302,7 +302,7 @@ static av_cold int tedcaptions_read_header(AVFormatContext *avf)
st->internal->probe_packets = 0;
st->start_time = 0;
st->duration = last->pts + last->duration;
st->cur_dts = 0;
st->internal->cur_dts = 0;

return 0;
}
Expand Down

1 comment on commit 591b88e

@jcelerier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.