| 122 | } |
| 123 | |
| 124 | int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, |
| 125 | uint8_t **poutbuf, int *poutbuf_size, |
| 126 | const uint8_t *buf, int buf_size, |
| 127 | int64_t pts, int64_t dts, int64_t pos) |
| 128 | { |
| 129 | const AVCodecDescriptor *desc; |
| 130 | int index, i; |
| 131 | uint8_t dummy_buf[AV_INPUT_BUFFER_PADDING_SIZE]; |
| 132 | |
| 133 | av_assert1(avctx->codec_id != AV_CODEC_ID_NONE); |
| 134 | |
| 135 | /* Parsers only work for the specified codec ids. */ |
| 136 | av_assert1(avctx->codec_id == s->parser->codec_ids[0] || |
| 137 | avctx->codec_id == s->parser->codec_ids[1] || |
| 138 | avctx->codec_id == s->parser->codec_ids[2] || |
| 139 | avctx->codec_id == s->parser->codec_ids[3] || |
| 140 | avctx->codec_id == s->parser->codec_ids[4] || |
| 141 | avctx->codec_id == s->parser->codec_ids[5] || |
| 142 | avctx->codec_id == s->parser->codec_ids[6]); |
| 143 | |
| 144 | desc = avcodec_descriptor_get(avctx->codec_id); |
| 145 | |
| 146 | if (!(s->flags & PARSER_FLAG_FETCHED_OFFSET)) { |
| 147 | s->next_frame_offset = |
| 148 | s->cur_offset = pos; |
| 149 | s->flags |= PARSER_FLAG_FETCHED_OFFSET; |
| 150 | } |
| 151 | |
| 152 | if (buf_size == 0) { |
| 153 | /* padding is always necessary even if EOF, so we add it here */ |
| 154 | memset(dummy_buf, 0, sizeof(dummy_buf)); |
| 155 | buf = dummy_buf; |
| 156 | } else if (s->cur_offset + buf_size != s->cur_frame_end[s->cur_frame_start_index]) { /* skip remainder packets */ |
| 157 | /* add a new packet descriptor */ |
| 158 | i = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1); |
| 159 | s->cur_frame_start_index = i; |
| 160 | s->cur_frame_offset[i] = s->cur_offset; |
| 161 | s->cur_frame_end[i] = s->cur_offset + buf_size; |
| 162 | s->cur_frame_pts[i] = pts; |
| 163 | s->cur_frame_dts[i] = dts; |
| 164 | s->cur_frame_pos[i] = pos; |
| 165 | } |
| 166 | |
| 167 | if (s->fetch_timestamp) { |
| 168 | s->fetch_timestamp = 0; |
| 169 | s->last_pts = s->pts; |
| 170 | s->last_dts = s->dts; |
| 171 | s->last_pos = s->pos; |
| 172 | ff_fetch_timestamp(s, 0, 0, 0); |
| 173 | } |
| 174 | /* WARNING: the returned index can be negative */ |
| 175 | index = ffcodecparser(s->parser)->parse(s, avctx, (const uint8_t **) poutbuf, |
| 176 | poutbuf_size, buf, buf_size); |
| 177 | av_assert0(index > -0x20000000); // The API does not allow returning AVERROR codes |
| 178 | #define FILL(name) if(s->name > 0 && avctx->name <= 0) avctx->name = s->name |
| 179 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 180 | FILL(field_order); |
| 181 | FILL(coded_width); |
no test coverage detected