1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Video Class */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_host_class_video.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_video_format_data_get PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function finds the format data within the input terminal. */
46 /* */
47 /* INPUT */
48 /* */
49 /* video Pointer to video class */
50 /* format_parameter Format Parameter structure */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _ux_system_error_handler Log system error */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Video Class */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_ux_host_class_video_format_data_get(UX_HOST_CLASS_VIDEO * video,UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA * format_parameter)73 UINT _ux_host_class_video_format_data_get(UX_HOST_CLASS_VIDEO *video, UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA *format_parameter)
74 {
75
76 UCHAR *descriptor;
77 ULONG total_descriptor_length;
78 ULONG descriptor_length;
79 ULONG descriptor_type;
80 ULONG descriptor_subtype;
81
82
83 /* Get the descriptor to the selected format. */
84 descriptor = video -> ux_host_class_video_format_address;
85 total_descriptor_length = video -> ux_host_class_video_length_formats;
86
87 /* Descriptors are arranged in order. First FORMAT then FRAME. */
88 while (total_descriptor_length)
89 {
90
91 /* Gather the length, type and subtype of the descriptor. */
92 descriptor_length = *descriptor;
93 descriptor_type = *(descriptor + 1);
94 descriptor_subtype = *(descriptor + 2);
95
96 /* Make sure this descriptor has at least the minimum length. */
97 if (descriptor_length < 3)
98 {
99
100 /* Error trap. */
101 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED);
102
103 /* If trace is enabled, insert this event into the trace buffer. */
104 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0)
105
106 return(UX_DESCRIPTOR_CORRUPTED);
107 }
108
109 /* Must be CS_INTERFACE. */
110 if (descriptor_type == UX_HOST_CLASS_VIDEO_CS_INTERFACE)
111 {
112
113 /* Process relative to descriptor type. */
114 switch (descriptor_subtype)
115 {
116
117 case UX_HOST_CLASS_VIDEO_VS_FORMAT_UNCOMPRESSED :
118 case UX_HOST_CLASS_VIDEO_VS_FORMAT_MJPEG :
119 case UX_HOST_CLASS_VIDEO_VS_FORMAT_MPEG2TS :
120 case UX_HOST_CLASS_VIDEO_VS_FORMAT_DV :
121 case UX_HOST_CLASS_VIDEO_VS_FORMAT_FRAME_BASED :
122 case UX_HOST_CLASS_VIDEO_VS_FORMAT_STREAM_BASED :
123
124
125 /* We found a Format descriptor. Is it the right one ? */
126 if (format_parameter -> ux_host_class_video_parameter_format_requested == *(descriptor + 3))
127 {
128
129 /* Save the subtype for this format. */
130 format_parameter -> ux_host_class_video_parameter_format_subtype = descriptor_subtype;
131
132 /* Save the number of frame descriptors associated with this format. */
133 format_parameter -> ux_host_class_video_parameter_number_frame_descriptors = *(descriptor + 4);
134
135 /* Save the address of this format. */
136 video -> ux_host_class_video_current_format_address = descriptor;
137
138 /* And the current format index. */
139 video -> ux_host_class_video_current_format = format_parameter -> ux_host_class_video_parameter_format_requested;
140
141 /* We are done here. */
142 return(UX_SUCCESS);
143
144 }
145
146 break;
147
148 }
149 }
150
151 /* Verify if the descriptor is still valid. */
152 if (descriptor_length > total_descriptor_length)
153 {
154
155 /* Error trap. */
156 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED);
157
158 /* If trace is enabled, insert this event into the trace buffer. */
159 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0)
160
161 return(UX_DESCRIPTOR_CORRUPTED);
162 }
163
164 /* Jump to the next descriptor if we have not reached the end. */
165 descriptor += descriptor_length;
166
167 /* And adjust the length left to parse in the descriptor. */
168 total_descriptor_length -= descriptor_length;
169 }
170
171 /* Error trap. */
172 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_VIDEO_WRONG_TYPE);
173
174 /* We get here when either the report descriptor has a problem or we could
175 not find the right video device. */
176 return(UX_HOST_CLASS_VIDEO_WRONG_TYPE);
177 }
178
179