mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibVideo: Migrate to east-const style & apply other minor fixes
This patch brings all of LibVideo up to the east-const style in the project. Additionally, it applies a few fixes from the reviews in #8170 that referred to older LibVideo code.
This commit is contained in:
parent
7d4053dde1
commit
988e17ed05
Notes:
sideshowbarker
2024-07-18 11:14:10 +09:00
Author: https://github.com/FalseHonesty Commit: https://github.com/SerenityOS/serenity/commit/988e17ed052 Pull-request: https://github.com/SerenityOS/serenity/pull/8170 Reviewed-by: https://github.com/Lubrsi Reviewed-by: https://github.com/MaxWipfli
12 changed files with 48 additions and 50 deletions
|
@ -20,11 +20,11 @@ int main(int argc, char** argv)
|
|||
auto window = GUI::Window::construct();
|
||||
|
||||
auto document = Video::MatroskaReader::parse_matroska_from_file("/home/anon/Videos/test-webm.webm");
|
||||
const auto& optional_track = document->track_for_track_type(Video::TrackEntry::TrackType::Video);
|
||||
auto const& optional_track = document->track_for_track_type(Video::TrackEntry::TrackType::Video);
|
||||
if (!optional_track.has_value())
|
||||
return 1;
|
||||
const auto& track = optional_track.value();
|
||||
const auto video_track = track.video_track().value();
|
||||
auto const& track = optional_track.value();
|
||||
auto const video_track = track.video_track().value();
|
||||
|
||||
auto image = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize(video_track.pixel_height, video_track.pixel_width));
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
|
@ -36,12 +36,12 @@ int main(int argc, char** argv)
|
|||
main_widget.add_child(image_widget);
|
||||
|
||||
Video::VP9::Decoder vp9_decoder;
|
||||
for (const auto& cluster : document->clusters()) {
|
||||
for (const auto& block : cluster.blocks()) {
|
||||
for (auto const& cluster : document->clusters()) {
|
||||
for (auto const& block : cluster.blocks()) {
|
||||
if (block.track_number() != track.track_number())
|
||||
continue;
|
||||
|
||||
const auto& frame = block.frame(0);
|
||||
auto const& frame = block.frame(0);
|
||||
dbgln("Reading frame 0 from block @ {}", block.timestamp());
|
||||
vp9_decoder.parse_frame(frame);
|
||||
vp9_decoder.dump_info();
|
||||
|
|
|
@ -67,9 +67,9 @@ public:
|
|||
TrackType track_type() const { return m_track_type; }
|
||||
void set_track_type(TrackType track_type) { m_track_type = track_type; }
|
||||
FlyString language() const { return m_language; }
|
||||
void set_language(const FlyString& language) { m_language = language; }
|
||||
void set_language(FlyString const& language) { m_language = language; }
|
||||
FlyString codec_id() const { return m_codec_id; }
|
||||
void set_codec_id(const FlyString& codec_id) { m_codec_id = codec_id; }
|
||||
void set_codec_id(FlyString const& codec_id) { m_codec_id = codec_id; }
|
||||
Optional<VideoTrack> video_track() const
|
||||
{
|
||||
if (track_type() != Video)
|
||||
|
@ -122,8 +122,8 @@ public:
|
|||
bool discardable() const { return m_discardable; }
|
||||
void set_discardable(bool discardable) { m_discardable = discardable; }
|
||||
u64 frame_count() const { return m_frames.size(); }
|
||||
const ByteBuffer& frame(size_t index) const { return m_frames.at(index); }
|
||||
void add_frame(const ByteBuffer& frame) { m_frames.append(move(frame)); }
|
||||
ByteBuffer const& frame(size_t index) const { return m_frames.at(index); }
|
||||
void add_frame(ByteBuffer frame) { m_frames.append(move(frame)); }
|
||||
|
||||
private:
|
||||
u64 m_track_number { 0 };
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
u64 timestamp() const { return m_timestamp; }
|
||||
void set_timestamp(u64 timestamp) { m_timestamp = timestamp; }
|
||||
NonnullOwnPtrVector<Block>& blocks() { return m_blocks; }
|
||||
const NonnullOwnPtrVector<Block>& blocks() const { return m_blocks; }
|
||||
NonnullOwnPtrVector<Block> const& blocks() const { return m_blocks; }
|
||||
|
||||
private:
|
||||
u64 m_timestamp { 0 };
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
const EBMLHeader& header() const { return m_header; }
|
||||
EBMLHeader const& header() const { return m_header; }
|
||||
|
||||
Optional<SegmentInformation> segment_information() const
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ public:
|
|||
return *m_segment_information;
|
||||
}
|
||||
void set_segment_information(OwnPtr<SegmentInformation> segment_information) { m_segment_information = move(segment_information); }
|
||||
const HashMap<u64, NonnullOwnPtr<TrackEntry>>& tracks() const { return m_tracks; }
|
||||
HashMap<u64, NonnullOwnPtr<TrackEntry>> const& tracks() const { return m_tracks; }
|
||||
Optional<TrackEntry> track_for_track_number(u64 track_number) const
|
||||
{
|
||||
auto track = m_tracks.get(track_number);
|
||||
|
|
|
@ -41,7 +41,7 @@ constexpr u32 BIT_DEPTH_ID = 0x6264;
|
|||
constexpr u32 SIMPLE_BLOCK_ID = 0xA3;
|
||||
constexpr u32 TIMESTAMP_ID = 0xE7;
|
||||
|
||||
OwnPtr<MatroskaDocument> MatroskaReader::parse_matroska_from_file(const StringView& path)
|
||||
OwnPtr<MatroskaDocument> MatroskaReader::parse_matroska_from_file(StringView const& path)
|
||||
{
|
||||
auto mapped_file_result = MappedFile::map(path);
|
||||
if (mapped_file_result.is_error())
|
||||
|
@ -51,7 +51,7 @@ OwnPtr<MatroskaDocument> MatroskaReader::parse_matroska_from_file(const StringVi
|
|||
return parse_matroska_from_data((u8*)mapped_file->data(), mapped_file->size());
|
||||
}
|
||||
|
||||
OwnPtr<MatroskaDocument> MatroskaReader::parse_matroska_from_data(const u8* data, size_t size)
|
||||
OwnPtr<MatroskaDocument> MatroskaReader::parse_matroska_from_data(u8 const* data, size_t size)
|
||||
{
|
||||
MatroskaReader reader(data, size);
|
||||
return reader.parse();
|
||||
|
@ -83,7 +83,7 @@ OwnPtr<MatroskaDocument> MatroskaReader::parse()
|
|||
return matroska_document;
|
||||
}
|
||||
|
||||
bool MatroskaReader::parse_master_element([[maybe_unused]] const StringView& element_name, Function<bool(u64)> element_consumer)
|
||||
bool MatroskaReader::parse_master_element([[maybe_unused]] StringView const& element_name, Function<bool(u64)> element_consumer)
|
||||
{
|
||||
auto element_data_size = m_streamer.read_variable_size_integer();
|
||||
CHECK_HAS_VALUE(element_data_size);
|
||||
|
|
|
@ -17,28 +17,28 @@ namespace Video {
|
|||
|
||||
class MatroskaReader {
|
||||
public:
|
||||
MatroskaReader(const u8* data, size_t size)
|
||||
MatroskaReader(u8 const* data, size_t size)
|
||||
: m_streamer(data, size)
|
||||
{
|
||||
}
|
||||
|
||||
static OwnPtr<MatroskaDocument> parse_matroska_from_file(const StringView& path);
|
||||
static OwnPtr<MatroskaDocument> parse_matroska_from_data(const u8*, size_t);
|
||||
static OwnPtr<MatroskaDocument> parse_matroska_from_file(StringView const& path);
|
||||
static OwnPtr<MatroskaDocument> parse_matroska_from_data(u8 const*, size_t);
|
||||
|
||||
OwnPtr<MatroskaDocument> parse();
|
||||
|
||||
private:
|
||||
class Streamer {
|
||||
public:
|
||||
Streamer(const u8* data, size_t size)
|
||||
Streamer(u8 const* data, size_t size)
|
||||
: m_data_ptr(data)
|
||||
, m_size_remaining(size)
|
||||
{
|
||||
}
|
||||
|
||||
const u8* data() { return m_data_ptr; }
|
||||
u8 const* data() { return m_data_ptr; }
|
||||
|
||||
const char* data_as_chars() { return reinterpret_cast<const char*>(m_data_ptr); }
|
||||
char const* data_as_chars() { return reinterpret_cast<char const*>(m_data_ptr); }
|
||||
|
||||
u8 read_octet()
|
||||
{
|
||||
|
@ -141,12 +141,12 @@ private:
|
|||
void set_remaining(size_t remaining) { m_size_remaining = remaining; }
|
||||
|
||||
private:
|
||||
const u8* m_data_ptr { nullptr };
|
||||
u8 const* m_data_ptr { nullptr };
|
||||
size_t m_size_remaining { 0 };
|
||||
Vector<size_t> m_octets_read { 0 };
|
||||
};
|
||||
|
||||
bool parse_master_element(const StringView& element_name, Function<bool(u64 element_id)> element_consumer);
|
||||
bool parse_master_element(StringView const& element_name, Function<bool(u64 element_id)> element_consumer);
|
||||
Optional<EBMLHeader> parse_ebml_header();
|
||||
|
||||
bool parse_segment_elements(MatroskaDocument&);
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Video::VP9 {
|
|||
|
||||
class BitStream {
|
||||
public:
|
||||
BitStream(const u8* data, size_t size)
|
||||
BitStream(u8 const* data, size_t size)
|
||||
: m_data_ptr(data)
|
||||
, m_bytes_remaining(size)
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
bool exit_bool();
|
||||
|
||||
private:
|
||||
const u8* m_data_ptr { nullptr };
|
||||
u8 const* m_data_ptr { nullptr };
|
||||
size_t m_bytes_remaining { 0 };
|
||||
Optional<u8> m_current_byte;
|
||||
i8 m_current_bit_position { 0 };
|
||||
|
|
|
@ -22,7 +22,7 @@ Decoder::Decoder()
|
|||
{
|
||||
}
|
||||
|
||||
bool Decoder::parse_frame(const ByteBuffer& frame_data)
|
||||
bool Decoder::parse_frame(ByteBuffer const& frame_data)
|
||||
{
|
||||
m_bit_stream = make<BitStream>(frame_data.data(), frame_data.size());
|
||||
m_syntax_element_counter = make<SyntaxElementCounter>();
|
||||
|
@ -301,13 +301,11 @@ bool Decoder::segmentation_params()
|
|||
|
||||
m_segmentation_update_map = m_bit_stream->read_bit();
|
||||
if (m_segmentation_update_map) {
|
||||
for (auto i = 0; i < 7; i++) {
|
||||
for (auto i = 0; i < 7; i++)
|
||||
m_segmentation_tree_probs[i] = read_prob();
|
||||
}
|
||||
m_segmentation_temporal_update = m_bit_stream->read_bit();
|
||||
for (auto i = 0; i < 3; i++) {
|
||||
for (auto i = 0; i < 3; i++)
|
||||
m_segmentation_pred_prob[i] = m_segmentation_temporal_update ? read_prob() : 255;
|
||||
}
|
||||
}
|
||||
|
||||
SAFE_CALL(m_bit_stream->read_bit());
|
||||
|
|
|
@ -22,7 +22,7 @@ class Decoder {
|
|||
public:
|
||||
Decoder();
|
||||
~Decoder();
|
||||
bool parse_frame(const ByteBuffer&);
|
||||
bool parse_frame(ByteBuffer const&);
|
||||
void dump_info();
|
||||
|
||||
private:
|
||||
|
|
|
@ -1150,22 +1150,22 @@ static constexpr CoefProbs default_coef_probs = {
|
|||
{ 1, 16, 6 } } } } }
|
||||
};
|
||||
|
||||
const ParetoTable& ProbabilityTables::pareto_table() const
|
||||
ParetoTable const& ProbabilityTables::pareto_table() const
|
||||
{
|
||||
return constant_pareto_table;
|
||||
}
|
||||
|
||||
const KfPartitionProbs& ProbabilityTables::kf_partition_probs() const
|
||||
KfPartitionProbs const& ProbabilityTables::kf_partition_probs() const
|
||||
{
|
||||
return constant_kf_partition_probs;
|
||||
}
|
||||
|
||||
const KfYModeProbs& ProbabilityTables::kf_y_mode_probs() const
|
||||
KfYModeProbs const& ProbabilityTables::kf_y_mode_probs() const
|
||||
{
|
||||
return constant_kf_y_mode_probs;
|
||||
}
|
||||
|
||||
const KfUVModeProbs& ProbabilityTables::kf_uv_mode_prob() const
|
||||
KfUVModeProbs const& ProbabilityTables::kf_uv_mode_prob() const
|
||||
{
|
||||
return constant_kf_uv_mode_prob;
|
||||
}
|
||||
|
|
|
@ -45,10 +45,10 @@ public:
|
|||
void load_probs(size_t index);
|
||||
void load_probs2(size_t index);
|
||||
|
||||
const ParetoTable& pareto_table() const;
|
||||
const KfPartitionProbs& kf_partition_probs() const;
|
||||
const KfYModeProbs& kf_y_mode_probs() const;
|
||||
const KfUVModeProbs& kf_uv_mode_prob() const;
|
||||
ParetoTable const& pareto_table() const;
|
||||
KfPartitionProbs const& kf_partition_probs() const;
|
||||
KfYModeProbs const& kf_y_mode_probs() const;
|
||||
KfUVModeProbs const& kf_uv_mode_prob() const;
|
||||
|
||||
PartitionProbs& partition_probs() { return m_current_probability_table.partition_probs; };
|
||||
YModeProbs& y_mode_probs() { return m_current_probability_table.y_mode_probs; };
|
||||
|
|
|
@ -265,7 +265,7 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value)
|
|||
}
|
||||
}
|
||||
|
||||
TreeParser::TreeSelection::TreeSelection(const int* values)
|
||||
TreeParser::TreeSelection::TreeSelection(int const* values)
|
||||
: m_is_single_value(false)
|
||||
, m_value { .m_tree = values }
|
||||
{
|
||||
|
|
|
@ -25,16 +25,16 @@ public:
|
|||
class TreeSelection {
|
||||
public:
|
||||
union TreeSelectionValue {
|
||||
const int* m_tree;
|
||||
int const* m_tree;
|
||||
int m_value;
|
||||
};
|
||||
|
||||
TreeSelection(const int* values);
|
||||
TreeSelection(int const* values);
|
||||
TreeSelection(int value);
|
||||
|
||||
bool is_single_value() const { return m_is_single_value; }
|
||||
int get_single_value() const { return m_value.m_value; }
|
||||
const int* get_tree_value() const { return m_value.m_tree; }
|
||||
int const* get_tree_value() const { return m_value.m_tree; }
|
||||
|
||||
private:
|
||||
bool m_is_single_value;
|
||||
|
|
|
@ -23,28 +23,28 @@ int main(int, char**)
|
|||
outln("Writing app is \"{}\"", segment_information.value().writing_app().as_string().to_string().characters());
|
||||
}
|
||||
outln("Document has {} tracks", document->tracks().size());
|
||||
for (const auto& track_entry : document->tracks()) {
|
||||
const auto& track = *track_entry.value;
|
||||
for (auto const& track_entry : document->tracks()) {
|
||||
auto const& track = *track_entry.value;
|
||||
outln("\tTrack #{} with TrackID {}", track.track_number(), track.track_uid());
|
||||
outln("\tTrack has TrackType {}", static_cast<u8>(track.track_type()));
|
||||
outln("\tTrack has Language \"{}\"", track.language().characters());
|
||||
outln("\tTrack has CodecID \"{}\"", track.codec_id().characters());
|
||||
|
||||
if (track.track_type() == Video::TrackEntry::TrackType::Video) {
|
||||
const auto video_track = track.video_track().value();
|
||||
auto const video_track = track.video_track().value();
|
||||
outln("\t\tVideo is {} pixels wide by {} pixels tall", video_track.pixel_width, video_track.pixel_height);
|
||||
} else if (track.track_type() == Video::TrackEntry::TrackType::Audio) {
|
||||
const auto audio_track = track.audio_track().value();
|
||||
auto const audio_track = track.audio_track().value();
|
||||
outln("\t\tAudio has {} channels with a bit depth of {}", audio_track.channels, audio_track.bit_depth);
|
||||
}
|
||||
}
|
||||
|
||||
outln("Document has {} clusters", document->clusters().size());
|
||||
for (const auto& cluster : document->clusters()) {
|
||||
for (auto const& cluster : document->clusters()) {
|
||||
outln("\tCluster timestamp is {}", cluster.timestamp());
|
||||
|
||||
outln("\tCluster has {} blocks", cluster.blocks().size());
|
||||
for (const auto& block : cluster.blocks()) {
|
||||
for (auto const& block : cluster.blocks()) {
|
||||
(void)block;
|
||||
outln("\t\tBlock for track #{} has {} frames", block.track_number(), block.frame_count());
|
||||
outln("\t\tBlock's timestamp is {}", block.timestamp());
|
||||
|
|
Loading…
Reference in a new issue