FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qsv.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV encoder/decoder shared code
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <mfx/mfxvideo.h>
22 
23 #include "libavutil/error.h"
24 
25 #include "avcodec.h"
26 #include "qsv_internal.h"
27 
29 {
30  switch (codec_id) {
31  case AV_CODEC_ID_H264:
32  return MFX_CODEC_AVC;
35  return MFX_CODEC_MPEG2;
36  case AV_CODEC_ID_VC1:
37  return MFX_CODEC_VC1;
38  default:
39  break;
40  }
41 
42  return AVERROR(ENOSYS);
43 }
44 
45 int ff_qsv_error(int mfx_err)
46 {
47  switch (mfx_err) {
48  case MFX_ERR_NONE:
49  return 0;
50  case MFX_ERR_MEMORY_ALLOC:
51  case MFX_ERR_NOT_ENOUGH_BUFFER:
52  return AVERROR(ENOMEM);
53  case MFX_ERR_INVALID_HANDLE:
54  return AVERROR(EINVAL);
55  case MFX_ERR_DEVICE_FAILED:
56  case MFX_ERR_DEVICE_LOST:
57  case MFX_ERR_LOCK_MEMORY:
58  return AVERROR(EIO);
59  case MFX_ERR_NULL_PTR:
60  case MFX_ERR_UNDEFINED_BEHAVIOR:
61  case MFX_ERR_NOT_INITIALIZED:
62  return AVERROR_BUG;
63  case MFX_ERR_UNSUPPORTED:
64  case MFX_ERR_NOT_FOUND:
65  return AVERROR(ENOSYS);
66  case MFX_ERR_MORE_DATA:
67  case MFX_ERR_MORE_SURFACE:
68  case MFX_ERR_MORE_BITSTREAM:
69  return AVERROR(EAGAIN);
70  case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
71  case MFX_ERR_INVALID_VIDEO_PARAM:
72  return AVERROR(EINVAL);
73  case MFX_ERR_ABORTED:
74  case MFX_ERR_UNKNOWN:
75  default:
76  return AVERROR_UNKNOWN;
77  }
78 }
79 
80 int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session)
81 {
82  mfxIMPL impl = MFX_IMPL_AUTO_ANY;
83  mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
84 
85  const char *desc;
86  int ret;
87 
88  ret = MFXInit(impl, &ver, session);
89  if (ret < 0) {
90  av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX session\n");
91  return ff_qsv_error(ret);
92  }
93 
94  MFXQueryIMPL(*session, &impl);
95 
96  switch (MFX_IMPL_BASETYPE(impl)) {
97  case MFX_IMPL_SOFTWARE:
98  desc = "software";
99  break;
100  case MFX_IMPL_HARDWARE:
101  case MFX_IMPL_HARDWARE2:
102  case MFX_IMPL_HARDWARE3:
103  case MFX_IMPL_HARDWARE4:
104  desc = "hardware accelerated";
105  break;
106  default:
107  desc = "unknown";
108  }
109 
110  av_log(avctx, AV_LOG_VERBOSE,
111  "Initialized an internal MFX session using %s implementation\n",
112  desc);
113 
114  return 0;
115 }
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:102
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
error code definitions
#define AVERROR(e)
Definition: error.h:43
enum AVCodecID codec_id
Definition: mov_chan.c:433
Libavcodec external API header.
#define QSV_VERSION_MINOR
Definition: qsv_internal.h:29
ret
Definition: avfilter.c:974
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
Definition: qsv.c:28
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:107
main external API structure.
Definition: avcodec.h:1241
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session)
Definition: qsv.c:80
int ff_qsv_error(int mfx_err)
Convert a libmfx error code into a ffmpeg error code.
Definition: qsv.c:45
#define QSV_VERSION_MAJOR
Definition: qsv_internal.h:28
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71