pans
2016-12-15 87e3ee273b2f84081ac45926be9d8e5be3166eaa
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright(C) 2010,Custom Co., Ltd 
 *    FileName: Voice.cpp
 * Description: 
 *     Version: 1.0
 *      Author: panyadong
 * Create Date: 2010-6-7
 * Modification History£º
 */
 
#include "public.h"
#include "Voice.h"
#include <stdio.h>
 
#ifdef _WIN32
#elif defined(__linux__)
#include   <unistd.h> 
 
#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.\n", icount, dwBufSize);
    icount++;
    //Send data to device after getting data.
    char pSendData[80] = {0};
    NET_DVR_VoiceComSendData(lVoiceComHandle, pSendData, 80);
}
 
int Demo_Voice()
{
    NET_DVR_Init();
    if (Demo_VoiceTrans() == HPR_ERROR)
    {
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
 
 
    printf("pyd---Test Voice successfully!\n");
    NET_DVR_Cleanup();
    return HPR_OK;
}
 
 
int Demo_VoiceTrans()
{
    
    long lUserID;
    //login
    NET_DVR_DEVICEINFO struDeviceInfo;
    lUserID = NET_DVR_Login("172.4.4.221", 8000, "admin", "12345", &struDeviceInfo);
    if (lUserID < 0)
    {
        printf("pyd1---Login error, %d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    while(1)
    {
 
   
    printf("in NET_DVR_StartVoiceCom_MR \n");
    //start voice
    long lVoiceHanle;
    lVoiceHanle = NET_DVR_StartVoiceCom_MR(lUserID, fdwVoiceDataCallBack, NULL);
    //lVoiceHanle = NET_DVR_StartVoiceCom_MR_V30(lUserID, 1, fVoiceDataCallBack, NULL);
    if (lVoiceHanle < 0)
    {
        printf("pyd---NET_DVR_StartVoiceCom_MR fail! %d\n", NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        return HPR_ERROR;
    }
 
    printf("NET_DVR_StartVoiceCom_MR_V30 step 1\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;
    }
    
    printf("step 3\n");
#ifdef _WIN32
    Sleep(2000);  //millisecond
#elif  defined(__linux__)
    sleep(2);   //second
#endif
 
    if (!NET_DVR_StopVoiceCom(lVoiceHanle))
    {
        printf("pyd---NET_DVR_StopVoiceCom fail!\n");
        NET_DVR_Logout(lUserID);
        return HPR_ERROR;
    }
     }
 
    return HPR_OK;
}