Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected crashing on Linux (FFmpeg 3.1.x) #9026

Closed
grawlinson opened this issue Oct 1, 2016 · 41 comments · Fixed by #11176
Closed

Unexpected crashing on Linux (FFmpeg 3.1.x) #9026

grawlinson opened this issue Oct 1, 2016 · 41 comments · Fixed by #11176
Milestone

Comments

@grawlinson
Copy link

grawlinson commented Oct 1, 2016

Currently using Arch Linux with PPSSPP 1.3.0 installed. These crashes do NOT occur on 1.2.2.

Here is some core dump info from journalctl. These problems occur on a few games, usually a few seconds after selecting the games from PPSSPP's main menu.

    Oct 01 13:45:42 computer-hostname systemd-coredump[4987]:
    Process 4770 (ppsspp) of user 1000 dumped core.
    Stack trace of thread 4770:
    #0  0x00007f1ec101004f raise (libc.so.6)
    #1  0x00007f1ec101147a abort (libc.so.6)
    #2  0x00007f1ec34f2ba9 avcodec_default_get_buffer2 (libavcodec.so.57)
    #3  0x00007f1ec34f387b n/a (libavcodec.so.57)
    #4  0x00007f1ec3410be7 n/a (libavcodec.so.57)
    #5  0x00007f1ec31b7d63 n/a (libavcodec.so.57)
    #6  0x00007f1ec31bbd8e n/a (libavcodec.so.57)
    #7  0x00007f1ec31688d2 n/a (libavcodec.so.57)
    #8  0x00007f1ec34f4e02 avcodec_decode_video2 (libavcodec.so.57)
    #9  0x00000000006774c6 _ZN11MediaEngine9stepVideoEib (ppsspp)
    #10 0x000000000063e984 n/a (ppsspp)
    #11 0x000000000075ce6e _Z23CallSyscallWithoutFlagsPK11HLEFunction (ppsspp)
    #12 0x00000000225c39dd n/a (n/a)
    -- Subject: Process 4770 (ppsspp) dumped core


    Oct 01 13:54:32 computer-hostname systemd-coredump[5560]:
    Process 5441 (ppsspp) of user 1000 dumped core.
    Stack trace of thread 5441:
    #0  0x00007f4b721eb04f raise (libc.so.6)
    #1  0x00007f4b721ec47a abort (libc.so.6)
    #2  0x00007f4b746cdba9 avcodec_default_get_buffer2 (libavcodec.so.57)
    #3  0x00007f4b746ce87b n/a (libavcodec.so.57)
    #4  0x00007f4b745ebbe7 n/a (libavcodec.so.57)
    #5  0x00007f4b74392d63 n/a (libavcodec.so.57)
    #6  0x00007f4b74396d8e n/a (libavcodec.so.57)
    #7  0x00007f4b743438d2 n/a (libavcodec.so.57)
    #8  0x00007f4b746cfe02 avcodec_decode_video2 (libavcodec.so.57)
    #9  0x00000000006774c6 _ZN11MediaEngine9stepVideoEib (ppsspp)
    #10 0x000000000063e984 n/a (ppsspp)
    #11 0x000000000075ce6e _Z23CallSyscallWithoutFlagsPK11HLEFunction (ppsspp)
    #12 0x00000000201e7265 n/a (n/a)
    -- Subject: Process 5441 (ppsspp) dumped core

EDIT: Let me know if you need more information, i.e. maybe core dump files?

Games I have tested:

  • FF7: Crisis Core
  • Monster Hunter 3: Freedom Unite
  • Persona 3 Portable
@idle-z
Copy link

idle-z commented Oct 1, 2016

This is happening for me too. Crashes on loading Trails in the Sky, Final Fantasy Type 0 still loads fine. This wasn't happening before 1.3. It's notable that the games only crash when being started normally. Selecting the option to load the last used savestate on launch works as expected.

@grawlinson
Copy link
Author

Selecting the option to load the last used savestate on launch works as expected.

I forgot to mention that when I load a savestate, PPSSPP eventually crashes with the same core dump message.

@idle-z
Copy link

idle-z commented Oct 1, 2016

