ADTF
Loading...
Searching...
No Matches
codec_sample_streamer_legacy.h
Go to the documentation of this file.
1
7#pragma once
10
11#include <functional>
12
13namespace adtf
14{
15
16namespace mediadescription
17{
18
19namespace flash
20{
21
27template <typename ReaderImplementation = streaming::flash::cDynamicSampleReader>
29 public ReaderImplementation,
30 public cSampleCodecFactory
31{
32 public:
37 {
38 ReaderImplementation::SetAcceptTypeCallback([&](const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType) -> tResult
39 {
40 static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
41 RETURN_IF_FAILED(get_codec_factory_from_stream_type(*pStreamType.Get(), *this));
42
43 if (m_fnAcceptCallback)
44 {
45 RETURN_IF_FAILED(m_fnAcceptCallback(pStreamType));
46 }
48 });
49 }
50
52 {
53 RETURN_IF_FAILED(ReaderImplementation::SetType(pStreamType));
54 // the initial type is not required to have a media description set
55 static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
56 if (pStreamType.Get())
57 {
58 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
59 }
61 }
62
68 void SetAcceptTypeCallback(const std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)> & fnAcceptTypeCallback)
69 {
70 m_fnAcceptCallback = fnAcceptTypeCallback;
71 }
72
80 {
81 base::flash::tNanoSeconds tmSampleTime;
82 return GetNextDecoder(oDecoder, tmSampleTime);
83 }
84
93 {
95 auto oResult = ReaderImplementation::GetNextSample(pSample);
96 if (IS_FAILED(oResult))
97 {
98 if (oResult == ERR_EMPTY)
99 {
100 return false;
101 }
102 THROW_IF_FAILED(oResult);
103 }
104
105 oDecoder = MakeDecoderFor(pSample);
106 THROW_IF_FAILED(oDecoder.IsValid());
107 tmSampleTime = streaming::get_sample_time(pSample);
108 return true;
109 }
110
118 {
119 base::flash::tNanoSeconds tmSampleTime;
120 return GetLastDecoder(oDecoder, tmSampleTime);
121 }
122
131 {
133 auto oResult = ReaderImplementation::GetLastSample(pSample);
134 if (IS_FAILED(oResult))
135 {
136 if (oResult == ERR_EMPTY)
137 {
138 return false;
139 }
140 THROW_IF_FAILED(oResult);
141 }
142
143 oDecoder = MakeDecoderFor(pSample);
144 THROW_IF_FAILED(oDecoder.IsValid());
145 tmSampleTime = streaming::get_sample_time(pSample);
146 return true;
147 }
148
149 private:
150 std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)> m_fnAcceptCallback;
151};
152
191
197template <typename WriterImplementation = streaming::flash::cSampleWriter>
199 public WriterImplementation,
200 public cSampleCodecFactory
201{
202 public:
209 {
211 THROW_IF_FAILED(streaming::alloc_sample(pSample, tmTimeStamp));
212 auto oCodec = MakeCodecFor(pSample);
213 THROW_IF_FAILED(oCodec.IsValid());
214 return cSampleWithCodec(std::move(oCodec), pSample);
215 }
216
218 {
219 RETURN_IF_FAILED(WriterImplementation::SetType(pStreamType));
220 if (pStreamType.Get())
221 {
222 // the initial type is not required to have a media description set
223 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
224 }
225 else
226 {
227 *static_cast<cSampleCodecFactory*>(this) = cSampleCodecFactory();
228 }
230 }
231
233 {
234 RETURN_IF_FAILED(WriterImplementation::ChangeType(pStreamType));
235 // the initial type is not required to have a media description set
236 get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
238 }
239
240 using WriterImplementation::Write;
241
248 tResult Write(cSampleWithCodec& oSampleWithCodec)
249 {
250 return Write(oSampleWithCodec.Release());
251 }
252};
253
254}
255
256}
257}
#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
cSampleDecoder MakeDecoderFor(const adtf::streaming::ISample &oSample, adtf_ddl::tDataRepresentation eDataRepresentation) const
cSampleCodec MakeCodecFor(adtf::streaming::ISample &oSample, adtf_ddl::tDataRepresentation eDataRepresentation) const
Definition sample_codec_legacy.h:139
Definition sample_codec_legacy.h:96
Definition codec_sample_streamer_legacy.h:157
cSampleWithCodec(ant::cSampleCodec &&oCodec, const ucom::ant::iobject_ptr< const streaming::ant::ISample > &pSample)
ucom::ant::object_ptr< const streaming::ant::ISample > Release()
void SetAcceptTypeCallback(const std::function< tResult(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType)> &fnAcceptTypeCallback)
Definition codec_sample_streamer_legacy.h:68
bool GetLastDecoder(ant::cSampleDecoder &oDecoder)
Definition codec_sample_streamer_legacy.h:117
bool GetLastDecoder(ant::cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Definition codec_sample_streamer_legacy.h:130
decoding_sample_reader()
Definition codec_sample_streamer_legacy.h:36
bool GetNextDecoder(ant::cSampleDecoder &oDecoder)
Definition codec_sample_streamer_legacy.h:79
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer_legacy.h:51
bool GetNextDecoder(ant::cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Definition codec_sample_streamer_legacy.h:92
Definition codec_sample_streamer_legacy.h:201
tResult Write(cSampleWithCodec &oSampleWithCodec)
Definition codec_sample_streamer_legacy.h:248
tResult ChangeType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer_legacy.h:232
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Definition codec_sample_streamer_legacy.h:217
cSampleWithCodec MakeSample(base::flash::tNanoSeconds tmTimeStamp)
Definition codec_sample_streamer_legacy.h:208
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_legacy.h:20
Namespace for the ADTF Mediadescription SDK.
Definition codec_sample_streamer.h:22
tResult get_codec_factory_from_stream_type(const adtf::streaming::IStreamType &oStreamType, cSampleCodecFactory &oFactory)
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