77
88namespace esp32cam {
99
10+ /* * MJPEG stream options. */
1011struct MjpegConfig {
11- /* * @brief minimum interval between frame captures. */
12+ /* *
13+ * @brief Minimum interval between frame captures in millis.
14+ */
1215 int minInterval = 0 ;
13- /* * @brief maximum number of frames before disconnecting. */
16+
17+ /* *
18+ * @brief Maximum number of frames before disconnecting.
19+ *
20+ * Negative value means unlimited.
21+ */
1422 int maxFrames = -1 ;
15- /* * @brief time limit of writing one frame in millis. */
23+
24+ /* * @brief Time limit of writing one frame in millis. */
1625 int frameTimeout = 10000 ;
1726};
1827
@@ -23,23 +32,11 @@ class MjpegController {
2332public:
2433 explicit MjpegController (MjpegConfig cfg);
2534
26- /* * @brief Retrieve config object. */
27- const MjpegConfig& getConfig () const {
28- return m_cfg;
29- }
30-
3135 /* * @brief Retrieve number of sent frames. */
3236 int countSentFrames () const {
3337 return m_count;
3438 }
3539
36- enum {
37- CAPTURE = -1 ,
38- RETURN = -2 ,
39- SEND = -3 ,
40- STOP = -4 ,
41- };
42-
4340 /* *
4441 * @brief Decide what to do now.
4542 * @retval CAPTURE capture a frame.
@@ -72,6 +69,9 @@ class MjpegController {
7269 * @brief Notify that a frame is sent to the client.
7370 * @param ok whether sent successfully.
7471 * @post getFrame()==nullptr
72+ *
73+ * The caller is expected to enforce @c MjpegConfig::frameTimeout and call
74+ * `notifySent(false)` in case of send timeout.
7575 */
7676 void notifySent (bool ok);
7777
@@ -82,8 +82,17 @@ class MjpegController {
8282 */
8383 void notifyFail ();
8484
85+ public:
86+ enum Action {
87+ CAPTURE = -1 ,
88+ RETURN = -2 ,
89+ SEND = -3 ,
90+ STOP = -4 ,
91+ };
92+
93+ const MjpegConfig cfg;
94+
8595private:
86- MjpegConfig m_cfg;
8796 std::unique_ptr<Frame> m_frame;
8897 unsigned long m_nextCaptureTime;
8998 int m_nextAction = CAPTURE;
@@ -105,7 +114,7 @@ class MjpegHeader {
105114
106115public:
107116 size_t size = 0 ;
108- char buf[160 ];
117+ char buf[120 ];
109118};
110119
111120} // namespace detail
0 commit comments