赞
踩
上篇传送门:OpenHarmony AVPlayer扩展支持rtsp协议:编译gstreamer插件库(一)
1、gstrtsp
rtsp插件库,库名必须为libgstrtsp.z.so,不可修改
third_party/gstreamer/gstplugins_good/BUILD.gn 增加
ohos_source_set("gstrtsp_source") { sources = [ "gst/rtsp/xxx.c", ... ] configs = [ ":gst_plugins_config" ] } ohos_shared_library("gstrtsp") { deps = [ ":gstrtsp_source", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/glib:gio", "//third_party/gstreamer/gstreamer:gstbase", "//third_party/gstreamer/gstreamer:gstreamer", "//third_party/gstreamer/gstplugins_base:gstrtsp-1.0", "//third_party/gstreamer/gstplugins_base:gstrtp-1.0", "//third_party/gstreamer/gstplugins_base:gstsdp", ] relative_install_dir = "media/plugins" part_name = "gstreamer" subsystem_name = "thirdparty" }
编译生成libgstrtsp.z.so,安装到/system/lib/media/plugins 目录
rtpmanager插件库,库名必须为libgstrtpmanager.z.so,不可修改
third_party/gstreamer/gstplugins_good/BUILD.gn 增加
ohos_source_set("gstrtpmanager_source") { sources = [ "gst/rtpmanager/xxx.c", ... ] configs = [ ":gst_plugins_config" ] } ohos_shared_library("gstrtpmanager") { deps = [ ":gstrtpmanager_source", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/glib:gio", "//third_party/gstreamer/gstreamer:gstbase", "//third_party/gstreamer/gstreamer:gstreamer", "//third_party/gstreamer/gstplugins_base:gstaudio", "//third_party/gstreamer/gstplugins_base:gstrtp-1.0", ] relative_install_dir = "media/plugins" part_name = "gstreamer" subsystem_name = "thirdparty" }
编译生成libgstrtpmanager.z.so,安装到/system/lib/media/plugins 目录
rtp插件库,库名必须为libgstrtp.z.so,不可修改
third_party/gstreamer/gstplugins_good/BUILD.gn 增加
ohos_source_set("gstrtp_source") { sources = [ "gst/rtp/xxx.c", ... ] configs = [ ":gst_plugins_config" ] } ohos_shared_library("gstrtp") { deps = [ ":gstrtp_source", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/gstreamer/gstreamer:gstbase", "//third_party/gstreamer/gstreamer:gstreamer", "//third_party/gstreamer/gstplugins_base:gstaudio", "//third_party/gstreamer/gstplugins_base:gstvideo", "//third_party/gstreamer/gstplugins_base:gsttag", "//third_party/gstreamer/gstplugins_base:gstrtp-1.0", "//third_party/gstreamer/gstplugins_base:gstpbutils", ] relative_install_dir = "media/plugins" part_name = "gstreamer" subsystem_name = "thirdparty" }
编译生成libgstrtp.z.so,安装到/system/lib/media/plugins 目录
如果rtp底层传输协议使用的是udp,需要编译该库
udp插件库,库名必须为libgstudp.z.so,不可修改
third_party/gstreamer/gstplugins_good/BUILD.gn 增加
ohos_source_set("gstudp_source") { sources = [ "gst/udp/xxx.c", ... ] configs = [ ":gst_plugins_config" ] } ohos_shared_library("gstudp") { deps = [ ":gstudp_source", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/glib:gio", "//third_party/gstreamer/gstreamer:gstbase", "//third_party/gstreamer/gstreamer:gstreamer", ] relative_install_dir = "media/plugins" part_name = "gstreamer" subsystem_name = "thirdparty" }
third_party/gstreamer/gstplugins_good/gst/udp/gstudpsrc.c 修改,_GNU_SOURCE重定义错误
+ #ifdef _GNU_SOURCE
+ #undef _GNU_SOURCE
+ #endif
#define _GNU_SOURCE
/* Needed for OSX/iOS to define the IPv6 variants */
#define __APPLE_USE_RFC_3542
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
编译生成libgstudp.z.so,安装到/system/lib/media/plugins 目录
third_party/gstreamer/gstplugins_good/BUILD.gn 修改
group("gstplugins_good_packages") {
deps = [
":gstaudiofx",
":gstaudioparsers",
":gstisomp4",
":gstmatroska",
":gstmultifile",
":gstwavparse",
+ ":gstrtsp",
+ ":gstrtpmanager",
+ ":gstrtp",
+ ":gstudp",
]
}
如果rtp底层传输协议使用的是tcp,需要编译该库
third_party/gstreamer/gstplugins_base/BUILD.gn 修改
ohos_source_set("gsttcp_source") { sources = [ "gst/tcp/xxx.c", ... ] configs = [ ":gst_plugins_config" ] } ohos_shared_library("gsttcp") { deps = [ ":gsttcp_source", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/glib:gio", "//third_party/gstreamer/gstreamer:gstbase", "//third_party/gstreamer/gstreamer:gstreamer", ] relative_install_dir = "media/plugins" part_name = "gstreamer" subsystem_name = "thirdparty" }
编译生成libgsttcp.z.so,安装到/system/lib/media/plugins 目录
1、在AVPlayer的NAPI代码中限制只能设置http前缀的网络url,需要解除限制
/foundation/multimedia/player_framework/frameworks/js/avplayer/avplayer_napi.cpp 修改
void AVPlayerNapi::SetSource(std::string url) { MEDIA_LOGI("input url is %{public}s!", url.c_str()); bool isFd = (url.find("fd://") != std::string::npos) ? true : false; - bool isNetwork = (url.find("http") != std::string::npos) ? true : false; + bool isNetwork = ((url.find("http") != std::string::npos) || (url.find("rtsp") != std::string::npos)) ? true : false; if (isNetwork) { auto task = std::make_shared<TaskHandler<void>>([this, url]() { MEDIA_LOGI("SetNetworkSource Task"); std::unique_lock<std::mutex> lock(taskMutex_); auto state = GetCurrentState(); if (state != AVPlayerState::STATE_IDLE) { OnErrorCb(MSERR_EXT_API9_OPERATE_NOT_PERMIT, "current state is not idle, unsupport set url"); return; } if (player_ != nullptr) { if (player_->SetSource(url) != MSERR_OK) { OnErrorCb(MSERR_EXT_API9_INVALID_PARAMETER, "failed to SetSourceNetWork"); } stopWait_ = false; LISTENER(stateChangeCond_.wait(lock, [this]() { return stopWait_.load(); }), "SetSourceNetWork", false) } }); (void)taskQue_->EnqueueTask(task); } else if (isFd) { ... }
2、支持网络缓冲
/foundation/multimedia/services/engine/gstreamer/common/playbin_adapter/playbin_ctrler_base.cpp 修改
int32_t PlayBinCtrlerBase::SetSource(const std::string &url)
{
std::unique_lock<std::mutex> lock(mutex_);
uri_ = url;
- if (url.find("http") == 0 || url.find("https") == 0 || EnableBufferingBySysParam()) {
+ if (url.find("http") == 0 || url.find("https") == 0 || url.find("rtsp") == 0 || EnableBufferingBySysParam()) {
isNetWorkPlay_ = true;
}
MEDIA_LOGI("Set source: %{public}s", url.c_str());
return MSERR_OK;
}
待补充
gstudpsrc->gstrtpsession->gstrtpstorage->gstrtpssrcdemux->gstrtpjitterbuffer->gstrtpptdemux->gsttypefindelement->gstrtpmp2tdepay->mpegtsdemux…
1、上述代码中BUILD.gn的sources 需要编译的C文件基本都没写,代码有点多,后续有时间补充;最简单的方法:gio库添加gio目录下所有的除window相关的源文件,gstreamer库添加相应目录下所有的源文件,编译过即可;其实部分源文件并不会被rtsp依赖,可以适当裁剪部分元素以减少动态库大小。
2、插件库的库名必须和文章中定义的相同,并设置relative_install_dir=“media/plugins”将库安装到/system/lib/media/plugins目录。
下一篇将介绍gstreamer rtsp插件及板端播放rtsp节目异常的一些调试方法。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。