ADTF  3.18.2
codec_sample_streamer_legacy.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "sample_codec_legacy.h"
10 
11 #include <functional>
12 
13 namespace adtf
14 {
15 
16 namespace mediadescription
17 {
18 
19 namespace flash
20 {
21 
29 template <typename ReaderImplementation = streaming::flash::cDynamicSampleReader>
31  public ReaderImplementation,
32  public cSampleCodecFactory
33 {
34  public:
39  {
40  ReaderImplementation::SetAcceptTypeCallback([&](const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType) -> tResult
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 
70  void SetAcceptTypeCallback(const std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)> & fnAcceptTypeCallback)
71  {
72  m_fnAcceptCallback = fnAcceptTypeCallback;
73  }
74 
82  {
83  base::flash::tNanoSeconds tmSampleTime;
84  return GetNextDecoder(oDecoder, tmSampleTime);
85  }
86 
95  {
97  auto oResult = ReaderImplementation::GetNextSample(pSample);
98  if (IS_FAILED(oResult))
99  {
100  if (oResult == ERR_EMPTY)
101  {
102  return false;
103  }
104  THROW_IF_FAILED(oResult);
105  }
106 
107  oDecoder = MakeDecoderFor(pSample);
108  THROW_IF_FAILED(oDecoder.IsValid());
109  tmSampleTime = streaming::get_sample_time(pSample);
110  return true;
111  }
112 
120  {
121  base::flash::tNanoSeconds tmSampleTime;
122  return GetLastDecoder(oDecoder, tmSampleTime);
123  }
124 
133  {
135  auto oResult = ReaderImplementation::GetLastSample(pSample);
136  if (IS_FAILED(oResult))
137  {
138  if (oResult == ERR_EMPTY)
139  {
140  return false;
141  }
142  THROW_IF_FAILED(oResult);
143  }
144 
145  oDecoder = MakeDecoderFor(pSample);
146  THROW_IF_FAILED(oDecoder.IsValid());
147  tmSampleTime = streaming::get_sample_time(pSample);
148  return true;
149  }
150 
151  private:
152  std::function<tResult(const ucom::ant::iobject_ptr<const streaming::ant::IStreamType>& pStreamType)> m_fnAcceptCallback;
153 };
154 
159 {
160  public:
164  cSampleWithCodec() = default;
165 
173 
174  cSampleWithCodec(cSampleWithCodec&&) = default;
175  cSampleWithCodec& operator=(cSampleWithCodec&&) = default;
176 
177  virtual ~cSampleWithCodec();
178 
189 
190  private:
192 };
193 
199 template <typename WriterImplementation = streaming::flash::cSampleWriter>
201  public WriterImplementation,
202  public cSampleCodecFactory
203 {
204  public:
211  {
213  THROW_IF_FAILED(streaming::alloc_sample(pSample, tmTimeStamp));
214  auto oCodec = MakeCodecFor(pSample);
215  THROW_IF_FAILED(oCodec.IsValid());
216  return cSampleWithCodec(std::move(oCodec), pSample);
217  }
218 
220  {
221  RETURN_IF_FAILED(WriterImplementation::SetType(pStreamType));
222  if (pStreamType.Get())
223  {
224  // the initial type is not required to have a media description set
225  get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
226  }
227  else
228  {
229  *static_cast<cSampleCodecFactory*>(this) = cSampleCodecFactory();
230  }
232  }
233 
235  {
236  RETURN_IF_FAILED(WriterImplementation::ChangeType(pStreamType));
237  // the initial type is not required to have a media description set
238  get_codec_factory_from_stream_type(*pStreamType.Get(), *this);
240  }
241 
242  using WriterImplementation::Write;
243 
250  tResult Write(cSampleWithCodec& oSampleWithCodec)
251  {
252  return Write(oSampleWithCodec.Release());
253  }
254 };
255 
256 }
257 
258 }
259 }
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.
cSampleDecoder MakeDecoderFor(const adtf::streaming::ISample &oSample, adtf_ddl::tDataRepresentation eDataRepresentation) const
Creates a decoder for the given sample.
cSampleCodec MakeCodecFor(adtf::streaming::ISample &oSample, adtf_ddl::tDataRepresentation eDataRepresentation) const
Creates a codec for the given sample.
Codec for samples with static and/or dynamic data.
Decoder for samples with static and/or dynamic data.
Helper class that combines a Sample Codec with a Sample instance.
cSampleWithCodec(ant::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(ant::cSampleDecoder &oDecoder)
Returns a decoder for the last Sample currently available.
bool GetNextDecoder(ant::cSampleDecoder &oDecoder)
Returns a decoder for the next available Sample.
tResult SetType(const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pStreamType) override
Sets the initial stream type of a streamer.
bool GetLastDecoder(ant::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(ant::cSampleDecoder &oDecoder, base::flash::tNanoSeconds &tmSampleTime)
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
virtual tResult IsValid() const override
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