zhangzengfei
2022-07-20 c90c3e794bdd95127d0c34ff1d9e8759d18a0445
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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
 
#if __USE_RTSPCLIENT__
#include "RtspClient.h"
#else
#include "librtsp.h"
#endif
 
 
void StreamCallBack(int datatype, int frametype, unsigned char *data, unsigned int datalen, long userdata)
{
#if 0
    printf("userdata:%ld,datatype:%d, frametype:%d,  datalen:%d\n", userdata, datatype, frametype, datalen);
 
    static FILE* fp_write = NULL;
    if (!fp_write)
    {
        fp_write = fopen("stream_callback.mp4", "wb+");
    }
    fwrite(data, sizeof(char), datalen, fp_write);    
#endif    
}
 
 
int main(int argc, char *argv[])
{
#if __USE_RTSPCLIENT__
    CRtspClient *rtsp_client = new CRtspClient();
    //if (rtsp_client != NULL)
    {
        long userdata = 1001;
        rtsp_client->OpenRtspStream("rtsp://192.168.12.122:9554/DevAor=11010100001320012122/StreamType=1/PlayType=1/BeginTime=2018-03-26T00:00:00/EndTime=2018-03-26T10:00:00/", StreamCallBack, userdata);
        sleep(10);
        rtsp_client->StopRtspStream();
    }
#else
    char test_rtspurl1[] = "rtsp://192.168.20.10:7554/DevAor=34020000001320000001";
    char test_rtspurl2[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125141";
    char test_rtspurl3[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125151";
    char test_rtspurl4[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125152";
    char test_rtspurl5[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125153";
    char test_rtspurl6[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125155";
    char test_rtspurl7[] = "rtsp://172.17.50.245:7554/DevAor=11010870111320125162";
    // for test
    //while (1)
    {
        long video_userdata = 1000;
        printf("start.>>>>>>>>>>>>>>>>>>>>\n");
        time_t start = time(NULL);    
        long video_handle = RTSPSTREAM_Open(test_rtspurl1, StreamCallBack, video_userdata);    
        time_t end = time(NULL);
        printf("time :%ld\n", end - start);
        printf("1.>>>>>>>>>>>>>>>>>>>>video_handle:%ld\n", video_handle);
        if (video_handle < 0) {
            return 1;
        }
        
        while(1){
            sleep(5);
        }
        RTSPSTREAM_Close(video_handle);
    }
    sleep(1000);
    return 0;
 
    if (argc < 2)
    {
        printf("please write rtsp url!!!!!!!!\n");
        return -1;
    }
    long userdata = 1001;
    long handle = -1;
    while (1)
    {
        handle = RTSPSTREAM_Open(argv[1], StreamCallBack, userdata);
 
        sleep(5);
        RTSPSTREAM_Close(handle);
        sleep(5);
    }
    //µã²¥¿ØÖÆ
    if (argc >= 3)
    {
        sleep(5);
        //µã²¥²¥·Å¿ØÖÆ
        RTSPSTREAM_Contrl(handle, HIS_VIDEO_CTRL_PAUSE, 0);    
        sleep(5);
        //µã²¥²¥·Å¿ØÖÆ
        RTSPSTREAM_Contrl(handle, HIS_VIDEO_CTRL_PLAY, 0);    
        sleep(5);
        //µã²¥Âý·Å¿ØÖÆ 
        RTSPSTREAM_Contrl(handle, HIS_VIDEO_CTRL_SLOW, 4);    
        sleep(5);
        //µã²¥¿ì·Å¿ØÖÆ
        RTSPSTREAM_Contrl(handle, HIS_VIDEO_CTRL_FAST, 4);    
        sleep(5);
        //µã²¥Ìø×ª¿ØÖÆ
        RTSPSTREAM_Contrl(handle, HIS_VIDEO_CTRL_JUMP, 600);    
    }
    
 
#endif
    return 0;
}