Skip to content

Commit 653a345

Browse files
Zaggy1024gmta
authored andcommitted
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.
1 parent dcc2359 commit 653a345

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

Libraries/LibMedia/Containers/Matroska/MatroskaDemuxer.cpp

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <AK/Debug.h>
99
#include <AK/Utf16String.h>
1010
#include <LibMedia/CodedFrame.h>
11+
#include <LibMedia/Containers/Matroska/Utilities.h>
1112
#include <LibMedia/DecoderError.h>
1213

1314
#include "MatroskaDemuxer.h"
@@ -125,44 +126,10 @@ DecoderErrorOr<MatroskaDemuxer::TrackStatus*> MatroskaDemuxer::get_track_status(
125126
return &m_track_statuses.get(track).release_value();
126127
}
127128

128-
static CodecID get_codec_id_for_string(String const& codec_id)
129-
{
130-
dbgln_if(MATROSKA_DEBUG, "Codec ID: {}", codec_id);
131-
if (codec_id == "V_VP8")
132-
return CodecID::VP8;
133-
if (codec_id == "V_VP9")
134-
return CodecID::VP9;
135-
if (codec_id == "V_MPEG1")
136-
return CodecID::MPEG1;
137-
if (codec_id == "V_MPEG2")
138-
return CodecID::H262;
139-
if (codec_id == "V_MPEG4/ISO/AVC")
140-
return CodecID::H264;
141-
if (codec_id == "V_MPEGH/ISO/HEVC")
142-
return CodecID::H265;
143-
if (codec_id == "A_MPEG/L3")
144-
return CodecID::MP3;
145-
if (codec_id == "A_AAC" || codec_id == "A_AAC/MPEG4/LC"
146-
|| codec_id == "A_AAC/MPEG4/LC/SBR" || codec_id == "A_AAC/MPEG4/LTP"
147-
|| codec_id == "A_AAC/MPEG4/MAIN" || codec_id == "A_AAC/MPEG4/SSR")
148-
return CodecID::AAC;
149-
if (codec_id == "V_AV1")
150-
return CodecID::AV1;
151-
if (codec_id == "V_THEORA")
152-
return CodecID::Theora;
153-
if (codec_id == "A_VORBIS")
154-
return CodecID::Vorbis;
155-
if (codec_id == "A_OPUS")
156-
return CodecID::Opus;
157-
if (codec_id == "A_FLAC")
158-
return CodecID::FLAC;
159-
return CodecID::Unknown;
160-
}
161-
162129
DecoderErrorOr<CodecID> MatroskaDemuxer::get_codec_id_for_track(Track const& track)
163130
{
164131
auto codec_id = TRY(m_reader.track_for_track_number(track.identifier()))->codec_id();
165-
return get_codec_id_for_string(codec_id);
132+
return codec_id_from_matroska_id_string(codec_id);
166133
}
167134

168135
DecoderErrorOr<ReadonlyBytes> MatroskaDemuxer::get_codec_initialization_data_for_track(Track const& track)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#include <AK/String.h>
10+
#include <LibMedia/CodecID.h>
11+
12+
namespace Media::Matroska {
13+
14+
static constexpr CodecID codec_id_from_matroska_id_string(String const& codec_id)
15+
{
16+
if (codec_id == "V_VP8")
17+
return CodecID::VP8;
18+
if (codec_id == "V_VP9")
19+
return CodecID::VP9;
20+
if (codec_id == "V_MPEG1")
21+
return CodecID::MPEG1;
22+
if (codec_id == "V_MPEG2")
23+
return CodecID::H262;
24+
if (codec_id == "V_MPEG4/ISO/AVC")
25+
return CodecID::H264;
26+
if (codec_id == "V_MPEGH/ISO/HEVC")
27+
return CodecID::H265;
28+
if (codec_id == "A_MPEG/L3")
29+
return CodecID::MP3;
30+
if (codec_id == "A_AAC" || codec_id == "A_AAC/MPEG4/LC"
31+
|| codec_id == "A_AAC/MPEG4/LC/SBR" || codec_id == "A_AAC/MPEG4/LTP"
32+
|| codec_id == "A_AAC/MPEG4/MAIN" || codec_id == "A_AAC/MPEG4/SSR")
33+
return CodecID::AAC;
34+
if (codec_id == "V_AV1")
35+
return CodecID::AV1;
36+
if (codec_id == "V_THEORA")
37+
return CodecID::Theora;
38+
if (codec_id == "A_VORBIS")
39+
return CodecID::Vorbis;
40+
if (codec_id == "A_OPUS")
41+
return CodecID::Opus;
42+
if (codec_id == "A_FLAC")
43+
return CodecID::FLAC;
44+
return CodecID::Unknown;
45+
}
46+
47+
}

0 commit comments

Comments
 (0)