aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/cuvid.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-04-22 20:08:42 -0300
committerJames Almer <jamrial@gmail.com>2017-04-22 20:08:42 -0300
commitbddb2343b6e594e312dadb5d21b408702929ae04 (patch)
tree0295342c799268930ce61e45844af7aadb77f52a /libavcodec/cuvid.c
parent1fd76277708cf83572ba243e98f9e848c652f83d (diff)
parent061a0c14bb5767bca72e3a7227ca400de439ba09 (diff)
downloadffmpeg-bddb2343b6e594e312dadb5d21b408702929ae04.tar.gz
Merge commit '061a0c14bb5767bca72e3a7227ca400de439ba09'
* commit '061a0c14bb5767bca72e3a7227ca400de439ba09': decode: restructure the core decoding code CUVID decoder adapted by wm4. Merged-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/cuvid.c')
-rw-r--r--libavcodec/cuvid.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c
index 916d7e9987..4d96cf0204 100644
--- a/libavcodec/cuvid.c
+++ b/libavcodec/cuvid.c
@@ -31,6 +31,7 @@
#include "libavutil/pixdesc.h"
#include "avcodec.h"
+#include "decode.h"
#include "internal.h"
typedef struct CuvidContext
@@ -357,6 +358,13 @@ static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINF
return 1;
}
+static int cuvid_is_buffer_full(AVCodecContext *avctx)
+{
+ CuvidContext *ctx = avctx->priv_data;
+
+ return (av_fifo_size(ctx->frame_queue) / sizeof(CuvidParsedFrame)) + 2 > ctx->nb_surfaces;
+}
+
static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
{
CuvidContext *ctx = avctx->priv_data;
@@ -373,7 +381,7 @@ static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
if (is_flush && avpkt && avpkt->size)
return AVERROR_EOF;
- if ((av_fifo_size(ctx->frame_queue) / sizeof(CuvidParsedFrame)) + 2 > ctx->nb_surfaces && avpkt && avpkt->size)
+ if (cuvid_is_buffer_full(avctx) && avpkt && avpkt->size)
return AVERROR(EAGAIN);
if (ctx->bsf && avpkt && avpkt->size) {
@@ -464,6 +472,20 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
return ret;
}
+ if (!cuvid_is_buffer_full(avctx)) {
+ AVPacket pkt = {0};
+ ret = ff_decode_get_packet(avctx, &pkt);
+ if (ret < 0 && ret != AVERROR_EOF)
+ return ret;
+ ret = cuvid_decode_packet(avctx, &pkt);
+ av_packet_unref(&pkt);
+ // cuvid_is_buffer_full() should avoid this.
+ if (ret == AVERROR(EAGAIN))
+ ret = AVERROR_EXTERNAL;
+ if (ret < 0 && ret != AVERROR_EOF)
+ return ret;
+ }
+
ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
if (ret < 0)
return ret;
@@ -1026,7 +1048,6 @@ static const AVOption options[] = {
.init = cuvid_decode_init, \
.close = cuvid_decode_end, \
.decode = cuvid_decode_frame, \
- .send_packet = cuvid_decode_packet, \
.receive_frame = cuvid_output_frame, \
.flush = cuvid_flush, \
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \