libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mediadesc.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/namespace.h>
14#include <promeki/sharedptr.h>
15#include <promeki/list.h>
16#include <promeki/imagedesc.h>
17#include <promeki/audiodesc.h>
18#include <promeki/ancdesc.h>
19#include <promeki/metadata.h>
20#include <promeki/framerate.h>
21#include <promeki/videoformat.h>
22
23PROMEKI_NAMESPACE_BEGIN
24
25class SdpSession;
26
43class MediaDesc {
44 PROMEKI_SHARED_FINAL(MediaDesc)
45 public:
47 using Ptr = SharedPtr<MediaDesc>;
48
50 using List = ::promeki::List<MediaDesc>;
51
53 using PtrList = ::promeki::List<Ptr>;
54
56 MediaDesc() = default;
57
79 static MediaDesc fromSdp(const SdpSession &session);
80
97 SdpSession toSdp(uint8_t videoPayloadType = 96) const;
98
109 bool isValid() const {
110 return _frameRate.isValid() &&
111 (_imageList.size() > 0 || _audioList.size() > 0 || _ancList.size() > 0);
112 }
113
115 const FrameRate &frameRate() const { return _frameRate; }
118 void setFrameRate(const FrameRate &val) { _frameRate = val; }
119
121 const ImageDesc::List &imageList() const { return _imageList; }
123 ImageDesc::List &imageList() { return _imageList; }
124
137 VideoFormat videoFormat(size_t index) const {
138 if (index >= _imageList.size()) return VideoFormat();
139 const ImageDesc &img = _imageList[index];
140 return VideoFormat(img.size(), _frameRate, img.videoScanMode());
141 }
142
144 const AudioDesc::List &audioList() const { return _audioList; }
146 AudioDesc::List &audioList() { return _audioList; }
147
152 const AncDesc::List &ancList() const { return _ancList; }
153
158 AncDesc::List &ancList() { return _ancList; }
159
161 const Metadata &metadata() const { return _metadata; }
163 Metadata &metadata() { return _metadata; }
164
166 bool operator==(const MediaDesc &other) const {
167 return _frameRate == other._frameRate && _imageList == other._imageList &&
168 _audioList == other._audioList && _ancList == other._ancList &&
169 _metadata == other._metadata;
170 }
171
173 bool operator!=(const MediaDesc &other) const { return !(*this == other); }
174
190 bool formatEquals(const MediaDesc &other) const {
191 if (_frameRate != other._frameRate) return false;
192 if (_imageList.size() != other._imageList.size()) return false;
193 if (_audioList.size() != other._audioList.size()) return false;
194 if (_ancList.size() != other._ancList.size()) return false;
195 for (size_t i = 0; i < _imageList.size(); ++i) {
196 if (!_imageList[i].formatEquals(other._imageList[i])) return false;
197 }
198 for (size_t i = 0; i < _audioList.size(); ++i) {
199 if (!_audioList[i].formatEquals(other._audioList[i])) return false;
200 }
201 for (size_t i = 0; i < _ancList.size(); ++i) {
202 if (!_ancList[i].formatEquals(other._ancList[i])) return false;
203 }
204 return true;
205 }
206
207 private:
208 FrameRate _frameRate;
209 ImageDesc::List _imageList;
210 AudioDesc::List _audioList;
211 AncDesc::List _ancList;
212 Metadata _metadata;
213};
214
221inline DataStream &operator<<(DataStream &stream, const MediaDesc &desc) {
222 stream.beginFrame(DataTypeMediaDesc, 1);
223 stream << desc.frameRate();
224 stream << desc.imageList();
225 stream << desc.audioList();
226 stream << desc.ancList();
227 stream << desc.metadata();
228 stream.endFrame();
229 return stream;
230}
231
238inline DataStream &operator>>(DataStream &stream, MediaDesc &desc) {
239 if (!stream.readFrame(DataTypeMediaDesc)) {
240 desc = MediaDesc();
241 return stream;
242 }
243 FrameRate fr;
244 ImageDesc::List imgs;
245 AudioDesc::List auds;
246 AncDesc::List ancs;
247 Metadata meta;
248 stream >> fr >> imgs >> auds >> ancs >> meta;
249 if (stream.status() != DataStream::Ok) {
250 desc = MediaDesc();
251 return stream;
252 }
253 desc = MediaDesc();
254 desc.setFrameRate(fr);
255 desc.imageList() = std::move(imgs);
256 desc.audioList() = std::move(auds);
257 desc.ancList() = std::move(ancs);
258 desc.metadata() = std::move(meta);
259 return stream;
260}
261
262PROMEKI_NAMESPACE_END
263
264#endif // PROMEKI_ENABLE_PROAV