LibMedia: Move conversion of Matroska codecs to CodecID to a new file

This function is needed in Matroska::Reader to check for Opus in the
next commit.
This commit is contained in:
Zaggy1024 2025-10-21 15:17:45 -05:00 committed by Jelle Raaijmakers
parent dcc2359eac
commit 653a3452df
Notes: github-actions[bot] 2025-11-21 10:04:02 +00:00
2 changed files with 49 additions and 35 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Debug.h>
#include <AK/Utf16String.h>
#include <LibMedia/CodedFrame.h>
#include <LibMedia/Containers/Matroska/Utilities.h>
#include <LibMedia/DecoderError.h>
#include "MatroskaDemuxer.h"
@ -125,44 +126,10 @@ DecoderErrorOr<MatroskaDemuxer::TrackStatus*> MatroskaDemuxer::get_track_status(
return &m_track_statuses.get(track).release_value();
}
static CodecID get_codec_id_for_string(String const& codec_id)
{
dbgln_if(MATROSKA_DEBUG, "Codec ID: {}", codec_id);
if (codec_id == "V_VP8")
return CodecID::VP8;
if (codec_id == "V_VP9")
return CodecID::VP9;
if (codec_id == "V_MPEG1")
return CodecID::MPEG1;
if (codec_id == "V_MPEG2")
return CodecID::H262;
if (codec_id == "V_MPEG4/ISO/AVC")
return CodecID::H264;
if (codec_id == "V_MPEGH/ISO/HEVC")
return CodecID::H265;
if (codec_id == "A_MPEG/L3")
return CodecID::MP3;
if (codec_id == "A_AAC" || codec_id == "A_AAC/MPEG4/LC"
|| codec_id == "A_AAC/MPEG4/LC/SBR" || codec_id == "A_AAC/MPEG4/LTP"
|| codec_id == "A_AAC/MPEG4/MAIN" || codec_id == "A_AAC/MPEG4/SSR")
return CodecID::AAC;
if (codec_id == "V_AV1")
return CodecID::AV1;
if (codec_id == "V_THEORA")
return CodecID::Theora;
if (codec_id == "A_VORBIS")
return CodecID::Vorbis;
if (codec_id == "A_OPUS")
return CodecID::Opus;
if (codec_id == "A_FLAC")
return CodecID::FLAC;
return CodecID::Unknown;
}
DecoderErrorOr<CodecID> MatroskaDemuxer::get_codec_id_for_track(Track const& track)
{
auto codec_id = TRY(m_reader.track_for_track_number(track.identifier()))->codec_id();
return get_codec_id_for_string(codec_id);
return codec_id_from_matroska_id_string(codec_id);
}
DecoderErrorOr<ReadonlyBytes> MatroskaDemuxer::get_codec_initialization_data_for_track(Track const& track)

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibMedia/CodecID.h>
namespace Media::Matroska {
static constexpr CodecID codec_id_from_matroska_id_string(String const& codec_id)
{
if (codec_id == "V_VP8")
return CodecID::VP8;
if (codec_id == "V_VP9")
return CodecID::VP9;
if (codec_id == "V_MPEG1")
return CodecID::MPEG1;
if (codec_id == "V_MPEG2")
return CodecID::H262;
if (codec_id == "V_MPEG4/ISO/AVC")
return CodecID::H264;
if (codec_id == "V_MPEGH/ISO/HEVC")
return CodecID::H265;
if (codec_id == "A_MPEG/L3")
return CodecID::MP3;
if (codec_id == "A_AAC" || codec_id == "A_AAC/MPEG4/LC"
|| codec_id == "A_AAC/MPEG4/LC/SBR" || codec_id == "A_AAC/MPEG4/LTP"
|| codec_id == "A_AAC/MPEG4/MAIN" || codec_id == "A_AAC/MPEG4/SSR")
return CodecID::AAC;
if (codec_id == "V_AV1")
return CodecID::AV1;
if (codec_id == "V_THEORA")
return CodecID::Theora;
if (codec_id == "A_VORBIS")
return CodecID::Vorbis;
if (codec_id == "A_OPUS")
return CodecID::Opus;
if (codec_id == "A_FLAC")
return CodecID::FLAC;
return CodecID::Unknown;
}
}