Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AV1Codec Class Reference

AOM AV1 video codec. More...

#include <Codec.h>

+ Inheritance diagram for Leviathan::AV1Codec:

Classes

struct  Implementation
 

Public Member Functions

DLLEXPORT AV1Codec ()
 
DLLEXPORT ~AV1Codec ()
 
DLLEXPORT bool FeedRawFrame (const uint8_t *data, size_t length) override
 Sends the raw data frame to the codec. More...
 
DLLEXPORT void ReceiveDecodedFrames (FrameCallback callback) override
 Returns decoded frames one by one after they are ready. More...
 
- Public Member Functions inherited from Leviathan::Codec
 Codec ()=default
 
 Codec (const Codec &other)=delete
 
Codecoperator= (const Codec &other)=delete
 

Additional Inherited Members

- Public Types inherited from Leviathan::Codec
using FrameCallback = std::function< bool(const DecodedFrame &frame)>
 

Detailed Description

AOM AV1 video codec.

Definition at line 83 of file Codec.h.

Constructor & Destructor Documentation

◆ AV1Codec()

DLLEXPORT AV1Codec::AV1Codec ( )

Definition at line 161 of file Codec.cpp.

161  : Pimpl(std::make_unique<Implementation>())
162 {
163  aom_codec_iface_t* codecInterface = aom_codec_av1_dx();
164  aom_codec_dec_cfg_t config;
165  std::memset(&config, 0, sizeof(config));
166  // TODO: allow adding threads (it might help with decode performance)
167  config.threads = 2;
168  // We prefer 8 bit output (but we can also handle 16 bit output correctly)
169  // in the hopes that it is faster
170  config.allow_lowbitdepth = 1;
171 
172  auto error = aom_codec_dec_init(Pimpl->Codec.get(), codecInterface, &config, 0);
173 
174  if(error) {
175  throw InvalidState(
176  std::string("AV1 codec creation failed: ") + aom_codec_error(Pimpl->Codec.get()));
177  }
178 
179  LOG_INFO(std::string("AV1Codec: using decoder interface: ") +
180  aom_codec_iface_name(codecInterface));
181 }
#define LOG_INFO(x)
Definition: Define.h:90

◆ ~AV1Codec()

DLLEXPORT AV1Codec::~AV1Codec ( )

Definition at line 183 of file Codec.cpp.

183 {}

Member Function Documentation

◆ FeedRawFrame()

DLLEXPORT bool AV1Codec::FeedRawFrame ( const uint8_t *  data,
size_t  length 
)
overridevirtual

Sends the raw data frame to the codec.

Returns
True on success. False if the codec couldn't handle the frame and is now possibly in broken state

Implements Leviathan::Codec.

Definition at line 185 of file Codec.cpp.

186 {
187  if(aom_codec_decode(Pimpl->Codec.get(), data, length, nullptr)) {
188  // Failed
189  LOG_ERROR(std::string("AV1Codec: decoding raw frame failed: ") +
190  aom_codec_error(Pimpl->Codec.get()));
191  return false;
192  }
193 
194  Pimpl->FrameIter = nullptr;
195 
196  return true;
197 }
#define LOG_ERROR(x)
Definition: Define.h:92

◆ ReceiveDecodedFrames()

DLLEXPORT void AV1Codec::ReceiveDecodedFrames ( FrameCallback  callback)
overridevirtual

Returns decoded frames one by one after they are ready.

Call FeedRawFrame and then call this afterwards, there may be more than 1 or no decoded frames for each raw frame. If the callback returns false the loop for iterating the finished frames stops before all frames are passed to the callback

Implements Leviathan::Codec.

Definition at line 199 of file Codec.cpp.

200 {
201  while(true) {
202  aom_image_t* img = aom_codec_get_frame(Pimpl->Codec.get(), &Pimpl->FrameIter);
203  if(img == nullptr) {
204  break;
205  }
206 
207  if(!callback(DecodedFrame(img)))
208  break;
209  }
210 }
Holds decoded data. This is only valid until the frame receive callback ends.
Definition: Codec.h:16

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