That's odd, I managed to play Tails in the Sky SC Disk 1 to completion using the savestate trick. It looks like the crash has something to do with loading a resource with certain properties, and in my case the game never tried to load it except for on startup.

@unknownbrackets
Copy link
Collaborator

Both of those crashes are when playing a video. Do the crashes always involve avcodec_default_get_buffer2?

If yes, how did you install / compile this? Are you using a system provided version of FFmpeg (which version?) or are you using the version we ship with in the ffmpeg directory? If you didn't compile PPSSPP, but downloaded a pre-compiled version, can you try compiling it (it's fairly easy)?

If it still reproduces with the above, bisecting would be awesome:
https://github.com/hrydgard/ppsspp/wiki/How-to-bisect-to-find-what-broke-a-game

We did update the version of FFmpeg we use (to 3.1) between 1.2.2 and 1.3, so that's probably the most likely culprit.

Are you both using Arch?

-[Unknown]

@idle-z
Copy link

idle-z commented Oct 1, 2016

I'm on Arch like @grawlinson. I tried building from source, but I get the same crash. I'm attempting to bisect atm.

@grawlinson
Copy link
Author

Yes, I can confirm that the crashes always involve avcodec_default_get_buffer2, the easiest game to reproduce this with is Crisis Core as there is a video during start-up.

I installed using this ppsspp package available in the Arch Linux community repos. My system updated ffmpeg this week, so it could be a contributing factor.

I've compiled the latest git version v1.3-37-g8b5693b using below commands, and I cannot reproduce this issue anymore.

git clone --recursive git@github.com:hrydgard/ppsspp.git
cd ppsspp
./b.sh --qt
cd build-qt
./ppsspp

I will try bisecting now.

@grawlinson
Copy link
Author

This occurs with the Arch Linux ppsspp v1.3.0 package

11:30:501 user_main    I[ME]: HLE/sceMpeg.cpp:427 sceMpegInit()
11:30:501 user_main    I[ME]: HLE/sceMpeg.cpp:541 09f5d120=sceMpegCreate(09f6d12c, 09f5d0f0, 65536, 09f6d130, 512, 0, 0)
11:31:135 user_main    I[HLE]: HLE/scePower.cpp:412 222=scePowerGetPllClockFrequencyInt()
11:31:135 user_main    I[HLE]: HLE/scePower.cpp:369 scePowerSetClockFrequency(190,190,95)
11:31:272 user_main    I[SCEGE]: Common/FramebufferCommon.cpp:414 Creating FBO for 00000000 : 480 x 272 x 3
11:31:272 user_main    W[G3D]: Common/FramebufferCommon.cpp:650 Memcpy fbo upload 04400000 -> 04000000
11:31:272 user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 10 fs 11
11:31:273 user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 13 fs 14
11:31:346 user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 16 fs 17
11:31:347 user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 19 fs 20
11:31:350 user_main    I[SCEGE]: Common/FramebufferCommon.cpp:414 Creating FBO for 00088000 : 480 x 272 x 3
11:31:468 idle0        I[SCEGE]: GLES/Framebuffer.cpp:1922 Decimating FBO for 00000000 (480 x 272 x 3), age 6
11:31:501 idle0        I[SCEGE]: GLES/Framebuffer.cpp:1922 Decimating FBO for 00088000 (480 x 272 x 3), age 6
11:39:243 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 297=sceKernelCreateThread(SQEXTEC Movie Streaming, 0885f058, 0000006f, 10240, 00000000, 00000000)
11:39:243 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 298=sceKernelCreateThread(SQEXTEC Movie Decode, 0885d708, 0000006f, 10240, 00000000, 00000000)
11:39:243 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 299=sceKernelCreateThread(SQEXTEC Movie AudioOutput, 0885d814, 00000010, 5120, 00000000, 00000000)
11:39:243 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(297, 0, 00000000)
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0x15EB000
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 10252152
11:39:276 SQEXTEC Movi W[ME]: HLE/sceMpeg.cpp:1824 UNIMPL sceMpegFlushAllStream(09f6d12c)
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(09f6d12c, 0, 0)
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(09f6d12c, 1, 0)
11:39:276 SQEXTEC Movi I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(298, 0, 00000000)
11:39:276 SQEXTEC Movi I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(299, 0, 00000000)
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0x15EB000
11:39:276 SQEXTEC Movi I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 10252152
11:39:282 SQEXTEC Movi E[ME]: HW/MediaEngine.cpp:82 FF: Assertion 0 failed at libavcodec/utils.c:596
[1]    21415 abort (core dumped)  ppsspp

