libctru  v1.6.0
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 /// Processing mode.
24 typedef enum {
25  MVDMODE_COLORFORMATCONV, ///< Converting color formats.
26  MVDMODE_VIDEOPROCESSING ///< Processing video.
27 } MVDSTD_Mode;
28 
29 /// Input format.
30 typedef enum {
31  MVD_INPUT_YUYV422 = 0x00010001, ///< YUYV422
32  MVD_INPUT_H264 = 0x00020001 ///< H264
34 
35 /// Output format.
36 typedef enum {
37  MVD_OUTPUT_YUYV422 = 0x00010001, ///< YUYV422
38  MVD_OUTPUT_BGR565 = 0x00040002, ///< BGR565
39  MVD_OUTPUT_RGB565 = 0x00040004 ///< RGB565
41 
42 /// Processing configuration.
43 typedef struct {
44  MVDSTD_InputFormat input_type; ///< Input type.
45  u32 unk_x04; ///< Unknown.
46  u32 unk_x08; ///< Unknown. Referred to as "H264 range" in SKATER.
47  u32 inwidth; ///< Input width.
48  u32 inheight; ///< Input height.
49  u32 physaddr_colorconv_indata; ///< Physical address of color conversion input data.
50  u32 physaddr_colorconv_unk0; ///< Physical address used with color conversion.
51  u32 physaddr_colorconv_unk1; ///< Physical address used with color conversion.
52  u32 physaddr_colorconv_unk2; ///< Physical address used with color conversion.
53  u32 physaddr_colorconv_unk3; ///< Physical address used with color conversion.
54  u32 unk_x28[0x18>>2]; ///< Unknown.
55  u32 enable_cropping; ///< Enables cropping with the input image when non-zero via the following 4 words.
56  u32 input_crop_x_pos;
57  u32 input_crop_y_pos;
58  u32 input_crop_height;
59  u32 input_crop_width;
60  u32 unk_x54; ///< Unknown.
61  MVDSTD_OutputFormat output_type; ///< Output type.
62  u32 outwidth; ///< Output width.
63  u32 outheight; ///< Output height.
64  u32 physaddr_outdata0; ///< Physical address of output data.
65  u32 physaddr_outdata1; ///< Additional physical address for output data, only used when the output format type is value 0x00020001.
66  u32 unk_x6c[0x98>>2]; ///< Unknown.
67  u32 flag_x104; ///< This enables using the following 4 words when non-zero.
68  u32 output_x_pos; ///< Output X position in the output buffer.
69  u32 output_y_pos; ///< Same as above except for the Y pos.
70  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.
71  u32 output_height_override; ///< Same as output_width_override except for the output height.
72  u32 unk_x118;
74 
75 typedef struct {
76  u32 end_vaddr;//"End-address of the processed NAL-unit(internal MVD heap vaddr)."
77  u32 end_physaddr;//"End-address of the processed NAL-unit(physaddr following the input physaddr)."
78  u32 remaining_size;//"Total remaining unprocessed input data. Buffer_end_pos=bufsize-<this value>."
80 
81 typedef struct {
82  void* outdata0;//Linearmem vaddr equivalent to config *_outdata0.
83  void* outdata1;//Linearmem vaddr equivalent to config *_outdata1.
85 
86 typedef struct {
87  u32 total_entries;//Total actual used entries below.
88  MVDSTD_OutputBuffersEntry entries[17];
90 
91 /// 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
92 typedef struct {
93  s8 cmd5_inval0, cmd5_inval1, cmd5_inval2;
94  u32 cmd5_inval3;
95 
96  u8 cmd1b_inval;
98 
99 /**
100  * @brief Initializes MVDSTD.
101  * @param mode Mode to initialize MVDSTD to.
102  * @param input_type Type of input to process.
103  * @param output_type Type of output to produce.
104  * @param size Size of the work buffer, MVD_DEFAULT_WORKBUF_SIZE can be used for this. Only used when type == MVDMODE_VIDEOPROCESSING.
105  * @param initstruct Optional MVDSTD_InitStruct, this should be NULL normally.
106  */
107 Result mvdstdInit(MVDSTD_Mode mode, MVDSTD_InputFormat input_type, MVDSTD_OutputFormat output_type, u32 size, MVDSTD_InitStruct *initstruct);
108 
109 /// Shuts down MVDSTD.
110 void mvdstdExit(void);
111 
112 /**
113  * @brief Generates a default MVDSTD configuration.
114  * @param config Pointer to output the generated config to.
115  * @param input_width Input width.
116  * @param input_height Input height.
117  * @param output_width Output width.
118  * @param output_height Output height.
119  * @param vaddr_colorconv_indata Virtual address of the color conversion input data.
120  * @param vaddr_outdata0 Virtual address of the output data.
121  * @param vaddr_outdata1 Additional virtual address for output data, only used when the output format type is value 0x00020001.
122  */
123 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);
124 
125 /**
126  * @brief Run color-format-conversion.
127  * @param config Pointer to the configuration to use.
128  */
130 
131 /**
132  * @brief Processes a video frame(specifically a NAL-unit).
133  * @param inbuf_vaddr Input NAL-unit starting with the 3-byte "00 00 01" prefix. Must be located in linearmem.
134  * @param size Size of the input buffer.
135  * @param flag See here regarding this input flag: https://www.3dbrew.org/wiki/MVDSTD:ProcessNALUnit
136  * @param out Optional output MVDSTD_ProcessNALUnitOut structure.
137  */
138 Result mvdstdProcessVideoFrame(void* inbuf_vaddr, size_t size, u32 flag, MVDSTD_ProcessNALUnitOut *out);
139 
140 /**
141  * @brief Renders the video frame.
142  * @param config Optional pointer to the configuration to use. When NULL, MVDSTD_SetConfig() should have been used previously for this video.
143  * @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.
144  */
145 Result mvdstdRenderVideoFrame(MVDSTD_Config* config, bool wait);
146 
147 /**
148  * @brief Sets the current configuration of MVDSTD.
149  * @param config Pointer to the configuration to set.
150  */
152 
153 /**
154  * @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
155  * @param entrylist Input entrylist.
156  * @param bufsize Size of each buffer from the entrylist.
157  */
159 
160 /**
161  * @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
162  * @param cur_outdata0 Linearmem vaddr. The current outdata0 for this entry must match this value.
163  * @param cur_outdata1 Linearmem vaddr. The current outdata1 for this entry must match this value.
164  * @param new_outdata0 Linearmem vaddr. This is the new address to use for outaddr0.
165  * @param new_outdata1 Linearmem vaddr. This is the new address to use for outaddr1.
166  */
167 Result mvdstdOverrideOutputBuffers(void* cur_outdata0, void* cur_outdata1, void* new_outdata0, void* new_outdata1);
168 
Result mvdstdSetupOutputBuffers(MVDSTD_OutputBuffersEntryList *entrylist, u32 bufsize)
New3DS Internet Browser doesn't use this.
u32 enable_cropping
Enables cropping with the input image when non-zero via the following 4 words.
Definition: mvd.h:55
u32 unk_x54
Unknown.
Definition: mvd.h:60
int8_t s8
8-bit signed integer
Definition: types.h:26
Definition: mvd.h:75
u32 output_width_override
Used for aligning the output width when larger than the output width. Overrides the output width when...
Definition: mvd.h:70
s32 Result
Function result.
Definition: types.h:42
Converting color formats.
Definition: mvd.h:25
u32 physaddr_colorconv_unk1
Physical address used with color conversion.
Definition: mvd.h:51
u32 inwidth
Input width.
Definition: mvd.h:47
RGB565.
Definition: mvd.h:39
Processing video.
Definition: mvd.h:26
u32 outwidth
Output width.
Definition: mvd.h:62
u32 unk_x08
Unknown. Referred to as "H264 range" in SKATER.
Definition: mvd.h:46
u32 inheight
Input height.
Definition: mvd.h:48
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
u32 outheight
Output height.
Definition: mvd.h:63
MVDSTD_OutputFormat output_type
Output type.
Definition: mvd.h:61
u32 physaddr_colorconv_unk3
Physical address used with color conversion.
Definition: mvd.h:53
u32 output_y_pos
Same as above except for the Y pos.
Definition: mvd.h:69
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
u32 unk_x04
Unknown.
Definition: mvd.h:45
YUYV422.
Definition: mvd.h:31
Definition: mvd.h:81
u32 physaddr_outdata0
Physical address of output data.
Definition: mvd.h:64
u32 physaddr_colorconv_indata
Physical address of color conversion input data.
Definition: mvd.h:49
Definition: mvd.h:86
Result mvdstdRenderVideoFrame(MVDSTD_Config *config, bool wait)
Renders the video frame.
u32 physaddr_outdata1
Additional physical address for output data, only used when the output format type is value 0x0002000...
Definition: mvd.h:65
Result mvdstdProcessVideoFrame(void *inbuf_vaddr, size_t size, u32 flag, MVDSTD_ProcessNALUnitOut *out)
Processes a video frame(specifically a NAL-unit).
u32 output_x_pos
Output X position in the output buffer.
Definition: mvd.h:68
u32 physaddr_colorconv_unk2
Physical address used with color conversion.
Definition: mvd.h:52
BGR565.
Definition: mvd.h:38
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.
MVDSTD_OutputFormat
Output format.
Definition: mvd.h:36
This can be used to override the default input values for MVDSTD commands during initialization with ...
Definition: mvd.h:92
H264.
Definition: mvd.h:32
u32 physaddr_colorconv_unk0
Physical address used with color conversion.
Definition: mvd.h:50
Result mvdstdInit(MVDSTD_Mode mode, MVDSTD_InputFormat input_type, MVDSTD_OutputFormat output_type, u32 size, MVDSTD_InitStruct *initstruct)
Initializes MVDSTD.
Processing configuration.
Definition: mvd.h:43
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.
u32 flag_x104
This enables using the following 4 words when non-zero.
Definition: mvd.h:67
YUYV422.
Definition: mvd.h:37
void mvdstdExit(void)
Shuts down MVDSTD.
MVDSTD_InputFormat input_type
Input type.
Definition: mvd.h:44
MVDSTD_InputFormat
Input format.
Definition: mvd.h:30
Result MVDSTD_SetConfig(MVDSTD_Config *config)
Sets the current configuration of MVDSTD.
MVDSTD_Mode
Processing mode.
Definition: mvd.h:24
u32 output_height_override
Same as output_width_override except for the output height.
Definition: mvd.h:71