@@ -146,41 +146,48 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
146146 return err;
147147 }
148148
149+ AVFrameHolder::instance ().prepare ();
150+
151+ // One extra frame for decoding processing
152+ m_frames_size = Settings::instance ().frames_queue_size () + 1 ;
153+ m_frames = new AVFrame*[m_frames_size];
154+
149155 tmp_frame = av_frame_alloc ();
150- for (auto & m_frame : m_frames) {
151- m_frame = av_frame_alloc ();
152- if (m_frame == nullptr ) {
156+ for (int i = 0 ; i < m_frames_size; i++) {
157+ auto & frame = m_frames[i];
158+ frame = av_frame_alloc ();
159+ if (frame == nullptr ) {
153160 brls::Logger::error (" FFmpeg: Couldn't allocate frame" );
154161 return -1 ;
155162 }
156163
157164#if defined(PLATFORM_SWITCH) && defined(BOREALIS_USE_DEKO3D)
158- m_frames[i] ->format = AV_PIX_FMT_NVTEGRA;
165+ frame ->format = AV_PIX_FMT_NVTEGRA;
159166#elif defined(PLATFORM_ANDROID)
160- m_frames[i] ->format = AV_PIX_FMT_MEDIACODEC;
167+ frame ->format = AV_PIX_FMT_MEDIACODEC;
161168#else
162169 if (video_format & VIDEO_FORMAT_MASK_10BIT)
163- m_frame ->format = AV_PIX_FMT_P010;
170+ frame ->format = AV_PIX_FMT_P010;
164171 else
165- m_frame ->format = AV_PIX_FMT_NV12;
172+ frame ->format = AV_PIX_FMT_NV12;
166173#endif
167- m_frame ->width = width;
168- m_frame ->height = height;
174+ frame ->width = width;
175+ frame ->height = height;
169176
170177// Need to align Switch frame to 256, need to de reviewed
171178#if defined(PLATFORM_SWITCH) && !defined(BOREALIS_USE_DEKO3D)
172- int err = av_frame_get_buffer (m_frame , 256 );
179+ int err = av_frame_get_buffer (frame , 256 );
173180 if (err < 0 ) {
174181 char errs[64 ];
175182 brls::Logger::error (" FFmpeg: Couldn't allocate frame buffer: {}" , av_make_error_string (errs, 64 , err));
176183 return -1 ;
177184 }
178185
179186 for (int j = 0 ; j < 2 ; j++) {
180- uintptr_t ptr = (uintptr_t )m_frame ->data [j];
187+ uintptr_t ptr = (uintptr_t )frame ->data [j];
181188 uintptr_t dst = (((ptr)+(256 )-1 )&~((256 )-1 ));
182189 uintptr_t gap = dst - ptr;
183- m_frame ->data [j] += gap;
190+ frame ->data [j] += gap;
184191 }
185192#endif
186193 }
@@ -235,7 +242,7 @@ void FFmpegVideoDecoder::cleanup() {
235242 }
236243
237244// if (m_frames) {
238- for (int i = 0 ; i < m_frames_count ; i++) {
245+ for (int i = 0 ; i < m_frames_size ; i++) {
239246 // if (m_extra_frames[i])
240247 av_frame_free (&m_frames[i]);
241248 }
@@ -254,6 +261,7 @@ void FFmpegVideoDecoder::cleanup() {
254261 }
255262
256263 AVFrameHolder::instance ().cleanup ();
264+ delete[] m_frames;
257265
258266 brls::Logger::info (" FFmpeg: Cleanup done!" );
259267}
@@ -445,7 +453,7 @@ AVFrame* FFmpegVideoDecoder::get_frame(bool native_frame) {
445453
446454 if (err == 0 ) {
447455 m_current_frame = m_next_frame;
448- m_next_frame = (m_current_frame + 1 ) % m_frames_count ;
456+ m_next_frame = (m_current_frame + 1 ) % m_frames_size ;
449457 if (/* ffmpeg_decoder == SOFTWARE ||*/ native_frame)
450458 return resultFrame;
451459 } else {
0 commit comments