chenshijun
2020-06-28 6b94b6095a0cda41eb01fa4211e7ce0235ab5289
cpp版本的代码,用来编译so
7个文件已添加
1个文件已修改
49045 ■■■■■ 已修改文件
8k_1_16.g711a 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Voice.cpp 179 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Voice.h 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
include/HCNetSDK.h 48745 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
include/public.h 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.c 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
8k_1_16.g711a
Binary files differ
CMakeLists.txt
New file
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.5)
project(hcAudioSDK)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/./build)
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_BUILD_TYPE debug)
add_compile_options(-fPIC)
#add_definitions(-DDEBUG_ERR -DDEBUG_INFO)
#add_definitions(-DDEBUG)
SET(SOURCES
        #    DBModal.cpp
        )
SET(LIBS
        #    pthread
        hcnetsdk
        HCCore
        hpr
#                AudioRender
        )
include_directories(
        include
)
link_directories(
        /usr/lib
        ../lib
)
add_executable(${PROJECT_NAME}
        main.c
        Voice.cpp
        ${SOURCES}
        )
target_link_libraries(${PROJECT_NAME}
        ${LIBS}
        )
README.md
@@ -2,3 +2,8 @@
海康cpp的voice库
里面写死了HCNetSDKCom的路径是/opt/vasystem/libs/hic/
编译动态库:
gcc Voice.cpp -fPIC -shared -o libHikVoice.so -Iinclude/
Voice.cpp
New file
@@ -0,0 +1,179 @@
/*
 * Copyright(C) 2010,Custom Co., Ltd
 *    FileName: Voice.cpp
 * Description:
 *     Version: 1.0
 *      Author: panyadong
 * Create Date: 2010-6-7
 * Modification History��
 */
