psxbios: don't limit pointers to ram
[pcsx_rearmed.git] / deps / libretro-common / include / streams / trans_stream.h
1 /* Copyright  (C) 2010-2020 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (trans_stream.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22
23 #ifndef LIBRETRO_SDK_TRANS_STREAM_H__
24 #define LIBRETRO_SDK_TRANS_STREAM_H__
25
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <boolean.h>
29
30 #ifdef _WIN32
31 #include <direct.h>
32 #else
33 #include <unistd.h>
34 #endif
35
36 #include <retro_miscellaneous.h>
37
38 #include <retro_common_api.h>
39
40 RETRO_BEGIN_DECLS
41
42 enum trans_stream_error
43 {
44     TRANS_STREAM_ERROR_NONE = 0,
45     TRANS_STREAM_ERROR_AGAIN, /* more work to do */
46     TRANS_STREAM_ERROR_ALLOCATION_FAILURE, /* malloc failure */
47     TRANS_STREAM_ERROR_INVALID, /* invalid state */
48     TRANS_STREAM_ERROR_BUFFER_FULL, /* output buffer full */
49     TRANS_STREAM_ERROR_OTHER
50 };
51
52 struct trans_stream_backend
53 {
54    const char *ident;
55    const struct trans_stream_backend *reverse;
56
57    /* Create a stream data structure */
58    void *(*stream_new)(void);
59
60    /* Free it */
61    void  (*stream_free)(void *);
62
63    /* (Optional) Set extra properties, defined per transcoder */
64    bool  (*define)(void *, const char *, uint32_t);
65
66    /* Set our input source */
67    void  (*set_in)(void *, const uint8_t *, uint32_t);
68
69    /* Set our output target */
70    void  (*set_out)(void *, uint8_t *, uint32_t);
71
72    /* Perform a transcoding, flushing/finalizing if asked to. Writes out how
73     * many bytes were read and written. Error target optional. */
74    bool  (*trans)(void *, bool, uint32_t *, uint32_t *, enum trans_stream_error *);
75 };
76
77 /**
78  * trans_stream_trans_full:
79  * @backend                     : transcoding backend
80  * @data                        : (optional) existing stream data, or a target
81  *                                for the new stream data to be saved
82  * @in                          : input data
83  * @in_size                     : input size
84  * @out                         : output data
85  * @out_size                    : output size
86  * @error                       : (optional) output for error code
87  *
88  * Perform a full transcoding from a source to a destination.
89  */
90 bool trans_stream_trans_full(
91     struct trans_stream_backend *backend, void **data,
92     const uint8_t *in, uint32_t in_size,
93     uint8_t *out, uint32_t out_size,
94     enum trans_stream_error *error);
95
96 const struct trans_stream_backend* trans_stream_get_zlib_deflate_backend(void);
97 const struct trans_stream_backend* trans_stream_get_zlib_inflate_backend(void);
98 const struct trans_stream_backend* trans_stream_get_pipe_backend(void);
99
100 extern const struct trans_stream_backend zlib_deflate_backend;
101 extern const struct trans_stream_backend zlib_inflate_backend;
102 extern const struct trans_stream_backend pipe_backend;
103
104 RETRO_END_DECLS
105
106 #endif