11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
23PROMEKI_NAMESPACE_BEGIN
44 PROMEKI_SHARED_FINAL(MediaDesc)
47 using Ptr = SharedPtr<MediaDesc>;
50 using List = ::promeki::List<MediaDesc>;
53 using PtrList = ::promeki::List<Ptr>;
56 MediaDesc() =
default;
79 static MediaDesc fromSdp(
const SdpSession &session);
97 SdpSession toSdp(uint8_t videoPayloadType = 96)
const;
109 bool isValid()
const {
110 return _frameRate.isValid() &&
111 (_imageList.size() > 0 || _audioList.size() > 0 || _ancList.size() > 0);
115 const FrameRate &frameRate()
const {
return _frameRate; }
118 void setFrameRate(
const FrameRate &val) { _frameRate = val; }
121 const ImageDesc::List &imageList()
const {
return _imageList; }
123 ImageDesc::List &imageList() {
return _imageList; }
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());
144 const AudioDesc::List &audioList()
const {
return _audioList; }
146 AudioDesc::List &audioList() {
return _audioList; }
152 const AncDesc::List &ancList()
const {
return _ancList; }
158 AncDesc::List &ancList() {
return _ancList; }
161 const Metadata &metadata()
const {
return _metadata; }
163 Metadata &metadata() {
return _metadata; }
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;
173 bool operator!=(
const MediaDesc &other)
const {
return !(*
this == other); }
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;
198 for (
size_t i = 0; i < _audioList.size(); ++i) {
199 if (!_audioList[i].formatEquals(other._audioList[i]))
return false;
201 for (
size_t i = 0; i < _ancList.size(); ++i) {
202 if (!_ancList[i].formatEquals(other._ancList[i]))
return false;
208 FrameRate _frameRate;
209 ImageDesc::List _imageList;
210 AudioDesc::List _audioList;
211 AncDesc::List _ancList;
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();
238inline DataStream &operator>>(DataStream &stream, MediaDesc &desc) {
239 if (!stream.readFrame(DataTypeMediaDesc)) {
244 ImageDesc::List imgs;
245 AudioDesc::List auds;
248 stream >> fr >> imgs >> auds >> ancs >> meta;
249 if (stream.status() != DataStream::Ok) {
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);