diff options
Diffstat (limited to 'src/liana/handlers')
| -rw-r--r-- | src/liana/handlers/cdio_server.c | 8 | ||||
| -rw-r--r-- | src/liana/handlers/codec_client.c | 35 | ||||
| -rw-r--r-- | src/liana/handlers/codec_server.c | 4 |
3 files changed, 30 insertions, 17 deletions
diff --git a/src/liana/handlers/cdio_server.c b/src/liana/handlers/cdio_server.c index d271829..641ed92 100644 --- a/src/liana/handlers/cdio_server.c +++ b/src/liana/handlers/cdio_server.c @@ -32,6 +32,8 @@ static void cdio_server_write_info(struct lia_server_handler *handler, struct ak aki_packet_write_u32(packet, 1); aki_packet_write_u8(packet, CAMU_NORMAL); aki_packet_write_u8(packet, CAMU_STREAM_AUDIO); + aki_packet_write_u64(packet, cdio->handler.get_duration(&cdio->handler)); + aki_packet_write_s32(packet, 0); aki_packet_write_s32(packet, cdio->fmt.format); aki_packet_write_s32(packet, cdio->fmt.sample_rate); aki_packet_write_s32(packet, cdio->fmt.channel_count); @@ -48,9 +50,9 @@ static u64 cdio_server_get_duration(struct lia_server_handler *handler) struct lia_cdio_server *cdio = (struct lia_cdio_server *)handler; struct cch_chapter *first = &al_array_at(cdio->handle->entry->chapters, 0); struct cch_chapter *last = &al_array_last(cdio->handle->entry->chapters); - f64 seconds = camu_audio_format_bytes_to_sec(&cdio->fmt, (last->end - first->start) * CDIO_CD_FRAMESIZE_RAW); - al_log_info("cdio", "Length: %.2fs.", seconds); - return (u64)(seconds * 1000000.0); + u64 length = camu_audio_format_bytes_to_usec(&cdio->fmt, (last->end - first->start) * CDIO_CD_FRAMESIZE_RAW); + al_log_info("cdio", "Length: %.2fs.", length / 1000000.0); + return length; } static bool cdio_server_seek(struct lia_server_handler *handler, u64 pos) diff --git a/src/liana/handlers/codec_client.c b/src/liana/handlers/codec_client.c index d420c59..7c57d03 100644 --- a/src/liana/handlers/codec_client.c +++ b/src/liana/handlers/codec_client.c @@ -21,13 +21,15 @@ static bool codec_client_init(struct lia_client_handler *handler, struct camu_re struct camu_codec_stream *stream) { struct lia_codec_client *codec = (struct lia_codec_client *)handler; - codec->dec = camu_ff_decoder_create(); - //codec->dec = camu_stbi_decoder_create(); - //codec->dec = camu_spng_decoder_create(); - //codec->dec = camu_wuffs_decoder_create(); codec->handler.stream = stream; - if (!codec->dec->init(codec->dec, renderer, stream, data_callback, codec)) { - return false; + if (stream->type == CAMU_STREAM_AUDIO || stream->type == CAMU_STREAM_VIDEO) { + codec->dec = camu_ff_decoder_create(); + //codec->dec = camu_stbi_decoder_create(); + //codec->dec = camu_spng_decoder_create(); + //codec->dec = camu_wuffs_decoder_create(); + if (!codec->dec->init(codec->dec, renderer, stream, data_callback, codec)) { + return false; + } } return true; } @@ -38,8 +40,6 @@ static bool push_av_packet(struct lia_codec_client *codec, AVPacket *pkt) struct camu_codec_packet packet; packet.av.pkt = pkt; s32 ret = codec->dec->push(codec->dec, &packet); - av_packet_unref(pkt); - av_packet_free(&pkt); return ret == CAMU_OK; } #endif @@ -56,7 +56,7 @@ static bool codec_client_handle_packet(struct lia_client_handler *handler, struc { struct lia_codec_client *codec = (struct lia_codec_client *)handler; if (!packet) { - struct lia_codec_client *codec = (struct lia_codec_client *)handler; + if (!codec->dec) return true; s32 ret = codec->dec->push(codec->dec, NULL); // Flush returns success. ret = codec->dec->process(codec->dec); @@ -68,6 +68,7 @@ static bool codec_client_handle_packet(struct lia_client_handler *handler, struc u8 type = aki_packet_read_u8(packet); switch (type) { case CAMU_NORMAL: { + if (!codec->dec) return true; struct aki_buffer buffer; aki_packet_read_buffer(packet, &buffer); success = push_packet(codec, &buffer); @@ -75,12 +76,20 @@ static bool codec_client_handle_packet(struct lia_client_handler *handler, struc } #ifdef CAMU_HAVE_FFMPEG case CAMU_FFMPEG_COMPAT: { - success = push_av_packet(codec, aki_packet_read_av_packet(packet)); + AVPacket *pkt = aki_packet_read_av_packet(packet); + if (!codec->dec) { + codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_SUBTITLE, codec->handler.stream, pkt); + return true; + } else { + success = push_av_packet(codec, pkt); + } + av_packet_unref(pkt); + av_packet_free(&pkt); break; } #endif } - // Forcing in EOF on errors is not necessary but should be a better experience client-side. + // Forcing in EOF on an error is not necessary but should be a better experience client-side. if (!success) { codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); return false; @@ -96,13 +105,13 @@ static bool codec_client_handle_packet(struct lia_client_handler *handler, struc static void codec_client_flush(struct lia_client_handler *handler) { struct lia_codec_client *codec = (struct lia_codec_client *)handler; - codec->dec->flush(codec->dec); + if (codec->dec) codec->dec->flush(codec->dec); } static void codec_client_free(struct lia_client_handler **handler) { struct lia_codec_client *codec = (struct lia_codec_client *)*handler; - codec->dec->free(&codec->dec); + if (codec->dec) codec->dec->free(&codec->dec); al_free(codec); *handler = NULL; } diff --git a/src/liana/handlers/codec_server.c b/src/liana/handlers/codec_server.c index 58da2e6..94b18df 100644 --- a/src/liana/handlers/codec_server.c +++ b/src/liana/handlers/codec_server.c @@ -42,9 +42,11 @@ static void codec_server_write_info(struct lia_server_handler *handler, struct a struct camu_codec_stream *stream; al_array_foreach_ptr(codec->demux->streams, i, stream) { aki_packet_write_u8(packet, stream->mode); + aki_packet_write_u8(packet, stream->type); + aki_packet_write_u64(packet, stream->duration); + aki_packet_write_s32(packet, i); switch (stream->mode) { case CAMU_NORMAL: { - aki_packet_write_u8(packet, stream->type); struct camu_video_format *fmt = &stream->video.fmt; aki_packet_write_s32(packet, fmt->width); aki_packet_write_s32(packet, fmt->height); |