BUG Report - Fire TV Cube (2nd gen AFTR): hardware MPEG-2 decoder fails with “not enough mem for decoder”

TL;DR version: Amlogic has fixed this issue in their driver, Fire CUBE OS needs to include the latest or more recent driver updates/fixes. i.e. a Fire OS 7 update for the Cube 2nd gen.

Technical Narrative:

Device: Fire TV Cube 2nd gen (AFTR / raven, Amlogic S922X), Fire OS 7.6.9.0 (PS7690/4716), kernel 4.9.113.

Symptom: after a day or two of uptime, starting MPEG-2 video often fails, typically when changing live TV channels. Other codecs keep working. A reboot fixes it for a while, then it comes back. It isn’t specific to one app. I reproduced it in a Media3/ExoPlayer app and in the stock Jellyfin Android TV client, and Channels DVR users have reported the same pattern on this model for years. MPEG-2 is the standard codec for US broadcast (ATSC) and cable TV, so any live-TV app on this device is affected.

What the device logs on each failure:

I/amcodec: codec_h_ioctl failed,handle=21,cmd=401053c2,subcmd=111, paramter=0, t=ffffffff errno=19
E/AmlogicVideoDecoderAwesome: codec init failed, ret=-0x100000a
E/AmlogicVideoDecoderAwesome: not enough mem for decoder
E/ACodec: [OMX.amlogic.mpeg2.decoder.awesome] ERROR(0x80001000)

What I found:

  1. Kernel trace. I traced 14 failures with Perfetto. Every one coincided with a kernel direct reclaim for an order-4 (64 KB) GFP_KERNEL|__GFP_ZERO allocation that recovered about one page and gave up. Snapshots of /proc/pagetypeinfo taken from bugreports at failure time show no free blocks of 16 KB or larger in the Unmovable or Movable pools, and an extfrag unusable index of about 0.93 at order 4. Free memory isn’t low; it’s fragmented. HEVC starts never triggered this allocation.
  2. Which code makes the request. cmd=401053c2, subcmd=111 is AMSTREAM_IOC_SET with AMSTREAM_PORT_INIT. It goes through amstream_port_init → video_port_init → vdec_init, which registers the ammvdec_mpeg12 device. In Amlogic’s media_modules from that period, ammvdec_mpeg12_probe allocates its per-instance state with devm_kzalloc(&pdev->dev, sizeof(struct vdec_mpeg12_hw_s), GFP_KERNEL). That struct embeds a pool of 32 struct vframe_s and comes to roughly 38–40 KB, so it lands in an order-4 page allocation. Order 4 is above PAGE_ALLOC_COSTLY_ORDER, so the 4.9 allocator makes no retries (mm/page_alloc.c, “Do not retry costly high order allocations”). The probe returns -ENOMEM, and vdec_init logs “driver probe failed” and returns -ENODEV. That’s the errno=19 above. The HEVC, H.264, VP9 and MPEG-4 drivers allocate the same state with vmalloc, which is why only MPEG-2 fails.
  3. The upstream fix. Amlogic fixed this on 9 April 2019 in media_modules commit bd39fead6 (“media_module: fix kasan check issue [1/2]”, PD#SWPL-6847). The commit message reads: “mpeg2/mjpeg multi instance alloc issue … use valloc instead of kzalloc”. It changes devm_kzalloc to vzalloc in ammvdec_mpeg12_probe. It’s public in CoreELEC/media_modules-aml, branch amlogic-4.9.269.
  4. Evidence the Cube has the pre-fix driver. On 7.6.9.0, /sys/module/amvdec_mmpeg12/parameters/ lists debug_enable dec_control decode_timeout_val error_frame_skip_level max_process_time pre_decode_buf_level radr rval udebug_flag. That set matches only vmpeg12_multi.c revisions from August 2018 to March 2019. Every revision from 28 March 2019 onwards, including the fix, adds again_threshold. I can’t read the .ko on a retail build to confirm directly.

Hi,

Thanks for posting. We have messaged the appropriate team for further investigation and will let you know once we receive an update.

In the meantime, could you please provide your Device Serial Number (DSN)?

You can find it here:

Settings → My Fire TV → About → Device Serial Number