Debian Codegraph @

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

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 25 апр. 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_MMIOWRITER_H_
23 #define PRIVATE_MM_MMIOWRITER_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #ifdef PLATFORM_WINDOWS
28
29 #include <lsp-plug.in/common/types.h>
30 #include <lsp-plug.in/common/status.h>
31 #include <lsp-plug.in/runtime/LSPString.h>
32
33 #include <windows.h>
34 #include <mmsystem.h>
35 #include <mmreg.h>
36
37 namespace lsp
38 {
39 namespace mm
40 {
41 /**
42 * Audio file writer using MMIO subsystem
43 */
44 class MMIOWriter
45 {
46 private:
47 MMIOWriter & operator = (const MMIOWriter &);
48
49 protected:
50 HMMIO hMMIO;
51 wsize_t nWritePos;
52 wsize_t nDataSize;
53 wssize_t nFrames;
54 bool bSeekable;
55 MMCKINFO ckRiff;
56 MMCKINFO ckData;
57 MMCKINFO ckFact;
58
59 protected:
60 status_t finalize_riff_file();
61 status_t write_padded(const void *buf, size_t count);
62
63 public:
64 explicit MMIOWriter();
65 virtual ~MMIOWriter();
66
67 public:
68 /**
69 * Check whether reader is seekable
70 * @return true if reader is seekable
71 */
72 inline bool seekable() const { return bSeekable; }
73
74 /**
75 * Set number of frames
76 * @param frames number of frames written
77 */
78 inline void set_frames(wssize_t frames) { nFrames = frames; }
79
80 /**
81 * Open audio file for writing
82 * @param path path to the file
83 * @param fmt output audio format
84 * @param frames number of frames
85 * @return status of operation
86 */
87 status_t open(const LSPString *path, WAVEFORMATEX *fmt, wssize_t frames);
88
89 /**
90 * Seek to the specified location
91 * @param offset offset in bytes from the beginning of data chunk
92 * @return actual offset in bytes from the beginning of data chunk
93 */
94 wssize_t seek(wsize_t offset);
95
96 /**
97 * Write number of bytes into buffer
98 * @param buf pointer to buffer to write
99 * @param count number of bytes to write
100 * @return actual bytes written or negative error code
101 */
102 ssize_t write(const void *buf, size_t count);
103
104 /**
105 * Close the file
106 * @return status of operation
107 */
108 status_t close(status_t code = STATUS_OK);
109
110 /**
111 * Flush pending write operations
112 * @return status of operation
113 */
114 status_t flush();
115 };
116
117 } /* namespace mm */
118 } /* namespace lsp */
119
120 #endif /* PLATFORM_WINDOWS */
121
122 #endif /* PRIVATE_MM_MMIOWRITER_H_ */