|
|
|
@ -1812,7 +1812,7 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
NVENCSTATUS nv_status; |
|
|
|
|
CUresult cu_res; |
|
|
|
|
CUcontext dummy; |
|
|
|
|
NvencSurface *tmpoutsurf, *inSurf; |
|
|
|
|
NvencSurface *tmp_out_surf, *in_surf; |
|
|
|
|
int res; |
|
|
|
|
|
|
|
|
|
NvencContext *ctx = avctx->priv_data; |
|
|
|
@ -1829,8 +1829,8 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
return AVERROR_EOF; |
|
|
|
|
|
|
|
|
|
if (frame) { |
|
|
|
|
inSurf = get_free_frame(ctx); |
|
|
|
|
if (!inSurf) |
|
|
|
|
in_surf = get_free_frame(ctx); |
|
|
|
|
if (!in_surf) |
|
|
|
|
return AVERROR(EAGAIN); |
|
|
|
|
|
|
|
|
|
cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); |
|
|
|
@ -1839,7 +1839,7 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
return AVERROR_EXTERNAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res = nvenc_upload_frame(avctx, frame, inSurf); |
|
|
|
|
res = nvenc_upload_frame(avctx, frame, in_surf); |
|
|
|
|
|
|
|
|
|
cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); |
|
|
|
|
if (cu_res != CUDA_SUCCESS) { |
|
|
|
@ -1850,12 +1850,12 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
if (res) |
|
|
|
|
return res; |
|
|
|
|
|
|
|
|
|
pic_params.inputBuffer = inSurf->input_surface; |
|
|
|
|
pic_params.bufferFmt = inSurf->format; |
|
|
|
|
pic_params.inputWidth = inSurf->width; |
|
|
|
|
pic_params.inputHeight = inSurf->height; |
|
|
|
|
pic_params.inputPitch = inSurf->pitch; |
|
|
|
|
pic_params.outputBitstream = inSurf->output_surface; |
|
|
|
|
pic_params.inputBuffer = in_surf->input_surface; |
|
|
|
|
pic_params.bufferFmt = in_surf->format; |
|
|
|
|
pic_params.inputWidth = in_surf->width; |
|
|
|
|
pic_params.inputHeight = in_surf->height; |
|
|
|
|
pic_params.inputPitch = in_surf->pitch; |
|
|
|
|
pic_params.outputBitstream = in_surf->output_surface; |
|
|
|
|
|
|
|
|
|
if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) { |
|
|
|
|
if (frame->top_field_first) |
|
|
|
@ -1900,7 +1900,7 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
return nvenc_print_error(avctx, nv_status, "EncodePicture failed!"); |
|
|
|
|
|
|
|
|
|
if (frame) { |
|
|
|
|
av_fifo_generic_write(ctx->output_surface_queue, &inSurf, sizeof(inSurf), NULL); |
|
|
|
|
av_fifo_generic_write(ctx->output_surface_queue, &in_surf, sizeof(in_surf), NULL); |
|
|
|
|
timestamp_queue_enqueue(ctx->timestamp_list, frame->pts); |
|
|
|
|
|
|
|
|
|
if (ctx->initial_pts[0] == AV_NOPTS_VALUE) |
|
|
|
@ -1912,8 +1912,8 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
|
/* all the pending buffers are now ready for output */ |
|
|
|
|
if (nv_status == NV_ENC_SUCCESS) { |
|
|
|
|
while (av_fifo_size(ctx->output_surface_queue) > 0) { |
|
|
|
|
av_fifo_generic_read(ctx->output_surface_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL); |
|
|
|
|
av_fifo_generic_write(ctx->output_surface_ready_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL); |
|
|
|
|
av_fifo_generic_read(ctx->output_surface_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL); |
|
|
|
|
av_fifo_generic_write(ctx->output_surface_ready_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1924,7 +1924,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
CUresult cu_res; |
|
|
|
|
CUcontext dummy; |
|
|
|
|
NvencSurface *tmpoutsurf; |
|
|
|
|
NvencSurface *tmp_out_surf; |
|
|
|
|
int res; |
|
|
|
|
|
|
|
|
|
NvencContext *ctx = avctx->priv_data; |
|
|
|
@ -1934,7 +1934,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt) |
|
|
|
|
return AVERROR(EINVAL); |
|
|
|
|
|
|
|
|
|
if (output_ready(avctx, ctx->encoder_flushing)) { |
|
|
|
|
av_fifo_generic_read(ctx->output_surface_ready_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL); |
|
|
|
|
av_fifo_generic_read(ctx->output_surface_ready_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL); |
|
|
|
|
|
|
|
|
|
cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); |
|
|
|
|
if (cu_res != CUDA_SUCCESS) { |
|
|
|
@ -1942,7 +1942,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt) |
|
|
|
|
return AVERROR_EXTERNAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res = process_output_surface(avctx, pkt, tmpoutsurf); |
|
|
|
|
res = process_output_surface(avctx, pkt, tmp_out_surf); |
|
|
|
|
|
|
|
|
|
cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); |
|
|
|
|
if (cu_res != CUDA_SUCCESS) { |
|
|
|
@ -1953,7 +1953,7 @@ int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt) |
|
|
|
|
if (res) |
|
|
|
|
return res; |
|
|
|
|
|
|
|
|
|
av_fifo_generic_write(ctx->unused_surface_queue, &tmpoutsurf, sizeof(tmpoutsurf), NULL); |
|
|
|
|
av_fifo_generic_write(ctx->unused_surface_queue, &tmp_out_surf, sizeof(tmp_out_surf), NULL); |
|
|
|
|
} else if (ctx->encoder_flushing) { |
|
|
|
|
return AVERROR_EOF; |
|
|
|
|
} else { |
|
|
|
|