RK3036发布的SDK中,内置有对dlna的支持,使用SDK提供的API接口实现设备查询。
发送M-SEARCH 并接收response
- 创建Control Poinit
#include <cybergarage/upnp/ccontrolpoint.h>
CgUpnpControlPoint* dmc = mupnp_controlpoint_new();
- 创建Response 回调
void dmc_ssdpresponse_listener(CgUpnpSSDPPacket* ssdpPacket)
{
CgHttpHeader *header;
/**** print ssdp headers ****/
for (header = cg_http_headerlist_gets(ssdpPacket->headerList); header != NULL; header = cg_http_header_next(header)) {
ALOGD("%s: %s\n",
cg_http_header_getname(header),
cg_http_header_getvalue(header));
}
}
- 启动
cg_upnp_controlpoint_setssdpresponselistener(dmc, dmc_ssdpresponse_listener);
cg_upnp_controlpoint_start(dmc);
- 发送M-SEARCH消息
cg_upnp_controlpoint_search(dmc,"ssdp:all");
- dmc_ssdpresponse_listener日志,这是我自己调试RK3036开发板时M-SEARCH收到的响应输出:
D/lollipop_mix( 152): LOCATION: http://192.168.2.5:62008/
D/lollipop_mix( 152): DATE: Thu, 30 Dec 2021 09:06:30 GMT
D/lollipop_mix( 152): EXT:
D/lollipop_mix( 152): SERVER: ANDROID, UPnP/1.0, Intel MicroStack/1.0.2718
D/lollipop_mix( 152): USN: uuid:9A:1A:CE:9E:E3:7B@www.basicgo.net::urn:schemas-upnp-org:service:UsbDisplay:1
D/lollipop_mix( 152): CACHE-CONTROL: max-age=1800
D/lollipop_mix( 152): ST: HUAWEI ALP-AL00:7B