xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/vl/vl_codec.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2022 Red Hat
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 #include "pipe/p_video_codec.h"
28 
29 #include "vl_codec.h"
30 
vl_codec_supported(struct pipe_screen * screen,enum pipe_video_profile profile,bool encode)31 bool vl_codec_supported(struct pipe_screen *screen,
32                         enum pipe_video_profile profile,
33                         bool encode)
34 {
35    static_assert(PIPE_VIDEO_PROFILE_MAX == 26, "Update table below when adding new video profiles");
36    if (profile == PIPE_VIDEO_PROFILE_AV1_MAIN) {
37       if (encode) {
38          if (!VIDEO_CODEC_AV1ENC)
39             return false;
40       } else if (!VIDEO_CODEC_AV1DEC) {
41          return false;
42       }
43    }
44    if (profile == PIPE_VIDEO_PROFILE_VP9_PROFILE0 ||
45        profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2) {
46       if (!VIDEO_CODEC_VP9DEC)
47          return false;
48    }
49    if (profile == PIPE_VIDEO_PROFILE_VC1_SIMPLE ||
50        profile == PIPE_VIDEO_PROFILE_VC1_MAIN ||
51        profile == PIPE_VIDEO_PROFILE_VC1_ADVANCED) {
52       if (!VIDEO_CODEC_VC1DEC)
53          return false;
54    }
55    if (profile >= PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE &&
56        profile <= PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444) {
57       if (encode) {
58          if (!VIDEO_CODEC_H264ENC)
59             return false;
60       } else if (!VIDEO_CODEC_H264DEC) {
61          return false;
62       }
63    }
64    if (profile >= PIPE_VIDEO_PROFILE_HEVC_MAIN &&
65        profile <= PIPE_VIDEO_PROFILE_HEVC_MAIN_444) {
66       if (encode) {
67          if (!VIDEO_CODEC_H265ENC)
68             return false;
69       } else if (!VIDEO_CODEC_H265DEC) {
70          return false;
71       }
72    }
73 
74    return screen->get_video_param(screen, profile, encode ? PIPE_VIDEO_ENTRYPOINT_ENCODE : PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED);
75 }
76