areaDetector  3-13
EPICS areaDetector framework
ffmpegServer.h
Go to the documentation of this file.
1 #ifndef ffmpegServer_H
2 #define ffmpegServer_H
3 
4 #ifndef __STDC_CONSTANT_MACROS
5 #define __STDC_CONSTANT_MACROS
6 #endif
7 
8 #include <epicsTypes.h>
9 #include <asynStandardInterfaces.h>
10 
11 #include "NDPluginDriver.h"
12 
13 /* null-httpd includes */
14 extern "C" {
15 #include "nullhttpd.h"
16 }
17 #include "ffmpegCommon.h"
18 
19 
21 #define MAX_FFMPEG_STREAMS 64
22 
23 #define ffmpegServerQualityString "FFMPEG_QUALITY" /* JPEG quality (int32 read/write) */
24 #define ffmpegServerFalseColString "FFMPEG_FALSE_COL" /* False Colour toggle (int32 (enum) read/write)*/
25 #define ffmpegServerHttpPortString "FFMPEG_HTTP_PORT" /* Http port (int32 read)*/
26 #define ffmpegServerHostString "FFMPEG_HOST" /* Host string (string read)*/
27 #define ffmpegServerJpgUrlString "FFMPEG_JPG_URL" /* JPEG Snapshot URL string (string read)*/
28 #define ffmpegServerMjpgUrlString "FFMPEG_MJPG_URL" /* MJPG Stream URL string (string read)*/
29 #define ffmpegServerClientsString "FFMPEG_CLIENTS" /* Number of connected clients (int32 read)*/
30 #define ffmpegServerAlwaysOnString "FFMPEG_ALWAYS_ON" /* Always produce jpeg, even when no-one is listening (int32 read)*/
31 #define ffmpegServerMaxWString "FFMPEG_MAXW" /* Maximum width of jpg to produce (int32 read/write)*/
32 #define ffmpegServerMaxHString "FFMPEG_MAXH" /* Maximum height of jpg to produce (int32 read/write)*/
33 #define ffmpegServerSetWString "FFMPEG_SETW" /* Specify width of jpg, forcing rescale (int32 read/write)*/
34 #define ffmpegServerSetHString "FFMPEG_SETH" /* Specify height of jpg, forcing rescale (int32 read/write)*/
35 
37 class ffmpegStream : public NDPluginDriver {
38 public:
39  ffmpegStream(const char *portName, int queueSize, int blockingCallbacks,
40  const char *NDArrayPort, int NDArrayAddr, int maxBuffers, int maxMemory,
41  int priority, int stackSize);
42  /* These methods override those in the base class */
43  void processCallbacks(NDArray *pArray);
44  /* These are used by the http server to access the data in this class */
45  int send_frame(int sid, NDArray *pArray);
46  void send_stream(int sid);
47  void send_snapshot(int sid, int index);
48 
49 protected:
51  #define FIRST_FFMPEG_SERVER_PARAM ffmpegServerQuality
63 
64 private:
65  NDArray *scArray;
66  NDArray *jpeg;
67  int nclients;
68 
69  AVCodec *codec;
70  AVCodecContext *c;
71  AVFrame *inPicture;
72  AVFrame *scPicture;
73  struct SwsContext *ctx;
74 
75  /* signal fresh frames */
76  pthread_cond_t *cond;
77  pthread_mutex_t mutex;
78 
79  NDArray* get_jpeg();
80  NDArray* wait_for_jpeg(int sid);
81  void allocScArray(size_t size);
82 };
83 
84 /* These are global to the http server */
85 static ffmpegStream **streams;
86 static int nstreams;
87 
88 #endif
GMutex * mutex
Definition: aravisTest.c:11
N-dimensional array class; each array has a set of dimensions, a data type, pointer to data,...
Definition: NDArray.h:99
Class from which actual plugin drivers are derived; derived from asynNDArrayDriver.
Definition: NDPluginDriver.h:57
Take an array source and compress it and serve it as an mjpeg stream.
Definition: ffmpegServer.h:37
void processCallbacks(NDArray *pArray)
Take an NDArray, add grid and false colour, compress it to a jpeg, then signal to the server process ...
Definition: ffmpegServer.cpp:376
int ffmpegServerAlwaysOn
Definition: ffmpegServer.h:62
int ffmpegServerJpgUrl
Definition: ffmpegServer.h:55
int ffmpegServerSetW
Definition: ffmpegServer.h:60
int ffmpegServerQuality
Definition: ffmpegServer.h:50
void send_snapshot(int sid, int index)
Internal function to send a single snapshot.
Definition: ffmpegServer.cpp:230
int ffmpegServerClients
Definition: ffmpegServer.h:57
int ffmpegServerMjpgUrl
Definition: ffmpegServer.h:56
int ffmpegServerHttpPort
Definition: ffmpegServer.h:53
int ffmpegServerMaxW
Definition: ffmpegServer.h:58
int ffmpegServerHost
Definition: ffmpegServer.h:54
int ffmpegServerFalseCol
Definition: ffmpegServer.h:52
int ffmpegServerMaxH
Definition: ffmpegServer.h:59
ffmpegStream(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int maxBuffers, int maxMemory, int priority, int stackSize)
Constructor for ffmpegStream; Class representing an mjpg stream served up by ffmpegServer.
Definition: ffmpegServer.cpp:601
void send_stream(int sid)
Internal function to send an mjpg stream.
Definition: ffmpegServer.cpp:323
int send_frame(int sid, NDArray *pArray)
Internal function to send a jpeg frame as part of an mjpeg stream.
Definition: ffmpegServer.cpp:275
int ffmpegServerSetH
Definition: ffmpegServer.h:61