]> git.sesse.net Git - fjl/blobdiff - bytesource.h
Add a new input source converting JPEG-format bytes into unstuffed bytes.
[fjl] / bytesource.h
diff --git a/bytesource.h b/bytesource.h
new file mode 100644 (file)
index 0000000..fe17259
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef _BYTESOURCE_H
+#define _BYTESOURCE_H 1
+
+#include <stdint.h>
+#include <sys/types.h>
+
+static const unsigned BYTESOURCE_CHUNK_SIZE = 4096;
+
+// Same as input_func_t, although it expects raw bytes, ie. with markers
+// and all.
+typedef ssize_t (raw_input_func_t)(void*, uint8_t*, size_t);
+
+// A data source taking in a byte stream and returning unstuffed bytes until
+// there's a marker. When there's a marker, it artificially returns EOF until
+// byte_source_read_marker() is called.
+struct byte_source {
+       uint8_t* bytes;
+       unsigned bytes_available;
+
+       raw_input_func_t* input_func;
+       void* userdata;
+};
+void init_byte_source(struct byte_source* source, raw_input_func_t* input_func, void* userdata);
+uint8_t byte_source_read_marker(struct byte_source* source);
+ssize_t byte_source_input_func(void* source, uint8_t* buf, size_t len);
+
+#endif /* !defined(_BYTESOURCE_H) */