ADTF  3.18.2
md_sample_data.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #ifdef USE_ADTF_MEDIA_DESCRIPTION_LEGACY
10  #ifndef NO_ADTF_MEDIA_DESCRIPTION_LEGACY
12  #endif
13 #endif
14 
15 #include <adtfbase/adtf_base_type_traits.h>
18 
19 #include <memory>
20 #include <cstdint>
21 #include <string>
22 
23 namespace adtf
24 {
25 namespace mediadescription
26 {
27 namespace osborn
28 {
29 namespace detail
30 {
31 
32 template<typename, typename = void>
33 constexpr bool is_defined_v = false;
34 
35 template<typename T>
36 constexpr bool is_defined_v<T, std::void_t<decltype(sizeof(T))>> = true;
37 
38 }
39 
51 template <typename T>
52 struct description;
53 
54 template<typename T>
55 constexpr bool has_description_v = detail::is_defined_v<description<T>>;
56 
60 template <typename T>
61 struct indices;
62 
75 template <typename T>
77 {
78  public:
80  {
81  static_assert(base::penguin::detail::always_false<T>,
82  "There is no md_sample_data specialization available for this type."
83  " Please make sure that you generate and include the corresponding header file.");
84  }
85 };
86 
95 template <typename T, typename UnderlyingType = T>
96 class md_array
97 {
98  public:
99  md_array(const tCodecIndex aIndices[],
100  std::shared_ptr<adtf::mediadescription::osborn::cSampleDecoder> pDecoder):
101  m_pIndices(aIndices),
102  m_pDecoder(pDecoder)
103  {
104  }
105 
106  T operator[](size_t nIndex) const
107  {
108  return static_cast<T>(m_pDecoder->template GetElementValue<UnderlyingType>(m_pIndices[nIndex]));
109  }
110 
111  private:
112  const tCodecIndex* m_pIndices = nullptr;
113  std::shared_ptr<adtf::mediadescription::osborn::cSampleDecoder> m_pDecoder;
114 };
115 
124 template <typename T>
126 {
127  public:
128  md_struct_array(const indices<T> aIndices[],
129  std::shared_ptr<adtf::mediadescription::osborn::cSampleDecoder> decoder):
130  m_pIndices(aIndices),
131  m_pDecoder(decoder)
132  {
133  }
134 
135  md_sample_data<T> operator[](size_t nIndex) const
136  {
137  return md_sample_data<T>(m_pIndices[nIndex], m_pDecoder);
138  }
139 
140  private:
141  const indices<T>* m_pIndices = nullptr;
142  std::shared_ptr<adtf::mediadescription::osborn::cSampleDecoder> m_pDecoder;
143 };
144 
145 namespace detail
146 {
147 
148 template <typename T>
150 {
152  std::shared_ptr<indices<T>> pIndices):
153  cSampleDecoder(std::move(oDecoder)),
154  pIndices(std::move(pIndices))
155  {}
156 
157  std::shared_ptr<indices<T>> pIndices;
158 };
159 
160 }
161 
173 template <typename T>
175 {
176  public:
177  static_assert(has_description_v<T>,
178  "md_sample_data_factory<T>() can only be used if ddl description was generated with adtf_mdgen!");
179 
180  /*
181  * Default constructor that intializes the factory with the generated media description.
182  */
186  {
187  }
188 
190  md_sample_data_factory& operator=(md_sample_data_factory&&) = default;
191 
192 
200  md_sample_data_factory(*pStreamType.Get())
201  {
202  }
203 
211  m_oFactory(oStreamType),
212  m_pIndices(std::make_shared<indices<T>>())
213  {
214  THROW_IF_FAILED(m_oFactory.IsValid());
215  m_pIndices->Find(m_oFactory, "");
216  }
217 
224  md_sample_data_factory(const char* strStructName, const char* strDefinition):
225  m_oFactory(strStructName, strDefinition),
226  m_pIndices(std::make_shared<indices<T>>())
227  {
228  THROW_IF_FAILED(m_oFactory.IsValid());
229  m_pIndices->Find(m_oFactory, "");
230  }
231 
238  {
239  return md_sample_data<T>(*m_pIndices,
240  std::make_shared<detail::decoder_with_indices<T>>(m_oFactory.MakeDecoderFor(pSample),
241  m_pIndices));
242  }
243 
244  private:
246  std::shared_ptr<indices<T>> m_pIndices;
247 };
248 
249 }
250 
251 using osborn::md_sample_data_factory;
252 using osborn::md_sample_data;
253 using osborn::description;
254 using osborn::has_description_v;
255 using osborn::md_array;
256 using osborn::md_struct_array;
257 
258 }
259 }
Copyright © Audi Electronics Venture GmbH.
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.
tResult IsValid() const
Check if the factory is in a valid state.
Decoder for samples with static and/or dynamic data.
Definition: sample_codec.h:605
cSampleDecoder()=default
Default constructor.
This class is used to wrap access to arrays of plain and enum types.
This factory provides instances of md_sample_data for incoming samples.
md_sample_data_factory(const adtf::streaming::IStreamType &oStreamType)
Initializes the factory with a stream type that has a media description set.
md_sample_data< T > Make(const adtf::ucom::ant::iobject_ptr< const adtf::streaming::ant::ISample > &pSample)
Returns a data access wrapper for the given sample.
md_sample_data_factory(const adtf::ucom::ant::iobject_ptr< const adtf::streaming::IStreamType > &pStreamType)
Initializes the factory with a stream type that has a media description set.
md_sample_data_factory(const char *strStructName, const char *strDefinition)
Initializes the factory with a media description.
Template to provide media description based access to Sample data.
This class is used to wrap access to arrays of struct types.
Defines access methods for the interface of a Stream Type - see also Stream Type and Stream Meta Type...
Base object pointer to realize binary compatible reference counting in interface methods.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
Copyright © Audi Electronics Venture GmbH.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Template to provide struct name and definition for a generated struct.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult