Commit 69ee915e authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/parser: add fuzzy mode to ff_fetch_timestamp()

This will be needed for the following timestamp fix
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent ddae03f6
......@@ -234,7 +234,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size,
}
}
if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) {
ff_fetch_timestamp(s, i - 3, 1);
ff_fetch_timestamp(s, i - 3, 1, 0);
}
}
}
......
......@@ -93,14 +93,16 @@ err_out:
return NULL;
}
void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove)
void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy)
{
int i;
s->dts =
s->pts = AV_NOPTS_VALUE;
s->pos = -1;
s->offset = 0;
if (!fuzzy) {
s->dts =
s->pts = AV_NOPTS_VALUE;
s->pos = -1;
s->offset = 0;
}
for (i = 0; i < AV_PARSER_PTS_NB; i++) {
if (s->cur_offset + off >= s->cur_frame_offset[i] &&
(s->frame_offset < s->cur_frame_offset[i] ||
......@@ -108,10 +110,12 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove)
// check disabled since MPEG-TS does not send complete PES packets
/*s->next_frame_offset + off <*/ s->cur_frame_end[i]){
s->dts = s->cur_frame_dts[i];
s->pts = s->cur_frame_pts[i];
s->pos = s->cur_frame_pos[i];
s->offset = s->next_frame_offset - s->cur_frame_offset[i];
if (!fuzzy || s->cur_frame_dts[i] != AV_NOPTS_VALUE) {
s->dts = s->cur_frame_dts[i];
s->pts = s->cur_frame_pts[i];
s->pos = s->cur_frame_pos[i];
s->offset = s->next_frame_offset - s->cur_frame_offset[i];
}
if (remove)
s->cur_frame_offset[i] = INT64_MAX;
if (s->cur_offset + off < s->cur_frame_end[i])
......@@ -154,7 +158,7 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
s->last_pts = s->pts;
s->last_dts = s->dts;
s->last_pos = s->pos;
ff_fetch_timestamp(s, 0, 0);
ff_fetch_timestamp(s, 0, 0, 0);
}
/* WARNING: the returned index can be negative */
index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
......
......@@ -53,7 +53,8 @@ void ff_parse_close(AVCodecParserContext *s);
* Fetch timestamps for a specific byte within the current access unit.
* @param off byte position within the access unit
* @param remove Found timestamps will be removed if set to 1, kept if set to 0.
* @param fuzzy Only use found value if it is more informative than what we already have
*/
void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove);
void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy);
#endif /* AVCODEC_PARSER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment