当前位置:   article > 正文

python/C++根据ip地址获取ipc摄像机rtsp地址_ipc摄像头 c调用

ipc摄像头 c调用

仓库代码:https://gitee.com/liudegui/gsoap-onvif

  • 借鉴于https://github.com/xris-hu/gsoap-onvif ,根据ip地址获取ipc摄像机rtsp地址;
  • merge高版本openssl不能编译的bug;
  • 去除冗余代码,修改app为动态库,增加get_rtsp_url c接口,增加测试程序;
  • 返回rtsp地址增加账号和密码;
  • Makefile改为CMakeLists.txt;
  • 增加基于cffi的封装模块ipconvif.py

C++测试代码

#include "ipconvif.h"
#include <iostream>
using namespace std;

int main()
{
    char buf1[1024] = {0};
    char buf2[1024] = {0};
    int ret = get_rtsp_url(buf1, buf2, "192.21.1.201", "admin", "123cpucpu");
    if (ret != 0)
    {
        std::cout << "not find" << std::endl;
    }

    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Python调用C++库代码

from cffi import FFI
import os
import sys


ffi = FFI()

ffi.cdef('''
    int get_rtsp_url(char* rtsp_url1, char* rtsp_url2, const char *ip, const char *username, const char *password);
''')

LIB_NAME = 'libipconvif.so'


class Ipconvif():
    def __init__(self, ip, username, passwd):
        self.rtsp_url1 = ffi.new("char[]", 1024) # first url
        self.rtsp_url2 = ffi.new("char[]", 1024) # second url
        self.ip = ffi.new("char[]", ip.encode())
        self.username = ffi.new("char[]", username.encode())
        self.passwd = ffi.new("char[]", passwd.encode())
        
        self.lib = None
        self.load_library()
    
    def load_library(self):
        lib_path = LIB_NAME
        if os.path.exists(lib_path):
            self.lib = ffi.dlopen(lib_path)
            return True
        return False
        
    def get_rtsp_url(self):
        self.lib.get_rtsp_url(self.rtsp_url1, self.rtsp_url2, self.ip, self.username, self.passwd)
        return ffi.string(self.rtsp_url1), ffi.string(self.rtsp_url2)
        
                
        
if __name__ == "__main__":
    ipc = Ipconvif('192.21.1.201', 'admin', '123cpucpu')
    urls = ipc.get_rtsp_url();
    print(urls[0])
    print(urls[1])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/628415
推荐阅读
相关标签
  

闽ICP备14008679号