Shaka Player Embedded
frames.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_MEDIA_FRAMES_H_
16 #define SHAKA_EMBEDDED_MEDIA_FRAMES_H_
17 
18 #include <iostream>
19 #include <memory>
20 #include <vector>
21 
22 #include "../eme/configuration.h"
23 #include "../eme/implementation.h"
24 #include "../macros.h"
25 #include "../variant.h"
26 #include "stream_info.h"
27 
28 namespace shaka {
29 namespace media {
30 
35 enum class MediaStatus : uint8_t {
36  Success,
37 
39  FatalError,
40 
46 };
47 
53 enum class PixelFormat : uint8_t {
54  Unknown,
55 
64  YUV420P,
65 
74  NV12,
75 
82  RGB24,
83 
84 
90 
96  //{
97  AppFormat1 = 128,
98  AppFormat2 = 129,
99  AppFormat3 = 130,
100  AppFormat4 = 131,
101  //}
102 };
103 
104 SHAKA_EXPORT std::ostream& operator<<(std::ostream& os, PixelFormat format);
105 
117 enum class SampleFormat : uint8_t {
118  Unknown,
119 
121  PackedU8,
123  PackedS16,
125  PackedS32,
127  PackedS64,
129  PackedFloat,
131  PackedDouble,
132 
134  PlanarU8,
136  PlanarS16,
138  PlanarS32,
140  PlanarS64,
142  PlanarFloat,
144  PlanarDouble,
145 
151  //{
152  AppFormat1 = 128,
153  AppFormat2 = 129,
154  AppFormat3 = 130,
155  AppFormat4 = 131,
156  //}
157 };
158 
159 SHAKA_EXPORT std::ostream& operator<<(std::ostream& os, SampleFormat format);
160 
161 inline std::ostream& operator<<(std::ostream& os,
163  if (holds_alternative<PixelFormat>(format))
164  return os << get<PixelFormat>(format);
165  else
166  return os << get<SampleFormat>(format);
167 }
168 
171 
178  size_t channels);
179 
180 
187  public:
188  BaseFrame(std::shared_ptr<const StreamInfo> stream_info, double pts,
189  double dts, double duration, bool is_key_frame);
190  virtual ~BaseFrame();
191 
193 
199  const std::shared_ptr<const StreamInfo> stream_info;
200 
202  const double pts;
203 
205  const double dts;
206 
208  const double duration;
209 
211  const bool is_key_frame;
212 
220  virtual size_t EstimateSize() const;
221 
222  private:
223  class Impl;
224  std::unique_ptr<Impl> impl_;
225 };
226 
234  public:
235  EncodedFrame(std::shared_ptr<const StreamInfo> stream, double pts, double dts,
236  double duration, bool is_key_frame, const uint8_t* data,
237  size_t data_size, double timestamp_offset,
238  std::shared_ptr<eme::FrameEncryptionInfo> encryption_info);
239  ~EncodedFrame() override;
240 
244  const uint8_t* const data;
245 
247  const size_t data_size;
248 
253  const double timestamp_offset;
254 
259  const std::shared_ptr<eme::FrameEncryptionInfo> encryption_info;
260 
261 
267  virtual MediaStatus Decrypt(const eme::Implementation* implementation,
268  uint8_t* dest) const;
269 
270 
271  size_t EstimateSize() const override;
272 
273  private:
274  class Impl;
275  std::unique_ptr<Impl> impl_;
276 };
277 
284  public:
285  DecodedFrame(std::shared_ptr<const StreamInfo> stream_info, double pts,
286  double dts, double duration,
287  variant<PixelFormat, SampleFormat> format, size_t sample_count,
288  const std::vector<const uint8_t*>& data,
289  const std::vector<size_t>& linesize);
290  ~DecodedFrame() override;
291 
296  const size_t sample_count;
297 
298 
312  const std::vector<const uint8_t*> data;
313 
322  const std::vector<size_t> linesize;
323 
326 
327 
328  size_t EstimateSize() const override;
329 
330  private:
331  class Impl;
332  std::unique_ptr<Impl> impl_;
333 };
334 
335 } // namespace media
336 } // namespace shaka
337 
338 #endif // SHAKA_EMBEDDED_MEDIA_FRAMES_H_
const char * dest
Definition: media_utils.cc:31
#define SHAKA_EXPORT
Definition: macros.h:30
const size_t sample_count
Definition: frames.h:296
const bool is_key_frame
Definition: frames.h:211
const size_t data_size
Definition: frames.h:247
const std::vector< size_t > linesize
Definition: frames.h:322
const std::shared_ptr< eme::FrameEncryptionInfo > encryption_info
Definition: frames.h:259
const std::vector< const uint8_t * > data
Definition: frames.h:312
const std::shared_ptr< const StreamInfo > stream_info
Definition: frames.h:199
std::ostream & operator<<(std::ostream &os, PixelFormat format)
Definition: frames.cc:22
#define SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE(Type)
Definition: macros.h:51
const variant< PixelFormat, SampleFormat > format
Definition: frames.h:325
bool IsPlanarFormat(variant< PixelFormat, SampleFormat > format)
Definition: frames.cc:68
const uint8_t *const data
Definition: frames.h:244
const double timestamp_offset
Definition: frames.h:253
size_t GetPlaneCount(variant< PixelFormat, SampleFormat > format, size_t channels)
Definition: frames.cc:92
const double duration
Definition: frames.h:208
const double dts
Definition: frames.h:205
const double pts
Definition: frames.h:202