上篇传送门: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 目录
2、gstrtpmanager
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 目录
3、gstrtp
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 目录
4、gstudp
如果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 目录
5、gstplugins_good_packages
third_party/gstreamer/gstplugins_good/BUILD.gn 修改
group("gstplugins_good_packages") {
deps = [
":gstaudiofx",
":gstaudioparsers",
":gstisomp4",
":gstmatroska",
":gstmultifile",
":gstwavparse",
+ ":gstrtsp",
+ ":gstrtpmanager",
+ ":gstrtp",
+ ":gstudp",
]
}
6、gsttcp
如果rtp底层传输协议使用的是tcp,需要编译该库
待补充。
六、AVPlayer framework
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、支持网络缓冲
待补充
七、dot图
待补充
gstudpsrc->gstrtpsession->gstrtpstorage->gstrtpssrcdemux->gstrtpjitterbuffer->gstrtpptdemux->gsttypefindelement->gstrtpmp2tdepay->mpegtsdemux…
八、注意事项
1、上述代码中BUILD.gn的sources 需要编译的C文件基本都没写,代码有点多,后续有时间补充;最简单的方法:gio库添加gio目录下所有的除window相关的源文件,gstreamer库添加相应目录下所有的源文件,编译过即可;其实部分源文件并不会被rtsp依赖,可以适当裁剪部分元素以减少动态库大小。
2、插件库的库名必须和文章定义的相同,并设置relative_install_dir安装到/system/lib/media/plugins目录。
九、结语
下一篇介绍rtsp插件运行调试相关方法。