#include "decode.h"
#include "hwconfig.h"
#include "internal.h"
+#include "packet_internal.h"
#include "thread.h"
typedef struct FramePool {
return 0;
}
-static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
+#define IS_EMPTY(pkt) (!(pkt)->data)
+
+static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt)
{
int ret = 0;
- av_packet_unref(avci->last_pkt_props);
- if (pkt) {
- ret = av_packet_copy_props(avci->last_pkt_props, pkt);
- if (!ret)
- avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_decode_frame_props().
+ ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt,
+ av_packet_copy_props, 0);
+ if (ret < 0)
+ return ret;
+ avci->pkt_props_tail->pkt.size = pkt->size; // HACK: Needed for ff_decode_frame_props().
+ avci->pkt_props_tail->pkt.data = (void*)1; // HACK: Needed for IS_EMPTY().
+
+ if (IS_EMPTY(avci->last_pkt_props)) {
+ ret = avpriv_packet_list_get(&avci->pkt_props,
+ &avci->pkt_props_tail,
+ avci->last_pkt_props);
+ av_assert0(ret != AVERROR(EAGAIN));
}
return ret;
}
* returning any output, so this function needs to be called in a loop until it
* returns EAGAIN.
**/
-static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame)
+static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
{
AVCodecInternal *avci = avctx->internal;
DecodeSimpleContext *ds = &avci->ds;
if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
if (frame->flags & AV_FRAME_FLAG_DISCARD)
got_frame = 0;
- if (got_frame)
- frame->best_effort_timestamp = guess_correct_pts(avctx,
- frame->pts,
- frame->pkt_dts);
} else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
uint8_t *side;
int side_size;
uint8_t discard_reason = 0;
if (ret >= 0 && got_frame) {
- frame->best_effort_timestamp = guess_correct_pts(avctx,
- frame->pts,
- frame->pkt_dts);
if (frame->format == AV_SAMPLE_FMT_NONE)
frame->format = avctx->sample_fmt;
if (!frame->channel_layout)
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
got_frame = 0;
+ *discarded_samples += frame->nb_samples;
}
if (avci->skip_samples > 0 && got_frame &&
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
if(frame->nb_samples <= avci->skip_samples){
got_frame = 0;
+ *discarded_samples += frame->nb_samples;
avci->skip_samples -= frame->nb_samples;
av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
avci->skip_samples);
}
av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
avci->skip_samples, frame->nb_samples);
+ *discarded_samples += avci->skip_samples;
frame->nb_samples -= avci->skip_samples;
avci->skip_samples = 0;
}
if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame &&
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
if (discard_padding == frame->nb_samples) {
+ *discarded_samples += frame->nb_samples;
got_frame = 0;
} else {
if(avctx->pkt_timebase.num && avctx->sample_rate) {
if (ret >= pkt->size || ret < 0) {
av_packet_unref(pkt);
+ av_packet_unref(avci->last_pkt_props);
} else {
int consumed = ret;
static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
{
int ret;
+ int64_t discarded_samples = 0;
while (!frame->buf[0]) {
- ret = decode_simple_internal(avctx, frame);
+ if (discarded_samples > avctx->max_samples)
+ return AVERROR(EAGAIN);
+ ret = decode_simple_internal(avctx, frame, &discarded_samples);
if (ret < 0)
return ret;
}
av_assert0(!frame->buf[0]);
- if (avctx->codec->receive_frame)
+ if (avctx->codec->receive_frame) {
ret = avctx->codec->receive_frame(avctx, frame);
- else
+ if (ret != AVERROR(EAGAIN))
+ av_packet_unref(avci->last_pkt_props);
+ } else
ret = decode_simple_receive_frame(avctx, frame);
if (ret == AVERROR_EOF)
avci->draining_done = 1;
if (!ret) {
+ frame->best_effort_timestamp = guess_correct_pts(avctx,
+ frame->pts,
+ frame->pkt_dts);
+
/* the only case where decode data is not set should be decoders
* that do not call ff_get_buffer() */
av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
{
- const AVPacket *pkt = avctx->internal->last_pkt_props;
+ AVPacket *pkt = avctx->internal->last_pkt_props;
int i;
static const struct {
enum AVPacketSideDataType packet;
{ AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
};
+ if (IS_EMPTY(pkt))
+ avpriv_packet_list_get(&avctx->internal->pkt_props,
+ &avctx->internal->pkt_props_tail,
+ pkt);
+
if (pkt) {
frame->pts = pkt->pts;
#if FF_API_PKT_PTS
int ret;
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
- if ((ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
+ if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
+ (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
ret = AVERROR(EINVAL);
goto fail;