csipsimple not enough buffer for decoded frame

With default H264 codec settings, i.e: level=3.0 and size=720x480, when receiving video with resolution 704x576, there will be no incoming video shown and repeated error messages in the log:

Error: not enough buffer for decoded frame (supplied=x, required=y)
codec decode() error: Size is too short (PJ_ETOOSMALL) [err:70019]

Initially, it is the application that should set the expected maximum size of the incoming video via H264 codec param, as described in this wiki. However, since #1622, the lib is equipped with such auto-adjust mechanism if the configured size is too small, unfortunately there is a bug in the auto-adjustment code, as described in the original report, this ticket should fix this bug.



I'd like to report a bug in how PJSIP 2.2 allocates H264 video decode buffer. I discovered the issue when connecting to another endpoint sending 4CIF format video (704x576), using H264. This resulted in no video decoding and the following repeated errors in log:

10:02:34.142 vstdec0298F6EC  Error: not enough buffer for decoded frame (supplied=589824, required=608256)
10:02:34.169 vstdec0298F6EC  codec decode() error: Size is too short (PJ_ETOOSMALL) [err:70019]

PJSIP uses the largest possible frame supported by the H264 profile level which also has 3/2 aspect ratio, in multiples of 16 pixels (the H264 macroblock size). See function find_highest_res() in vid_codec_util.c. So at level 3.0 PJSIP allocates a 768x512 frame, exactly 3/2 aspect ratio. PJSIP can resize dynamically, but only to smaller frame sizes. So when 4CIF comes in at 704x576 (which is a slightly larger image but still supported by level 3.0) PJSIP can't decode the video and emits error messages. Fortunately an easy workaround is to set the profile level to 3.1 and then PJSIP allocates a pretty huge frame for decoding.

It seems the proper fix is to allocate a frame buffer large enough to hold the maximum number of macroblocks for the profile level, without concern for accurate aspect ratio. I realize now that 4CIF is 1620 macroblocks which is the maximum for profile level 3.0, and 704x576 is the closest to 3/2 ratio you can get using 1620 macroblocks. So maybe these max sizes need to be baked in?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值