summaryrefslogtreecommitdiff
path: root/common/usbx_device_classes/src/ux_device_class_video_uninitialize.c
blob: a43680885bd4dd7e02d47f327d7e05d2522b2cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/

/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Device Video Class                                                  */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files.  */

#include "ux_api.h"
#include "ux_device_class_video.h"
#include "ux_device_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_device_class_video_uninitialize                 PORTABLE C      */
/*                                                           6.3.0        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function uninitialize the Video class.                         */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    command                               Pointer to a class command    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    Completion Status                                                   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_utility_thread_delete             Delete thread used            */
/*    _ux_utility_memory_free               Free used local memory        */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Device Video Class                                                  */
/*                                                                        */
/**************************************************************************/
UINT  _ux_device_class_video_uninitialize(UX_SLAVE_CLASS_COMMAND *command)
{

UX_DEVICE_CLASS_VIDEO           *video;
UX_DEVICE_CLASS_VIDEO_STREAM    *stream;
UX_SLAVE_CLASS                  *class_inst;
ULONG                            i;


    /* Get the class container.  */
    class_inst =  command -> ux_slave_class_command_class_ptr;

    /* Get the class instance in the container.  */
    video = (UX_DEVICE_CLASS_VIDEO *) class_inst -> ux_slave_class_instance;

    /* Sanity check.  */
    if (video != UX_NULL)
    {

        /* Free the stream resources.  */
        stream = (UX_DEVICE_CLASS_VIDEO_STREAM *)((UCHAR *)video + sizeof(UX_DEVICE_CLASS_VIDEO));
        for (i = 0; i < video -> ux_device_class_video_streams_nb; i ++)
        {
#if !defined(UX_DEVICE_STANDALONE)
            _ux_utility_thread_delete(&stream -> ux_device_class_video_stream_thread);
            _ux_utility_memory_free(stream -> ux_device_class_video_stream_thread_stack);
#endif
            _ux_utility_memory_free(stream -> ux_device_class_video_stream_buffer);

            /* Next stream instance.  */
            stream ++;
        }

        /* Free the video instance with controls and streams.  */
        _ux_utility_memory_free(video);
    }

    /* Return completion status.  */
    return(UX_SUCCESS);
}