forked from edsiper/h264dec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h264dec.c
124 lines (107 loc) · 3.14 KB
/
h264dec.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* RTSP Client
* -----------
* Written by Eduardo Silva P. <[email protected]>
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
/* local headers */
#include "rtsp.h"
#include "streamer.h"
#include "h264dec.h"
void help(int status)
{
printf("Usage: h264dec [-v] [-V] [-d FILENAME] -n CHANNEL_NAME -s rtsp://stream\n\n");
printf(" -d, --dump=FILENAME Dump H264 video data to a file\n");
printf(" -s, --stream=URL RTSP media stream address\n");
printf(" -n, --name=CHANNEL_NAME Name for local channel identifier\n");
printf(" -h, --help print this help\n");
printf(" -v, --version print version number\n");
printf(" -V, --verbose enable verbose mode\n");
printf("\n");
exit(status);
}
void banner()
{
printf("H264Dec v%s\n\n", VERSION);
}
int main(int argc, char **argv)
{
int opt;
/* defaults */
opt_stdout = 0;
opt_verbose = 0;
opt_stream = NULL;
opt_name = NULL;
stream_port = RTSP_PORT;
client_port = RTSP_CLIENT_PORT;
stream_dump = NULL;
static const struct option long_opts[] = {
{ "stdout", no_argument , NULL, 'o' },
{ "dump", required_argument, NULL, 'd' },
{ "stream", required_argument, NULL, 's' },
{ "port", required_argument, NULL, 'p' },
{ "name", required_argument, NULL, 'n' },
{ "version", no_argument, NULL, 'v' },
{ "verbose", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
while ((opt = getopt_long(argc, argv, "od:s:p:n:vVh",
long_opts, NULL)) != -1) {
switch (opt) {
case 'o':
opt_stdout = 1;
break;
case 'd':
stream_dump = strdup(optarg);
break;
case 's':
opt_stream = strdup(optarg);
break;
case 'p':
client_port = atoi(optarg);
break;
case 'n':
opt_name = strdup(optarg);
break;
case 'v':
banner();
exit(EXIT_SUCCESS);
case 'V':
opt_verbose = 1;
break;
case 'h':
help(EXIT_SUCCESS);
case '?':
help(EXIT_FAILURE);
}
}
if (!opt_stream || strncmp(opt_stream, PROTOCOL_PREFIX,
sizeof(PROTOCOL_PREFIX) - 1) != 0) {
printf("Error: Invalid stream input.\n\n");
help(EXIT_FAILURE);
}
if (!opt_name) {
printf("Error: Local channel name not specified.\n\n");
help(EXIT_FAILURE);
}
/* RTSP loop */
while (1) {
rtsp_loop();
printf("[ERROR] RTSP Loop stopped, waiting 5 seconds...\n");
sleep(5);
exit(1);
}
return 0;
}