11// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
22// SPDX-License-Identifier: GPL-2.0-or-later
33
4+ #include " ajm_error.h"
5+ #include " ajm_mp3.h"
6+ #include " ajm_result.h"
7+
48#include " common/assert.h"
5- #include " core/libraries/ajm/ajm_error.h"
6- #include " core/libraries/ajm/ajm_mp3.h"
79#include " core/libraries/error_codes.h"
810
911extern " C" {
@@ -122,7 +124,6 @@ void AjmMp3Decoder::Reset() {
122124 avcodec_flush_buffers (m_codec_context);
123125 m_header.reset ();
124126 m_frame_samples = 0 ;
125- m_frame_size = 0 ;
126127}
127128
128129void AjmMp3Decoder::GetInfo (void * out_info) const {
@@ -141,20 +142,19 @@ void AjmMp3Decoder::GetInfo(void* out_info) const {
141142
142143u32 AjmMp3Decoder::GetMinimumInputSize () const {
143144 // 4 bytes is for mp3 header that contains frame_size
144- return std::max< u32 >(m_frame_size, 4 ) ;
145+ return 4 ;
145146}
146147
147148DecoderResult AjmMp3Decoder::ProcessData (std::span<u8 >& in_buf, SparseOutputBuffer& output,
148149 AjmInstanceGapless& gapless) {
149150 DecoderResult result{};
150151 AVPacket* pkt = av_packet_alloc ();
151152
152- if ((!m_header.has_value () || m_frame_samples == 0 ) && in_buf.size () >= 4 ) {
153- m_header = std::byteswap (*reinterpret_cast <u32 *>(in_buf.data ()));
154- AjmDecMp3ParseFrame info{};
155- ParseMp3Header (in_buf.data (), in_buf.size (), true , &info);
156- m_frame_samples = info.samples_per_channel ;
157- m_frame_size = info.frame_size ;
153+ m_header = std::byteswap (*reinterpret_cast <u32 *>(in_buf.data ()));
154+ AjmDecMp3ParseFrame info{};
155+ ParseMp3Header (in_buf.data (), in_buf.size (), true , &info);
156+ m_frame_samples = info.samples_per_channel ;
157+ if (info.total_samples != 0 && gapless.current .total_samples == 0 ) {
158158 gapless.init = {
159159 .total_samples = info.total_samples ,
160160 .skip_samples = static_cast <u16 >(info.encoder_delay ),
@@ -163,6 +163,10 @@ DecoderResult AjmMp3Decoder::ProcessData(std::span<u8>& in_buf, SparseOutputBuff
163163 gapless.current = gapless.init ;
164164 }
165165
166+ if (in_buf.size () < info.frame_size ) {
167+ result.result |= ORBIS_AJM_RESULT_PARTIAL_INPUT;
168+ }
169+
166170 int ret = av_parser_parse2 (m_parser, m_codec_context, &pkt->data , &pkt->size , in_buf.data (),
167171 in_buf.size (), AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0 );
168172 ASSERT_MSG (ret >= 0 , " Error while parsing {}" , ret);
@@ -424,11 +428,7 @@ int AjmMp3Decoder::ParseMp3Header(const u8* p_begin, u32 stream_size, int parse_
424428 frame->encoder_delay = std::byteswap (*reinterpret_cast <const u16 *>(p_fgh + 1 ));
425429 frame->total_samples = std::byteswap (*reinterpret_cast <const u32 *>(p_fgh + 3 ));
426430 frame->ofl_type = AjmDecMp3OflType::Fgh;
427- } else {
428- LOG_ERROR (Lib_Ajm, " FGH header CRC is incorrect." );
429431 }
430- } else {
431- LOG_ERROR (Lib_Ajm, " Could not find vendor header." );
432432 }
433433 }
434434
0 commit comments