之前参考 Google 官方 native codec demo 实现了一个 Android 机上硬解码的功能,期望能改善手机的 CPU 使用率,提高应用性能。但是后来同事报出说在 华为 Mate10 手机上解码失败,由于当时我手边没有 Mate10,只有 P30,而在 P30 、小米8 和 小米 MIX 2S 上测试均未复现。因此一直没处理,最近再次提上日程,本想给华为提 case,写了个硬解码 Demo,竟然解决了这一概率性失败的问题。
代码实现
代码实现完全参考 Google 官方 native codec demo,具体工程可从我的 GitHub 上下载 NdkMediaCodecDemo。
原始问题
原始问题在于使用 NDK MediaCodec 硬解码 h264/mp4 视频时,概率性地从开始就解码失败,具体表现为:在 P30、小米8、小米 Mix2S 手机上几乎不复现该问题,一直都能解码成功。而在 mate10 上几乎没有能成功解码的时候,一直返回 EAGAIN,从 log 里看,和正常解码时的 log 相比,有以下异常内容:
12-15 19:00:11.554 21696 21956 I ACodec : [OMX.hisi.video.decoder.avc] ExecutingState flushing now (codec owns 1/5 input, 8/8 output).
12-15 19:00:12.269 1000 21960 E VIDEO : VIDEO-[InquireSliceProperty]:[11002]sliceheader first part dec err
此外,正常解码的 log 中还多出了一些 log:
12-15 19:00:40.720 1000 21999 W HiDecoder: VIDEO-[EraseOutputBufferRecord]:[696]invalid buffer, shareFd:30
12-15 19:00:40.720 1000 21999 W HiDecoder: VIDEO-[EraseOutputBufferRecord]:[696]invalid buffer, shareFd:45
12-15 19:00:40.747 1000 21995 I VIDEO : VIDEO-[H264_ReportColorAspectsInfo]:[454]syntax value : range 0 primaries 0 matrix 2 transfer 0
12-15 19:00:40.747 1000 21999 I ComponentImp: VIDEO-[EventProcess]:[333]event type (0)
12-15 19:00:40.747 1000 21999 I ColorParams: VIDEO-[PrintColorAspects]:[104]Range 2 Primaries 0 MatrixCoeffs 0 Transfer 0
12-15 19:00:40.748 1000 1188 I OMXParms: VIDEO-[GetParameter]:[257]index(0x2000001) ParamPortDefinition
12-15 19:00:40.749 1000 1188 I OMXParms: VIDEO-[GetParameter]:[257]index(0x7f000006) ??
12-15 19:00:40.749 1000 1188 I OMXParms: VIDEO-[GetConfig]:[310]index(0x700000f) ConfigCommonOutputCrop
12-15 19:00:40.749 1000 1188 D OMXParms: VIDEO-[GetImageCropInfo]:[924]GetImageCropInfo: left 0, top 0, width 720, height 1080
12-15 19:00:40.749 1000 1188 I OMXParms: VIDEO-[SetConfig]:[336]index(0x7f00000b) ??
12-15 19:00:40.749 1000 1188 I OMXParms: VIDEO-[GetConfig]:[310]index(0x7f00000b) ??
12-15 19:00:40.749 1000 1188 I ColorParams: VIDEO-[PrintColorAspects]:[104]Range 2 Primaries 0 MatrixCoeffs 0 Transfer 0
12-15 19:00:40.749 21696 21992 I ACodec : [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:0(Unspecified), M:0(Unspecified), T:0(Unspecified)) err=0(NO_ERROR)
12-15 19:00:40.766 21696 21696 D DECODE_DEMO: Try again later. tryagaincnt = 0.
12-15 19:00:40.767 21696 21696 D DECODE_DEMO: read time = 1, samplesize = 37888
12-15 19:00:40.778 1000 21999 I HiDecoder: VIDEO-[UpdateDecodeParam]:[1546]need report image info change:0, need realloc pmv buf:1
12-15 19:00:40.778 1000 21999 I HiDecoder: VIDEO-[UpdateDecodeParam]:[1551]update decode params: bitDepth:8=>8, dispWidth:720=>720, dispHeight:1080=>1080
12-15 19:00:40.779 1000 21999 I HiDecoder: VIDEO-[UpdateDecodeParam]:[1554]update decode params: decWidth:720=>720, decHeight:1080=>1088
12-15 19:00:40.779 1000 21999 I HiDecoder: VIDEO-

最低0.47元/天 解锁文章
2807

被折叠的 条评论
为什么被折叠?



