ADTF  3.18.2
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 
19 namespace adtf
20 {
21 namespace mediadescription
22 {
23 namespace osborn
24 {
32 template<typename ReaderImplementation = streaming::flash::cDynamicSampleReader>
34  public ReaderImplementation,
35  public cSampleCodecFactory
36 {
37 public:
42  {
43  ReaderImplementation::SetAcceptTypeCallback([&](const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType) -> tResult {
44  static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
45  RETURN_IF_FAILED(get_codec_factory_from_stream_type(*pStreamType.Get(), *this));
46 
47  if (m_fnAcceptCallback)
48  {
49  RETURN_IF_FAILED(m_fnAcceptCallback(pStreamType));
50  }
52  });
53  }
54 
56  {
57  RETURN_IF_FAILED(ReaderImplementation::SetType(pStreamType));
58  // the initial type is not required to have a media description set
59  static_cast<cSampleCodecFactory&>(*this) = cSampleCodecFactory();
60  if (pStreamType.Get())
61  {
62  get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
63  }
65  }
66 
72  void SetAcceptTypeCallback(const std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)>& fnAcceptTypeCallback)
73  {
74  m_fnAcceptCallback = fnAcceptTypeCallback;
75  }
76 
84  {
85  base::flash::tNanoSeconds tmSampleTime;
86  return GetNextDecoder(oDecoder, tmSampleTime);
87  }
88 
97  {
99  auto oResult = ReaderImplementation::GetNextSample(pSample);
100  if (IS_FAILED(oResult))
101  {
102  if (oResult == ERR_EMPTY)
103  {
104  return false;
105  }
106  THROW_IF_FAILED(oResult);
107  }
108 
109  oDecoder = MakeDecoderFor(pSample);
110  THROW_IF_FAILED(oDecoder.IsValid());
111  tmSampleTime = streaming::get_sample_time(pSample);
112  return true;
113  }
114 
122  {
123  base::flash::tNanoSeconds tmSampleTime;
124  return GetLastDecoder(oDecoder, tmSampleTime);
125  }
126 
135  {
137  auto oResult = ReaderImplementation::GetLastSample(pSample);
138  if (IS_FAILED(oResult))
139  {
140  if (oResult == ERR_EMPTY)
141  {
142  return false;
143  }
144  THROW_IF_FAILED(oResult);
145  }
146 
147  oDecoder = MakeDecoderFor(pSample);
148  THROW_IF_FAILED(oDecoder.IsValid());
149  tmSampleTime = streaming::get_sample_time(pSample);
150  return true;
151  }
152 
153 private:
154  std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)> m_fnAcceptCallback;
155 };
156 
161 {
162 public:
166  cSampleWithCodec() = default;
167 
175 
176  cSampleWithCodec(cSampleWithCodec&&) = default;
177  cSampleWithCodec& operator=(cSampleWithCodec&&) = default;
178 
179  virtual ~cSampleWithCodec();
180 
191 
192 private:
194 };
195 
201 template<typename WriterImplementation = streaming::flash::cSampleWriter>
203  public WriterImplementation,
204  public cSampleCodecFactory
205 {
206 public:
213  {
215  THROW_IF_FAILED(streaming::alloc_sample(pSample, tmTimeStamp));
216  auto oCodec = MakeCodecFor(pSample);
217  THROW_IF_FAILED(oCodec.IsValid());
218  return cSampleWithCodec(std::move(oCodec), pSample);
219  }
220 
222  {
223  RETURN_IF_FAILED(WriterImplementation::SetType(pStreamType));
224  if (pStreamType.Get())
225  {
226  // the initial type is not required to have a media description set
227  get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
228  }
229  else
230  {
231  *static_cast<cSampleCodecFactory*>(this) = cSampleCodecFactory();
232  }
234  }
235 
237  {
238  RETURN_IF_FAILED(WriterImplementation::ChangeType(pStreamType));
239  // the initial type is not required to have a media description set
240  get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
242  }
243 
244  using WriterImplementation::Write;
245 
252  tResult Write(cSampleWithCodec& oSampleWithCodec)
253  {
254  return Write(oSampleWithCodec.Release());
255  }
256 };
257 
258 } // namespace osborn
259 
260 using osborn::decoding_sample_reader;
261 using osborn::encoding_sample_writer;
262 
263 } // namespace mediadescription
264 } // namespace adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Factory class for ddl codecs for samples.
Definition: sample_codec.h:946
cSampleDecoder MakeDecoderFor(const adtf::streaming::ISample &oSample, ddl::tDataRepresentation eDataRepresentation) const
Creates a decoder for the given sample.
cSampleCodec MakeCodecFor(adtf::streaming::ISample &oSample, ddl::tDataRepresentation eDataRepresentation) const
Creates a codec for the given sample.
Codec for samples with static and/or dynamic data.
Definition: sample_codec.h:675
tResult IsValid() const
Returns the validation state of the coder.
Decoder for samples with static and/or dynamic data.
Definition: sample_codec.h:605
Helper class that combines a Sample Codec with a Sample instance.
cSampleWithCodec(cSampleCodec &&oCodec, const ucom::ant::iobject_ptr< const streaming::ant::ISample > &pSample)
Constructor that initializes a valid object.
ucom::ant::object_ptr< const streaming::ant::ISample > Release()
Retrieve the sample instance.
cSampleWithCodec()=default
Default Constructor -> invalid object.
This reader uses the media description to decode sample data.
bool GetLastDecoder(cSampleDecoder &oDecoder)
Returns a decoder for the last Sample currently available.
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Sets the initial stream type of a streamer.
bool GetNextDecoder(cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Returns a decoder for the next available Sample.
bool GetLastDecoder(cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
Returns a decoder for the last Sample currently available.
void SetAcceptTypeCallback(const std::function< tResult(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType)> &fnAcceptTypeCallback)
Sets a callback that will be called for each new Stream Type.
bool GetNextDecoder(cSampleDecoder &oDecoder)
Returns a decoder for the next available Sample.
Sample Writer that provides samples that can be updated via a Codec.
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Sets the initial stream type of a streamer.
tResult Write(cSampleWithCodec &oSampleWithCodec)
Write a sample to the attached Sample Stream.
cSampleWithCodec MakeSample(base::flash::tNanoSeconds tmTimeStamp)
Creates a new Sample with an attached Sample Codec.
tResult ChangeType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Communicates a type change for all following samples.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
tResult get_codec_factory_from_stream_type(const adtf::streaming::IStreamType &oStreamType, cSampleCodecFactory &oFactory)
Create a sample codec factory from a given stream type.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the adtf::ucom::ant::IRuntime.
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Returns the sample time stamp with nanosecond precision.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult