This class implements a simple video decoder for Android using encoded media samples from memory as input.
More...
#include <VideoDecoder.h>
|
| VideoDecoder () |
| Default constructor creating an un-initialized decoder.
|
|
| VideoDecoder (VideoDecoder &&videoDecoder) noexcept |
| Move constructor.
|
|
| ~VideoDecoder () |
| Destructs the video decoder and releases all associated resources.
|
|
bool | initialize (const std::string &mime, const unsigned int width, const unsigned int height) |
|
bool | start () |
| Starts the video decoder.
|
|
bool | stop () |
| Stops the video decoder.
|
|
bool | pushSample (const void *data, const size_t size, const uint64_t presentationTime) |
| Adds a new media sample which needs to be decoded to the video decoder.
|
|
Frame | popFrame (int64_t *presentationTime=nullptr) |
| Optional the frame's presentation time will be returned, this is the presentation time which was used when the corresponding sample was provided in decodedSample().
|
|
bool | isInitialized () const |
| Returns whether this decode is initialized.
|
|
bool | isStarted () const |
| Returns whether this decoder is currently running.
|
|
void | release () |
| Explicitly releases this video encoder.
|
|
VideoDecoder & | operator= (VideoDecoder &&videoDecoder) noexcept |
| Move operator.
|
|
This class implements a simple video decoder for Android using encoded media samples from memory as input.
Usage:
void threadRun()
{
if (!videoDecoder.
initialize(
"video/avc", 1920u, 1080u))
{
}
if (!videoDecoder.
start())
{
}
unsigned int frameIndex = 0u;
double frameRate = 30.0;
while (true)
{
void* sampleData = nullptr;
size_t sampleSize = 0;
if (doesNewInputSampleExist(sampleData, &sampleSize))
{
uint64_t presentationTime = uint64_t(1.0e6 * double(frameIndex) / frameRate);
if (!videoDecoder.
pushSample(sampleData, sampleSize, presentationTime))
{
}
++frameIndex;
}
Frame newFrame = videoDecoder.
popFrame();
if (newFrame.isValid())
{
sendFrameToReceiver(std::move(newFrame));
}
}
}
◆ VideoDecoder() [1/3]
Ocean::Media::Android::VideoDecoder::VideoDecoder |
( |
| ) |
|
Default constructor creating an un-initialized decoder.
◆ VideoDecoder() [2/3]
Ocean::Media::Android::VideoDecoder::VideoDecoder |
( |
VideoDecoder && |
videoDecoder | ) |
|
|
inlinenoexcept |
Move constructor.
- Parameters
-
videoDecoder | The decoder to be moved |
◆ ~VideoDecoder()
Ocean::Media::Android::VideoDecoder::~VideoDecoder |
( |
| ) |
|
Destructs the video decoder and releases all associated resources.
◆ VideoDecoder() [3/3]
Ocean::Media::Android::VideoDecoder::VideoDecoder |
( |
const VideoDecoder & |
| ) |
|
|
protecteddelete |
Disabled copy constructor.
◆ extractVideoFrameFromCodecOutputBuffer()
static Frame Ocean::Media::Android::VideoDecoder::extractVideoFrameFromCodecOutputBuffer |
( |
AMediaCodec *const |
mediaCodec, |
|
|
int64_t * |
presentationTime = nullptr |
|
) |
| |
|
static |
Extracts the video frame from an output buffer of a video codec.
- Parameters
-
mediaCodec | The media codec to which the output buffer belongs, must be valid |
presentationTime | Optional resulting presentation time in micro seconds, with range (-infinity, infinity) |
- Returns
- The resulting extracted frame, invalid if the frame could not be extracted
◆ initialize()
bool Ocean::Media::Android::VideoDecoder::initialize |
( |
const std::string & |
mime, |
|
|
const unsigned int |
width, |
|
|
const unsigned int |
height |
|
) |
| |
- Parameters
-
mime | The MIME type (Multipurpose Internet Mail Extensions) of the video to be decoded, e.g., "video/avc", "video/hevc", ... |
width | The width of the video to be decoded, in pixel, with range [1, infinity) |
height | The height of the video to be decoded, in pixel, with range [1, infinity) |
- Returns
- True, if succeeded
- See also
- isInitialized().
◆ isInitialized()
bool Ocean::Media::Android::VideoDecoder::isInitialized |
( |
| ) |
const |
|
inline |
Returns whether this decode is initialized.
- Returns
- True, if so
- See also
- initialize().
◆ isStarted()
bool Ocean::Media::Android::VideoDecoder::isStarted |
( |
| ) |
const |
|
inline |
Returns whether this decoder is currently running.
- Returns
- True, if so
- See also
- start().
◆ operator=() [1/2]
Disabled copy operator.
- Returns
- Reference to this object
◆ operator=() [2/2]
Move operator.
- Parameters
-
videoDecoder | The video decoder to be moved |
- Returns
- Reference to this object
◆ popFrame()
Frame Ocean::Media::Android::VideoDecoder::popFrame |
( |
int64_t * |
presentationTime = nullptr | ) |
|
Optional the frame's presentation time will be returned, this is the presentation time which was used when the corresponding sample was provided in decodedSample().
- Parameters
-
presentationTime | Optional resulting presentation time in micro seconds, with range (-infinity, infinity) |
- Returns
- The resulting frame, invalid if currently no decoded frame is available
- See also
- pushSample().
◆ pushSample()
bool Ocean::Media::Android::VideoDecoder::pushSample |
( |
const void * |
data, |
|
|
const size_t |
size, |
|
|
const uint64_t |
presentationTime |
|
) |
| |
Adds a new media sample which needs to be decoded to the video decoder.
The decoder needs to be initialized and started.
The presentation time is mainly intended to allow associating the provided encoded media sample with the resulting decoded frame when calling popFrame().
However, it's recommended to define a reasonable presentation time for each sample (e.g., let the first sample start at 0 and increment the time by 1^6/fps for each following sample.
- Parameters
-
data | The data of the encoded media sample, must be valid |
size | The size of the encoded media sample, in bytes, with range [1, infinity) |
presentationTime | The presentation time of the sample, in microseconds, with range [0, infinity) |
- Returns
- True, if succeeded
- See also
- start(), isInitialized(), isStarted().
◆ release()
void Ocean::Media::Android::VideoDecoder::release |
( |
| ) |
|
Explicitly releases this video encoder.
If the encoder is still running, the encoder will be stopped as well.
◆ start()
bool Ocean::Media::Android::VideoDecoder::start |
( |
| ) |
|
Starts the video decoder.
- Returns
- True, if succeeded
- See also
- isStarted().
◆ stop()
bool Ocean::Media::Android::VideoDecoder::stop |
( |
| ) |
|
Stops the video decoder.
- Returns
- True, if succeeded
◆ decoder_
The Android media decoder used to decode the video.
◆ isStarted_
bool Ocean::Media::Android::VideoDecoder::isStarted_ = false |
|
protected |
True, if the decoder is currently started.
◆ lock_
Lock Ocean::Media::Android::VideoDecoder::lock_ |
|
mutableprotected |
◆ nativeMediaLibrarySubscription_
The subscription for the native media library.
The documentation for this class was generated from the following file: