OpenHarmony AVPlayer扩展支持rtsp协议:编译gstreamer插件库(一)
一、简介 OpenHarmony-5.0 之前的版本播放器AVPlayer使用gstreamer引擎实现播放能力,可以支持http、https、hls网络协议,但还无法支持rtsp协议。本篇文章介绍如何基于gstreamer扩展支持rtsp协议。 二、前言 版本信息:OpenHarmony-4.0-Release标准32位系统(不同版本代码可
一、简介
OpenHarmony-5.0 之前的版本播放器AVPlayer使用gstreamer引擎实现播放能力,可以支持http、https、hls网络协议,但还无法支持rtsp协议。本篇文章介绍如何基于gstreamer扩展支持rtsp协议。
二、前言
版本信息:OpenHarmony-4.0-Release标准32位系统(不同版本代码可能略有不同)
备注:下面代码中“+”代表新增行,“-”代表删除行,“增加”代表以下代码均需添加,“...”代表省略n行代码
三、说明
想要AVPlayer支持rtsp网络协议需要增加rtsp相关的gstreamer库,包括glib库,gstreamer基础能力库,rtsp、rtp、sdp基础库,rtsp、rtp、udp、tcp等插件库等,还需要修改AVPlayer框架层代码。
四、基础库
1、glib
(1)gio
后续与网络相关的插件库都需要依赖glib下的gio库,需要新增编译该库
third_party/glib/BUILD.gn 增加
config("gio_config") {
visibility = [ ":*" ]
include_dirs = [
".",
"glib",
"gobject",
"gio",
"gmodule",
"//third_party/libffi/include",
"//third_party/zlib/",
]
cflags = [
"-DG_LOG_DOMAIN=\"GIO\"",
"-Wno-sign-compare",
"-Wno-unused-function",
"-Wno-int-conversion",
"-DGIO_COMPILATION",
"-DGIO_MODULE_DIR=\"system/lib/gio/modules\"",
"-DHAVE_NETLINK",
"-DLOCALSTATEDIR=\"system\"",
"-DXDG_PREFIX=_gio_xdg",
]
}
ohos_source_set("gio_source") {
source = [
gio/xxx.c,
...
gio/inotify/xxx.c,
...,
gio/xdgmime/xxx.c,
需要编译的C文件
]
config = [ ":gio_config" ]
}
ohos_shared_library("gio") {
deps = [
":gio_source",
"glib"
"gobject",
"gmodule"
"//third_party/libffi:ffi",
"//third_party/zlib:shared_libz",
]
part_name = "glib"
subsystem_name = "thirdparty"
}
生成libgio.z.so,安装到/system/lib/ 目录
(2)glib_packages
third_party/glib/BUILD.gn 修改
group("glib_packages") {
deps = [
":glib",
":gmodule",
":gobject",
+ ":gio",
]
}
2、gstreamer
(1)gstnet
后续的rtsp、udp插件等都需要依赖这个库,这里为了方便编译成了静态库被libgstreamer.z.so链接,后续其他库直接依赖libgstreamer.z.so即可,也可修改编译成动态库
third_party/gstreamer/gstreamer/BUILD.gn 增加
config("gstnet_config") {
include_dirs = [
".",
"libs",
"//third_party/glib/glib",
"//third_party/glib",
"//third_party/glib/gmodule",
]
cflags = [
"-DHAVE_CONFIG_H",
"-fno-strict-aliasing",
"-Wno-sign-compare",
"-Wno-builtin-requires-header",
"-DG_LOG_DOMAIN=\"GStreamer-Net\"",
"-DBUILDING_GST_NET",
]
}
ohos_source_set("gstnet_source") {
sources = [
"libs/gst/net/xxx.c",
...
]
configs = [ ":gstnet_config" ]
}
ohos_static_library("gstnet") {
deps = [
":gstnet_source"
"//third_party/glib:gio",
]
part_name = "gstreamer"
subsystem_name = "thirdparty"
}
third_party/gstreamer/gstreamer/BUILD.gn 修改
ohos_shared_library("gstreamer") {
deps = [
":gst_source",
":gstprintf",
+ ":gstnet",
"//third_party/glib:glib",
"//third_party/glib:gmodule",
"//third_party/glib:gobject",
]
+ include_dirs = [
+ "./libs",
+ ]
part_name = "gstreamer"
subsystem_name = "thirdparty"
}
(2)fakesrc element
gstrtspsrc插件运行时会创建该元素,如果不存在会报错
third_party/gstreamer/gstreamer/BUILD.gn 修改
ohos_source_set("gstcoreelements_source") {
sources = [
"plugins/elements/gstcapsfilter.c",
"plugins/elements/gstcoreelementsplugin.c",
...
"plugins/elements/gsttypefindelement.c",
+ “plugins/elements/gstfakesrc.c”,
]
注册fakesrc插件
third_party/gstreamer/gstreamer/plugins/elements/gstcoreelementselements.h 修改
#ifndef OHOS_EXT_FUNC
/* ohos.ext.func.0032 remove the unused features */
GST_ELEMENT_REGISTER_DECLARE (capsfilter);
...
GST_ELEMENT_REGISTER_DECLARE (typefind);
GST_ELEMENT_REGISTER_DECLARE (valve);
#else
GST_ELEMENT_REGISTER_DECLARE (capsfilter);
GST_ELEMENT_REGISTER_DECLARE (fakesink);
+ GST_ELEMENT_REGISTER_DECLARE (fakesrc);
...
GST_ELEMENT_REGISTER_DECLARE (typefind);
#endif
third_party/gstreamer/gstreamer/plugins/elements/gstcoreelementsplugin.c 修改
#ifndef OHOS_EXT_FUNC
/* ohos.ext.func.0032 remove the unused features */
ret |= GST_ELEMENT_REGISTER (capsfilter, plugin);
...
ret |= GST_ELEMENT_REGISTER (streamiddemux, plugin);
#else
ret |= GST_ELEMENT_REGISTER (capsfilter, plugin);
ret |= GST_ELEMENT_REGISTER (fakesink, plugin);
+ ret |= GST_ELEMENT_REGISTER (fakesrc, plugin);
...
ret |= GST_ELEMENT_REGISTER (multiqueue, plugin);
#endif
(3)gstaudio
后续插件依赖该库部分未编译的源码
third_party/gstreamer/gstplugins_base/BUILD.gn 修改
ohos_source_set("gstaudio_source") {
sources = [
"gst-libs/gst/audio/audio-buffer.c",
"gst-libs/gst/audio/audio-channel-mixer.c",
...
"gst-libs/gst/audio/streamvolume.c",
+ "gst-libs/gst/audio/gstaudiostreamalign.c"
]
(4)gstrtp-1.0
rtp基础库,后续插件依赖,源码库名为gstrtp,与后续插件库名冲突,必须修改库名,这里修改为gstrtp-1.0
third_party/gstreamer/gstplugins_base/BUILD.gn 修改
- ohos_source_set("rtp_source") {
+ ohos_source_set("rtp-1.0_source") {
sources = [
"gst-libs/gst/rtp/gstrtcpbuffer.c",
...,
]
configs = [ ":gst_plugins_config" ]
}
- ohos_shared_library("gstrtp") {
+ ohos_shared_library("gstrtp-1.0") {
deps = [
- ":rtp_source",
+ ":rtp-1.0_source",
"//third_party/glib:glib",
"//third_party/glib:gobject",
"//third_party/gstreamer/gstreamer:gstbase",
"//third_party/gstreamer/gstreamer:gstreamer",
]
part_name = "gstreamer"
subsystem_name = "thirdparty"
}
编译生成libgstrtp-1.0.z.so,安装到/system/lib/ 目录
(5)gstrtsp-1.0
rtsp基础库,后续插件依赖,源码库名不能为gstrtsp
third_party/gstreamer/gstplugins_base/BUILD.gn 增加
ohos_source_set("rtsp-1.0_source") {
sources = [
"gst-libs/gst/rtsp/xxx.c",
...
]
configs = [ ":gst_plugins_config" ]
}
ohos_shared_library("gstrtsp-1.0") {
deps = [
":rtsp-1.0_source",
"//third_party/glib:glib",
"//third_party/glib:gobject",
"//third_party/glib:gio",
"//third_party/gstreamer/gstreamer:gstbase",
"//third_party/gstreamer/gstreamer:gstreamer",
":gstvideo",
":gstaudio",
]
part_name = "gstreamer"
subsystem_name = "thirdparty"
}
编译生成libgstrtsp-1.0.z.so,安装到/system/lib/ 目录
(6)gstsdp
sdp基础库,后续插件依赖
third_party/gstreamer/gstplugins_base/BUILD.gn 增加
ohos_source_set("gstsdp_source") {
sources = [
"gst-libs/gst/sdp/gstmikey.c",
"gst-libs/gst/sdp/gstsdpmessage.c",
]
configs = [ ":gst_plugins_config" ]
}
ohos_shared_library("gstsdp") {
deps = [
":gstsdp_source",
"//third_party/glib:glib",
"//third_party/glib:gobject",
"//third_party/glib:gio",
"//third_party/gstreamer/gstreamer:gstbase",
"//third_party/gstreamer/gstreamer:gstreamer",
":gstvideo",
":gstaudio",
":gstrtp-1.0",
":gstpbutils",
]
part_name = "gstreamer"
subsystem_name = "thirdparty"
}
编译生成libgstsdp.z.so,安装到/system/lib/ 目录
(7)gstplugins_base_packages
third_party/gstreamer/gstplugins_base/BUILD.gn 修改
group("gstplugins_base_packages") {
deps = [
":gstapp",
":gstaudioconvert",
":gstaudioresample",
...
":gstvideoscale",
+ ":gstrtp-1.0",
+ "gstrtsp-1.0",
+ "gstsdp",
+ "gstpbutils",
]
}
五、插件库
更多推荐
所有评论(0)