Leviathan  0.8.0.0
Leviathan game engine
Leviathan::DecodedFrame Struct Reference

Holds decoded data. This is only valid until the frame receive callback ends. More...

#include <Codec.h>

Classes

struct  Image
 
struct  Sound
 

Public Member Functions

DLLEXPORT DecodedFrame (aom_image *img)
 
DLLEXPORT DecodedFrame (const float *const *pcm, int samples, int channels)
 

Public Attributes

std::variant< std::monostate, Image, SoundTypeSpecificData
 

Detailed Description

Holds decoded data. This is only valid until the frame receive callback ends.

Definition at line 16 of file Codec.h.

Constructor & Destructor Documentation

◆ DecodedFrame() [1/2]

DLLEXPORT DecodedFrame::DecodedFrame ( aom_image *  img)

Definition at line 27 of file Codec.cpp.

28 {
29  Image image;
30 
31  image.Width = img->w;
32  image.Height = img->h;
33  image.BitDepth = img->bit_depth;
34  // img->bps
35 
36  image.ConvertImage = [img, image](uint8_t* target, size_t targetlength,
37  Image::IMAGE_TARGET_FORMAT format) -> bool {
39  return false;
40 
41  const auto targetStride = image.Width * 4;
42 
43  if(targetlength != targetStride * image.Height)
44  return false;
45 
46  std::array<int, 3> planeIndices = {0, 1, 2};
47 
48  // Depending on the img->fmt the Y, U and V planes can be in different order
49  if(img->fmt & AOM_IMG_FMT_UV_FLIP) {
50  planeIndices = {0, 2, 1};
51  }
52 
53  if(img->fmt & AOM_IMG_FMT_HAS_ALPHA) {
54  LOG_WARNING("AOM alpha channel handling is not implemented");
55  }
56 
57  if(img->fmt == AOM_IMG_FMT_AOMYV12 || img->fmt == AOM_IMG_FMT_AOMI420) {
58  LOG_WARNING("AOM colourspace handling not implemented");
59  }
60 
61  // Setup plane data for the conversion call
62  std::array<const uint8_t*, 3> planes;
63  std::array<int, 3> strides;
64  std::array<std::tuple<int, int>, 3> planeSizes;
65 
66  for(int plane = 0; plane < 3; ++plane) {
67  const auto aomPlane = planeIndices[plane];
68  planes[plane] = img->planes[aomPlane];
69  strides[plane] = img->stride[aomPlane];
70  planeSizes[plane] = {
71  aom_img_plane_width(img, aomPlane), aom_img_plane_height(img, aomPlane)};
72  }
73 
74  return YUVToRGBA(planes, strides, planeSizes, img->fmt & AOM_IMG_FMT_HIGHBITDEPTH,
75  target, image.Width, image.Height);
76  };
77 
78  TypeSpecificData = image;
79 }
#define LOG_WARNING(x)
Definition: Define.h:91
DLLEXPORT bool YUVToRGBA(const std::array< const uint8_t *, 3 > &planes, const std::array< int, 3 > &strides, const std::array< std::tuple< int, int >, 3 > &planesizes, bool bytesare16bit, uint8_t *target, size_t width, size_t height, YUV_COLOUR_SPACE colourtype=YUV_COLOUR_SPACE::BT_601)
Converts a few kinds of supported YUV formats to RGBA.
Definition: YUVToRGB.cpp:128
unsigned char uint8_t
Definition: core.h:38
std::variant< std::monostate, Image, Sound > TypeSpecificData
Definition: Codec.h:56

◆ DecodedFrame() [2/2]

DLLEXPORT DecodedFrame::DecodedFrame ( const float *const *  pcm,
int  samples,
int  channels 
)
Parameters
pcmIs a multidimensional array where each array is of size samples, channels tells how many arrays there are in pcm

Definition at line 81 of file Codec.cpp.

82 {
83  Sound sound;
84 
85  sound.Samples = samples;
86  sound.Channels = channels;
87 
88  sound.ConvertSamples = [pcm, sound](uint8_t* target, size_t targetlength,
89  Sound::SOUND_TARGET_FORMAT format) -> bool {
91  return false;
92 
93  if(targetlength != sizeof(int16_t) * sound.Samples * sound.Channels)
94  return false;
95 
96  bool clipped = false;
97 
98  // Converts floats to 16 bit signed ints in an interleaved form
99  for(int channel = 0; channel < sound.Channels; ++channel) {
100  int16_t* writePtr = reinterpret_cast<int16_t*>(target) + channel;
101 
102  const float* monoSamples = pcm[channel];
103 
104  for(int sample = 0; sample < sound.Samples; ++sample) {
105  // The vorbis decoding sample uses dithering here, not sure what that does, but
106  // we skip it here
107  int val = std::floor(monoSamples[sample] * 32767.f + .5f);
108 
109  // Protect against clipping, skipping this might make things faster
110  if(val > std::numeric_limits<int16_t>::max()) {
111  val = std::numeric_limits<int16_t>::max();
112  clipped = true;
113  }
114  if(val < std::numeric_limits<int16_t>::min()) {
115  val = std::numeric_limits<int16_t>::min();
116  clipped = true;
117  }
118 
119  *writePtr = val;
120  writePtr += sound.Channels;
121  }
122  }
123 
124  if(clipped)
125  LOG_WARNING("DecodedFrame: detected audio clipping on conversion");
126 
127  return true;
128  };
129 
130  TypeSpecificData = sound;
131 }
#define LOG_WARNING(x)
Definition: Define.h:91
unsigned char uint8_t
Definition: core.h:38
std::variant< std::monostate, Image, Sound > TypeSpecificData
Definition: Codec.h:56

Member Data Documentation

◆ TypeSpecificData

std::variant<std::monostate, Image, Sound> Leviathan::DecodedFrame::TypeSpecificData

Definition at line 56 of file Codec.h.


The documentation for this struct was generated from the following files: