dvbsub: Check for errors from system()
[libav.git] / avconv_qsv.c
CommitLineData
fb472e1a
AK
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"
02c27619
AK
23#include "libavutil/hwcontext.h"
24#include "libavutil/hwcontext_qsv.h"
fb472e1a
AK
25#include "libavutil/mem.h"
26#include "libavutil/opt.h"
27#include "libavcodec/qsv.h"
28
29#include "avconv.h"
30
fb472e1a
AK
31static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
32{
33 InputStream *ist = s->opaque;
fb472e1a 34
02c27619 35 return av_hwframe_get_buffer(ist->hw_frames_ctx, frame, 0);
fb472e1a
AK
36}
37
38static void qsv_uninit(AVCodecContext *s)
39{
40 InputStream *ist = s->opaque;
02c27619 41 av_buffer_unref(&ist->hw_frames_ctx);
fb472e1a
AK
42}
43
02c27619 44static int qsv_device_init(InputStream *ist)
fb472e1a 45{
02c27619 46 int err;
fb472e1a 47
02c27619
AK
48 err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
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;
fb472e1a
AK
53 }
54
fb472e1a
AK
55 return 0;
56}
57
02c27619 58int qsv_init(AVCodecContext *s)
fb472e1a 59{
02c27619
AK
60 InputStream *ist = s->opaque;
61 AVHWFramesContext *frames_ctx;
62 AVQSVFramesContext *frames_hwctx;
63 int ret;
fb472e1a 64
02c27619
AK
65 if (!hw_device_ctx) {
66 ret = qsv_device_init(ist);
67 if (ret < 0)
68 return ret;
fb472e1a
AK
69 }
70
02c27619
AK
71 av_buffer_unref(&ist->hw_frames_ctx);
72 ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
73 if (!ist->hw_frames_ctx)
74 return AVERROR(ENOMEM);
fb472e1a 75
02c27619
AK
76 frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
77 frames_hwctx = frames_ctx->hwctx;
fb472e1a 78
6f40181c
AK
79 frames_ctx->width = FFALIGN(s->coded_width, 32);
80 frames_ctx->height = FFALIGN(s->coded_height, 32);
02c27619 81 frames_ctx->format = AV_PIX_FMT_QSV;
8b7a9729 82 frames_ctx->sw_format = s->sw_pix_fmt;
02c27619
AK
83 frames_ctx->initial_pool_size = 32;
84 frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
fb472e1a 85
02c27619
AK
86 ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
87 if (ret < 0) {
88 av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n");
89 return ret;
fb472e1a
AK
90 }
91
02c27619
AK
92 ist->hwaccel_get_buffer = qsv_get_buffer;
93 ist->hwaccel_uninit = qsv_uninit;
fb472e1a
AK
94
95 return 0;
fb472e1a 96}