| 230 | } |
| 231 | |
| 232 | int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, |
| 233 | AVFrame *frame, int *got_packet) |
| 234 | { |
| 235 | const FFCodec *const codec = ffcodec(avctx->codec); |
| 236 | int ret; |
| 237 | |
| 238 | ret = codec->cb.encode(avctx, avpkt, frame, got_packet); |
| 239 | ff_assert1_fpu(); |
| 240 | av_assert0(ret <= 0); |
| 241 | |
| 242 | if (!ret && *got_packet) { |
| 243 | if (avpkt->data) { |
| 244 | ret = encode_make_refcounted(avctx, avpkt); |
| 245 | if (ret < 0) |
| 246 | goto unref; |
| 247 | // Date returned by encoders must always be ref-counted |
| 248 | av_assert0(avpkt->buf); |
| 249 | } |
| 250 | |
| 251 | // set the timestamps for the simple no-delay case |
| 252 | // encoders with delay have to set the timestamps themselves |
| 253 | if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || |
| 254 | (frame && (codec->caps_internal & FF_CODEC_CAP_EOF_FLUSH))) { |
| 255 | if (avpkt->pts == AV_NOPTS_VALUE) |
| 256 | avpkt->pts = frame->pts; |
| 257 | |
| 258 | if (!avpkt->duration) { |
| 259 | if (frame->duration) |
| 260 | avpkt->duration = frame->duration; |
| 261 | else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { |
| 262 | avpkt->duration = ff_samples_to_time_base(avctx, |
| 263 | frame->nb_samples); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | ret = ff_encode_reordered_opaque(avctx, avpkt, frame); |
| 268 | if (ret < 0) |
| 269 | goto unref; |
| 270 | } |
| 271 | |
| 272 | // dts equals pts unless there is reordering |
| 273 | // there can be no reordering if there is no encoder delay |
| 274 | if (!(avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) || |
| 275 | !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || |
| 276 | (codec->caps_internal & FF_CODEC_CAP_EOF_FLUSH)) |
| 277 | avpkt->dts = avpkt->pts; |
| 278 | } else { |
| 279 | unref: |
| 280 | av_packet_unref(avpkt); |
| 281 | } |
| 282 | |
| 283 | if (frame) |
| 284 | av_frame_unref(frame); |
| 285 | |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) |
no test coverage detected