mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibVideo: Make VP9::Decoder a subclass of a new abstract VideoDecoder
This will allow other decoders to be used in place of VP9::Decoder when new video decoders are implemented, such as AV1.
This commit is contained in:
parent
3720f66bb1
commit
2b4b6c5613
4 changed files with 34 additions and 12 deletions
|
@ -49,7 +49,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
main_widget->set_layout<GUI::VerticalBoxLayout>();
|
main_widget->set_layout<GUI::VerticalBoxLayout>();
|
||||||
auto image_widget = TRY(main_widget->try_add<GUI::ImageWidget>());
|
auto image_widget = TRY(main_widget->try_add<GUI::ImageWidget>());
|
||||||
|
|
||||||
Video::VP9::Decoder vp9_decoder;
|
OwnPtr<Video::VideoDecoder> decoder = make<Video::VP9::Decoder>();
|
||||||
size_t cluster_index = 0;
|
size_t cluster_index = 0;
|
||||||
size_t block_index = 0;
|
size_t block_index = 0;
|
||||||
size_t frame_index = 0;
|
size_t frame_index = 0;
|
||||||
|
@ -76,14 +76,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
if (!optional_sample.has_value())
|
if (!optional_sample.has_value())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto result = vp9_decoder.receive_sample(optional_sample.release_value());
|
auto result = decoder->receive_sample(optional_sample.release_value());
|
||||||
|
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
outln("Error decoding frame {}: {}", frame_number, result.error().string_literal());
|
outln("Error decoding frame {}: {}", frame_number, result.error().string_literal());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto frame_result = vp9_decoder.get_decoded_frame();
|
auto frame_result = decoder->get_decoded_frame();
|
||||||
if (frame_result.is_error()) {
|
if (frame_result.is_error()) {
|
||||||
outln("Error retrieving frame {}: {}", frame_number, frame_result.error().string_literal());
|
outln("Error retrieving frame {}: {}", frame_number, frame_result.error().string_literal());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -42,11 +42,6 @@ DecoderErrorOr<void> Decoder::receive_sample(Span<u8 const> chunk_data)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
DecoderErrorOr<void> Decoder::receive_sample(ByteBuffer const& chunk_data)
|
|
||||||
{
|
|
||||||
return receive_sample(chunk_data.span());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Decoder::dump_frame_info()
|
void Decoder::dump_frame_info()
|
||||||
{
|
{
|
||||||
m_parser->dump_info();
|
m_parser->dump_info();
|
||||||
|
|
|
@ -13,23 +13,24 @@
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <LibVideo/Color/CodingIndependentCodePoints.h>
|
#include <LibVideo/Color/CodingIndependentCodePoints.h>
|
||||||
#include <LibVideo/DecoderError.h>
|
#include <LibVideo/DecoderError.h>
|
||||||
|
#include <LibVideo/VideoDecoder.h>
|
||||||
#include <LibVideo/VideoFrame.h>
|
#include <LibVideo/VideoFrame.h>
|
||||||
|
|
||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
|
||||||
namespace Video::VP9 {
|
namespace Video::VP9 {
|
||||||
|
|
||||||
class Decoder {
|
class Decoder : public VideoDecoder {
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Decoder();
|
Decoder();
|
||||||
|
~Decoder() override { }
|
||||||
/* (8.1) General */
|
/* (8.1) General */
|
||||||
DecoderErrorOr<void> receive_sample(Span<u8 const>);
|
DecoderErrorOr<void> receive_sample(Span<u8 const>) override;
|
||||||
DecoderErrorOr<void> receive_sample(ByteBuffer const&);
|
|
||||||
void dump_frame_info();
|
void dump_frame_info();
|
||||||
|
|
||||||
DecoderErrorOr<NonnullOwnPtr<VideoFrame>> get_decoded_frame();
|
DecoderErrorOr<NonnullOwnPtr<VideoFrame>> get_decoded_frame() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef i32 Intermediate;
|
typedef i32 Intermediate;
|
||||||
|
|
26
Userland/Libraries/LibVideo/VideoDecoder.h
Normal file
26
Userland/Libraries/LibVideo/VideoDecoder.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/NonnullOwnPtr.h>
|
||||||
|
|
||||||
|
#include "DecoderError.h"
|
||||||
|
#include "VideoFrame.h"
|
||||||
|
|
||||||
|
namespace Video {
|
||||||
|
|
||||||
|
class VideoDecoder {
|
||||||
|
public:
|
||||||
|
virtual ~VideoDecoder() {};
|
||||||
|
|
||||||
|
virtual DecoderErrorOr<void> receive_sample(Span<u8 const> sample) = 0;
|
||||||
|
DecoderErrorOr<void> receive_sample(ByteBuffer const& sample) { return receive_sample(sample.span()); }
|
||||||
|
virtual DecoderErrorOr<NonnullOwnPtr<VideoFrame>> get_decoded_frame() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue