Mailing List Archive

mediacodec errors
Hi Aman

I am making progress with mediacodec, but I have hit a new problems that
I am not sure what to do about.

When the user Fast Forwards a video, the code  decodes a frame, then
clear buffers, skip forward some period of time in the file then decodes
another frame, and repeats the process.

After sending packets to the system and getting back a frame, it issues
avcodec_flush_buffers then starts with a new set of packets.

it loops on
  avcodec_receive_frame
  avcodec_send_packet
until it has a frame (taking account of EAGAIN return codes as appropriate)
then it runs
  avcodec_flush_buffers
Then starts from the beginning again with a frame from another part of
the file.

This works for a while (maybe 10 or 20 frames) then I get these error
messages:

E  [amediacodec @ 0x202443e118] java.lang.IllegalStateException occurred
E  [mpeg2_mediacodec @ 0x2024425378] Failed to dequeue output buffer
(status=-542398533)

The code gets a return code from the send or receive call : "Generic
error in an external library" (-542398533).

These two messages and the error return repeat until I kill the program.

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: mediacodec errors [ In reply to ]
On 06/28/2018 04:24 PM, Aman Gupta wrote:
>
>
> On Thu, Jun 28, 2018 at 3:59 PM Peter Bennett <pb.mythtv@gmail.com
> <mailto:pb.mythtv@gmail.com>> wrote:
>
> Hi Aman
>
> I am making progress with mediacodec, but I have hit a new
> problems that
> I am not sure what to do about.
>
> When the user Fast Forwards a video, the code  decodes a frame, then
> clear buffers, skip forward some period of time in the file then
> decodes
> another frame, and repeats the process.
>
> After sending packets to the system and getting back a frame, it
> issues
> avcodec_flush_buffers then starts with a new set of packets.
>
> it loops on
>    avcodec_receive_frame
>    avcodec_send_packet
> until it has a frame (taking account of EAGAIN return codes as
> appropriate)
> then it runs
>    avcodec_flush_buffers
> Then starts from the beginning again with a frame from another
> part of
> the file.
>
>
> I use a similar technique for fast forwarding, but haven't run into
> this issue.
>
>
>
> This works for a while (maybe 10 or 20 frames) then I get these error
> messages:
>
> E  [amediacodec @ 0x202443e118] java.lang.IllegalStateException
> occurred
> E  [mpeg2_mediacodec @ 0x2024425378] Failed to dequeue output buffer
> (status=-542398533)
>
>
> If you look at the official MediaCodec docs it talks about how to deal
> with these state exceptions. There are different types, and the
> decoder can either be reset or recreated. I haven't had a reproducible
> way to make this happen so I haven't added the code to deal with them.
> Ideally this would be added to ffmpeg- if you create a patch I can
> commit it to ffmpeg.
>
The method dequeueOutputBuffer can throw IllegalStateException.
According to the MediaCodec documentation that means it is not in the
Executing state, or codec is configured in asynchronous mode. I don't
have enough understanding of how it works to know why that would be.

I believe that this may only happen with 1080i interlaced video.

The situation only occurs if you send several packets until there are
frames available, then receive only one frame from the codec context and
then flush, expecting to lose any remaining frames. Doing this sequence
repeatedly causes the error after about 10 or 15 times. Somehow those
available frames are not being correctly flushed. By adding my own code
to discard those frames I avoid the problem.

Add this code before avcodec_flush_buffers:

                int ret = 0;
                while (ret == 0)
                {
                    AVFrame *frame = av_frame_alloc();
                    ret = avcodec_receive_frame(enc, frame);
                    av_frame_free(&frame);
                }

No More exceptions!!

It should not be necessary to receive all available frames and discard
them like this before flushing. Perhaps something like this code snippet
should be added to avcodec_flush_buffers.

Please let me know if you make any change in ffmpeg to solve this issue
so that I can remove this piece of code.

Peter
Re: mediacodec errors [ In reply to ]
Hi Aman

This workaround that I sent you (see below) is not successful. On
Android 8 I am getting illegal state exceptions with FF with 720p
recordings, with the workaround in place.

Peter


On 06/29/2018 05:40 PM, Peter Bennett wrote:
> The method dequeueOutputBuffer can throw IllegalStateException.
> According to the MediaCodec documentation that means it is not in the
> Executing state, or codec is configured in asynchronous mode. I don't
> have enough understanding of how it works to know why that would be.
>
> I believe that this may only happen with 1080i interlaced video.
>
> The situation only occurs if you send several packets until there are
> frames available, then receive only one frame from the codec context
> and then flush, expecting to lose any remaining frames. Doing this
> sequence repeatedly causes the error after about 10 or 15 times.
> Somehow those available frames are not being correctly flushed. By
> adding my own code to discard those frames I avoid the problem.
>
> Add this code before avcodec_flush_buffers:
>
>                 int ret = 0;
>                 while (ret == 0)
>                 {
>                     AVFrame *frame = av_frame_alloc();
>                     ret = avcodec_receive_frame(enc, frame);
>                     av_frame_free(&frame);
>                 }
>
> No More exceptions!!
>
> It should not be necessary to receive all available frames and discard
> them like this before flushing. Perhaps something like this code
> snippet should be added to avcodec_flush_buffers.
>
> Please let me know if you make any change in ffmpeg to solve this
> issue so that I can remove this piece of code.
>
> Peter
>

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: mediacodec errors [ In reply to ]
Hi Peter,

I've been working on trying to reproduce this issue. It looks like it never
happens when using Surface based zero-copy rendering.

When copying frame data, I can reproduce after flushing rapidly. Looking at
logcat, I see that the entire mediacodec decoder appears to be crashing:

A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint:
'NVIDIA/foster_e/foster:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys'
Revision: '0'
ABI: 'arm'
pid: 431, tid: 27041, name: media.codec >>> android.hardwar <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
Cause: null pointer dereference
A/DEBUG: r0 4a22f810 r1 00000010 r2 00000220 r3 00000030
r4 4a203240 r5 4e7ed000 r6 4e7ee18c r7 4a22f800
r8 00000000 r9 00000002 sl 00030d40 fp 5246a91c
ip 80000000 sp 5246a868 lr 4cf455d1 pc 4936be9c cpsr a00f0010
A/DEBUG: backtrace:
#00 pc 00018e9c /system/lib/libc.so (memcpy+124)
#01 pc 0000b5cd /vendor/lib/libnvmmlite_video.so
#02 pc 0000aaab /vendor/lib/libnvmmlite_video.so
#03 pc 0000636c /vendor/lib/libnvos.so
#04 pc 0004831f /system/lib/libc.so (_ZL15__pthread_startPv+22)
#05 pc 0001b4df /system/lib/libc.so (__start_thread+32)
E//system/bin/tombstoned: Tombstone written to:
/data/tombstones//tombstone_03
E/ACodec: OMX/mediaserver died, signalling error!
signalError(omxError 0x8000100d, internalError -32)
I/ServiceManager: service 'media.codec' died
E/MediaCodec: Codec reported err 0xffffffe0, actionCode 0, while in state 7
E/NdkMediaCodec: sf error code: -32
E/ffmpeg: [ffmpeg/video] h264_mediacodec: Failed to flush codec

Are you seeing anything like this in the logs?

Aman

On Mon, Jul 2, 2018 at 1:06 PM Peter Bennett <pb.mythtv@gmail.com> wrote:

> Hi Aman
>
> This workaround that I sent you (see below) is not successful. On
> Android 8 I am getting illegal state exceptions with FF with 720p
> recordings, with the workaround in place.
>
> Peter
>
>
> On 06/29/2018 05:40 PM, Peter Bennett wrote:
> > The method dequeueOutputBuffer can throw IllegalStateException.
> > According to the MediaCodec documentation that means it is not in the
> > Executing state, or codec is configured in asynchronous mode. I don't
> > have enough understanding of how it works to know why that would be.
> >
> > I believe that this may only happen with 1080i interlaced video.
> >
> > The situation only occurs if you send several packets until there are
> > frames available, then receive only one frame from the codec context
> > and then flush, expecting to lose any remaining frames. Doing this
> > sequence repeatedly causes the error after about 10 or 15 times.
> > Somehow those available frames are not being correctly flushed. By
> > adding my own code to discard those frames I avoid the problem.
> >
> > Add this code before avcodec_flush_buffers:
> >
> > int ret = 0;
> > while (ret == 0)
> > {
> > AVFrame *frame = av_frame_alloc();
> > ret = avcodec_receive_frame(enc, frame);
> > av_frame_free(&frame);
> > }
> >
> > No More exceptions!!
> >
> > It should not be necessary to receive all available frames and discard
> > them like this before flushing. Perhaps something like this code
> > snippet should be added to avcodec_flush_buffers.
> >
> > Please let me know if you make any change in ffmpeg to solve this
> > issue so that I can remove this piece of code.
> >
> > Peter
> >
>
>
Re: mediacodec errors [ In reply to ]
On 08/05/2018 02:38 PM, Aman Gupta wrote:
> Hi Peter,
>
> I've been working on trying to reproduce this issue. It looks like it
> never happens when using Surface based zero-copy rendering.
>
> When copying frame data, I can reproduce after flushing rapidly.
> Looking at logcat, I see that the entire mediacodec decoder appears to
> be crashing:
>
> A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
>     Build fingerprint:
> 'NVIDIA/foster_e/foster:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys'
>     Revision: '0'
>     ABI: 'arm'
>     pid: 431, tid: 27041, name: media.codec  >>> android.hardwar <<<
>     signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
>     Cause: null pointer dereference
> A/DEBUG:     r0 4a22f810  r1 00000010  r2 00000220  r3 00000030
>         r4 4a203240  r5 4e7ed000  r6 4e7ee18c  r7 4a22f800
>         r8 00000000  r9 00000002  sl 00030d40  fp 5246a91c
>         ip 80000000  sp 5246a868  lr 4cf455d1  pc 4936be9c  cpsr a00f0010
> A/DEBUG: backtrace:
>         #00 pc 00018e9c  /system/lib/libc.so (memcpy+124)
>         #01 pc 0000b5cd  /vendor/lib/libnvmmlite_video.so
>         #02 pc 0000aaab  /vendor/lib/libnvmmlite_video.so
>         #03 pc 0000636c  /vendor/lib/libnvos.so
>         #04 pc 0004831f  /system/lib/libc.so (_ZL15__pthread_startPv+22)
>         #05 pc 0001b4df  /system/lib/libc.so (__start_thread+32)
> E//system/bin/tombstoned: Tombstone written to:
> /data/tombstones//tombstone_03
> E/ACodec: OMX/mediaserver died, signalling error!
>     signalError(omxError 0x8000100d, internalError -32)
> I/ServiceManager: service 'media.codec' died
> E/MediaCodec: Codec reported err 0xffffffe0, actionCode 0, while in
> state 7
> E/NdkMediaCodec: sf error code: -32
> E/ffmpeg: [ffmpeg/video] h264_mediacodec: Failed to flush codec
>
> Are you seeing anything like this in the logs?
>
> Aman
>

Hi Aman

I see something similar in logcat, see below. The problem seems to be
that Deinterlace sees a buffer as null.

08-10 17:17:36.635   450  1861 D NvOsDebugPrintf: NVMEDIA: Deinterlace:
339: input buffer is NULL
08-10 17:17:36.635   450  1861 D NvOsDebugPrintf: NVMEDIA: Deinterlace:
339: input buffer is NULL
08-10 17:17:36.644   454   454 I /system/bin/tombstoned: received crash
request for pid 450
08-10 17:17:36.646   450  1861 F DEBUG   : *** *** *** *** *** *** ***
*** *** *** *** *** *** *** *** ***
08-10 17:17:36.646   450  1861 F DEBUG   : Build fingerprint:
'NVIDIA/darcy/darcy:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys'
08-10 17:17:36.646   450  1861 F DEBUG   : Revision: '0'
08-10 17:17:36.646   450  1861 F DEBUG   : ABI: 'arm'
08-10 17:17:36.646   450  1861 F DEBUG   : pid: 450, tid: 1861, name:
media.codec  >>> android.hardwar <<<
08-10 17:17:36.646   450  1861 F DEBUG   : signal 11 (SIGSEGV), code 1
(SEGV_MAPERR), fault addr 0x390
08-10 17:17:36.646   450  1861 F DEBUG   : Cause: null pointer dereference
08-10 17:17:36.866   450  1861 F DEBUG   :     r0 00000000  r1 4ebc317c 
r2 00000000  r3 00000780
08-10 17:17:36.866   450  1861 F DEBUG   :     r4 4ebc3000  r5 4ebba000 
r6 51a90400  r7 00000438
08-10 17:17:36.866   450  1861 F DEBUG   :     r8 4ebc3d8c  r9 00000001 
sl 4ebc418c  fp 0000021c
08-10 17:17:36.866   450  1861 F DEBUG   :     ip 00000800  sp 56950808 
lr 00000002  pc 5185aa12  cpsr 200f0030
08-10 17:17:36.880   450  1861 F DEBUG   :
08-10 17:17:36.880   450  1861 F DEBUG   : backtrace:
08-10 17:17:36.880   450  1861 F DEBUG   :     #00 pc 0000ba12
/vendor/lib/libnvmmlite_video.so
08-10 17:17:36.880   450  1861 F DEBUG   :     #01 pc 0000b5b3
/vendor/lib/libnvmmlite_video.so
08-10 17:17:36.880   450  1861 F DEBUG   :     #02 pc 0000aaab
/vendor/lib/libnvmmlite_video.so
08-10 17:17:36.880   450  1861 F DEBUG   :     #03 pc 0000636c
/vendor/lib/libnvos.so
08-10 17:17:36.880   450  1861 F DEBUG   :     #04 pc 0004831f
/system/lib/libc.so (_ZL15__pthread_startPv+22)
08-10 17:17:36.880   450  1861 F DEBUG   :     #05 pc 0001b4df
/system/lib/libc.so (__start_thread+32)
08-10 17:17:36.886   454   454 E /system/bin/tombstoned: Tombstone
written to: /data/tombstones//tombstone_08
08-10 17:17:36.897   288   288 I ServiceManager: service 'media.codec' died
08-10 17:17:36.897  1741  1851 E ACodec  : OMX/mediaserver died,
signalling error!
08-10 17:17:36.897  1741  1851 E ACodec  : signalError(omxError
0x8000100d, internalError -32)
08-10 17:17:36.897  1741  1850 E MediaCodec: Codec reported err
0xffffffe0, actionCode 0, while in state 6
08-10 17:17:36.901   678   701 I BootReceiver: Copying
/data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
08-10 17:17:36.927   445   465 D MediaAnalyticsService:
MediaAnalyticsService::newSummarizerSet
08-10 17:17:36.951  1741  1872 I ServiceManager: Waiting for service
media.codec...
08-10 17:17:36.969  1741  1779 I mfe     : 2018-08-10 17:17:36.909417 E 
AFD: video avcodec_receive_frame error: Generic error in an external
library (-542398533) gotpicture:0

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: mediacodec errors [ In reply to ]
On Fri, Aug 10, 2018 at 2:26 PM Peter Bennett <pb.mythtv@gmail.com> wrote:

>
>
> On 08/05/2018 02:38 PM, Aman Gupta wrote:
> > Hi Peter,
> >
> > I've been working on trying to reproduce this issue. It looks like it
> > never happens when using Surface based zero-copy rendering.
> >
> > When copying frame data, I can reproduce after flushing rapidly.
> > Looking at logcat, I see that the entire mediacodec decoder appears to
> > be crashing:
> >
> > A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
> > Build fingerprint:
> >
> 'NVIDIA/foster_e/foster:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys'
> > Revision: '0'
> > ABI: 'arm'
> > pid: 431, tid: 27041, name: media.codec >>> android.hardwar <<<
> > signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
> > Cause: null pointer dereference
> > A/DEBUG: r0 4a22f810 r1 00000010 r2 00000220 r3 00000030
> > r4 4a203240 r5 4e7ed000 r6 4e7ee18c r7 4a22f800
> > r8 00000000 r9 00000002 sl 00030d40 fp 5246a91c
> > ip 80000000 sp 5246a868 lr 4cf455d1 pc 4936be9c cpsr a00f0010
> > A/DEBUG: backtrace:
> > #00 pc 00018e9c /system/lib/libc.so (memcpy+124)
> > #01 pc 0000b5cd /vendor/lib/libnvmmlite_video.so
> > #02 pc 0000aaab /vendor/lib/libnvmmlite_video.so
> > #03 pc 0000636c /vendor/lib/libnvos.so
> > #04 pc 0004831f /system/lib/libc.so (_ZL15__pthread_startPv+22)
> > #05 pc 0001b4df /system/lib/libc.so (__start_thread+32)
> > E//system/bin/tombstoned: Tombstone written to:
> > /data/tombstones//tombstone_03
> > E/ACodec: OMX/mediaserver died, signalling error!
> > signalError(omxError 0x8000100d, internalError -32)
> > I/ServiceManager: service 'media.codec' died
> > E/MediaCodec: Codec reported err 0xffffffe0, actionCode 0, while in
> > state 7
> > E/NdkMediaCodec: sf error code: -32
> > E/ffmpeg: [ffmpeg/video] h264_mediacodec: Failed to flush codec
> >
> > Are you seeing anything like this in the logs?
> >
> > Aman
> >
>
> Hi Aman
>
> I see something similar in logcat, see below. The problem seems to be
> that Deinterlace sees a buffer as null.
>

Great, thanks for the confirmation. I sent the tombstone (grabbed via `adb
bugreport`) to Nvidia. Hopefully they can fix this quickly.

Aman


>
> 08-10 17:17:36.635 450 1861 D NvOsDebugPrintf: NVMEDIA: Deinterlace:
> 339: input buffer is NULL
> 08-10 17:17:36.635 450 1861 D NvOsDebugPrintf: NVMEDIA: Deinterlace:
> 339: input buffer is NULL
> 08-10 17:17:36.644 454 454 I /system/bin/tombstoned: received crash
> request for pid 450
> 08-10 17:17:36.646 450 1861 F DEBUG : *** *** *** *** *** *** ***
> *** *** *** *** *** *** *** *** ***
> 08-10 17:17:36.646 450 1861 F DEBUG : Build fingerprint:
>
> 'NVIDIA/darcy/darcy:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys'
> 08-10 17:17:36.646 450 1861 F DEBUG : Revision: '0'
> 08-10 17:17:36.646 450 1861 F DEBUG : ABI: 'arm'
> 08-10 17:17:36.646 450 1861 F DEBUG : pid: 450, tid: 1861, name:
> media.codec >>> android.hardwar <<<
> 08-10 17:17:36.646 450 1861 F DEBUG : signal 11 (SIGSEGV), code 1
> (SEGV_MAPERR), fault addr 0x390
> 08-10 17:17:36.646 450 1861 F DEBUG : Cause: null pointer dereference
> 08-10 17:17:36.866 450 1861 F DEBUG : r0 00000000 r1 4ebc317c
> r2 00000000 r3 00000780
> 08-10 17:17:36.866 450 1861 F DEBUG : r4 4ebc3000 r5 4ebba000
> r6 51a90400 r7 00000438
> 08-10 17:17:36.866 450 1861 F DEBUG : r8 4ebc3d8c r9 00000001
> sl 4ebc418c fp 0000021c
> 08-10 17:17:36.866 450 1861 F DEBUG : ip 00000800 sp 56950808
> lr 00000002 pc 5185aa12 cpsr 200f0030
> 08-10 17:17:36.880 450 1861 F DEBUG :
> 08-10 17:17:36.880 450 1861 F DEBUG : backtrace:
> 08-10 17:17:36.880 450 1861 F DEBUG : #00 pc 0000ba12
> /vendor/lib/libnvmmlite_video.so
> 08-10 17:17:36.880 450 1861 F DEBUG : #01 pc 0000b5b3
> /vendor/lib/libnvmmlite_video.so
> 08-10 17:17:36.880 450 1861 F DEBUG : #02 pc 0000aaab
> /vendor/lib/libnvmmlite_video.so
> 08-10 17:17:36.880 450 1861 F DEBUG : #03 pc 0000636c
> /vendor/lib/libnvos.so
> 08-10 17:17:36.880 450 1861 F DEBUG : #04 pc 0004831f
> /system/lib/libc.so (_ZL15__pthread_startPv+22)
> 08-10 17:17:36.880 450 1861 F DEBUG : #05 pc 0001b4df
> /system/lib/libc.so (__start_thread+32)
> 08-10 17:17:36.886 454 454 E /system/bin/tombstoned: Tombstone
> written to: /data/tombstones//tombstone_08
> 08-10 17:17:36.897 288 288 I ServiceManager: service 'media.codec' died
> 08-10 17:17:36.897 1741 1851 E ACodec : OMX/mediaserver died,
> signalling error!
> 08-10 17:17:36.897 1741 1851 E ACodec : signalError(omxError
> 0x8000100d, internalError -32)
> 08-10 17:17:36.897 1741 1850 E MediaCodec: Codec reported err
> 0xffffffe0, actionCode 0, while in state 6
> 08-10 17:17:36.901 678 701 I BootReceiver: Copying
> /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
> 08-10 17:17:36.927 445 465 D MediaAnalyticsService:
> MediaAnalyticsService::newSummarizerSet
> 08-10 17:17:36.951 1741 1872 I ServiceManager: Waiting for service
> media.codec...
> 08-10 17:17:36.969 1741 1779 I mfe : 2018-08-10 17:17:36.909417 E
> AFD: video avcodec_receive_frame error: Generic error in an external
> library (-542398533) gotpicture:0
>
> Peter
>