arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
Communication
RTSP
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
7
#include "
AudioTools/CoreAudio/AudioTypes.h
"
8
9
namespace
audio_tools
{
10
22
enum class
RTSPVideoFormat
{
23
RGB24
,
24
RGB565
,
25
YUV420
,
26
JPEG
,
27
MJPEG
,
28
GRAYSCALE
,
29
H264
30
};
31
43
struct
RTSPVideoInfo
{
44
uint16_t
width
= 640;
45
uint16_t
height
= 480;
46
float
framerate
= 30.0f;
47
RTSPVideoFormat
format
=
RTSPVideoFormat::MJPEG
;
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
) {
60
case
RTSPVideoFormat::RGB24
:
61
return
width
*
height
* 3;
62
case
RTSPVideoFormat::RGB565
:
63
return
width
*
height
* 2;
64
case
RTSPVideoFormat::YUV420
:
65
return
(
width
*
height
* 3) / 2;
// Y + U/2 + V/2
66
case
RTSPVideoFormat::GRAYSCALE
:
67
return
width
*
height
;
68
case
RTSPVideoFormat::JPEG
:
69
case
RTSPVideoFormat::MJPEG
:
70
// Variable size - return max estimate (1/4 compression ratio)
71
return
(
width
*
height
*
bits_per_pixel
) / (8 * 4);
72
case
RTSPVideoFormat::H264
:
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
97
bool
isCompressed
()
const
{
98
return
format
==
RTSPVideoFormat::JPEG
||
format
==
RTSPVideoFormat::MJPEG
||
99
format
==
RTSPVideoFormat::H264
;
100
}
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
141
class
RTSPVideoInfoSupport
{
142
public
:
143
virtual
~RTSPVideoInfoSupport
() =
default
;
144
virtual
void
setVideoInfo
(
RTSPVideoInfo
info) = 0;
145
virtual
RTSPVideoInfo
videoInfo
() = 0;
146
};
147
148
}
// namespace audio_tools
LOGI
#define LOGI(...)
Definition
AudioLoggerIDF.h:28
AudioTypes.h
audio_tools::RTSPVideoInfoSupport
Base class for video information support.
Definition
VideoInfo.h:141
audio_tools::RTSPVideoInfoSupport::videoInfo
virtual RTSPVideoInfo videoInfo()=0
audio_tools::RTSPVideoInfoSupport::~RTSPVideoInfoSupport
virtual ~RTSPVideoInfoSupport()=default
audio_tools::RTSPVideoInfoSupport::setVideoInfo
virtual void setVideoInfo(RTSPVideoInfo info)=0
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
LMSEchoCancellationStream.h:6
audio_tools::RTSPVideoFormat
RTSPVideoFormat
Video format enumeration for different pixel formats.
Definition
VideoInfo.h:22
audio_tools::RTSPVideoFormat::RGB24
@ RGB24
24-bit RGB (8 bits per channel)
audio_tools::RTSPVideoFormat::MJPEG
@ MJPEG
Motion JPEG format.
audio_tools::RTSPVideoFormat::RGB565
@ RGB565
16-bit RGB (5-6-5 bits per channel)
audio_tools::RTSPVideoFormat::YUV420
@ YUV420
YUV 4:2:0 planar format.
audio_tools::RTSPVideoFormat::H264
@ H264
H.264/AVC compressed format.
audio_tools::RTSPVideoFormat::JPEG
@ JPEG
JPEG compressed format.
audio_tools::RTSPVideoFormat::GRAYSCALE
@ GRAYSCALE
8-bit grayscale
audio_tools::RTSPVideoInfo
Video Information Structure.
Definition
VideoInfo.h:43
audio_tools::RTSPVideoInfo::format
RTSPVideoFormat format
Pixel format.
Definition
VideoInfo.h:47
audio_tools::RTSPVideoInfo::toString
String toString() const
Convert to string for debugging.
Definition
VideoInfo.h:103
audio_tools::RTSPVideoInfo::logInfo
void logInfo(const char *source="VideoInfo") const
Log video info.
Definition
VideoInfo.h:130
audio_tools::RTSPVideoInfo::bits_per_pixel
uint8_t bits_per_pixel
Bits per pixel (depends on format)
Definition
VideoInfo.h:48
audio_tools::RTSPVideoInfo::framerate
float framerate
Frames per second.
Definition
VideoInfo.h:46
audio_tools::RTSPVideoInfo::aspectRatio
float aspectRatio() const
Get aspect ratio.
Definition
VideoInfo.h:92
audio_tools::RTSPVideoInfo::isCompressed
bool isCompressed() const
Check if format is compressed.
Definition
VideoInfo.h:97
audio_tools::RTSPVideoInfo::RTSPVideoInfo
RTSPVideoInfo()=default
audio_tools::RTSPVideoInfo::rtp_clock_rate
uint32_t rtp_clock_rate
RTP clock rate (90kHz for video per RFC)
Definition
VideoInfo.h:49
audio_tools::RTSPVideoInfo::frameSize
uint32_t frameSize() const
Calculate frame size in bytes (uncompressed)
Definition
VideoInfo.h:58
audio_tools::RTSPVideoInfo::framePeriodUs
uint32_t framePeriodUs() const
Calculate frame period in microseconds.
Definition
VideoInfo.h:87
audio_tools::RTSPVideoInfo::height
uint16_t height
Video height in pixels.
Definition
VideoInfo.h:45
audio_tools::RTSPVideoInfo::timestampIncrement
uint32_t timestampIncrement() const
Calculate RTP timestamp increment per frame.
Definition
VideoInfo.h:82
audio_tools::RTSPVideoInfo::width
uint16_t width
Video width in pixels.
Definition
VideoInfo.h:44
audio_tools::RTSPVideoInfo::RTSPVideoInfo
RTSPVideoInfo(uint16_t w, uint16_t h, float fps=30.0f, RTSPVideoFormat fmt=RTSPVideoFormat::MJPEG, uint8_t bpp=24)
Definition
VideoInfo.h:53
Generated by
1.9.8