如何讓Android平臺像網絡攝像機一樣實現(xiàn)GB28181前端設備接入?
技術背景
/*+++++++++++++++GB28181相關接口+++++++++++++++*/
private native long nativeCreate(String server_ip, int
port, String server_id,
String
server_domain, String device_id, String device_pwd,
String
device_name, int tcpudp, int heartbeat_interval,
int
reg_expire, String sdk_version);
private native void nativeRegister(final long ptr);
private native void nativeUnRegister(final long ptr);
/*+++++++++++++++GB28181相關接口+++++++++++++++*/
/*+++++++++++++++RTP Sender相關接口+++++++++++++++*/
public native void nativePushEncodedAudio(long handle,
int devId, byte[] data, int length);
public native void nativePushEncodedVideo(long handle,
int devId, byte[] data, int length);
/*+++++++++++++++RTP Sender相關接口+++++++++++++++*/
void sip_audio_decode_cb(AVFrame * frame, void *
userdata)
{
log_print(HT_LOG_INFO,"PTT- %s start
sip_audio_decode_cb",__FUNCTION__ );
SUA * p_sua =
(SUA *) userdata;
if (NULL ==
p_sua->media_info.audio_player)
{
log_print(HT_LOG_INFO,"PTT- %s, p_sua->media_info.audio_player
is null###",__FUNCTION__ );
#ifdef ANDROID_AS
p_sua->media_info.dataQueue = new DataQueue();
p_sua->media_info.audio_player = new
OpenSlEsPlayer(p_sua->media_info.dataQueue, 8000);
p_sua->media_info.audio_player->play();
#endif
}
if
(p_sua->media_info.audio_player)
{
PcmData
*pdata = new PcmData((char *) frame->data[0], frame->nb_samples *
frame->channels * av_get_bytes_per_sample((enum
AVSampleFormat)frame->format));
p_sua->media_info.dataQueue->putPcmData(pdata);
}
}
GBParam(
ip =
"222.185.255.66",
port = 5060,
server_id =
"34020000002000000001",
server_domain =
"3402000000",
device_id =
"34020000001320000609",
device_pwd =
"123456",
device_name =
"GB28181 Device",
tcpudp = 0,
heartbeat_interval = 30,
reg_expire =
3600
)
信令交互處理:
private val engineEventHandler =
IEngineEventHandler { type, state ->
if (type ==
EventHandlerStatus.EventHandlerType.type_register) {
when
(state) {
EventHandlerStatus.RegisterState.unregister -> { //反注冊
logI("onState: id=${type.toCallTypeString()},
state=unregister($state)")
}
EventHandlerStatus.RegisterState.register_fail -> { //注冊失敗
logI("onState: id=${type.toCallTypeString()},
state=register_fail($state)")
}
EventHandlerStatus.RegisterState.register_success
-> { //注冊成功
logI("onState: id=${type.toCallTypeString()},
state=register_success($state)")
}
EventHandlerStatus.RegisterState.register_forbidden -> { //注冊失敗,udp/tcp協(xié)議不對、密碼不對等注冊參數(shù)不對
logI("onState: id=${type.toCallTypeString()},
state=register_forbidden($state)")
}
else -> {
logI("onState: id=${type.toCallTypeString()},
state=PUEVT_REG_PASS($state)")
}
}
} else {
logI("onState: id=${type.toCallTypeString()},
state=${state.toEventString()}")
}
if (type ==
EventHandlerStatus.EventHandlerType.type_call_in) { //呼入事件
when
(state) {
EventHandlerStatus.EventState.PUEVT_CALL_IN -> { //視頻監(jiān)控呼入
}
EventHandlerStatus.EventState.PUEVT_CONNECT -> { //視頻監(jiān)控接通
}
EventHandlerStatus.EventState.PUEVT_HANGUP -> { //視頻監(jiān)控掛斷
}
}
}
}