libctru v2.5.0
Loading...
Searching...
No Matches
mvd.h
Go to the documentation of this file.
1/**
2 * @file mvd.h
3 * @brief MVD service.
4 */
5#pragma once
6
7//New3DS-only, see also: http://3dbrew.org/wiki/MVD_Services
8
9///These values are the data returned as "result-codes" by MVDSTD.
10#define MVD_STATUS_OK 0x17000
11#define MVD_STATUS_PARAMSET 0x17001 ///"Returned after processing NAL-unit parameter-sets."
12#define MVD_STATUS_BUSY 0x17002
13#define MVD_STATUS_FRAMEREADY 0x17003
14#define MVD_STATUS_INCOMPLETEPROCESSING 0x17004 ///"Returned when not all of the input NAL-unit buffer was processed."
15#define MVD_STATUS_NALUPROCFLAG 0x17007 ///See here: https://www.3dbrew.org/wiki/MVDSTD:ProcessNALUnit
16
17///This can be used to check whether mvdstdProcessVideoFrame() was successful.
18#define MVD_CHECKNALUPROC_SUCCESS(x) (x==MVD_STATUS_OK || x==MVD_STATUS_PARAMSET || x==MVD_STATUS_FRAMEREADY || x==MVD_STATUS_INCOMPLETEPROCESSING || x==MVD_STATUS_NALUPROCFLAG)
19
20/// Default input size for mvdstdInit(). This is what the New3DS Internet Browser uses, from the MVDSTD:CalculateWorkBufSize output.
21#define MVD_DEFAULT_WORKBUF_SIZE 0x9006C8
22
23#define MVD_CALC_WITH_LEVEL_FLAG_NONE 0x00 //Nothing.
24#define MVD_CALC_WITH_LEVEL_FLAG_ENABLE_CALC 0x01 //Enable calculation with level.
25#define MVD_CALC_WITH_LEVEL_FLAG_ENABLE_EXTRA_OP 0x02 //Enable extra op after base calculation (see : https://www.3dbrew.org/wiki/MVDSTD:CalculateWorkBufSize).
26#define MVD_CALC_WITH_LEVEL_FLAG_UNK 0x04 //Unknown.
27
28#define MVD_H264_LEVEL_1_0 0x00 //H.264 level 1.0.
29#define MVD_H264_LEVEL_1_0B 0x01 //H.264 level 1.0b.
30#define MVD_H264_LEVEL_1_1 0x02 //H.264 level 1.1.
31#define MVD_H264_LEVEL_1_2 0x03 //H.264 level 1.2.
32#define MVD_H264_LEVEL_1_3 0x04 //H.264 level 1.3.
33#define MVD_H264_LEVEL_2_0 0x05 //H.264 level 2.0.
34#define MVD_H264_LEVEL_2_1 0x06 //H.264 level 2.1.
35#define MVD_H264_LEVEL_2_2 0x07 //H.264 level 2.2.
36#define MVD_H264_LEVEL_3_0 0x08 //H.264 level 3.0.
37#define MVD_H264_LEVEL_3_1 0x09 //H.264 level 3.1.
38#define MVD_H264_LEVEL_3_2 0x0A //H.264 level 3.2.
39#define MVD_H264_LEVEL_4_0 0x0B //H.264 level 4.0.
40#define MVD_H264_LEVEL_4_1 0x0C //H.264 level 4.1.
41#define MVD_H264_LEVEL_4_2 0x0D //H.264 level 4.2.
42#define MVD_H264_LEVEL_5_0 0x0E //H.264 level 5.0.
43#define MVD_H264_LEVEL_5_1 0x0F //H.264 level 5.1.
44#define MVD_H264_LEVEL_5_2 0x10 //H.264 level 5.2.
45
46/// Processing mode.
47typedef enum {
48 MVDMODE_COLORFORMATCONV, ///< Converting color formats.
49 MVDMODE_VIDEOPROCESSING ///< Processing video.
51
52/// Input format.
53typedef enum {
54 MVD_INPUT_YUYV422 = 0x00010001, ///< YUYV422
55 MVD_INPUT_H264 = 0x00020001 ///< H264
57
58/// Output format.
59typedef enum {
60 MVD_OUTPUT_YUYV422 = 0x00010001, ///< YUYV422
61 MVD_OUTPUT_BGR565 = 0x00040002, ///< BGR565
62 MVD_OUTPUT_RGB565 = 0x00040004 ///< RGB565
64
65/// Processing configuration.
66typedef struct {
68 u32 unk_x04; ///< Unknown.
69 u32 unk_x08; ///< Unknown. Referred to as "H264 range" in SKATER.
70 u32 inwidth; ///< Input width.
71 u32 inheight; ///< Input height.
72 u32 physaddr_colorconv_indata; ///< Physical address of color conversion input data.
73 u32 physaddr_colorconv_unk0; ///< Physical address used with color conversion.
74 u32 physaddr_colorconv_unk1; ///< Physical address used with color conversion.
75 u32 physaddr_colorconv_unk2; ///< Physical address used with color conversion.
76 u32 physaddr_colorconv_unk3; ///< Physical address used with color conversion.
77 u32 unk_x28[0x18>>2]; ///< Unknown.
78 u32 enable_cropping; ///< Enables cropping with the input image when non-zero via the following 4 words.
79 u32 input_crop_x_pos;
80 u32 input_crop_y_pos;
81 u32 input_crop_height;
82 u32 input_crop_width;
83 u32 unk_x54; ///< Unknown.
85 u32 outwidth; ///< Output width.
86 u32 outheight; ///< Output height.
87 u32 physaddr_outdata0; ///< Physical address of output data.
88 u32 physaddr_outdata1; ///< Additional physical address for output data, only used when the output format type is value 0x00020001.
89 u32 unk_x6c[0x98>>2]; ///< Unknown.
90 u32 flag_x104; ///< This enables using the following 4 words when non-zero.
91 u32 output_x_pos; ///< Output X position in the output buffer.
92 u32 output_y_pos; ///< Same as above except for the Y pos.
93 u32 output_width_override; ///< Used for aligning the output width when larger than the output width. Overrides the output width when smaller than the output width.
94 u32 output_height_override; ///< Same as output_width_override except for the output height.
95 u32 unk_x118;
97
98typedef struct {
99 u32 end_vaddr;//"End-address of the processed NAL-unit(internal MVD heap vaddr)."
100 u32 end_physaddr;//"End-address of the processed NAL-unit(physaddr following the input physaddr)."
101 u32 remaining_size;//"Total remaining unprocessed input data. Buffer_end_pos=bufsize-<this value>."
103
104typedef struct {
105 void* outdata0;//Linearmem vaddr equivalent to config *_outdata0.
106 void* outdata1;//Linearmem vaddr equivalent to config *_outdata1.
108
109typedef struct {
110 u32 total_entries;//Total actual used entries below.
111 MVDSTD_OutputBuffersEntry entries[17];
113
114/// This can be used to override the default input values for MVDSTD commands during initialization with video-processing. The default for these fields are all-zero, except for cmd1b_inval which is 1. See also here: https://www.3dbrew.org/wiki/MVD_Services
115typedef struct {
116 s8 cmd5_inval0, cmd5_inval1, cmd5_inval2;
117 u32 cmd5_inval3;
118
119 u8 cmd1b_inval;
121
122typedef struct
123{
124 u8 enable; //Whether use this calculation method.
125 u8 flag; //Flag for calculation (MVD_CALC_WITH_LEVEL_FLAG_XXXXXX).
126 u8 double_size; //If set, size calculation result is doubled.
127 u8 level; //H.264 (AVC) level (MVD_H264_LEVEL_1_0 ~ MVD_H264_LEVEL_5_2).
129
130typedef struct
131{
132 u8 enable; //Whether use this calculation method.
133 u8 ref_frames; //Number of reference frames.
135
136/// H.264 buffer calculation configuration.
137/// See here for detailed explanations : https://www.3dbrew.org/wiki/MVDSTD:CalculateWorkBufSize.
138typedef struct {
139 u8 unused_0x00; //Unused.
140 MVDSTD_WithLevel level; //Calc buffer size with H.264 level.
141 MVDSTD_WithNumOfRefFrames ref_frames_a; //Calc buffer size with num of reference frames and resolution.
142 MVDSTD_WithNumOfRefFrames ref_frames_b; //Calc buffer size with num of reference frames and resolution.
143 u8 unused_0x09[3]; //Unused.
144 u32 unk_0x0c; //Unknown.
145 u32 unk_0x10; //Unknown.
146 u32 unk_0x14; //Unknown.
147 u32 unk_0x18; //Unknown.
148 u32 unk_0x1c; //Unknown.
149 u32 unk_0x20; //Unknown.
150 u32 unk_0x24; //Unknown.
151 u32 width; //Video width.
152 u32 height; //Video height.
154
155/**
156 * @brief Initializes MVDSTD.
157 * @param mode Mode to initialize MVDSTD to.
158 * @param input_type Type of input to process.
159 * @param output_type Type of output to produce.
160 * @param size Size of the work buffer, MVD_DEFAULT_WORKBUF_SIZE can be used for this. Only used when type == MVDMODE_VIDEOPROCESSING.
161 * @param initstruct Optional MVDSTD_InitStruct, this should be NULL normally.
162 */
164
165/// Shuts down MVDSTD.
166void mvdstdExit(void);
167
168/**
169 * @brief Calculate working buffer size for H.264 decoding.
170 * @param config Calculation config, config->level.level must NOT exceed MVD_H264_LEVEL_5_2. See here for more explanations : https://www.3dbrew.org/wiki/MVDSTD:CalculateWorkBufSize.
171 * @param size_out Calculated buffer size in bytes.
172 */
174
175/**
176 * @brief Generates a default MVDSTD configuration.
177 * @param config Pointer to output the generated config to.
178 * @param input_width Input width.
179 * @param input_height Input height.
180 * @param output_width Output width.
181 * @param output_height Output height.
182 * @param vaddr_colorconv_indata Virtual address of the color conversion input data.
183 * @param vaddr_outdata0 Virtual address of the output data.
184 * @param vaddr_outdata1 Additional virtual address for output data, only used when the output format type is value 0x00020001.
185 */
186void mvdstdGenerateDefaultConfig(MVDSTD_Config*config, u32 input_width, u32 input_height, u32 output_width, u32 output_height, u32 *vaddr_colorconv_indata, u32 *vaddr_outdata0, u32 *vaddr_outdata1);
187
188/**
189 * @brief Run color-format-conversion.
190 * @param config Pointer to the configuration to use.
191 */
193
194/**
195 * @brief Processes a video frame(specifically a NAL-unit).
196 * @param inbuf_vaddr Input NAL-unit starting with the 3-byte "00 00 01" prefix. Must be located in linearmem.
197 * @param size Size of the input buffer.
198 * @param flag See here regarding this input flag: https://www.3dbrew.org/wiki/MVDSTD:ProcessNALUnit
199 * @param out Optional output MVDSTD_ProcessNALUnitOut structure.
200 */
201Result mvdstdProcessVideoFrame(void* inbuf_vaddr, size_t size, u32 flag, MVDSTD_ProcessNALUnitOut *out);
202
203/**
204 * @brief Renders the video frame.
205 * @param config Optional pointer to the configuration to use. When NULL, MVDSTD_SetConfig() should have been used previously for this video.
206 * @param wait When true, wait for rendering to finish. When false, you can manually call this function repeatedly until it stops returning MVD_STATUS_BUSY.
207 */
209
210/**
211 * @brief Sets the current configuration of MVDSTD.
212 * @param config Pointer to the configuration to set.
213 */
215
216/**
217 * @brief New3DS Internet Browser doesn't use this. Once done, rendered frames will be written to the output buffers specified by the entrylist instead of the output specified by configuration. See here: https://www.3dbrew.org/wiki/MVDSTD:SetupOutputBuffers
218 * @param entrylist Input entrylist.
219 * @param bufsize Size of each buffer from the entrylist.
220 */
222
223/**
224 * @brief New3DS Internet Browser doesn't use this. This overrides the entry0 output buffers originally setup by mvdstdSetupOutputBuffers(). See also here: https://www.3dbrew.org/wiki/MVDSTD:OverrideOutputBuffers
225 * @param cur_outdata0 Linearmem vaddr. The current outdata0 for this entry must match this value.
226 * @param cur_outdata1 Linearmem vaddr. The current outdata1 for this entry must match this value.
227 * @param new_outdata0 Linearmem vaddr. This is the new address to use for outaddr0.
228 * @param new_outdata1 Linearmem vaddr. This is the new address to use for outaddr1.
229 */
230Result mvdstdOverrideOutputBuffers(void* cur_outdata0, void* cur_outdata1, void* new_outdata0, void* new_outdata1);
231
void mvdstdExit(void)
Shuts down MVDSTD.
Result MVDSTD_SetConfig(MVDSTD_Config *config)
Sets the current configuration of MVDSTD.
Result mvdstdSetupOutputBuffers(MVDSTD_OutputBuffersEntryList *entrylist, u32 bufsize)
New3DS Internet Browser doesn't use this.
MVDSTD_Mode
Processing mode.
Definition mvd.h:47
@ MVDMODE_VIDEOPROCESSING
Processing video.
Definition mvd.h:49
@ MVDMODE_COLORFORMATCONV
Converting color formats.
Definition mvd.h:48
Result mvdstdCalculateBufferSize(const MVDSTD_CalculateWorkBufSizeConfig *config, u32 *size_out)
Calculate working buffer size for H.264 decoding.
Result mvdstdRenderVideoFrame(MVDSTD_Config *config, bool wait)
Renders the video frame.
void mvdstdGenerateDefaultConfig(MVDSTD_Config *config, u32 input_width, u32 input_height, u32 output_width, u32 output_height, u32 *vaddr_colorconv_indata, u32 *vaddr_outdata0, u32 *vaddr_outdata1)
Generates a default MVDSTD configuration.
Result mvdstdInit(MVDSTD_Mode mode, MVDSTD_InputFormat input_type, MVDSTD_OutputFormat output_type, u32 size, MVDSTD_InitStruct *initstruct)
Initializes MVDSTD.
MVDSTD_InputFormat
Input format.
Definition mvd.h:53
@ MVD_INPUT_H264
H264.
Definition mvd.h:55
@ MVD_INPUT_YUYV422
YUYV422.
Definition mvd.h:54
MVDSTD_OutputFormat
Output format.
Definition mvd.h:59
@ MVD_OUTPUT_RGB565
RGB565.
Definition mvd.h:62
@ MVD_OUTPUT_BGR565
BGR565.
Definition mvd.h:61
@ MVD_OUTPUT_YUYV422
YUYV422.
Definition mvd.h:60
Result mvdstdOverrideOutputBuffers(void *cur_outdata0, void *cur_outdata1, void *new_outdata0, void *new_outdata1)
New3DS Internet Browser doesn't use this.
Result mvdstdConvertImage(MVDSTD_Config *config)
Run color-format-conversion.
Result mvdstdProcessVideoFrame(void *inbuf_vaddr, size_t size, u32 flag, MVDSTD_ProcessNALUnitOut *out)
Processes a video frame(specifically a NAL-unit).
H.264 buffer calculation configuration.
Definition mvd.h:138
Processing configuration.
Definition mvd.h:66
u32 output_y_pos
Same as above except for the Y pos.
Definition mvd.h:92
u32 unk_x04
Unknown.
Definition mvd.h:68
u32 physaddr_colorconv_unk2
Physical address used with color conversion.
Definition mvd.h:75
u32 output_height_override
Same as output_width_override except for the output height.
Definition mvd.h:94
MVDSTD_InputFormat input_type
Input type.
Definition mvd.h:67
u32 flag_x104
This enables using the following 4 words when non-zero.
Definition mvd.h:90
u32 outwidth
Output width.
Definition mvd.h:85
MVDSTD_OutputFormat output_type
Output type.
Definition mvd.h:84
u32 physaddr_outdata0
Physical address of output data.
Definition mvd.h:87
u32 inheight
Input height.
Definition mvd.h:71
u32 unk_x08
Unknown. Referred to as "H264 range" in SKATER.
Definition mvd.h:69
u32 outheight
Output height.
Definition mvd.h:86
u32 enable_cropping
Enables cropping with the input image when non-zero via the following 4 words.
Definition mvd.h:78
u32 physaddr_colorconv_unk0
Physical address used with color conversion.
Definition mvd.h:73
u32 output_x_pos
Output X position in the output buffer.
Definition mvd.h:91
u32 unk_x54
Unknown.
Definition mvd.h:83
u32 physaddr_colorconv_indata
Physical address of color conversion input data.
Definition mvd.h:72
u32 physaddr_colorconv_unk1
Physical address used with color conversion.
Definition mvd.h:74
u32 inwidth
Input width.
Definition mvd.h:70
u32 output_width_override
Used for aligning the output width when larger than the output width. Overrides the output width when...
Definition mvd.h:93
u32 physaddr_colorconv_unk3
Physical address used with color conversion.
Definition mvd.h:76
u32 physaddr_outdata1
Additional physical address for output data, only used when the output format type is value 0x0002000...
Definition mvd.h:88
This can be used to override the default input values for MVDSTD commands during initialization with ...
Definition mvd.h:115
Definition mvd.h:109
Definition mvd.h:104
Definition mvd.h:98
Definition mvd.h:123
Definition mvd.h:131
uint8_t u8
would be nice if newlib had this already
Definition types.h:21
int8_t s8
8-bit signed integer
Definition types.h:26
s32 Result
Function result.
Definition types.h:42
uint32_t u32
32-bit unsigned integer
Definition types.h:23