Kurento API¶
**Kurento媒体服务**可以通过暴露API的方式来控制, 以便于开发者通过高级语言与它相交互. Kurento项目已经为多个平台提供了该API的 Kurento Client 实现方式.
如果你需要使用其他没被已提供的高级语言,你可以使用 Kurento Protocol 来实现自己的Kurento client, kurento协议是基于 WebSocket 和 JSON-RPC.
下面的教程将介绍Kurento Api的高级使用方式,关于kurento媒体服务向客户端暴露的媒体能力,如果你是需要查阅kurento的可运行demo,请参考 教程摘录.
媒体元素与媒体管道¶
Kurento是基于两种概念作为积木向应用开发人员展示的:
媒体元素. 媒体元素是对媒体流执行特定操作的功能单元,媒体元素是一种将每种功能的方式表示为应用程序开发人员的独立“黑盒子”(媒体元素),他不需要了解元素的底层细节而方便使用它。媒体元素能够从其他元素(通过媒体源)*接收* 媒体并将媒体 发送 到其他元素(通过媒体接收器)。 基于它们功能的不通,媒体元素可以被分析不同的组:
- 输入端: 媒体元素可以接收媒体流和将其注入媒体管道。这里有几种不同方式的输入端,文件输入是指从文件中获取媒体流,网络输入是指从网络中获取媒体流,捕获端输入是指通过相机获取其他硬件资源来截取媒体流.
- 过滤器: 负责转换或分析媒体的媒体元素. 因此它可以执行混流,复用,分析,扩展等过滤操作.
- 中心枢纽: 媒体对象通过管道管理多媒体流,一个 中心 包含不同的 中心点 以便于其他媒体元素互联,取决于中心的类型,有不同的方式来控制媒体流。例如,有一个叫 Composite 的中心合并所有的输入流来合并成唯一的输出视频流,所有输入都排列成网格.
- 输出端: 体元素能够从媒体管道中取出媒体流。同样,有几种类型的输出端点,专门用于文件,网络,屏幕等。
媒体管道: 媒体管道是媒体元素通道, 其中源元素生成的输出流被馈送到一个或多个宿元素中。 因此, 管道表示能够在流上执行一系列操作的"pipe"。
实现从WebRtcEndpoint接收媒体流的交互式多媒体应用程序的媒体管道示例,在检测到的面部上叠加和图像并发送回结果流
Kurento API 是 面向对象编程. 这意味着这些类都可以被实例化为队形,这些对象提供的 属性 代表kurento服务的网络状态,暴露出的 方法 可以被服务所执行.
下面的类图展示了Kurento Api主要之间的关系:
主要类的类图¶
Endpoints¶
WebRtcEndpoint 是通过web进行流媒体实时通讯(RTC)的输入/输出端. 它基于浏览器实现了 WebRTC 技术.
A RecorderEndpoint 是一个输出端点,提供以可靠模式存储内容的功能(不丢弃数据).它包含用于音频和视频的媒体 媒体接收器 .
以下类图显示了主要endpoint类的关系:
![digraph endpoints {
bgcolor = "transparent";
fontname = "Bitstream Vera Sans";
fontsize = 8;
size = "12,8";
node [
fillcolor = "#E7F2FA";
fontname = "Bitstream Vera Sans";
fontsize = 8;
shape = "record";
style = "filled";
]
edge [
arrowtail = "empty";
dir = "back";
fontname = "Bitstream Vera Sans";
fontsize = 8;
]
"MediaElement" -> "Endpoint";
"Endpoint" -> "SessionEndpoint";
"Endpoint" -> "UriEndpoint";
"SessionEndpoint" -> "HttpEndpoint";
"SessionEndpoint" -> "SdpEndpoint";
"HttpEndpoint" -> "HttpPostEndpoint";
"SdpEndpoint" -> "RtpEndpoint";
"SdpEndpoint" -> "WebRtcEndpoint";
"UriEndpoint" -> "PlayerEndpoint";
"UriEndpoint" -> "RecorderEndpoint";
}](../_images/graphviz-8ed918138381b94c7109f95ebbc45e962d882428.png)
Class diagram of main Endpoints in Kurento API¶
Filters¶
过滤器是一个可执行媒体处理,计算机视觉,增强现实等的媒体元素。
ZBarFilter 过滤器检测视频流中的二维码和条形码.当发现对应的条码时,过滤器会触发一个CodeFoundEvent事件. 客户端可以向此事件添加侦听器以执行某些操作.
GStreamerFilter 是一个通用的过滤器接口,允许任何GStreamer元素注入到Kurento媒体管道. 但请注意当前GStreamerFilter仅支持单个元素的注入,同一时间不能超过一个; 如果你需要同时注入多个元素可以使用多个GStreamerFilters.
以下类图显示了主要过滤器类间的关系:
![digraph filters {
bgcolor = "transparent";
fontname = "Bitstream Vera Sans";
fontsize = 8;
size = "12,8";
node [
fillcolor = "#E7F2FA";
fontname = "Bitstream Vera Sans";
fontsize = 8;
shape = "record";
style = "filled";
]
edge [
arrowtail = "empty";
dir = "back";
fontname = "Bitstream Vera Sans";
fontsize = 8;
]
"MediaElement" -> "Filter";
"Filter" -> "ZBarFilter";
"Filter" -> "FaceOverlayFilter";
"Filter" -> "GStreamerFilter";
}](../_images/graphviz-2aa0820aeb5179b8abb981a27ea5aa7994535ffb.png)
Class diagram of main Filters in Kurento API¶
![digraph hubs {
bgcolor = "transparent";
fontname = "Bitstream Vera Sans";
fontsize = 8;
size = "12,8";
node [
fillcolor = "#E7F2FA";
fontname = "Bitstream Vera Sans";
fontsize = 8;
shape = "record";
style = "filled";
]
edge [
arrowtail = "empty";
dir = "back";
fontname = "Bitstream Vera Sans";
fontsize = 8;
]
"MediaObject" -> "Hub";
"MediaObject" -> "MediaElement";
"Hub" -> "HubPort" [headlabel = "*", constraint = false, dir = normal, arrowhead = "vee", labelangle = 60];
"MediaElement" -> "HubPort";
"Hub" -> "Composite";
"Hub" -> "Dispatcher";
"Hub" -> "DispatcherOneToMany";
}](../_images/graphviz-2c7d32aa463bf9e7d3cea0708e0f0326aa5dd1bc.png)