mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibMedia: Set Matroska "complex" tracks' types based on the codec
The spec indicates that the codec defines how to interpret the data, so use our CodecIDs to determine the track type.
This commit is contained in:
parent
f0e6bfbc9f
commit
c34b5a544e
Notes:
github-actions[bot]
2025-11-21 22:53:44 +00:00
Author: https://github.com/Zaggy1024
Commit: c34b5a544e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6881
4 changed files with 67 additions and 7 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <LibMedia/TrackType.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
|
|
@ -33,6 +34,32 @@ enum class CodecID : u32 {
|
|||
FLAC,
|
||||
};
|
||||
|
||||
inline TrackType track_type_from_codec_id(CodecID codec)
|
||||
{
|
||||
switch (codec) {
|
||||
case CodecID::VP8:
|
||||
case CodecID::VP9:
|
||||
case CodecID::H261:
|
||||
case CodecID::MPEG1:
|
||||
case CodecID::H262:
|
||||
case CodecID::H263:
|
||||
case CodecID::H264:
|
||||
case CodecID::H265:
|
||||
case CodecID::AV1:
|
||||
return TrackType::Video;
|
||||
case CodecID::MP3:
|
||||
case CodecID::AAC:
|
||||
case CodecID::Theora:
|
||||
case CodecID::Vorbis:
|
||||
case CodecID::Opus:
|
||||
case CodecID::FLAC:
|
||||
return TrackType::Audio;
|
||||
case CodecID::Unknown:
|
||||
break;
|
||||
}
|
||||
return TrackType::Unknown;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/Time.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibMedia/CodecID.h>
|
||||
#include <LibMedia/Containers/Matroska/Utilities.h>
|
||||
|
||||
#include "Reader.h"
|
||||
|
|
@ -538,6 +539,24 @@ static DecoderErrorOr<NonnullRefPtr<TrackEntry>> parse_track_entry(Streamer& str
|
|||
return IterationDecision::Continue;
|
||||
}));
|
||||
|
||||
if (track_entry->track_type() == TrackEntry::TrackType::Complex) {
|
||||
// A mix of different other TrackType. The codec needs to define how the Matroska Player
|
||||
// should interpret such data.
|
||||
auto codec_track_type = track_type_from_codec_id(codec_id_from_matroska_id_string(track_entry->codec_id()));
|
||||
switch (codec_track_type) {
|
||||
case TrackType::Video:
|
||||
track_entry->set_track_type(TrackEntry::TrackType::Video);
|
||||
break;
|
||||
case TrackType::Audio:
|
||||
track_entry->set_track_type(TrackEntry::TrackType::Audio);
|
||||
break;
|
||||
case TrackType::Subtitles:
|
||||
track_entry->set_track_type(TrackEntry::TrackType::Subtitle);
|
||||
break;
|
||||
case TrackType::Unknown:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return track_entry;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,16 +13,10 @@
|
|||
#include <AK/Utf16String.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibMedia/Color/CodingIndependentCodePoints.h>
|
||||
#include <LibMedia/TrackType.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
enum class TrackType : u32 {
|
||||
Video,
|
||||
Audio,
|
||||
Subtitles,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
class Track {
|
||||
struct VideoData {
|
||||
u64 pixel_width { 0 };
|
||||
|
|
|
|||
20
Libraries/LibMedia/TrackType.h
Normal file
20
Libraries/LibMedia/TrackType.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
enum class TrackType : u8 {
|
||||
Video,
|
||||
Audio,
|
||||
Subtitles,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue