-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.c
More file actions
67 lines (61 loc) · 2.61 KB
/
Copy pathcli.c
File metadata and controls
67 lines (61 loc) · 2.61 KB
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
/* CamStreamEmu — camera stream reproduction (no control) (Linux/Raspberry Pi).
*
* Reproduces a real CCTV camera captured by PacketScope: reads the camera
* profile JSON, encodes the built-in camera to that video format via GStreamer
* (HW on Pi) and delivers it (multicast / RTSP / HTTP-MJPEG). The MLIT PTZF
* control plane (mlit_device) is out of scope here;
*
* camvideo <profile.json> reproduce the video stream
* camvideo --dump <profile.json> print the parsed profile + gst pipeline
*/
#include "profile.h"
#include "video_pipe.h"
#include "rtsp_serve.h"
#include "mjpeg_serve.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CAMSTREAMEMU_VERSION "0.1.1"
int main(int argc, char **argv)
{
const char *path = NULL;
int dump = 0, force_rtsp = 0, force_mcast = 0, force_mjpeg = 0;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--dump")) dump = 1;
else if (!strcmp(argv[i], "--rtsp")) force_rtsp = 1;
else if (!strcmp(argv[i], "--multicast")) force_mcast = 1;
else if (!strcmp(argv[i], "--mjpeg")) force_mjpeg = 1;
else if (!strcmp(argv[i], "--version")) { printf("CamStreamEmu %s\n", CAMSTREAMEMU_VERSION); return 0; }
else path = argv[i];
}
if (!path) {
fprintf(stderr, "CamStreamEmu %s — reproduce a PacketScope camera profile\n"
"usage: camstreamemu [--dump|--rtsp|--mjpeg|--multicast|--version] <camera_profile.json>\n",
CAMSTREAMEMU_VERSION);
return 2;
}
cam_profile_t p;
if (cam_profile_load(path, &p) != 0) {
fprintf(stderr, "cannot load profile: %s\n", path);
return 1;
}
cam_profile_dump(&p);
if (dump) {
char pipe[2048];
if (video_pipe_build(&p, pipe, sizeof pipe) == 0) printf("\npipeline:\n%s\n", pipe);
else printf("\n(unsupported container/codec for pipeline)\n");
return 0;
}
/* P4: start mlit_device control server here (own thread) before streaming. */
/* Delivery mode by the camera's control plane:
* http-mjpeg -> HTTP multipart MJPEG server
* rtsp -> RTSP server (DESCRIBE/SETUP/PLAY)
* else -> bare multicast push (RTP/TS/TTS/JPEG per container) */
if (force_mjpeg || (!force_rtsp && !force_mcast &&
(!strcmp(p.ctrl_proto, "http-mjpeg") || !strcmp(p.container, "http-mjpeg"))))
return mjpeg_serve_run(&p) == 0 ? 0 : 1;
int use_rtsp = force_rtsp || (!force_mcast && !strcmp(p.ctrl_proto, "rtsp"));
if (use_rtsp)
return rtsp_serve_run(&p) == 0 ? 0 : 1;
return video_pipe_run(&p) == 0 ? 0 : 1;
}