Mercurial > libavcodec.hg
changeset 9140:322fa07fd397 libavcodec
Add handling of frame position in the parser.
author | schreter |
---|---|
date | Thu, 05 Mar 2009 07:35:06 +0000 |
parents | 4564ec1f21b0 |
children | 489def16f0c7 |
files | avcodec.h parser.c |
diffstat | 2 files changed, 72 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/avcodec.h Thu Mar 05 04:40:42 2009 +0000 +++ b/avcodec.h Thu Mar 05 07:35:06 2009 +0000 @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 20 +#define LIBAVCODEC_VERSION_MINOR 21 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -3198,6 +3198,23 @@ * For example, this corresponds to H.264 dpb_output_delay. */ int pts_dts_delta; + + /** + * Position of the packet in file. + * + * Analogous to cur_frame_pts/dts + */ + int64_t cur_frame_pos[AV_PARSER_PTS_NB]; + + /** + * Byte position of currently parsed frame in stream. + */ + int64_t pos; + + /** + * Previous frame byte position. + */ + int64_t last_pos; } AVCodecParserContext; typedef struct AVCodecParser { @@ -3217,11 +3234,49 @@ void av_register_codec_parser(AVCodecParser *parser); AVCodecParserContext *av_parser_init(int codec_id); + +attribute_deprecated int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts); + +/** + * Parse a packet. + * + * @param s parser context. + * @param avctx codec context. + * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished. + * @param poutbuf_size set to size of parsed buffer or zero if not yet finished. + * @param buf input buffer. + * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output). + * @param pts input presentation timestamp. + * @param dts input decoding timestamp. + * @param pos input byte position in stream. + * @return the number of bytes of the input bitstream used. + * + * Example: + * @code + * while(in_len){ + * len = av_parser_parse2(myparser, AVCodecContext, &data, &size, + * in_data, in_len, + * pts, dts, pos); + * in_data += len; + * in_len -= len; + * + * if(size) + * decode_frame(data, size); + * } + * @endcode + */ +int av_parser_parse2(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, + int64_t pts, int64_t dts, + int64_t pos); + int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size,
--- a/parser.c Thu Mar 05 04:40:42 2009 +0000 +++ b/parser.c Thu Mar 05 07:35:06 2009 +0000 @@ -85,6 +85,7 @@ int i; 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] @@ -93,6 +94,7 @@ && /*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(remove) s->cur_frame_offset[i]= INT64_MAX; @@ -125,6 +127,8 @@ * decode_frame(data, size); * } * @endcode + * + * @deprecated Use av_parser_parse2() instead. */ int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, @@ -132,6 +136,16 @@ const uint8_t *buf, int buf_size, int64_t pts, int64_t dts) { + return av_parser_parse2(s, avctx, poutbuf, poutbuf_size, buf, buf_size, pts, dts, AV_NOPTS_VALUE); +} + +int av_parser_parse2(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, + int64_t pts, int64_t dts, + int64_t pos) +{ int index, i; uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; @@ -147,12 +161,14 @@ s->cur_frame_end[i] = s->cur_offset + buf_size; s->cur_frame_pts[i] = pts; s->cur_frame_dts[i] = dts; + s->cur_frame_pos[i] = pos; } if (s->fetch_timestamp){ s->fetch_timestamp=0; s->last_pts = s->pts; s->last_dts = s->dts; + s->last_pos = s->pos; ff_fetch_timestamp(s, 0, 0); }