ADTF
Loading...
Searching...
No Matches
codec_sample_streamer.h
Go to the documentation of this file.
1
7#pragma once
8#include "sample_codec.h"
10
11#ifdef USE_ADTF_MEDIA_DESCRIPTION_LEGACY
12 #ifndef NO_ADTF_MEDIA_DESCRIPTION_LEGACY
14 #endif
15#endif
16
17#include <functional>
18
19namespace adtf
20{
22{
23namespace osborn
24{
30template<typename ReaderImplementation = streaming::flash::cDynamicSampleReader>
31class decoding_sample_reader : public ReaderImplementation, public cSampleCodecFactory
32{
33public:
38 {
39 ReaderImplementation::SetAcceptTypeCallback(
41 {
42 static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
43 RETURN_IF_FAILED(get_codec_factory_from_stream_type(*pStreamType.Get(), *this));
44
45 if (m_fnAcceptCallback)
46 {
47 RETURN_IF_FAILED(m_fnAcceptCallback(pStreamType));
48 }
50 });
51 }
52
54 {
55 RETURN_IF_FAILED(ReaderImplementation::SetType(pStreamType));
56 // the initial type is not required to have a media description set
57 static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
58 if (pStreamType.Get())
59 {
60 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
61 }
63 }
64
72 const std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)>&
73 fnAcceptTypeCallback)
74 {
75 m_fnAcceptCallback = fnAcceptTypeCallback;
76 }
77
85 {
86 base::flash::tNanoSeconds tmSampleTime;
87 return GetNextDecoder(oDecoder, tmSampleTime);
88 }
89
98 {
100 auto oResult = ReaderImplementation::GetNextSample(pSample);
101 if (IS_FAILED(oResult))
102 {
103 if (oResult == ERR_EMPTY)
104 {
105 return false;
106 }
107 THROW_IF_FAILED(oResult);
108 }
109
110 oDecoder = MakeDecoderFor(pSample);
111 THROW_IF_FAILED(oDecoder.IsValid());
112 tmSampleTime = streaming::get_sample_time(pSample);
113 return true;
114 }
115
123 {
124 base::flash::tNanoSeconds tmSampleTime;
125 return GetLastDecoder(oDecoder, tmSampleTime);
126 }
127
136 {
138 auto oResult = ReaderImplementation::GetLastSample(pSample);
139 if (IS_FAILED(oResult))
140 {
141 if (oResult == ERR_EMPTY)
142 {
143 return false;
144 }
145 THROW_IF_FAILED(oResult);
146 }
147
148 oDecoder = MakeDecoderFor(pSample);
149 THROW_IF_FAILED(oDecoder.IsValid());
150 tmSampleTime = streaming::get_sample_time(pSample);
151 return true;
152 }
153
154private:
156 m_fnAcceptCallback;
157};
158
205
212template<typename WriterImplementation = streaming::flash::cSampleWriter>
213class encoding_sample_writer : public WriterImplementation, public cSampleCodecFactory
214{
215public:
222 {
224 THROW_IF_FAILED(streaming::alloc_sample(pSample, tmTimeStamp));
225 auto oCodec = MakeCodecFor(pSample);
226 THROW_IF_FAILED(oCodec.IsValid());
227 return cSampleWithCodec(std::move(oCodec), pSample);
228 }
229
231 {
232 RETURN_IF_FAILED(WriterImplementation::SetType(pStreamType));
233 if (pStreamType.Get())
234 {
235 // the initial type is not required to have a media description set
236 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
237 }
238 else
239 {
240 *static_cast<cSampleCodecFactory*>(this) = cSampleCodecFactory();
241 }
243 }
244
246 {
247 RETURN_IF_FAILED(WriterImplementation::ChangeType(pStreamType));
248 // the initial type is not required to have a media description set
249 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
251 }
252
253 using WriterImplementation::Write;
254
261 tResult Write(cSampleWithCodec& oSampleWithCodec)
262 {
263 return Write(oSampleWithCodec.Release());
264 }
265};
266
267} // namespace osborn
268
269using osborn::decoding_sample_reader;
270using osborn::encoding_sample_writer;
271
272} // namespace mediadescription
273} // namespace adtf
#define IS_FAILED(s)
Check if result is failed.
Definition result.h:20
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult
Definition result.h:88
decoding_sample_reader()
Definition codec_sample_streamer.h:37
cSampleDecoder MakeDecoderFor(const adtf::streaming::ISample &oSample, ddl::tDataRepresentation eDataRepresentation) const
cSampleCodec MakeCodecFor(adtf::streaming::ISample &oSample, ddl::tDataRepresentation eDataRepresentation) const
Definition codec_sample_streamer.h:163
cSampleWithCodec & operator=(cSampleWithCodec &&)=default
cSampleWithCodec(cSampleCodec &&oCodec, const ucom::ant::iobject_ptr< const streaming::ant::ISample > &pSample)
cSampleWithCodec(cSampleWithCodec &&)=default
ucom::ant::object_ptr< const streaming::ant::ISample > Release()
bool GetLastDecoder(cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Definition codec_sample_streamer.h:135
bool GetLastDecoder(cSampleDecoder &oDecoder)
Definition codec_sample_streamer.h:122
decoding_sample_reader()
Definition codec_sample_streamer.h:37
void SetAcceptTypeCallback(const std::function< tResult(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType)> &fnAcceptTypeCallback)
Definition codec_sample_streamer.h:71
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer.h:53
bool GetNextDecoder(cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Definition codec_sample_streamer.h:97
bool GetNextDecoder(cSampleDecoder &oDecoder)
Definition codec_sample_streamer.h:84
Definition codec_sample_streamer.h:214
cSampleWithCodec MakeSample(base::flash::tNanoSeconds tmTimeStamp)
Definition codec_sample_streamer.h:221
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer.h:230
tResult Write(cSampleWithCodec &oSampleWithCodec)
Definition codec_sample_streamer.h:261
tResult ChangeType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer.h:245
virtual T * Get() const =0
Get raw pointer to shared object.
Base object pointer to realize binary compatible reference counting in interface methods.
Definition object_ptr_intf.h:112
Definition object_ptr.h:384
Namespace for all functionality of the ADTF Mediadescription SDK provided since v3....
Definition codec_sample_streamer.h:24
tResult get_codec_factory_from_stream_type(const adtf::streaming::IStreamType &oStreamType, cSampleCodecFactory &oFactory)
Namespace for the ADTF Mediadescription SDK.
Definition codec_sample_streamer.h:22
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSample)
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
A timestamp with nanosecond precision.
Definition chrono.h:23