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_max_payload_length           PORTABLE C      */
36 /*                                                           6.1.11       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function return max payload length in the Video stream.        */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    stream                                Address of video stream       */
48 /*                                            instance                    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application                                                         */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  04-25-2022     Chaoqiong Xiao           Initial Version 6.1.11        */
67 /*                                                                        */
68 /**************************************************************************/
_ux_device_class_video_max_payload_length(UX_DEVICE_CLASS_VIDEO_STREAM * stream)69 ULONG _ux_device_class_video_max_payload_length(UX_DEVICE_CLASS_VIDEO_STREAM *stream)
70 {
71 
72 UX_SLAVE_ENDPOINT           *endpoint;
73 UX_SLAVE_DEVICE             *device;
74 
75 
76     /* Get the pointer to the device.  */
77     device =  &_ux_system_slave -> ux_system_slave_device;
78 
79     /* As long as the device is in the CONFIGURED state.  */
80     if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
81         return(0);
82 
83     /* Check if endpoint is available.  */
84     endpoint = stream -> ux_device_class_video_stream_endpoint;
85     if (endpoint == UX_NULL)
86         return(0);
87 
88     /* Return enumerated payload size.  */
89     return(endpoint -> ux_slave_endpoint_transfer_request.
90                                     ux_slave_transfer_request_transfer_length);
91 }
92 
93 /**************************************************************************/
94 /*                                                                        */
95 /*  FUNCTION                                               RELEASE        */
96 /*                                                                        */
97 /*    _uxe_device_class_video_max_payload_length          PORTABLE C      */
98 /*                                                           6.3.0        */
99 /*  AUTHOR                                                                */
100 /*                                                                        */
101 /*    Yajun Xia, Microsoft Corporation                                    */
102 /*                                                                        */
103 /*  DESCRIPTION                                                           */
104 /*                                                                        */
105 /*    This function checks errors in getting video stream max payload     */
106 /*    length function call.                                               */
107 /*                                                                        */
108 /*  INPUT                                                                 */
109 /*                                                                        */
110 /*    stream                                Address of video stream       */
111 /*                                            instance                    */
112 /*                                                                        */
113 /*  OUTPUT                                                                */
114 /*                                                                        */
115 /*    None                                                                */
116 /*                                                                        */
117 /*  CALLS                                                                 */
118 /*                                                                        */
119 /*    _ux_device_class_video_max_payload_length                           */
120 /*                                          Get max payload length in the */
121 /*                                            video stream.               */
122 /*                                                                        */
123 /*  CALLED BY                                                             */
124 /*                                                                        */
125 /*    Application                                                         */
126 /*                                                                        */
127 /*  RELEASE HISTORY                                                       */
128 /*                                                                        */
129 /*    DATE              NAME                      DESCRIPTION             */
130 /*                                                                        */
131 /*  10-31-2023     Yajun Xia                Initial Version 6.3.0         */
132 /*                                                                        */
133 /**************************************************************************/
_uxe_device_class_video_max_payload_length(UX_DEVICE_CLASS_VIDEO_STREAM * stream)134 ULONG _uxe_device_class_video_max_payload_length(UX_DEVICE_CLASS_VIDEO_STREAM *stream)
135 {
136 
137     /* Sanity check. */
138     if (stream == UX_NULL)
139         return(0);
140 
141     /* Call the actual function.  */
142     return(_ux_device_class_video_max_payload_length(stream));
143 }