diff --git a/src/audio_core/adsp/apps/opus/opus_decoder.cpp b/src/audio_core/adsp/apps/opus/opus_decoder.cpp index 207e5dd158..f9737f0f92 100644 --- a/src/audio_core/adsp/apps/opus/opus_decoder.cpp +++ b/src/audio_core/adsp/apps/opus/opus_decoder.cpp @@ -58,6 +58,7 @@ public: /// idempotency of initialize is guaranteed Result InitializeDecoder(u32 sample_rate, u32 total_stream_count, u32 channel_count, u32 stereo_stream_count, u8 const* mappings) { + LOG_INFO(Audio_DSP, "sample_rate={}, total_stream_count={}, channel_count={}, stereo_stream_count={}, mappings={}", sample_rate, total_stream_count, channel_count, stereo_stream_count, fmt::ptr(mappings)); // prefer libopus, ffmpeg docs say to use libopus **if** available // However, native opus can also work with swrescale: // it uses planarfloat, we can resample to s16 @@ -67,8 +68,6 @@ public: LOG_WARNING(Audio_DSP, "using ffmpeg native opus decoder"); codec = avcodec_find_decoder(AV_CODEC_ID_OPUS); } - // handles null codec - avcodec_free_context(&avc); if ((avc = avcodec_alloc_context3(codec))) { if (is_libopus) { const std::array mapping_arr{0, 1}; @@ -121,6 +120,7 @@ public: } Result Shutdown() { + LOG_INFO(Audio_DSP, "called avc={}", fmt::ptr(avc)); av_freep(stg_arr); swr_free(&swr); av_frame_free(&frame); @@ -130,6 +130,7 @@ public: } Result ResetDecoder() { + LOG_INFO(Audio_DSP, "called avc={}", fmt::ptr(avc)); if (avc) { if (avcodec_is_open(avc)) avcodec_flush_buffers(avc); return ResultSuccess; @@ -138,15 +139,22 @@ public: } Result Decode(u32& out_sample_count, u64 output_data, u64 output_data_size, u64 input_data, u64 input_data_size) { + LOG_INFO(Audio_DSP, "called out_sample_count={},output_data={:#x},output_data_size={},input_data={:#x},input_data_size={}", fmt::ptr(&out_sample_count), output_data, output_data_size, input_data, input_data_size); + ASSERT(avc); + out_sample_count = 0; if (input_data_size == 0 || output_data_size == 0) return Service::Audio::ResultLibOpusInvalidPacket; + if (avc) { int r; + LOG_INFO(Audio_DSP, "old packet data={}", fmt::ptr(pkt->data)); if ((r = av_new_packet(pkt, int(input_data_size))) >= 0) { + LOG_INFO(Audio_DSP, "new packet data={}", fmt::ptr(pkt->data)); std::memcpy(pkt->data, reinterpret_cast(input_data), input_data_size); if ((r = avcodec_send_packet(avc, pkt)) >= 0) { while ((r = avcodec_receive_frame(avc, frame)) >= 0) { + LOG_INFO(Audio_DSP, "frame data={},data[0]={},nb_samples={}", fmt::ptr(frame->data), fmt::ptr(frame->data[0]), frame->nb_samples); u8 *dst_arr[8] = {reinterpret_cast(output_data), 0}; if (frame->format == avc->request_sample_fmt) { // input_bsize == output_bsize @@ -160,21 +168,16 @@ public: } } av_frame_unref(frame); - if (r == AVERROR(EAGAIN) || r == AVERROR_EOF) { - // non-errors - LOG_DEBUG(Audio_DSP, "{}", r); - } else if (r < 0) { - // errors - LOG_ERROR(Audio_DSP, "{}", r); - } av_packet_unref(pkt); + if (r == AVERROR(EAGAIN) || r == AVERROR_EOF) { + LOG_DEBUG(Audio_DSP, "{}", r); // non-errors + } else if (r < 0) { + LOG_ERROR(Audio_DSP, "{}", r); // errors + } return ResultSuccess; - } else { - LOG_ERROR(Audio_DSP, "{}", r); } - } else { - LOG_ERROR(Audio_DSP, "{}", r); } + LOG_ERROR(Audio_DSP, "{}", r); av_packet_unref(pkt); } return Service::Audio::ResultLibOpusInvalidState; @@ -202,6 +205,7 @@ OpusDecoder::OpusDecoder(Core::System& system) { ::Common::unordered_map decode_objects; while (!stop_token.stop_requested()) { auto msg = Receive(Direction::DSP, stop_token); + LOG_INFO(Audio_DSP, "msg={}", msg); switch (msg) { case Shutdown: Send(Direction::Host, Message::ShutdownOK);