ESP_IOT v2.5
IOT ESP Coding
CStreamer.h
Go to the documentation of this file.
1#pragma once
2#include "../../../Defines.h"
3
4#ifdef USE_CAMERA_MODULE
5
6#include "platglue.h"
7
8typedef unsigned const char *BufPtr;
9
10class CStreamer
11{
12public:
13 CStreamer(SOCKET aClient, u_short width, u_short height);
14 virtual ~CStreamer();
15
16 void InitTransport(u_short aRtpPort, u_short aRtcpPort, bool TCP);
17 u_short GetRtpServerPort();
18 u_short GetRtcpServerPort();
19
20 virtual void streamImage(uint32_t curMsec) = 0; // send a new image to the client
21protected:
22
23 void streamFrame(unsigned const char *data, uint32_t dataLen, uint32_t curMsec);
24
25private:
26 int SendRtpPacket(unsigned const char *jpeg, int jpegLen, int fragmentOffset, BufPtr quant0tbl = NULL, BufPtr quant1tbl = NULL);// returns new fragmentOffset or 0 if finished with frame
27
28 UDPSOCKET m_RtpSocket; // RTP socket for streaming RTP packets to client
29 UDPSOCKET m_RtcpSocket; // RTCP socket for sending/receiving RTCP packages
30
31 uint16_t m_RtpClientPort; // RTP receiver port on client (in host byte order!)
32 uint16_t m_RtcpClientPort; // RTCP receiver port on client (in host byte order!)
33 IPPORT m_RtpServerPort; // RTP sender port on server
34 IPPORT m_RtcpServerPort; // RTCP sender port on server
35
36 u_short m_SequenceNumber;
37 uint32_t m_Timestamp;
38 int m_SendIdx;
39 bool m_TCPTransport;
40 SOCKET m_Client;
41 uint32_t m_prevMsec;
42
43 u_short m_width; // image data info
44 u_short m_height;
45};
46
47
48
49// When JPEG is stored as a file it is wrapped in a container
50// This function fixes up the provided start ptr to point to the
51// actual JPEG stream data and returns the number of bytes skipped
52// returns true if the file seems to be valid jpeg
53// If quant tables can be found they will be stored in qtable0/1
54bool decodeJPEGfile(BufPtr *start, uint32_t *len, BufPtr *qtable0, BufPtr *qtable1);
55bool findJPEGheader(BufPtr *start, uint32_t *len, uint8_t marker);
56
57// Given a jpeg ptr pointing to a pair of length bytes, advance the pointer to
58// the next 0xff marker byte
59void nextJpegBlock(BufPtr *start);
60
61#endif