Skip to content

Instantly share code, notes, and snippets.

@BtbN
Created October 7, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BtbN/71e79155759c3c2274b8261c8972119e to your computer and use it in GitHub Desktop.
Save BtbN/71e79155759c3c2274b8261c8972119e to your computer and use it in GitHub Desktop.
stdin
diff --git a/libavfilter/vf_hwupload_cuda.c b/libavfilter/vf_hwupload_cuda.c
index 94cfe97..8e15c7b 100644
--- a/libavfilter/vf_hwupload_cuda.c
+++ b/libavfilter/vf_hwupload_cuda.c
@@ -16,11 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <cuda.h>
-
#include "libavutil/buffer.h"
#include "libavutil/hwcontext.h"
-#include "libavutil/hwcontext_cuda.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
@@ -37,60 +34,11 @@ typedef struct CudaUploadContext {
AVBufferRef *hwframe;
} CudaUploadContext;
-static void cudaupload_ctx_free(AVHWDeviceContext *ctx)
-{
- AVCUDADeviceContext *hwctx = ctx->hwctx;
- cuCtxDestroy(hwctx->cuda_ctx);
-}
-
static av_cold int cudaupload_init(AVFilterContext *ctx)
{
CudaUploadContext *s = ctx->priv;
- AVHWDeviceContext *device_ctx;
- AVCUDADeviceContext *device_hwctx;
- CUdevice device;
- CUcontext cuda_ctx = NULL, dummy;
- CUresult err;
- int ret;
-
- err = cuInit(0);
- if (err != CUDA_SUCCESS) {
- av_log(ctx, AV_LOG_ERROR, "Could not initialize the CUDA driver API\n");
- return AVERROR_UNKNOWN;
- }
-
- err = cuDeviceGet(&device, s->device_idx);
- if (err != CUDA_SUCCESS) {
- av_log(ctx, AV_LOG_ERROR, "Could not get the device number %d\n", s->device_idx);
- return AVERROR_UNKNOWN;
- }
-
- err = cuCtxCreate(&cuda_ctx, 0, device);
- if (err != CUDA_SUCCESS) {
- av_log(ctx, AV_LOG_ERROR, "Error creating a CUDA context\n");
- return AVERROR_UNKNOWN;
- }
-
- cuCtxPopCurrent(&dummy);
-
- s->hwdevice = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_CUDA);
- if (!s->hwdevice) {
- cuCtxDestroy(cuda_ctx);
- return AVERROR(ENOMEM);
- }
-
- device_ctx = (AVHWDeviceContext*)s->hwdevice->data;
- device_ctx->free = cudaupload_ctx_free;
-
- device_hwctx = device_ctx->hwctx;
- device_hwctx->cuda_ctx = cuda_ctx;
-
- ret = av_hwdevice_ctx_init(s->hwdevice);
- if (ret < 0)
- return ret;
-
- return 0;
+ return av_hwdevice_ctx_create(&s->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0);
}
static av_cold void cudaupload_uninit(AVFilterContext *ctx)
@@ -136,8 +84,8 @@ static int cudaupload_config_output(AVFilterLink *outlink)
hwframe_ctx = (AVHWFramesContext*)s->hwframe->data;
hwframe_ctx->format = AV_PIX_FMT_CUDA;
hwframe_ctx->sw_format = inlink->format;
- hwframe_ctx->width = FFALIGN(inlink->w, 16);
- hwframe_ctx->height = FFALIGN(inlink->h, 16);
+ hwframe_ctx->width = inlink->w;
+ hwframe_ctx->height = inlink->h;
ret = av_hwframe_ctx_init(s->hwframe);
if (ret < 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment