Libav
avconv_qsv.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <mfx/mfxvideo.h>
20 #include <stdlib.h>
21 
22 #include "libavutil/dict.h"
23 #include "libavutil/hwcontext.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/opt.h"
27 #include "libavcodec/qsv.h"
28 
29 #include "avconv.h"
30 
31 static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
32 {
33  InputStream *ist = s->opaque;
34 
35  return av_hwframe_get_buffer(ist->hw_frames_ctx, frame, 0);
36 }
37 
38 static void qsv_uninit(AVCodecContext *s)
39 {
40  InputStream *ist = s->opaque;
42 }
43 
44 static int qsv_device_init(InputStream *ist)
45 {
46  int err;
47 
49  ist->hwaccel_device, NULL, 0);
50  if (err < 0) {
51  av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
52  return err;
53  }
54 
55  return 0;
56 }
57 
59 {
60  InputStream *ist = s->opaque;
61  AVHWFramesContext *frames_ctx;
62  AVQSVFramesContext *frames_hwctx;
63  int ret;
64 
65  if (!hw_device_ctx) {
66  ret = qsv_device_init(ist);
67  if (ret < 0)
68  return ret;
69  }
70 
73  if (!ist->hw_frames_ctx)
74  return AVERROR(ENOMEM);
75 
76  frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
77  frames_hwctx = frames_ctx->hwctx;
78 
79  frames_ctx->width = FFALIGN(s->coded_width, 32);
80  frames_ctx->height = FFALIGN(s->coded_height, 32);
81  frames_ctx->format = AV_PIX_FMT_QSV;
82  frames_ctx->sw_format = s->sw_pix_fmt;
83  frames_ctx->initial_pool_size = 32;
84  frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
85 
87  if (ret < 0) {
88  av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n");
89  return ret;
90  }
91 
94 
95  return 0;
96 }
int qsv_init(AVCodecContext *s)
Definition: avconv_qsv.c:58
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:106
static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
Definition: avconv_qsv.c:31
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
AVBufferRef * hw_frames_ctx
Definition: avconv.h:303
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1595
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
Definition: hwcontext_qsv.h:49
memory handling functions
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_qsv.h:42
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:222
void(* hwaccel_uninit)(AVCodecContext *s)
Definition: avconv.h:298
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:202
Public dictionary API.
AVOptions.
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:463
static int flags
Definition: log.c:50
#define FFALIGN(x, a)
Definition: macros.h:48
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
#define AVERROR(e)
Definition: error.h:43
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:263
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:394
static int qsv_device_init(InputStream *ist)
Definition: avconv_qsv.c:44
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:192
AVBufferRef * hw_device_ctx
Definition: avconv_opt.c:77
NULL
Definition: eval.c:55
main external API structure.
Definition: avcodec.h:1409
uint8_t * data
The data buffer.
Definition: buffer.h:89
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:155
int coded_height
Definition: avcodec.h:1595
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:215
int(* hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags)
Definition: avconv.h:299
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:177
static void qsv_uninit(AVCodecContext *s)
Definition: avconv_qsv.c:38
char * hwaccel_device
Definition: avconv.h:292
An API-specific header for AV_HWDEVICE_TYPE_QSV.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:215
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3070
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:1466