input: add input_SetProgramId
[vlc.git] / modules / codec / hxxx_helper_testdec.c
blobc0dd3119e97970a6e0d8d60db1a5a934b62662bd
1 /*****************************************************************************
2 * hxxx_helper_testdec.c: test decoder for hxxx_helper API
3 *****************************************************************************
4 * Copyright © 2020 VideoLAN, VLC authors and libbluray AUTHORS
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_codec.h>
28 #include "hxxx_helper.h"
30 struct decoder_sys {
31 struct hxxx_helper hh;
34 static void
35 Flush(decoder_t *dec)
37 (void) dec;
40 static int
41 DecodeBlock(decoder_t *dec, block_t *block)
43 struct decoder_sys *sys = dec->p_sys;
45 if (block == NULL)
46 return VLCDEC_SUCCESS;
48 bool config_changed;
49 block = sys->hh.pf_process_block(&sys->hh, block, &config_changed);
51 if (block == NULL)
52 return VLCDEC_SUCCESS;
54 if (config_changed)
56 int ret;
57 video_color_primaries_t primaries;
58 video_transfer_func_t transfer;
59 video_color_space_t colorspace;
60 video_color_range_t full_range;
62 ret = hxxx_helper_get_colorimetry(&sys->hh, &primaries, &transfer,
63 &colorspace, &full_range);
64 if (ret == VLC_SUCCESS)
66 dec->fmt_out.video.primaries = primaries;
67 dec->fmt_out.video.transfer = transfer;
68 dec->fmt_out.video.space = colorspace;
69 dec->fmt_out.video.color_range = full_range;
72 unsigned width, height, vis_width, vis_height;
73 ret = hxxx_helper_get_current_picture_size(&sys->hh,
74 &width, &height,
75 &vis_width, &vis_height);
76 if (ret == VLC_SUCCESS)
78 dec->fmt_out.video.i_width =
79 dec->fmt_out.video.i_visible_width = vis_width;
80 dec->fmt_out.video.i_height =
81 dec->fmt_out.video.i_visible_height = vis_height;
84 int sar_num, sar_den;
85 ret = hxxx_helper_get_current_sar(&sys->hh, &sar_num, &sar_den);
86 if (ret == VLC_SUCCESS)
88 dec->fmt_out.video.i_sar_num = sar_num;
89 dec->fmt_out.video.i_sar_den = sar_den;
92 ret = decoder_UpdateVideoOutput(dec, NULL);
93 if (ret != 0)
94 return VLCDEC_ECRITICAL;
97 block_Release(block);
99 return VLCDEC_SUCCESS;
102 static void
103 CloseDecoder(vlc_object_t *this)
105 decoder_t *dec = (void *)this;
106 struct decoder_sys *sys = dec->p_sys;
108 hxxx_helper_clean(&sys->hh);
109 free(sys);
112 static int
113 OpenDecoder(vlc_object_t *this)
115 decoder_t *dec = (void *)this;
117 switch (dec->fmt_in.i_codec)
119 case VLC_CODEC_H264:
120 case VLC_CODEC_HEVC:
121 break;
122 default:
123 return VLC_EGENERIC;
126 struct decoder_sys *sys = malloc(sizeof(*sys));
127 if (sys == NULL)
128 return VLC_EGENERIC;
130 hxxx_helper_init(&sys->hh, this, dec->fmt_in.i_codec,
131 var_InheritBool(this, "hxxx-helper-testdec-xvcC"));
133 int ret = hxxx_helper_set_extra(&sys->hh, dec->fmt_in.p_extra,
134 dec->fmt_in.i_extra);
135 if (ret != VLC_SUCCESS)
137 hxxx_helper_clean(&sys->hh);
138 free(sys);
139 return ret;
142 dec->p_sys = sys;
143 dec->pf_decode = DecodeBlock;
144 dec->pf_flush = Flush;
146 dec->fmt_out.video = dec->fmt_in.video;
147 dec->fmt_out.video.p_palette = NULL;
149 return VLC_SUCCESS;
152 vlc_module_begin()
153 set_category(CAT_INPUT)
154 set_subcategory(SUBCAT_INPUT_VCODEC)
155 set_description(N_("hxxx test decoder"))
156 add_shortcut("hxxxhelper")
157 set_capability("video decoder", 0)
158 add_bool("hxxx-helper-testdec-xvcC", false, NULL, NULL, true)
159 set_callbacks(OpenDecoder, CloseDecoder)
160 vlc_module_end()