forked from Motion-Project/motion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
netcam_rtsp.h
106 lines (87 loc) · 5.86 KB
/
netcam_rtsp.h
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
#ifndef _INCLUDE_NETCAM_RTSP_H
#define _INCLUDE_NETCAM_RTSP_H
struct context;
struct image_data;
enum RTSP_STATUS {
RTSP_CONNECTED, /* The camera is currently connected */
RTSP_READINGIMAGE, /* Motion is reading a image from camera */
RTSP_NOTCONNECTED, /* The camera has never connected */
RTSP_RECONNECTING /* Motion is trying to reconnect to camera */
};
struct imgsize_context {
int width;
int height;
};
#ifdef HAVE_FFMPEG
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
struct packet_item{
AVPacket packet;
int64_t idnbr;
int iskey;
int iswritten;
struct timeval timestamp_tv;
};
struct rtsp_context {
AVFormatContext *format_context; /* Main format context for the camera */
AVCodecContext *codec_context; /* Codec being sent from the camera */
AVFrame *frame; /* Reusable frame for images from camera */
AVFrame *swsframe_in; /* Used when resizing image sent from camera */
AVFrame *swsframe_out; /* Used when resizing image sent from camera */
struct SwsContext *swsctx; /* Context for the resizing of the image */
AVPacket packet_recv; /* The packet that is currently being processed */
AVFormatContext *transfer_format; /* Format context just for transferring to pass-through */
struct packet_item *pktarray; /* Pointer to array of packets for passthru processing */
int pktarray_size; /* The number of packets in array. 1 based */
int pktarray_index; /* The index to the most current packet in array */
int64_t idnbr; /* A ID number to track the packet vs image */
AVDictionary *opts; /* AVOptions when opening the format context */
int swsframe_size; /* The size of the image after resizing */
int video_stream_index; /* Stream index associated with video from camera */
enum RTSP_STATUS status; /* Status of whether the camera is connecting, closed, etc*/
struct timeval interruptstarttime; /* The time set before calling the av functions */
struct timeval interruptcurrenttime; /* Time during the interrupt to determine duration since start*/
int interruptduration; /* Seconds permitted before triggering a interrupt */
netcam_buff_ptr img_recv; /* The image buffer that is currently being processed */
netcam_buff_ptr img_latest; /* The most recent image buffer that finished processing */
int interrupted; /* Boolean for whether interrupt has been tripped */
int finish; /* Boolean for whether we are finishing the application */
int high_resolution; /* Boolean for whether this context is the Norm or High */
int handler_finished; /* Boolean for whether the handler is running or not */
int first_image; /* Boolean for whether we have captured the first image */
int passthrough; /* Boolean for whether we are doing pass-through processing */
char *path; /* The connection string to use for the camera */
char service[5]; /* String specifying the type of camera http, rtsp, v4l2 */
const char *camera_name; /* The name of the camera as provided in the config file */
char cameratype[30]; /* String specifying Normal or High for use in logging */
struct imgsize_context imgsize; /* The image size parameters */
int rtsp_uses_tcp; /* Flag from config for whether to use tcp transport */
int v4l2_palette; /* Palette from config for v4l2 devices */
int framerate; /* Frames per second from configuration file */
long cnct_delay; /* Delay offset to prevent handler being too slow*/
int src_fps; /* The fps provided from source*/
struct timeval frame_prev_tm; /* The time set before calling the av functions */
struct timeval frame_curr_tm; /* Time during the interrupt to determine duration since start*/
struct config *conf; /* Pointer to conf parms of parent cnt*/
char threadname[16]; /* The thread name*/
int threadnbr; /* The thread number */
pthread_t thread_id; /* thread i.d. for a camera-handling thread (if required). */
pthread_mutex_t mutex; /* mutex used with conditional waits */
pthread_mutex_t mutex_transfer; /* mutex used with transferring stream info for pass-through */
pthread_mutex_t mutex_pktarray; /* mutex used with the packet array */
};
#else /* Do not have FFmpeg */
struct rtsp_context {
int dummy;
pthread_t thread_id;
int handler_finished;
};
#endif /* end HAVE_FFMPEG */
int netcam_rtsp_setup(struct context *cnt);
int netcam_rtsp_next(struct context *cnt, struct image_data *img_data);
void netcam_rtsp_cleanup(struct context *cnt, int init_retry_flag);
#endif /* _INCLUDE_NETCAM_RTSP_H */