1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 /**************************************************************************/
12 /**************************************************************************/
13 /**                                                                       */
14 /** USBX Component                                                        */
15 /**                                                                       */
16 /**   Device Video Class                                                  */
17 /**                                                                       */
18 /**************************************************************************/
19 /**************************************************************************/
20 
21 #define UX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "ux_api.h"
27 #include "ux_device_class_video.h"
28 #include "ux_device_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_video_read_payload_get             PORTABLE C      */
36 /*                                                           6.3.0        */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function obtain payload access pointer from the Video class.   */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    stream                                Address of video stream       */
48 /*                                            instance                    */
49 /*    payload_data                          Pointer to buffer to save     */
50 /*                                          pointer to payload data       */
51 /*    payload_length                        Pointer to buffer to save     */
52 /*                                          Pointer to payload length     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application                                                         */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  04-25-2022     Chaoqiong Xiao           Initial Version 6.1.11        */
70 /*  10-31-2023     Yajun Xia                Modified comment(s),          */
71 /*                                            resulting in version 6.3.0  */
72 /*                                                                        */
73 /**************************************************************************/
_ux_device_class_video_read_payload_get(UX_DEVICE_CLASS_VIDEO_STREAM * stream,UCHAR ** payload_data,ULONG * payload_length)74 UINT _ux_device_class_video_read_payload_get(UX_DEVICE_CLASS_VIDEO_STREAM *stream,
75                                            UCHAR **payload_data, ULONG *payload_length)
76 {
77 
78 UX_SLAVE_ENDPOINT           *endpoint;
79 UX_SLAVE_DEVICE             *device;
80 
81 
82     /* Get the pointer to the device.  */
83     device =  &_ux_system_slave -> ux_system_slave_device;
84 
85     /* As long as the device is in the CONFIGURED state.  */
86     if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
87     {
88 
89         /* Cannot proceed with command, the interface is down.  */
90         return(UX_CONFIGURATION_HANDLE_UNKNOWN);
91     }
92 
93     /* Check if endpoint is available.  */
94     endpoint = stream -> ux_device_class_video_stream_endpoint;
95     if (endpoint == UX_NULL)
96         return(UX_ERROR);
97 
98     /* Check if endpoint direction is OK.  */
99     if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_OUT)
100         return(UX_ERROR);
101 
102     /* Underflow!!  */
103     if (stream -> ux_device_class_video_stream_access_pos -> ux_device_class_video_payload_length == 0)
104     {
105         return(UX_BUFFER_OVERFLOW);
106     }
107 
108     /* Obtain payload structure pointer.  */
109     *payload_data = stream -> ux_device_class_video_stream_access_pos -> ux_device_class_video_payload_data;
110     *payload_length = stream -> ux_device_class_video_stream_access_pos -> ux_device_class_video_payload_length;
111 
112     return(UX_SUCCESS);
113 }
114 
115 /**************************************************************************/
116 /*                                                                        */
117 /*  FUNCTION                                               RELEASE        */
118 /*                                                                        */
119 /*    _uxe_device_class_video_read_payload_get            PORTABLE C      */
120 /*                                                           6.3.0        */
121 /*  AUTHOR                                                                */
122 /*                                                                        */
123 /*    Yajun Xia, Microsoft Corporation                                    */
124 /*                                                                        */
125 /*  DESCRIPTION                                                           */
126 /*                                                                        */
127 /*    This function checks errors in video read payload get function      */
128 /*    call.                                                               */
129 /*                                                                        */
130 /*  INPUT                                                                 */
131 /*                                                                        */
132 /*    stream                                Address of video stream       */
133 /*                                            instance                    */
134 /*    payload_data                          Pointer to buffer to save     */
135 /*                                          pointer to payload data       */
136 /*    payload_length                        Pointer to buffer to save     */
137 /*                                          Pointer to payload length     */
138 /*                                                                        */
139 /*  OUTPUT                                                                */
140 /*                                                                        */
141 /*    None                                                                */
142 /*                                                                        */
143 /*  CALLS                                                                 */
144 /*                                                                        */
145 /*    _ux_device_class_video_read_payload_get                             */
146 /*                                          Video read payload get        */
147 /*                                                                        */
148 /*  CALLED BY                                                             */
149 /*                                                                        */
150 /*    Application                                                         */
151 /*                                                                        */
152 /*  RELEASE HISTORY                                                       */
153 /*                                                                        */
154 /*    DATE              NAME                      DESCRIPTION             */
155 /*                                                                        */
156 /*  10-31-2023     Yajun Xia                Initial Version 6.3.0         */
157 /*                                                                        */
158 /**************************************************************************/
_uxe_device_class_video_read_payload_get(UX_DEVICE_CLASS_VIDEO_STREAM * stream,UCHAR ** payload_data,ULONG * payload_length)159 UINT _uxe_device_class_video_read_payload_get(UX_DEVICE_CLASS_VIDEO_STREAM *stream,
160                                            UCHAR **payload_data, ULONG *payload_length)
161 {
162 
163     /* Sanity check. */
164     if ((stream == UX_NULL) || (payload_data == UX_NULL) || (payload_length == UX_NULL))
165         return(UX_INVALID_PARAMETER);
166 
167     /* Call the actual video read payload get function.  */
168     return(_ux_device_class_video_read_payload_get(stream, payload_data, payload_length));
169 }