refactored code and start work on streaming.
This commit is contained in:
38
src/frame.cxx
Normal file
38
src/frame.cxx
Normal file
@ -0,0 +1,38 @@
|
||||
#include "frame.h"
|
||||
|
||||
const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
|
||||
{
|
||||
Frame *f = (Frame *)malloc(sizeof(Frame));
|
||||
f->stream = stream;
|
||||
f->w = w;
|
||||
f->h = h;
|
||||
f->depth = depth;
|
||||
return f;
|
||||
}
|
||||
|
||||
FILE *make_buffer(const uint8_t *data, const size_t data_len)
|
||||
{
|
||||
FILE *file = fmemopen((void *)data, data_len, "r+");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
perror("Error opening file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Seek to the beginning of the file
|
||||
rewind(file);
|
||||
|
||||
// Write the data to the file
|
||||
fwrite(data, sizeof(uint8_t), data_len, file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
_FFI_PLUGIN
|
||||
const Frame *
|
||||
new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, int depth)
|
||||
{
|
||||
FILE *buf = make_buffer(data, data_len);
|
||||
return new_frame_from_handle(buf, w, h, depth);
|
||||
}
|
Reference in New Issue
Block a user