FFmpeg
ffmpeg_cuvid.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/hwcontext.h"
20 #include "libavutil/pixdesc.h"
21 
22 #include "ffmpeg.h"
23 
24 static void cuvid_uninit(AVCodecContext *avctx)
25 {
26  InputStream *ist = avctx->opaque;
28 }
29 
31 {
32  InputStream *ist = avctx->opaque;
33  AVHWFramesContext *frames_ctx;
34  int ret;
35 
36  av_log(avctx, AV_LOG_VERBOSE, "Initializing cuvid hwaccel\n");
37 
38  if (!hw_device_ctx) {
40  ist->hwaccel_device, NULL, 0);
41  if (ret < 0) {
42  av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n");
43  return ret;
44  }
45  }
46 
49  if (!ist->hw_frames_ctx) {
50  av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n");
51  return AVERROR(ENOMEM);
52  }
53 
54  frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
55 
56  frames_ctx->format = AV_PIX_FMT_CUDA;
57  frames_ctx->sw_format = avctx->sw_pix_fmt;
58  frames_ctx->width = avctx->width;
59  frames_ctx->height = avctx->height;
60 
61  av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n",
62  av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height);
63 
65  if (ret < 0) {
66  av_log(avctx, AV_LOG_ERROR, "Error initializing a CUDA frame pool\n");
67  return ret;
68  }
69 
71 
72  return 0;
73 }
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:235
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:366
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:329
pixdesc.h
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:243
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
AV_HWDEVICE_TYPE_CUDA
@ AV_HWDEVICE_TYPE_CUDA
Definition: hwcontext.h:30
InputStream
Definition: ffmpeg.h:295
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVHWFramesContext::height
int height
Definition: hwcontext.h:228
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
hw_device_ctx
static AVBufferRef * hw_device_ctx
Definition: hw_decode.c:45
InputStream::hwaccel_uninit
void(* hwaccel_uninit)(AVCodecContext *s)
Definition: ffmpeg.h:371
AVCodecContext::height
int height
Definition: avcodec.h:1738
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
ret
ret
Definition: filter_design.txt:187
av_hwdevice_ctx_create
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition: hwcontext.c:571
AVCodecContext::opaque
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:1607
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
cuvid_uninit
static void cuvid_uninit(AVCodecContext *avctx)
Definition: ffmpeg_cuvid.c:24
cuvid_init
int cuvid_init(AVCodecContext *avctx)
Definition: ffmpeg_cuvid.c:30
InputStream::hw_frames_ctx
AVBufferRef * hw_frames_ctx
Definition: ffmpeg.h:376
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:1738
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3112
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2438