summaryrefslogtreecommitdiff
path: root/src/codec/spng
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-10-21 19:22:50 -0400
committerAndrew Opalach <andrew@akon.city> 2024-10-21 19:22:50 -0400
commit60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2 (patch)
tree08ff2ce7975f523112e7ad2fe4f797b4fc7db5de /src/codec/spng
parent2f9a0945bfeee3296cec3d38d094e4c49f9cb65f (diff)
downloadcamu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.tar.gz
camu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.tar.bz2
camu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.zip
Everything before initial synced list
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/codec/spng')
-rw-r--r--src/codec/spng/decoder.h3
-rw-r--r--src/codec/spng/impl.c59
2 files changed, 30 insertions, 32 deletions
diff --git a/src/codec/spng/decoder.h b/src/codec/spng/decoder.h
index fee30c6..c027fce 100644
--- a/src/codec/spng/decoder.h
+++ b/src/codec/spng/decoder.h
@@ -4,7 +4,8 @@
struct camu_spng_decoder {
struct camu_decoder dec;
- void (*callback)(void *, struct camu_frame *);
+ struct camu_codec_stream *stream;
+ void (*callback)(void *, struct camu_codec_frame *);
void (*userdata);
};
diff --git a/src/codec/spng/impl.c b/src/codec/spng/impl.c
index 9089e99..198d514 100644
--- a/src/codec/spng/impl.c
+++ b/src/codec/spng/impl.c
@@ -31,10 +31,12 @@ static bool spng_demuxer_init(struct camu_demuxer *demux, struct cch_handle *han
struct spng_ihdr ihdr;
spng_get_ihdr(ctx, &ihdr);
- struct camu_stream stream;
- stream.type = CAMU_NORMAL;
+ struct camu_codec_stream stream;
+ stream.mode = CAMU_NORMAL;
+ stream.type = CAMU_STREAM_VIDEO;
stream.video.width = ihdr.width;
stream.video.height = ihdr.height;
+ stream.video.format = CAMU_PIXEL_FORMAT_RGBA;
al_array_push(spng->demux.streams, stream);
@@ -43,14 +45,16 @@ static bool spng_demuxer_init(struct camu_demuxer *demux, struct cch_handle *han
return true;
}
-static s32 spng_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet *packet)
+static s32 spng_demuxer_get_packet(struct camu_demuxer *demux, struct camu_codec_packet *packet)
{
struct camu_spng_demuxer *spng = (struct camu_spng_demuxer *)demux;
- if (spng->eof) return CAMU_ERR_EOF;
- packet->type = CAMU_NORMAL;
- packet->buffer = &spng->buffer;
- spng->eof = true;
- return CAMU_OK;
+ if (!spng->eof) {
+ packet->mode = CAMU_NORMAL;
+ packet->buffer = &spng->buffer;
+ spng->eof = true;
+ return CAMU_OK;
+ }
+ return CAMU_ERR_EOF;
}
static u64 spng_demuxer_get_duration(struct camu_demuxer *demux)
@@ -69,31 +73,27 @@ static bool spng_demuxer_seek(struct camu_demuxer *demux, u64 pos)
static void spng_demuxer_free(struct camu_demuxer **demux)
{
struct camu_spng_demuxer *spng = (struct camu_spng_demuxer *)*demux;
+ aki_buffer_free(&spng->buffer);
+ al_array_free(spng->demux.streams);
al_free(spng);
*demux = NULL;
}
-static bool spng_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_stream *stream)
+static bool spng_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_codec_stream *stream,
+ void (*callback)(void *, struct camu_codec_frame *), void *userdata)
{
struct camu_spng_decoder *spng = (struct camu_spng_decoder *)dec;
- (void)spng;
- (void)stream;
(void)renderer;
- return true;
-}
-
-static void spng_decoder_set_callback(struct camu_decoder *dec, void (*callback)(void *, struct camu_frame *), void *userdata)
-{
- struct camu_spng_decoder *spng = (struct camu_spng_decoder *)dec;
+ spng->stream = stream;
spng->callback = callback;
spng->userdata = userdata;
+ return true;
}
-static s32 spng_decoder_push(struct camu_decoder *dec, struct camu_packet *packet)
+static s32 spng_decoder_push(struct camu_decoder *dec, struct camu_codec_packet *packet)
{
- if (!packet) return CAMU_OK;
-
struct camu_spng_decoder *spng = (struct camu_spng_decoder *)dec;
+ if (!packet) return CAMU_OK;
spng_ctx *ctx = spng_ctx_new(SPNG_CTX_IGNORE_ADLER32);
spng_set_png_buffer(ctx, aki_buffer_get_ptr(packet->buffer, 0), packet->buffer->size);
@@ -103,19 +103,17 @@ static s32 spng_decoder_push(struct camu_decoder *dec, struct camu_packet *packe
size_t out_size;
spng_decoded_image_size(ctx, SPNG_FMT_RGBA8, &out_size);
- struct camu_frame *frame = al_alloc_object(struct camu_frame);
- frame->type = CAMU_NORMAL;
- frame->width = spng->dec.stream->video.width;
- frame->height = spng->dec.stream->video.height;
- frame->fmt = CAMU_PIXEL_FMT_RGBA;
- frame->pts = 0.0;
- frame->flags = 0;
-
+ struct camu_codec_frame *frame = al_alloc_object(struct camu_codec_frame);
+ frame->mode = CAMU_NORMAL;
frame->data = camu_page_alloc(out_size);
spng_decode_chunks(ctx);
spng_decode_image(ctx, frame->data, out_size, SPNG_FMT_RGBA8, 0);
-
spng_ctx_free(ctx);
+ frame->flags = 0;
+ frame->format = CAMU_PIXEL_FORMAT_RGBA;
+ frame->width = spng->stream->video.width;
+ frame->height = spng->stream->video.height;
+ frame->pts = 0.0;
spng->callback(spng->userdata, frame);
@@ -143,7 +141,7 @@ static void spng_decoder_free(struct camu_decoder **dec)
struct camu_demuxer *camu_spng_demuxer_create(void)
{
struct camu_spng_demuxer *spng = al_alloc_object(struct camu_spng_demuxer);
- spng->demux.type = CAMU_NORMAL;
+ spng->demux.mode = CAMU_NORMAL;
al_array_init(spng->demux.streams);
spng->demux.init = spng_demuxer_init;
spng->demux.get_packet = spng_demuxer_get_packet;
@@ -157,7 +155,6 @@ struct camu_decoder *camu_spng_decoder_create(void)
{
struct camu_spng_decoder *spng = al_alloc_object(struct camu_spng_decoder);
spng->dec.init = spng_decoder_init;
- spng->dec.set_callback = spng_decoder_set_callback;
spng->dec.push = spng_decoder_push;
spng->dec.process = spng_decoder_process;
spng->dec.flush = spng_decoder_flush;