File size: 2,774 Bytes
dffe123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2022 Intel Corporation

#include <type_traits>

#include "streaming/onevpl/engine/preproc/utils.hpp"

#ifdef HAVE_ONEVPL
#include "streaming/onevpl/onevpl_export.hpp"
#include "logger.hpp"

namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
namespace utils {

cv::MediaFormat fourcc_to_MediaFormat(int value) {
    switch (value)
    {
        case MFX_FOURCC_BGRP:
            return cv::MediaFormat::BGR;
        case MFX_FOURCC_NV12:
            return cv::MediaFormat::NV12;
        default:
            GAPI_LOG_WARNING(nullptr, "Unsupported FourCC format requested: " << value <<
                                     ". Cannot cast to cv::MediaFrame");
            GAPI_Error("Unsupported FOURCC");

    }
}

int MediaFormat_to_fourcc(cv::MediaFormat value) {
    switch (value)
    {
        case cv::MediaFormat::BGR:
            return MFX_FOURCC_BGRP;
        case cv::MediaFormat::NV12:
            return MFX_FOURCC_NV12;
        default:
            GAPI_LOG_WARNING(nullptr, "Unsupported cv::MediaFormat format requested: " <<
                                      static_cast<typename std::underlying_type<cv::MediaFormat>::type>(value) <<
                                     ". Cannot cast to FourCC");
            GAPI_Error("Unsupported cv::MediaFormat");
    }
}
int MediaFormat_to_chroma(cv::MediaFormat value) {
    switch (value)
    {
        case cv::MediaFormat::BGR:
            return MFX_CHROMAFORMAT_MONOCHROME;
        case cv::MediaFormat::NV12:
            return MFX_CHROMAFORMAT_YUV420;
        default:
            GAPI_LOG_WARNING(nullptr, "Unsupported cv::MediaFormat format requested: " <<
                                      static_cast<typename std::underlying_type<cv::MediaFormat>::type>(value) <<
                                     ". Cannot cast to ChromaFormateIdc");
            GAPI_Error("Unsupported cv::MediaFormat");
    }
}

mfxFrameInfo to_mfxFrameInfo(const cv::GFrameDesc& frame_info) {
    mfxFrameInfo ret {0};
    ret.FourCC        = MediaFormat_to_fourcc(frame_info.fmt);
    ret.ChromaFormat  = MediaFormat_to_chroma(frame_info.fmt);
    ret.Width         = frame_info.size.width;
    ret.Height        = frame_info.size.height;
    ret.CropX         = 0;
    ret.CropY         = 0;
    ret.CropW         = 0;
    ret.CropH         = 0;
    ret.PicStruct     = MFX_PICSTRUCT_UNKNOWN;
    ret.FrameRateExtN = 0;
    ret.FrameRateExtD = 0;
    return ret;
}
} // namespace utils
} // namespace cv
} // namespace gapi
} // namespace wip
} // namespace onevpl

#endif // HAVE_ONEVPL