The most important line seems to be the second to last line where an assertion fails.

@unknownbrackets
Copy link
Collaborator

https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/utils.c#L596

Hm. We're expecting this to set the codec_type:

if (avcodec_open2(m_pCodecCtx, pCodec, nullptr) < 0) {

Does it help if you add above m_pCodecCtxs[streamNum] = m_pCodecCtx;:

m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;

(may need to add `#include "libavutil/avutil.h" in the includes if that fails to compile.)

-[Unknown]

@grawlinson
Copy link
Author

grawlinson commented Oct 1, 2016

I haven't managed to find the issue and I've gone back all the way to 1.2.2.

Odds are it's something specific to the Arch Linux package. I'll file an issue there.

EDIT: Bug report filed

@idle-z
Copy link

idle-z commented Oct 1, 2016

I haven't managed to find the issue and I've gone back all the way to 1.2.2.

I compiled 1.2.2 and am no longer having the issue.

@grawlinson
Copy link
Author

I'm not sure what's happening but the problem seems to be occurring even if I add m_pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; to Core/HW/MediaEngine.cpp to master.

Starting another git bisect from scratch, feel free to disregard all my comments. Will let you know my results once I'm done.

@grawlinson
Copy link
Author

$ git bisect log
git bisect start
# bad: [8b5693b4d727af0f3328b1a01fe60c82edce9805] Merge pull request #9014 from unknownbrackets/mpeg-minor
git bisect bad 8b5693b4d727af0f3328b1a01fe60c82edce9805
# good: [8c9f3b9509e8a6850e086ec36a59ca7fa4082d60] Update version numbers to 1.2.2, more README fixes
git bisect good 8c9f3b9509e8a6850e086ec36a59ca7fa4082d60
# good: [dd8e2d326a6e5cb9d1cc6aa5eec18f15a67adb84] Merge pull request #8752 from unknownbrackets/ir-vfpu
git bisect good dd8e2d326a6e5cb9d1cc6aa5eec18f15a67adb84
# good: [e0845b876fd7b5cb146945c8f6c70d1760b10372] Fix some bugs in the IRJit. Hopefully helps #8848
git bisect good e0845b876fd7b5cb146945c8f6c70d1760b10372
# skip: [daf10ec882bc4da7de8b3ee79cb9edde2591581e] Use JIT on iOS (not actually working yet, but it will start working in later commits)
git bisect skip daf10ec882bc4da7de8b3ee79cb9edde2591581e
# skip: [13e73f8c86579784291734e63d16475c461ca02c] Make sure to reset memory protection as appropriate. Remove unused WriteProtect on codeblocks (to be redesigned)
git bisect skip 13e73f8c86579784291734e63d16475c461ca02c
# good: [64403e520f5815a77df524f24c632b43cc5bb664] UI: Wrap browsing path if long.
git bisect good 64403e520f5815a77df524f24c632b43cc5bb664
# good: [b06359edd182456c4b107b00d6424b52b0193a99] Merge pull request #8945 from RisingFog/frame_dump
git bisect good b06359edd182456c4b107b00d6424b52b0193a99
# good: [20195424965ff1ba3da4237876bcea2c43982151] Merge pull request #8977 from sum2012/lang
git bisect good 20195424965ff1ba3da4237876bcea2c43982151
# good: [246f3aa68dafd75a7326a8d6c2cb68a4efc061b9] Merge pull request #8993 from neilmunday/master
git bisect good 246f3aa68dafd75a7326a8d6c2cb68a4efc061b9
# good: [6bbb3c04423f4be61b4af7ea7d08f77edc66f07d] Handle clear gpu cache as a global message.
git bisect good 6bbb3c04423f4be61b4af7ea7d08f77edc66f07d
# good: [b3a7c0e6711aa5fbe82e53c0059b034d991b17d2] Merge pull request #9021 from unknownbrackets/win-ui
git bisect good b3a7c0e6711aa5fbe82e53c0059b034d991b17d2
# good: [dfda67e815a274eba6545c0279d76d6b3e54f9d4] Merge pull request #9016 from unknownbrackets/screenshot
git bisect good dfda67e815a274eba6545c0279d76d6b3e54f9d4
# good: [209500ac0ec820eeb7ebb98f8ca14a3575f8392a] Read only the mpeg header when reading packets.
git bisect good 209500ac0ec820eeb7ebb98f8ca14a3575f8392a
# good: [f70f05668fc419dc241eaaf44c64e6cd68a1f9e6] Mpeg: Return errors when no audio is available.
git bisect good f70f05668fc419dc241eaaf44c64e6cd68a1f9e6
# first bad commit: [8b5693b4d727af0f3328b1a01fe60c82edce9805] Merge pull request #9014 from unknownbrackets/mpeg-minor

After this, I checked out master & compiled again. No issue. I then reinstalled the 1.3.0 package and the problem started again.

@nadiaholmquist
Copy link

Here's a modified PKGBUILD of the ppsspp-git AUR package that doesn't use the system's ffmpeg. This seems to fix crashing on video playback for me. Don't know if I made the changes to the PKGBUILD properly, but this will at least work until the package maintainer fixes it.

@unknownbrackets
Copy link
Collaborator

Hmm, 8b5693b is after v1.3.0. It is sounding to me like something (perhaps timing - you have multithreaded off, right?) is making this problem not strictly repeatable.

-[Unknown]

@unknownbrackets
Copy link
Collaborator

What version of FFmpeg is it being linked or run with on Arch? It's possible we have a bug with newer versions of FFmpeg than PPSSPP was built for; FFmpeg tends to change APIs quite frequently.

Maybe it would help to know the FFmpeg configure line - you can get this from ffmpeg -version.

Distro packagers tend to have a rule that if a package (e.g. ppsspp) includes other packages (like ffmpeg), they must be disconnected and ppsspp must be forced to build/link with the newest version of ffmpeg at all times. Unfortunately, it seems to me this requires that library developers (e.g. ffmpeg) never deprecate or change their APIs, which FFmpeg simply does not do.

I don't think PPSSPP has been tested against anything more recent than FFmpeg 3.0.2.

-[Unknown]

@grawlinson
Copy link
Author

Seems to be ver 3.1.4, according to output below.

$ ffmpeg -version
ffmpeg version 3.1.4 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.2.1 (GCC) 20160830
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-netcdf --enable-shared --enable-version3 --enable-x11grab
libavutil      55. 28.100 / 55. 28.100
libavcodec     57. 48.101 / 57. 48.101
libavformat    57. 41.100 / 57. 41.100
libavdevice    57.  0.101 / 57.  0.101
libavfilter     6. 47.100 /  6. 47.100
libavresample   3.  0.  0 /  3.  0.  0
libswscale      4.  1.100 /  4.  1.100
libswresample   2.  1.100 /  2.  1.100
libpostproc    54.  0.100 / 54.  0.100

@unknownbrackets unknownbrackets changed the title Unexpected crashing on Linux Unexpected crashing on Linux (FFmpeg 3.1.x) Oct 16, 2016
@KhelbenArunsun
Copy link

Can confirm this is still an issue in ffmpeg 3.2.
ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 6.2.1 (GCC) 20160830 configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-netcdf --enable-shared --enable-version3 --enable-x11grab libavutil 55. 34.100 / 55. 34.100 libavcodec 57. 64.100 / 57. 64.100 libavformat 57. 56.100 / 57. 56.100 libavdevice 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100

@ghost
Copy link

ghost commented Nov 3, 2016

Here's a modified PKGBUILD of the ppsspp-git AUR package that doesn't use the system's ffmpeg.

This doesn't build for me. @Nikolaj64 error: pathspec 'lang' did not match any file(s) known to git.

@Orphis
Copy link
Collaborator

Orphis commented Nov 3, 2016

Files have been moved, it's very likely some buildscript you are using needs to be updated.

@cmouzaoui
Copy link

@okabekudo here's another modified PKGBUILD that worked for me
PKGBUILD.txt

@re-l124c41plus
Copy link

I am having the same problem.
I try to start Monster Hunter Portable 3rd HD ver. and the game starts loading, then after the loading screen it crashes. What should happen is it should play the intro video, then proceed to the start screen.

As everyone else has already said: it's probably related to loading videos with an incompatible ffmpeg version.
uname -r:
4.8.13-1-ARCH

ffmpeg -version:

ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.2.1 (GCC) 20160830
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping 
--enable-avisynth --enable-avresample --enable-fontconfig --enable-gmp 
--enable-gnutls --enable-gpl --enable-ladspa --enable-libass 
--enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm 
--enable-libiec61883 --enable-libmodplug --enable-libmp3lame 
--enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg 
--enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr 
--enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 
--enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp 
--enable-libx264 --enable-libx265 --enable-libxvid --enable-netcdf 
--enable-shared --enable-version3 --enable-x11grab
libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libavresample   3.  1.  0 /  3.  1.  0
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

pacman -Qi ppsspp | grep Version:
Version : 1.3-1

When I build PPSSPP with the included ffmpeg version (3.0.2) then there is no crash and everything works as it should, as far as I can see.
If I am interpreting this nice site right then everything from 3.0 to 3.0.5 should work, right?

@jbeich
Copy link
Contributor

jbeich commented Dec 19, 2016

Also affects freebsd/freebsd-ports@587677d11f9e. A quick bisecting led to FFmpeg/FFmpeg@79af094b9304 (or 3.1.1 release) as the first bad. After locally reverting it here's what I see with ULUS10114 intro:

idle0        I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 34 fs 35
user_main    I[ME]: HLE/sceMpeg.cpp:427 sceMpegInit()
user_main    E[IO]: HLE/sceIo.cpp:1878 UNIMPL sceIoChangeAsyncPriority(4, 107)
user_main    I[ME]: HLE/sceMpeg.cpp:541 092e07c0=sceMpegCreate(0919edd8, 092e0790, 65536, 08cabeb0, 512, 0, 0)
user_main    I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(0919edd8, 0, 0)
user_main    I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(0919edd8, 1, 0)
user_main    I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0x71000
user_main    I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 405315
user_main    I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0x71000
user_main    I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 405315
user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 322=sceKernelCreateThread(PspMpegStreamer::Thread, 08b418d4, 0000006e, 32768, 00000000, 00000000)
user_main    I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(322, 4, 08bfe9e8)
PspMpegStrea I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0x71000
PspMpegStrea I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 405315
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Frame num change from 0 to 1
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: decode_slice_header error
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Broken frame packetizing
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: error while decoding MB 24 2, bytestream -10
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: illegal short term buffer state detected
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: deprecated pixel format used, make sure you did set range correctly
user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 37 fs 20
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: error while decoding MB 6 1, bytestream -24
user_main    W[ME]: HLE/sceMpeg.cpp:1667 Audio end reach. pts: 105968 dts: 315315
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
user_main    I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.

@htfy96
Copy link

htfy96 commented Jan 12, 2017

Reproduced on Arch Linux with ppsspp=1.3.0 and ffmpeg=3.2.2-2:

Log:

[New Thread 0x7fffc4b7c700 (LWP 22545)]
[Thread 0x7fffc4b7c700 (LWP 22545) exited]
13:03:092 user_main    I[UTIL]: HLE/sceUtility.cpp:342 00000000=sceUtilityMsgDialogInitStart(09ef28b4)
13:05:264 user_main    I[G3D]: GLES/ShaderManager.cpp:165 Linked shader: vs 13 fs 25
13:05:345 user_main    I[ME]: HLE/sceMpeg.cpp:541 09cd52c8=sceMpegCreate(09f0158c, 09cd5298, 65536, 09f01590, 512, 0, 0)
13:05:361 user_main    I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(09f0158c, 0, 0)
13:05:361 user_main    I[ME]: HLE/sceMpeg.cpp:659 sceMpegRegistStream(09f0158c, 1, 0)
13:05:362 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 326=sceKernelCreateThread(soundThread, 0894aaac, 00000011, 2048, 00000000, 00000000)
13:05:362 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:1975 328=sceKernelCreateThread(SofdecThread, 08948610, 00000032, 8192, 00000000, 00000000)
13:05:363 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(326, 4, 09f01808)
13:05:363 user_main    I[KERNEL]: HLE/sceKernelThread.cpp:2064 0=sceKernelStartThread(328, 4, 09fff270)
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0xBA000
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 720630
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0xBA000
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 720630
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:352 Stream offset: 2048, Stream size: 0xBA000
13:05:396 SofdecThread I[ME]: HLE/sceMpeg.cpp:353 First timestamp: 90000, Last timestamp: 720630
13:05:401 SofdecThread E[ME]: HW/MediaEngine.cpp:82 FF: Assertion 0 failed at libavcodec/utils.c:596

GDB log:

Thread 1 "ppsspp" received signal SIGABRT, Aborted.
0x00007ffff3ef904f in raise () from /usr/lib/libc.so.6
(gdb) bt full
#0  0x00007ffff3ef904f in raise () from /usr/lib/libc.so.6
No symbol table info available.
#1  0x00007ffff3efa47a in abort () from /usr/lib/libc.so.6
No symbol table info available.
#2  0x00007ffff58523c3 in avcodec_default_get_buffer2 () from /usr/lib/libavcodec.so.57
No symbol table info available.
#3  0x00007ffff5852deb in ?? () from /usr/lib/libavcodec.so.57
No symbol table info available.
#4  0x00007ffff576fc97 in ?? () from /usr/lib/libavcodec.so.57
No symbol table info available.
#5  0x00007ffff5507a56 in ?? () from /usr/lib/libavcodec.so.57
No symbol table info available.
#6  0x00007ffff550b8e0 in ?? () from /usr/lib/libavcodec.so.57
No symbol table info available.
#7  0x00007ffff5510781 in ?? () from /usr/lib/libavcodec.so.57
No symbol table info available.
#8  0x00007ffff5854312 in avcodec_decode_video2 () from /usr/lib/libavcodec.so.57
No symbol table info available.
#9  0x000000000058e246 in MediaEngine::stepVideo (this=0x39e1a90, videoPixelMode=0, skipFrame=skipFrame@entry=false)
    at /tmp/yaourt-tmp-lz/aur-ppsspp-git/src/ppsspp/Core/HW/MediaEngine.cpp:599
        result = <optimized out>
        dataEnd = <optimized out>
        codecIter = <optimized out>
        m_pCodecCtx = 0x3b95da0
        packet = {buf = 0x3be9d40, pts = 90000, dts = 86997, data = 0x3be9940 "", size = 775, stream_index = 0, flags = 0, 
          side_data = 0x0, side_data_elems = 0, duration = 0, pos = 2340, convergence_duration = 0}
        frameFinished = 0
        bGetFrame = false
#10 0x00000000005557d4 in sceMpegAvcDecode (initAddr=<optimized out>, bufferAddr=<optimized out>, frameWidth=<optimized out>, 
    auAddr=<optimized out>, mpeg=<optimized out>) at /tmp/yaourt-tmp-lz/aur-ppsspp-git/src/ppsspp/Core/HLE/sceMpeg.cpp:1113
        ctx = <optimized out>
        ringbuffer = <optimized out>
        buffer = 164518704
        ispmp = false
        avcAu = {pts = <optimized out>, dts = 86997, esBuffer = 0, esSize = 2048}
        beforeAvail = 32
        afterAvail = <optimized out>
#11 WrapU_UUUUU<sceMpegAvcDecode> () at /tmp/yaourt-tmp-lz/aur-ppsspp-git/src/ppsspp/Core/HLE/FunctionWrappers.h:702
No locals.
#12 0x00000000006bbb8e in CallSyscallWithoutFlags (info=0x9ca6c0 <sceMpeg+864>)
    at /tmp/yaourt-tmp-lz/aur-ppsspp-git/src/ppsspp/Core/HLE/HLE.cpp:473
No locals.
#13 0x0000000020257425 in ?? ()
No symbol table info available.
#14 0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) info threads 
  Id   Target Id         Frame 
* 1    Thread 0x7ffff7f85040 (LWP 22532) "ppsspp" 0x00007ffff3ef904f in raise () from /usr/lib/libc.so.6
  2    Thread 0x7ffff7e7c700 (LWP 22538) "PulseHotplug" 0x00007ffff3fa5551 in ppoll () from /usr/lib/libc.so.6
  3    Thread 0x7fffdc93c700 (LWP 22539) "ppsspp" 0x00007ffff7bca10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
  4    Thread 0x7ffff7fbe700 (LWP 22540) "SDLAudioDev1" 0x00007ffff3fa5551 in ppoll () from /usr/lib/libc.so.6
  5    Thread 0x7fffc6dfe700 (LWP 22542) "ppsspp" 0x00007ffff7bca10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
  6    Thread 0x7fffc65fd700 (LWP 22543) "ppsspp" 0x00007ffff7bca10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0

@multiSnow
Copy link

It seems that m_pCodecCtx->codec_id is changed to 0 after bool dataEnd = av_read_frame(m_pFormatCtx, &packet) < 0; at

bool dataEnd = av_read_frame(m_pFormatCtx, &packet) < 0;
.

@sakhmatd
Copy link

I have the same exact problem on FreeBSD 11-STABLE, ffmpeg 3.2.4.

Backtraces look identical to the ones posted and building using ffmpeg 3.0.2 does fix the issue.
Just to let you know that the issue isn't Linux only.

@jankusanagi
Copy link

Seeing this exact problem on Mageia, with ffmpeg 3.2.4.

As soon as any game tries to show a video, crash. Loading game+quickly loading savestate works fine.

@idle-z
Copy link

idle-z commented Mar 28, 2017

Compiling HEAD, I no longer get the crash, still ffmpeg 3.2.4, Arch Linux.

@htfy96
Copy link

htfy96 commented Mar 28, 2017

Same as @idle-zealot. This bug disappears on the latest version on Arch Linux.

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Mar 28, 2017
hrydgard/ppsspp#9026


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@437149 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Mar 28, 2017
@jbeich
Copy link
Contributor

jbeich commented Mar 28, 2017

7a7e4ed made it stop crashing but I'm still getting a lot of decoding errors that don't manifest when using system ffmpeg 3.0.7.

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Mar 28, 2017
emulators/ppsspp: backport ffmpeg >= 3.1.1 crash workaround

hrydgard/ppsspp#9026

Approved by:	ports-secteam blanket
@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Mar 29, 2017

TBH it's kinda concerning that that improved it.

We found that previously, FFmpeg was decoding with multiple threads even though we hadn't configured it to (or not to.) It turned out that avformat_find_stream_info() apparently disables and then re-enables threads. It's probably a bug in FFmpeg that calling that function affects whether FFmpeg uses multithreaded decoding or not.

The change you linked to simply explicitly enables multithreaded decoding, because users were reporting performance regressions during videos.

If it also fixes this crash, it's probably an accident / threading race condition or something. It may not consistently fix it, or it may be a bug in FFmpeg that fixed it.

Anyway, looking specifically at FFmpeg/FFmpeg@79af094b9304, my guess is we have something updating codec but not codecpar:
https://github.com/FFmpeg/FFmpeg/blob/66963d4b8d302611553e7928063c1cb2ff0efdff/libavcodec/utils.c#L4269

But that probably isn't causing this crash. Searching it seems like we may need to manually do this sometimes (why isn't this documented in APIchanges)?
https://github.com/FFmpeg/FFmpeg/blob/7e3e0f87e6e911250855f03dd2fa8b4533a3e654/doc/examples/muxing.c#L250

So somewhere we need to set the codecpar values with avcodec_parameters_from_context, maybe here:

And maybe also after this line?

int result = avcodec_decode_video2(m_pCodecCtx, m_pFrame, &frameFinished, &packet);

Haven't done any testing, just theory.

-[Unknown]

@hrydgard
Copy link
Owner

hrydgard commented Mar 29, 2017

Yeah, scary indeed.

I'm gonna make a pull request with the proposed changes. I haven't been able to repro this myself yet, Ubuntu only uses FFMPEG 2.8. What's the easiest distro to install in VirtualBox with this issue? :)

Or wait, avcodec_parameters_from_context does not even exist in "our" version of ffmpeg. Sigh.

It seems that following FFMPEG is a very laborious process, we should probably change the build process to build our own FFMPEG copy if a precompiled build is missing, and use that in all cases.

@Pulfer
Copy link

Pulfer commented Mar 29, 2017

Yes, with 7a7e4ed PPSSPP doesn't crash anymore but the video is messed up. For example, Tekken 6 intro looks like this:

screenshot

Console output is flooded with:

10:08:177 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
10:08:177 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
10:08:177 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: error while decoding MB 9 2, bytestream -20
10:08:177 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
10:08:177 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.
10:08:194 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: No start code is found.
10:08:194 displayThrea I[ME]: HW/MediaEngine.cpp:86 FF: Error splitting the input into NAL units.

P.S. ffmpeg 3.2.4, ppsspp 1.3 + 7a7e4ed

@jbeich
Copy link
Contributor

jbeich commented Mar 29, 2017

FFmpeg/FFmpeg@6f69f7a8bf is the first bad causing decoding errors (garbled video), confirming @unknownbrackets' suspicions.

@hrydgard
Copy link
Owner

Well, yeah, it's not really "bad" but an API change that affects us in an unfortunate way.

We're going to need to do some #ifdef of FFMPEG version to choose whether or not to make that function call. Since you can repro, maybe you can try it? Otherwise I'll look into it sometime after 1.4 (which will be soon).

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Mar 30, 2017

It seems that following FFMPEG is a very laborious process, we should probably change the build process to build our own FFMPEG copy if a precompiled build is missing, and use that in all cases.

The problem is that distro packagers don't like/allow this. Even if we do this, they will patch the repo before compiling to use system ffmpeg. My understanding is that they do this very commonly, almost as a force-of-habit whenever packaging any repo.

That being said, a mess of defines for breaking FFmpeg changes isn't great either, so maybe we can add an #error or osm if an unsupported version of FFmpeg is used. If the packager removes this, at least they must know about our version constraint.

But maybe it's just a couple well placed function calls...

@hrydgard if you are still wanting an environment, you can probably use vagrant. From a quick Google:
https://atlas.hashicorp.com/freebsd/boxes/FreeBSD-12.0-CURRENT
(guessing it has this issue from recent commits referencing this issue #...)

https://releases.hashicorp.com/vagrant/1.9.3/vagrant_1.9.3.msi
vagrant init freebsd/FreeBSD-12.0-CURRENT
vagrant up --provider virtualbox
(or get arch with vagrant init terrywang/archlinux)

Then you can use vagrant ssh to get into it, or go to the VirtualBox GUI to get graphics. But maybe it will not have graphics libs installed (yet) because this is mainly for servers.

-[Unknown]

@akien-mga
Copy link
Contributor

I think it might be worth contacting FFmpeg developers to know what's the best way forward to be compatible with 3.2.x while ideally staying compatible with 3.0.x.

@ghost
Copy link

ghost commented May 19, 2017

Hello, is there any progress on this or am I supposed to expect crashes by using my system's FFmpeg (3.3.x) ? Would be a deal breaker to not be able to on Gentoo.

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented May 20, 2017

Well, patches are welcome (or if someone wants to file an upstream bug.) We bundle a slimmed ffmpeg exactly because its APIs are not stable (well, and more because it's a pain to build.)

On the other hand, we switched to libpng17 in 2014 to get a fix for an iOS bug, and yet that still hasn't had a stable release 3 years later.

-[Unknown]

@ghost
Copy link

ghost commented May 20, 2017

Well, I was more asking about intent than action. Basically, are we supposed to use the bundled one all the time or will this be fixed in the future?
I understand the problem and that's why I'm making our ebuild support both options. Still, building FFmpeg is no fun.

@unknownbrackets
Copy link
Collaborator

I think we intend to support the newer versions of FFmpeg.

-[Unknown]

@jbeich
Copy link
Contributor

jbeich commented Jun 13, 2018

Does #11176 help?

@unknownbrackets unknownbrackets added this to the v1.7.0 milestone Jun 18, 2018
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 1, 2021
emulators/ppsspp: backport ffmpeg >= 3.1.1 crash workaround

hrydgard/ppsspp#9026

Approved by:	ports-secteam blanket
svmhdvn pushed a commit to svmhdvn/freebsd-ports that referenced this issue Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.