HarmonyOS 鸿蒙Next 关于native层视频编解码的问题

发布于 1周前 作者 bupafengyu 最后一次编辑是 5天前 来自 鸿蒙OS

HarmonyOS 鸿蒙Next 关于native层视频编解码的问题

在看demo(com.samples.AVCodecSample)的时候,发现player是写成单例的(如下),不知道是做了什么考虑。是推荐都做成单例么?
static Player &GetInstance() {
static Player player;
return player;
}

发现在把视频帧塞到解码器的时候,会等待五秒。若是快速地进出播放页面,即不断地开关Player时,会有小概率(1/50左右)报错。当然我不敢肯定是这里,因为报错的日志没有定位到具体的地方,我只是一直打log追踪到这个地方。若是每次都重新实例化player会不会有什么问题?

 bool condRet = videoDecContext_->outputCond.wait_for(
lock, 5s, this { return !isStarted_ || !videoDecContext_->outputBufferInfoQueue.empty(); });

报错如下:


#00 pc 0000000000085b24 /system/lib64/librender_service_client.z.so(OHOS::Rosen::RSAnimation::SetFinishCallback(std::__h::shared_ptr<OHOS::Rosen::AnimationFinishCallback> const&)+88)(5085c6619ca0d8001444738bda4ec822)
#01 pc 0000000000096e60 /system/lib64/librender_service_client.z.so(OHOS::Rosen::RSImplicitAnimator::CloseImplicitAnimation()+1644)(5085c6619ca0d8001444738bda4ec822)
#02 pc 000000000013c43c /system/lib64/librender_service_client.z.so(OHOS::Rosen::RSNode::CloseImplicitAnimation()+92)(5085c6619ca0d8001444738bda4ec822)
#03 pc 0000000000aee8c0 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::AnimationUtils::CloseImplicitAnimation()+52)(fe18d119640d70fd43747fb9067b8933)
#04 pc 0000000000b3b3d4 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::RosenRenderContext::MaskAnimation(OHOS::Ace::Color const&, OHOS::Ace::Color const&)+288)(fe18d119640d70fd43747fb9067b8933)
#05 pc 0000000000b3b040 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::RosenRenderContext::TriggerPageTransition(OHOS::Ace::PageTransitionType, std::__h::function<void ()> const&)+2484)(fe18d119640d70fd43747fb9067b8933)
#06 pc 00000000016d918c /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::PagePattern::TriggerPageTransition(OHOS::Ace::PageTransitionType, std::__h::function<void ()> const&)+668)(fe18d119640d70fd43747fb9067b8933)
#07 pc 00000000016dc9c8 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::(anonymous namespace)::FirePageTransition(OHOS::Ace::RefPtr<OHOS::Ace::NG::FrameNode> const&, OHOS::Ace::PageTransitionType)+456)(fe18d119640d70fd43747fb9067b8933)
#08 pc 00000000016dc798 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::StageManager::StartTransition(OHOS::Ace::RefPtr<OHOS::Ace::NG::FrameNode> const&, OHOS::Ace::RefPtr<OHOS::Ace::NG::FrameNode> const&, OHOS::Ace::RouteType)+376)(fe18d119640d70fd43747fb9067b8933)
#09 pc 00000000016dfb80 /system/lib64/platformsdk/libace_compatible.z.so(fe18d119640d70fd43747fb9067b8933)
#10 pc 0000000000aa0c54 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::UITaskScheduler::FlushAfterLayoutTask()+96)(fe18d119640d70fd43747fb9067b8933)
#11 pc 0000000000aa0bd0 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::UITaskScheduler::FlushTask(bool)+216)(fe18d119640d70fd43747fb9067b8933)
#12 pc 0000000000a7e7ac /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::PipelineContext::FlushVsync(unsigned long, unsigned int)+364)(fe18d119640d70fd43747fb9067b8933)
#13 pc 0000000000a335a4 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::PipelineBase::OnVsyncEvent(unsigned long, unsigned int)+296)(fe18d119640d70fd43747fb9067b8933)
#14 pc 0000000000a353c8 /system/lib64/platformsdk/libace_compatible.z.so(fe18d119640d70fd43747fb9067b8933)
#15 pc 00000000009635e0 /system/lib64/platformsdk/libace_compatible.z.so(std::__h::function<void (unsigned long, unsigned int)>::operator()(unsigned long, unsigned int) const+64)(fe18d119640d70fd43747fb9067b8933)
#16 pc 0000000000963580 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::Window::OnVsync(unsigned long, unsigned int)+64)(fe18d119640d70fd43747fb9067b8933)
#17 pc 0000000000b5f9f0 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::RosenWindow::OnVsync(unsigned long, unsigned int)+36)(fe18d119640d70fd43747fb9067b8933)
#18 pc 0000000000b5ff70 /system/lib64/platformsdk/libace_compatible.z.so(OHOS::Ace::NG::RosenWindow::RosenWindow(OHOS::sptr<OHOS::Rosen::Window> const&, OHOS::Ace::RefPtr<OHOS::Ace::TaskExecutor>, int)::$_0::operator()(long, long) const::‘lambda()::operator()() const+192)(fe18d119640d70fd43747fb9067b8933)
#19 pc 0000000000b5fdb4 /system/lib64/platformsdk/libace_compatible.z.so(fe18d119640d70fd43747fb9067b8933)
#20 pc 00000000000de2b8 /system/lib64/libwm.z.so(OHOS::Rosen::VsyncStation::VsyncCallbackInner(long, long)+712)(b429fe6e2c432310cec2100e0f8c3145)
#21 pc 00000000000ddf54 /system/lib64/libwm.z.so(b429fe6e2c432310cec2100e0f8c3145)
#22 pc 0000000000023bd8 /system/lib64/libvsync.z.so(OHOS::Rosen::VSyncCallBackListener::HandleVsyncCallbacks(long*, long, int)+688)(62759ae29a6649c6b4d6161c981be016)
#23 pc 000000000002372c /system/lib64/libvsync.z.so(OHOS::Rosen::VSyncCallBackListener::OnReadable(int)+208)(62759ae29a6649c6b4d6161c981be016)
#24 pc 0000000000020430 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(18b758aed6d3f22e6d40f65c3e5284b9)
#25 pc 000000000001bdb4 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventHandler::DistributeEvent(std::_h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)> const&)+1140)(18b758aed6d3f22e6d40f65c3e5284b9)
#26 pc 000000000002d6a8 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::ExecuteEventHandler(std::h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)>&)+348)(18b758aed6d3f22e6d40f65c3e5284b9)
#27 pc 000000000002cf64 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::Run()+908)(18b758aed6d3f22e6d40f65c3e5284b9)
#28 pc 0000000000030308 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventRunner::Run()+528)(18b758aed6d3f22e6d40f65c3e5284b9)
#29 pc 00000000000aebb4 /system/lib64/platformsdk/libappkit_native.z.so(OHOS::AppExecFwk::MainThread::Start()+400)(86597fa70e3e423d170f27e0911bfbac)
#30 pc 0000000000004e34 /system/lib64/appspawn/appspawn/libappspawn_ace.z.so(RunChildProcessor(AppSpawnContent*, AppSpawnClient*)+568)(dd2ca1f08cb4bfd1411e66a36ca88644)
#31 pc 000000000000b9e4 /system/bin/appspawn(AppSpawnChild+576)(5d854d9cb7b4d6b81bb827491b8f24eb)
#32 pc 00000000000150e8 /system/bin/appspawn(ProcessSpawnReqMsg+2956)(5d854d9cb7b4d6b81bb827491b8f24eb)
#33 pc 0000000000013360 /system/bin/appspawn(OnReceiveRequest+132)(5d854d9cb7b4d6b81bb827491b8f24eb)
#34 pc 0000000000016cd0 /system/lib64/chipset-pub-sdk/libbegetutil.z.so(HandleRecvMsg+344)(5fbff8622072f916b215ff44bfa1595c)
#35 pc 00000000000167a4 /system/lib64/chipset-pub-sdk/libbegetutil.z.so(HandleStreamEvent+192)(5fbff8622072f916b215ff44bfa1595c)
#36 pc 0000000000013e84 /system/lib64/chipset-pub-sdk/libbegetutil.z.so(ProcessEvent+88)(5fbff8622072f916b215ff44bfa1595c)
#37 pc 0000000000013a40 /system/lib64/chipset-pub-sdk/libbegetutil.z.so(RunLoop+308)(5fbff8622072f916b215ff44bfa1595c)
#38 pc 00000000000112d0 /system/bin/appspawn(AppSpawnRun+136)(5d854d9cb7b4d6b81bb827491b8f24eb)
#39 pc 000000000000ec3c /system/bin/appspawn(main+764)(5d854d9cb7b4d6b81bb827491b8f24eb)
#40 pc 00000000000a1280 /system/lib/ld-musl-aarch64.so.1(libc_start_main_stage2+64)(61f80ae3f62d97e8ddcaef8fc8c24af1)
========SubmitterStacktrace========
#00 pc 0000000000013068 /system/lib64/platformsdk/libuv.so(uv_timer_start+128)(69dbb78eada5e50b7ac9c30986b2782d)
#01 pc 0000000000013700 /system/lib64/platformsdk/libuv.so(uv__run_timers+136)(69dbb78eada5e50b7ac9c30986b2782d)
#02 pc 0000000000016ee0 /system/lib64/platformsdk/libuv.so(uv_run+272)(69dbb78eada5e50b7ac9c30986b2782d)
#03 pc 000000000007cd90 /system/lib64/platformsdk/libruntime.z.so(OHOS::AbilityRuntime::OHOSLoopHandler::OnTriggered()+144)(1aec9ce0fe93450550f770674a340635)
#04 pc 000000000007d33c /system/lib64/platformsdk/libruntime.z.so(std::__h::__function::__func<OHOS::AbilityRuntime::OHOSLoopHandler::OnTriggered()::$_0, std::__h::allocator<OHOS::AbilityRuntime::OHOSLoopHandler::OnTriggered()::$_0>, void ()>::operator()() (.9efded9864dc55830f61b3b92d59beab)+56)(1aec9ce0fe93450550f770674a340635)
#05 pc 000000000001bdb8 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventHandler::DistributeEvent(std::__h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)> const&)+1144)(18b758aed6d3f22e6d40f65c3e5284b9)
#06 pc 000000000002d6ac /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::ExecuteEventHandler(std::__h::unique_ptr<OHOS::AppExecFwk::InnerEvent, void ()(OHOS::AppExecFwk::InnerEvent)>&)+352)(18b758aed6d3f22e6d40f65c3e5284b9)
#07 pc 000000000002cf68 /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::(anonymous namespace)::EventRunnerImpl::Run()+912)(18b758aed6d3f22e6d40f65c3e5284b9)
#08 pc 000000000003030c /system/lib64/chipset-pub-sdk/libeventhandler.z.so(OHOS::AppExecFwk::EventRunner::Run()+532)(18b758aed6d3f22e6d40f65c3e5284b9)
#09 pc 00000000000aebb8 /system/lib64/platformsdk/libappkit_native.z.so(OHOS::AppExecFwk::MainThread::Start()+404)(86597fa70e3e423d170f27e0911bfbac)
#10 pc 0000000000004e38 /system/lib64/appspawn/appspawn/libappspawn_ace.z.so(RunChildProcessor(AppSpawnContent*, AppSpawnClient*)+572)(dd2ca1f08cb4bfd1411e66a36ca88644)
#11 pc 000000000000b9e8 /system/bin/appspawn(AppSpawnChild+580)(5d854d9cb7b4d6b81bb827491b8f24eb)
#12 pc 00000000000150ec /system/bin/appspawn(ProcessSpawnReqMsg+2960)(5d854d9cb7b4d6b81bb827491b8f24eb)
#13 pc 0000000000013364 /system/bin/appspawn(OnReceiveRequest+136)(5d854d9cb7b4d6b81bb827491b8f24eb)

3 回复

楼主,com.samples.AVCodecSample是从哪看的?

针对HarmonyOS 鸿蒙Next关于native层视频编解码的问题,以下是一些专业解答:

HarmonyOS 鸿蒙Next系统提供了强大的native层视频编解码能力,主要通过AVCodec API实现。视频解码时,可以利用系统提供的native解码API,对视频流进行解码,解码过程中需处理不同视频格式、码率等参数,确保解码效率和质量。同时,HarmonyOS支持软解码和硬解码,软解码目前支持H264,硬解码则支持H264和H265。

解码后的视频数据可以通过XComponent等模块进行显示。XComponent支持跨组件通信,可以将视频数据在多个窗口间共享和显示,从而实现多窗口视频播放功能。

在开发过程中,需要注意以下几点:

  1. 确保已掌握视频解码的核心技术,以及XComponent等模块的基本使用方法。
  2. 根据实际需求选择合适的解码模式(如Surface模式或Buffer模式),并正确配置解码器。
  3. 处理好解码后的视频数据,确保能够正确显示和播放。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部