Imported Upstream version 6.1
[platform/upstream/ffmpeg.git] / libavcodec / qsvenc_jpeg.c
1 /*
2  * Intel MediaSDK QSV based MJPEG encoder
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
22 #include <stdint.h>
23 #include <sys/types.h>
24
25 #include <mfxvideo.h>
26
27 #include "libavutil/common.h"
28 #include "libavutil/opt.h"
29
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "qsv.h"
33 #include "qsvenc.h"
34
35 typedef struct QSVMJPEGEncContext {
36     AVClass *class;
37     QSVEncContext qsv;
38 } QSVMJPEGEncContext;
39
40 static av_cold int qsv_enc_init(AVCodecContext *avctx)
41 {
42     QSVMJPEGEncContext *q = avctx->priv_data;
43
44     return ff_qsv_enc_init(avctx, &q->qsv);
45 }
46
47 static int qsv_enc_frame(AVCodecContext *avctx, AVPacket *pkt,
48                          const AVFrame *frame, int *got_packet)
49 {
50     QSVMJPEGEncContext *q = avctx->priv_data;
51
52     return ff_qsv_encode(avctx, &q->qsv, pkt, frame, got_packet);
53 }
54
55 static av_cold int qsv_enc_close(AVCodecContext *avctx)
56 {
57     QSVMJPEGEncContext *q = avctx->priv_data;
58
59     return ff_qsv_enc_close(avctx, &q->qsv);
60 }
61
62 #define OFFSET(x) offsetof(QSVMJPEGEncContext, x)
63 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
64 static const AVOption options[] = {
65     { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE },
66     { NULL },
67 };
68
69 static const AVClass class = {
70     .class_name = "mjpeg_qsv encoder",
71     .item_name  = av_default_item_name,
72     .option     = options,
73     .version    = LIBAVUTIL_VERSION_INT,
74 };
75
76 static const FFCodecDefault qsv_enc_defaults[] = {
77     { "global_quality",  "80" },
78     { NULL },
79 };
80
81 const FFCodec ff_mjpeg_qsv_encoder = {
82     .p.name         = "mjpeg_qsv",
83     CODEC_LONG_NAME("MJPEG (Intel Quick Sync Video acceleration)"),
84     .priv_data_size = sizeof(QSVMJPEGEncContext),
85     .p.type         = AVMEDIA_TYPE_VIDEO,
86     .p.id           = AV_CODEC_ID_MJPEG,
87     .init           = qsv_enc_init,
88     FF_CODEC_ENCODE_CB(qsv_enc_frame),
89     .close          = qsv_enc_close,
90     .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
91     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
92                                                     AV_PIX_FMT_YUYV422,
93                                                     AV_PIX_FMT_BGRA,
94                                                     AV_PIX_FMT_QSV,
95                                                     AV_PIX_FMT_NONE },
96     .p.priv_class   = &class,
97     .defaults       = qsv_enc_defaults,
98     .p.wrapper_name = "qsv",
99     .hw_configs     = ff_qsv_enc_hw_configs,
100     .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
101 };