Squash  0.7.0
stream.h
1 /* Copyright (c) 2013-2015 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #ifndef SQUASH_STREAM_H
28 #define SQUASH_STREAM_H
29 
30 #if !defined (SQUASH_H_INSIDE) && !defined (SQUASH_COMPILATION)
31 #error "Only <squash/squash.h> can be included directly."
32 #endif
33 
34 SQUASH_BEGIN_DECLS
35 
36 typedef struct _SquashStreamPrivate SquashStreamPrivate;
37 
38 typedef enum {
42 
43 typedef enum {
44  SQUASH_STREAM_STATE_IDLE = 0,
45  SQUASH_STREAM_STATE_RUNNING = 1,
46  SQUASH_STREAM_STATE_FLUSHING = 2,
47  SQUASH_STREAM_STATE_FINISHING = 3,
48  SQUASH_STREAM_STATE_FINISHED = 4
49 } SquashStreamState;
50 
51 typedef enum {
57 
58 struct _SquashStream {
59  SquashObject base_object;
60  SquashStreamPrivate* priv;
61 
62  const uint8_t* next_in;
63  size_t avail_in;
64  size_t total_in;
65 
66  uint8_t* next_out;
67  size_t avail_out;
68  size_t total_out;
69 
70  SquashCodec* codec;
71  SquashOptions* options;
73  SquashStreamState state;
74 
75  void* user_data;
77 };
78 
79 SQUASH_API SquashStream* squash_stream_new (const char* codec,
80  SquashStreamType stream_type,
81  ...);
82 SQUASH_API SquashStream* squash_stream_newv (const char* codec,
83  SquashStreamType stream_type,
84  va_list options);
85 SQUASH_API SquashStream* squash_stream_newa (const char* codec,
86  SquashStreamType stream_type,
87  const char* const* keys,
88  const char* const* values);
89 SQUASH_API SquashStream* squash_stream_new_with_options (const char* codec,
90  SquashStreamType stream_type,
91  SquashOptions* options);
92 SQUASH_API SquashStream* squash_stream_new_codec (SquashCodec* codec,
93  SquashStreamType stream_type,
94  ...);
95 SQUASH_API SquashStream* squash_stream_new_codec_with_options (SquashCodec* codec,
96  SquashStreamType stream_type,
97  SquashOptions* options);
98 
99 SQUASH_API SquashStatus squash_stream_process (SquashStream* stream);
100 SQUASH_API SquashStatus squash_stream_flush (SquashStream* stream);
101 SQUASH_API SquashStatus squash_stream_finish (SquashStream* stream);
102 
103 SQUASH_API void squash_stream_init (void* stream,
104  SquashCodec* codec,
105  SquashStreamType stream_type,
106  SquashOptions* options,
107  SquashDestroyNotify destroy_notify);
108 SQUASH_API void squash_stream_destroy (void* stream);
109 
110 SQUASH_API SquashOperation squash_stream_yield (SquashStream* stream, SquashStatus status);
111 
112 SQUASH_END_DECLS
113 
114 #endif /* SQUASH_STREAM_H */
SquashStreamState state
State the stream is in.
Definition: stream.h:73
SQUASH_API SquashStatus squash_stream_finish(SquashStream *stream)
Finish writing to a stream.
Definition: stream.c:743
SQUASH_API SquashOperation squash_stream_yield(SquashStream *stream, SquashStatus status)
Yield execution back to the main thread.
Definition: stream.c:223
size_t avail_in
Size (in bytes) of available input.
Definition: stream.h:63
SquashOptions * options
Options used for this stream.
Definition: stream.h:71
SQUASH_API SquashStream * squash_stream_new_codec(SquashCodec *codec, SquashStreamType stream_type,...)
Create a new stream using a codec instance.
Definition: stream.c:471
void * user_data
User data.
Definition: stream.h:75
void(* SquashDestroyNotify)(void *data)
Callback to be invoked when information data is no longer needed.
Definition: object.h:43
SQUASH_API SquashStream * squash_stream_newa(const char *codec, SquashStreamType stream_type, const char *const *keys, const char *const *values)
Create a new stream with key/value option arrays.
Definition: stream.c:433
const uint8_t * next_in
The next input data to consume.
Definition: stream.h:62
A decompression stream.
Definition: stream.h:40
Private data for streams.
SQUASH_API SquashStream * squash_stream_new_codec_with_options(SquashCodec *codec, SquashStreamType stream_type, SquashOptions *options)
Create a new stream using codec and options intances.
Definition: stream.c:495
size_t avail_out
Number of bytes available in the output buffer.
Definition: stream.h:67
Compression/decompression streams.
Definition: stream.h:58
Continue processing the stream normally.
Definition: stream.h:52
SquashStreamType stream_type
Stream type.
Definition: stream.h:72
SquashDestroyNotify destroy_user_data
Squashlback to invoke on user_data when it is no longer necessary.
Definition: stream.h:76
SQUASH_API SquashStream * squash_stream_newv(const char *codec, SquashStreamType stream_type, va_list options)
Create a new stream with a variadic list of options.
Definition: stream.c:404
SQUASH_API SquashStatus squash_stream_flush(SquashStream *stream)
Flush a stream.
Definition: stream.c:732
SQUASH_API void squash_stream_init(void *stream, SquashCodec *codec, SquashStreamType stream_type, SquashOptions *options, SquashDestroyNotify destroy_notify)
Initialize a stream.
Definition: stream.c:277
SquashObject base_object
Base object.
Definition: stream.h:59
SquashStatus
Status codes.
Definition: status.h:36
Flush the stream.
Definition: stream.h:53
A compression stream.
Definition: stream.h:39
size_t total_out
Total number of bytes output.
Definition: stream.h:68
SQUASH_API SquashStream * squash_stream_new_with_options(const char *codec, SquashStreamType stream_type, SquashOptions *options)
Create a new stream with options.
Definition: stream.c:449
SquashOperation
Operations to perform on a stream.
Definition: stream.h:51
SquashCodec * codec
Codec used for this stream.
Definition: stream.h:70
SQUASH_API void squash_stream_destroy(void *stream)
Destroy a stream.
Definition: stream.c:342
size_t total_in
The total number of bytes input.
Definition: stream.h:64
SQUASH_API SquashStream * squash_stream_new(const char *codec, SquashStreamType stream_type,...)
Create a new stream.
Definition: stream.c:382
uint8_t * next_out
The buffer to write output to.
Definition: stream.h:66
SQUASH_API SquashStatus squash_stream_process(SquashStream *stream)
Process a stream.
Definition: stream.c:717
Finish processing the stream.
Definition: stream.h:54
SquashStreamType
Stream type.
Definition: stream.h:38
SquashStreamPrivate * priv
Private data.
Definition: stream.h:60