diff options
Diffstat (limited to 'src/liana')
| -rw-r--r-- | src/liana/handlers/codec_client.c | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/liana/handlers/codec_client.c b/src/liana/handlers/codec_client.c index 7c57d03..f15b3f8 100644 --- a/src/liana/handlers/codec_client.c +++ b/src/liana/handlers/codec_client.c @@ -55,50 +55,68 @@ static bool push_packet(struct lia_codec_client *codec, struct aki_buffer *buffe static bool codec_client_handle_packet(struct lia_client_handler *handler, struct aki_packet *packet) { struct lia_codec_client *codec = (struct lia_codec_client *)handler; + + // NULL packet = flush. if (!packet) { - if (!codec->dec) return true; - s32 ret = codec->dec->push(codec->dec, NULL); - // Flush returns success. - ret = codec->dec->process(codec->dec); - // process() could still error. - codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); - return ret == CAMU_ERR_EOF; + if (codec->dec) { + s32 ret = codec->dec->push(codec->dec, NULL); + // Flush always returns success. + ret = codec->dec->process(codec->dec); + // process() could still error. + codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); + return ret == CAMU_ERR_EOF; + } else { + return true; + } } - bool success = false; + + // Push packet. + bool success; 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); + if (codec->dec) { + struct aki_buffer buffer; + aki_packet_read_buffer(packet, &buffer); + success = push_packet(codec, &buffer); + } else { + success = true; + } break; } #ifdef CAMU_HAVE_FFMPEG case CAMU_FFMPEG_COMPAT: { 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 { + if (codec->dec) { success = push_av_packet(codec, pkt); + } else { + codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_SUBTITLE, codec->handler.stream, pkt); + success = true; } av_packet_unref(pkt); av_packet_free(&pkt); break; } + default: + al_assert_and_return(false); #endif } - // Forcing in EOF on an error is not necessary but should be a better experience client-side. + if (!success) { + // Forcing in EOF on an error is not necessary but should exhibit less erratic behavior sink-side. codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); return false; } - s32 ret = codec->dec->process(codec->dec); - if (!(ret == CAMU_ERR_AGAIN || ret == CAMU_ERR_EOF)) { - codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); - return false; + + // Process, if needed. + if (codec->dec) { + s32 ret = codec->dec->process(codec->dec); + if (!(ret == CAMU_ERR_AGAIN || ret == CAMU_ERR_EOF)) { + codec->handler.callback(codec->handler.userdata, LIANA_CLIENT_EOF, codec->handler.stream, NULL); + return false; + } } + return true; } |