Debian Codegraph @

modules/lsp-runtime-lib/include/private/mm/ACMStream.h

raw
1 /*
2 * Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2024 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 24 апр. 2020 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef PRIVATE_MM_ACMSTREAM_H_
23 #define PRIVATE_MM_ACMSTREAM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #include <lsp-plug.in/common/types.h>
28
29 #ifdef PLATFORM_WINDOWS
30
31 #include <lsp-plug.in/common/status.h>
32 #include <lsp-plug.in/lltl/darray.h>
33 #include <lsp-plug.in/lltl/parray.h>
34
35 #include <windows.h>
36 #include <mmreg.h>
37 #include <msacm.h>
38
39 namespace lsp
40 {
41 namespace mm
42 {
43 /**
44 * This is Windows-specific only data conversion class
45 * responsible for multimedia conversion
46 */
47 class ACMStream
48 {
49 private:
50 ACMStream & operator = (const ACMStream &);
51
52 public:
53 static const size_t IO_BUF_SIZE = 0x2000;
54
55 protected:
56 // ACM Format descriptor
57 typedef struct fmt_t
58 {
59 size_t id; // Format index
60 size_t fdw; // Format flags
61 WAVEFORMATEX *wfex; // Format descriptor
62 } fmt_t;
63
64 // ACM Format tag
65 typedef struct fmt_tag_t
66 {
67 size_t id; // Tag index
68 size_t fdw; // Format flags
69 LSPString name; // Tag name
70 lltl::darray<fmt_t> vfmt; // List of formats
71 } fmt_tag_t;
72
73 // ACM driver
74 typedef struct drv_t
75 {
76 HACMDRIVERID drv_id; // ACM Driver identifier
77 size_t pwfx_sz; // Maximum size fo WAVEFORMATEX struct
78 LSPString short_name;
79 LSPString full_name;
80 LSPString copyright;
81 LSPString license;
82 LSPString features;
83 lltl::parray<fmt_tag_t> vtag; // List of tags
84 } drv_t;
85
86 typedef struct drv_lookup_t
87 {
88 ACMDRIVERDETAILSW dd; // Driver details
89 HACMDRIVER hd; // Driver handle
90 ACMFORMATTAGDETAILSW ftd; // Details for current format tag
91 ACMFORMATDETAILSW fd; // Format details
92 WAVEFORMATEX *req; // Requested format details
93 DWORD req_sz; // Requested format maximum size
94
95 lltl::parray<drv_t> vdrv; // Complete list of drivers
96 drv_t *pdrv; // Current driver
97 fmt_tag_t *ptag; // Current tag
98 fmt_t *pfmt; // Current format
99 } drv_lookup_t;
100
101 protected:
102 WAVEFORMATEX *pFmtIn;
103 WAVEFORMATEX *pFmtOut;
104 HACMDRIVER hDriver;
105 HACMSTREAM hStream;
106 ACMSTREAMHEADER *pHeader;
107 lltl::parray<drv_t> vDrv;
108
109 protected:
110 static WAVEFORMATEX *copy_fmt(const WAVEFORMATEX *src);
111
112 protected:
113 static WINBOOL CALLBACK acm_driver_enum_cb(HACMDRIVERID hadid, DWORD_PTR dwInstance, DWORD fdwSupport);
114
115 static void acm_query_format_tags(drv_lookup_t *s);
116 static void acm_query_formats(drv_lookup_t *s);
117 static status_t acm_enum_drivers(lltl::parray<drv_t> *res);
118 static void acm_destroy_drivers(lltl::parray<drv_t> *res);
119 static fmt_tag_t *acm_find_tag(drv_t *drv, size_t fmt_tag);
120 static fmt_t *acm_select_format(fmt_t *best, fmt_t *curr, WAVEFORMATEX *req);
121
122 status_t acm_configure_stream(WAVEFORMATEX *dst, WAVEFORMATEX *src);
123 status_t acm_try_format_dec(WAVEFORMATEX *to, WAVEFORMATEX *from);
124 status_t acm_try_format_enc(HACMDRIVER drv, WAVEFORMATEX *to, WAVEFORMATEX *from, size_t szof);
125 status_t acm_find_nonstandard_dec(WAVEFORMATEX *fmt);
126 status_t acm_find_standard_dec(WAVEFORMATEX *fmt);
127 status_t acm_suggest_format_enc(WAVEFORMATEX *fmt);
128
129 public:
130 explicit ACMStream();
131 ~ACMStream();
132
133 public:
134 /**
135 * Get input stream format
136 * @return input stream format
137 */
138 inline WAVEFORMATEX *in_format() { return pFmtIn; }
139
140 /**
141 * Get output stream format
142 * @return output stream format
143 */
144 inline WAVEFORMATEX *out_format() { return pFmtOut; }
145
146 /**
147 * Reserve space for writing data
148 * @param buf pointer to return pointer to the buffer (may be NULL)
149 * @return number of bytes available for write or negative error code
150 */
151 ssize_t push(void **buf);
152
153 /**
154 * Commit the push
155 * @param bytes number of bytes read into push buffer returned by push()
156 */
157 inline void commit(size_t bytes) { pHeader->cbSrcLength += bytes; };
158
159 /**
160 * Perform conversion and fetch data into buffer
161 * @param buf pointer to buffer to perform read
162 * @param size maximum number of bytes to pull
163 * @param force retrieve last (final) portion of data
164 * @return number of bytes stored into buffer or negative error code
165 */
166 ssize_t pull(void **buf, size_t size, bool force);
167
168 /**
169 * Get number of bytes available for pulling
170 * @return number of bytes available for pulling
171 */
172 size_t avail();
173
174 /**
175 * Initialize ACM stream for reading PCM stream described
176 * by the specific format
177 * @param in the input stream format
178 * @return status of operation
179 */
180 status_t read_pcm(WAVEFORMATEX *in);
181
182 /**
183 * Initialize ACM stream for writing PCM stream described
184 * by the specific format
185 * @param out the output stream format
186 * @return status of operation
187 */
188 status_t write_pcm(WAVEFORMATEX *out);
189
190 /**
191 * Close ACM stream
192 * @param res the result to return
193 * @return status of operation
194 */
195 status_t close(status_t res = STATUS_OK);
196 };
197
198 } /* namespace mm */
199 } /* namespace lsp */
200
201 #endif /* PLATFORM_WINDOWS */
202
203 #endif /* PRIVATE_MM_ACMSTREAM_H_ */