arduino-audio-tools
Loading...
Searching...
No Matches
VideoInfo.h
Go to the documentation of this file.
1/*
2 * Author: Phil Schatzmann
3 * Video Information Structure for RTSP Video Streaming
4 */
5
6#pragma once
8
9namespace audio_tools {
10
22enum class RTSPVideoFormat {
23 RGB24,
24 RGB565,
25 YUV420,
26 JPEG,
27 MJPEG,
28 GRAYSCALE,
29 H264
30};
31
44 uint16_t width = 640;
45 uint16_t height = 480;
46 float framerate = 30.0f;
48 uint8_t bits_per_pixel = 24;
49 uint32_t rtp_clock_rate = 90000;
50
51 RTSPVideoInfo() = default;
52
53 RTSPVideoInfo(uint16_t w, uint16_t h, float fps = 30.0f,
54 RTSPVideoFormat fmt = RTSPVideoFormat::MJPEG, uint8_t bpp = 24)
55 : width(w), height(h), framerate(fps), format(fmt), bits_per_pixel(bpp) {}
56
58 uint32_t frameSize() const {
59 switch (format) {
61 return width * height * 3;
63 return width * height * 2;
65 return (width * height * 3) / 2; // Y + U/2 + V/2
67 return width * height;
70 // Variable size - return max estimate (1/4 compression ratio)
71 return (width * height * bits_per_pixel) / (8 * 4);
73 // Variable size - return a rough estimate (much higher compression
74 // ratio than JPEG thanks to inter-frame prediction)
75 return (width * height * bits_per_pixel) / (8 * 20);
76 default:
77 return width * height * (bits_per_pixel / 8);
78 }
79 }
80
82 uint32_t timestampIncrement() const {
83 return (uint32_t)(rtp_clock_rate / framerate);
84 }
85
87 uint32_t framePeriodUs() const {
88 return (uint32_t)(1000000.0f / framerate);
89 }
90
92 float aspectRatio() const {
93 return (float)width / (float)height;
94 }
95
101
103 String toString() const {
104 String result = "VideoInfo: ";
105 result += width;
106 result += "x";
107 result += height;
108 result += " @ ";
109 result += framerate;
110 result += "fps, ";
111
112 switch (format) {
113 case RTSPVideoFormat::RGB24: result += "RGB24"; break;
114 case RTSPVideoFormat::RGB565: result += "RGB565"; break;
115 case RTSPVideoFormat::YUV420: result += "YUV420"; break;
116 case RTSPVideoFormat::JPEG: result += "JPEG"; break;
117 case RTSPVideoFormat::MJPEG: result += "MJPEG"; break;
118 case RTSPVideoFormat::GRAYSCALE: result += "GRAY"; break;
119 case RTSPVideoFormat::H264: result += "H264"; break;
120 default: result += "UNKNOWN"; break;
121 }
122
123 result += " (";
124 result += bits_per_pixel;
125 result += "bpp)";
126 return result;
127 }
128
130 void logInfo(const char* source = "VideoInfo") const {
131 LOGI("%s: %s", source, toString().c_str());
132 }
133};
134
142 public:
143 virtual ~RTSPVideoInfoSupport() = default;
144 virtual void setVideoInfo(RTSPVideoInfo info) = 0;
146};
147
148} // namespace audio_tools
#define LOGI(...)
Definition AudioLoggerIDF.h:28
Base class for video information support.
Definition VideoInfo.h:141
virtual RTSPVideoInfo videoInfo()=0
virtual ~RTSPVideoInfoSupport()=default
virtual void setVideoInfo(RTSPVideoInfo info)=0
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
RTSPVideoFormat
Video format enumeration for different pixel formats.
Definition VideoInfo.h:22
@ RGB24
24-bit RGB (8 bits per channel)
@ MJPEG
Motion JPEG format.
@ RGB565
16-bit RGB (5-6-5 bits per channel)
@ YUV420
YUV 4:2:0 planar format.
@ H264
H.264/AVC compressed format.
@ JPEG
JPEG compressed format.
@ GRAYSCALE
8-bit grayscale
Video Information Structure.
Definition VideoInfo.h:43
RTSPVideoFormat format
Pixel format.
Definition VideoInfo.h:47
String toString() const
Convert to string for debugging.
Definition VideoInfo.h:103
void logInfo(const char *source="VideoInfo") const
Log video info.
Definition VideoInfo.h:130
uint8_t bits_per_pixel
Bits per pixel (depends on format)
Definition VideoInfo.h:48
float framerate
Frames per second.
Definition VideoInfo.h:46
float aspectRatio() const
Get aspect ratio.
Definition VideoInfo.h:92
bool isCompressed() const
Check if format is compressed.
Definition VideoInfo.h:97
uint32_t rtp_clock_rate
RTP clock rate (90kHz for video per RFC)
Definition VideoInfo.h:49
uint32_t frameSize() const
Calculate frame size in bytes (uncompressed)
Definition VideoInfo.h:58
uint32_t framePeriodUs() const
Calculate frame period in microseconds.
Definition VideoInfo.h:87
uint16_t height
Video height in pixels.
Definition VideoInfo.h:45
uint32_t timestampIncrement() const
Calculate RTP timestamp increment per frame.
Definition VideoInfo.h:82
uint16_t width
Video width in pixels.
Definition VideoInfo.h:44
RTSPVideoInfo(uint16_t w, uint16_t h, float fps=30.0f, RTSPVideoFormat fmt=RTSPVideoFormat::MJPEG, uint8_t bpp=24)
Definition VideoInfo.h:53