#include "HCNetSDK.h"
#include "public.h"
#include "Voice.h"
#include <stdio.h>
//#include <map>
//#include <string>
#include <string.h>
#ifdef _WIN32
#elif defined(__linux__)
#include   <unistd.h>
//std::map<std::string, char*> FileName2Byte;
#endif
#ifdef __cplusplus
extern "C" {  // 即使这是一个C++程序,下列这个函数的实现也要以C约定的风格来搞!
#endif
void CALLBACK fdwVoiceDataCallBack(LONG lVoiceComHandle, char *pRecvDataBuffer, DWORD dwBufSize, BYTE byAudioFlag, DWORD pUser)
{
}
void CALLBACK fVoiceDataCallBack(LONG lVoiceComHandle, char *pRecvDataBuffer, DWORD dwBufSize, BYTE byAudioFlag, void* pUser)
{
//    static int icount = 0;
//    printf("   pyd---%5d Get voice data. size:%d. byAudioFlag:%d\n", icount, dwBufSize, byAudioFlag);
//    icount++;
//    //Send data to device after getting data.
//    char pSendData[160] = {0};
//
//    while(1){
//
//        NET_DVR_VoiceComSendData(lVoiceComHandle, pcbdata + icount*160, 160);
//        icount++;
//        usleep(40000);
//    }
}
int sendVoiceTrans(char *ip, char *userName, char *password, char *filename)
{
    long lUserID;
    //login
    NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
    NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
    struLoginInfo.bUseAsynLogin = false;
    struLoginInfo.wPort = 8000;
    memcpy(struLoginInfo.sDeviceAddress, ip, NET_DVR_DEV_ADDRESS_MAX_LEN);
    memcpy(struLoginInfo.sUserName, userName, NAME_LEN);
    memcpy(struLoginInfo.sPassword, password, NAME_LEN);
    lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
    if (lUserID < 0)
    {
        printf("pyd1---Login error, %d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
    //read g711a file
    FILE *fp = fopen(filename,"rt");
#define AUDIOMAXLEN (1024*1024)
    char pcbdata[AUDIOMAXLEN] = {0};
    int len = fread(pcbdata,1,AUDIOMAXLEN,fp);
    fclose(fp);
    //start voice
    long lVoiceHanle;
    printf("NET_DVR_StartVoiceCom_MR_V30\n");
    lVoiceHanle = NET_DVR_StartVoiceCom_MR_V30(lUserID, 0, fVoiceDataCallBack, NULL);
    if (lVoiceHanle < 0)
    {
        printf("pyd---NET_DVR_StartVoiceCom_MR_V30 fail %d\n", NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        return HPR_ERROR;
    }
//
//    LPNET_DVR_COMPRESSION_AUDIO audioType;
//    printf("audioType ret:%d \n", NET_DVR_GetCurrentAudioCompress(lUserID, audioType));
//    printf("audioType->byAudioEncType:%d \n", audioType->byAudioEncType);
//    printf("audioType->byAudioBitRate:%d \n", audioType->byAudioBitRate);
//    printf("audioType->byAudioSamplingRate:%d \n", audioType->byAudioSamplingRate);
    int icount = 0;
    while(1){
        if((icount+1)*160 > len){
            break;
        }
        NET_DVR_VoiceComSendData(lVoiceHanle, pcbdata + icount*160, 160);
        icount++;
        usleep(2000);
    }
    if (!NET_DVR_StopVoiceCom(lVoiceHanle))
    {
        printf("pyd---NET_DVR_StopVoiceCom fail!\n");
        NET_DVR_Logout(lUserID);
        return HPR_ERROR;
    }
    NET_DVR_Logout(lUserID);
    return HPR_OK;
}
int SendVoice(char *ip, char *userName, char *password, char *filename)
{
    char libPath[128] = "/opt/vasystem/libs/hic";
    NET_DVR_LOCAL_SDK_PATH struComPath = {0};
    sprintf(struComPath.sPath, "%s", libPath); //HCNetSDKCom文件夹所在的路径
    NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_SDK_PATH, &struComPath);
    NET_DVR_Init();
    if (sendVoiceTrans(ip, userName, password, filename) == HPR_ERROR)
    {
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
    printf("pyd---Test Voice successfully!\n");
    NET_DVR_Cleanup();
    return HPR_OK;
}
//
//#define AUDIOMAXLEN (1024*1024)
//bool AddVoiceFile(std::string basePath, std::string fileName){
//    std::string filePath = basePath + "/" + fileName;
//    //read g711a file
//    FILE *fp = fopen(filePath.c_str(),"rb");
//    if(fp == NULL){
//        return false;
//    }
//
//    fseek(fp, 0L, SEEK_END);
//    int flen = (int)ftell(fp);
//    if(flen > AUDIOMAXLEN){
//        flen = AUDIOMAXLEN;
//    }
//
//    char * pfile = (char *)malloc(flen+1);
//
//    fseek(fp, 0L, SEEK_SET);
//    int len = fread(pfile,1,flen,fp);
//    fclose(fp);
//
//    FileName2Byte.emplace(fileName, pfile);
//
//    return true;
//}
//
//bool DeleteVoiceFile(std::string fileName){
//    auto iter = FileName2Byte.find(fileName);
//
//    if(iter != FileName2Byte.end()){
//        FileName2Byte.erase(fileName);
//    }
//
//    return true;
//}
#ifdef __cplusplus
}
#endif
Voice.h
New file
@@ -0,0 +1,29 @@
/*
 * Copyright(C) 2010,Custom Co., Ltd
 *    FileName: Voice.h
 * Description:
 *     Version: 1.0
 *      Author: panyadong
 * Create Date: 2010-6-7
 * Modification History:
 */
#ifndef _VOICE_H
#define _VOICE_H_
#ifdef __cplusplus
extern "C" {  // 即使这是一个C++程序,下列这个函数的实现也要以C约定的风格来搞!
#endif
int SendVoice(char *ip, char *userName, char *password, char *filename);
//语音转发
//int Demo_VoiceTrans(char * ip, char * userName, char * password, char * filename);
#ifdef __cplusplus
}
#endif
#endif
include/HCNetSDK.h
New file
Diff too large
include/public.h
New file
@@ -0,0 +1,26 @@
/*
 * Copyright(C) 2010,Hikvision Digital Technology Co., Ltd
 *
 * 文件名称:public.h
 * 描    述:
 * 当前版本:1.0
 * 作    者:潘亚东
 * 创建日期:2010年3月25日
 * 修改记录:
 */
#ifndef _PUBLIC_H_
#define _PUBLIC_H_
#define  HPR_OK 0
#define  HPR_ERROR -1
#if (defined(_WIN32)) //windows
#include <windows.h>
#endif
#include "./HCNetSDK.h"
#endif
main.c
New file
@@ -0,0 +1,25 @@
#include <stdio.h>
#include "Voice.h"
int main(int argc, char *argv[])
{
//    for(int i= 0; i < argc; i++)
//        printf("argv[%d]=%s\n",i, argv[i]);
//
//    if(argc < 5){
//        return 0;
//    }
//
//    char* ip=argv[1];
//    char* usename=argv[2];
//    char* password=argv[3];
//    char* filename=argv[4];
//    SendVoice(ip, usename, password, filename);
    int ret = SendVoice("192.168.5.35", "admin", "a1234567",
            "/media/basic/cdbfb548-3100-4738-b9c1-0a7e1e002170/c++/Qt-test/hcAudioSDK/8k_1_16.g711a");
    printf("ret:%d\n", ret);
    //    system("pause");
while(1);
    return 0;
}