mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 11:54:01 +00:00
id info: more convenience variants for add()
This commit is contained in:
parent
a450c315b9
commit
6afe6d0db1
37
src/common/id_info.cpp
Normal file
37
src/common/id_info.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
mkvmerge -- utility for splicing together matroska files
|
||||
from component media subtypes
|
||||
|
||||
Distributed under the GPL v2
|
||||
see the file COPYING for details
|
||||
or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
|
||||
Written by Moritz Bunkus <moritz@bunkus.org>.
|
||||
*/
|
||||
|
||||
#include "common/common_pch.h"
|
||||
|
||||
#include "common/id_info.h"
|
||||
#include "common/strings/formatting.h"
|
||||
|
||||
namespace mtx::id {
|
||||
|
||||
info_c &
|
||||
info_c::add(std::string const &key,
|
||||
memory_cptr const &value) {
|
||||
if (value && value->get_size())
|
||||
set(key, mtx::string::to_hex(value->get_buffer(), value->get_size(), true));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
info_c &
|
||||
info_c::add(std::string const &key,
|
||||
memory_c const *value) {
|
||||
if (value && value->get_size())
|
||||
set(key, mtx::string::to_hex(value->get_buffer(), value->get_size(), true));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace mtx::id
|
@ -86,6 +86,29 @@ class info_c {
|
||||
protected:
|
||||
verbose_info_t m_info;
|
||||
|
||||
private:
|
||||
template<typename... Args>
|
||||
bool
|
||||
all(Args... args) {
|
||||
return (... && args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string
|
||||
join([[maybe_unused]] std::string const &separator,
|
||||
T const &value) {
|
||||
return fmt::to_string(value);
|
||||
}
|
||||
|
||||
template<typename Tfirst,
|
||||
typename... Trest>
|
||||
std::string
|
||||
join(std::string const &separator,
|
||||
Tfirst const &first,
|
||||
Trest... rest) {
|
||||
return fmt::to_string(first) + separator + join(separator, rest...);
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename T> info_c &
|
||||
set(std::string const &key,
|
||||
@ -103,6 +126,9 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
info_c &add(std::string const &key, memory_c const *value);
|
||||
info_c &add(std::string const &key, memory_cptr const &value);
|
||||
|
||||
info_c &
|
||||
add(std::string const &key,
|
||||
char const *value,
|
||||
@ -112,14 +138,26 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
info_c &
|
||||
add(std::string const &key,
|
||||
std::optional<bool> const &value) {
|
||||
std::optional<T> const &value) {
|
||||
if (value.has_value())
|
||||
set(key, *value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Tvalues>
|
||||
info_c &
|
||||
add_joined(std::string const &key,
|
||||
std::string const &separator,
|
||||
Tvalues... values) {
|
||||
if (!all(values...))
|
||||
return *this;
|
||||
|
||||
return add(key, join(separator, values...));
|
||||
}
|
||||
|
||||
verbose_info_t const &get() const {
|
||||
return m_info;
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ void
|
||||
avc_es_reader_c::identify() {
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::packetizer, mtx::id::mpeg4_p10_es_video);
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_width, m_height));
|
||||
info.add(mtx::id::default_duration, m_default_duration);
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_width, m_height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec_c::type_e::V_MPEG4_P10, "MPEG-4 part 10 ES"), info.get());
|
||||
|
@ -866,7 +866,7 @@ avi_reader_c::extended_identify_mpeg4_l2(mtx::id::info_c &info) {
|
||||
disp_height = mtx::to_int_rounded(m_video_width / aspect_ratio);
|
||||
}
|
||||
|
||||
info.add(mtx::id::display_dimensions, fmt::format("{0}x{1}", disp_width, disp_height));
|
||||
info.add_joined(mtx::id::display_dimensions, "x"s, disp_width, disp_height);
|
||||
}
|
||||
}
|
||||
|
||||
@ -894,10 +894,8 @@ avi_reader_c::identify_video() {
|
||||
else if (codec.is(codec_c::type_e::V_MPEG4_P10))
|
||||
info.add(mtx::id::packetizer, mtx::id::mpeg4_p10_es_video);
|
||||
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_video_width, m_video_height));
|
||||
|
||||
if (m_video_display_width)
|
||||
info.add(mtx::id::display_dimensions, fmt::format("{0}x{1}", m_video_display_width, m_video_display_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_video_width, m_video_height);
|
||||
info.add_joined(mtx::id::display_dimensions, "x"s, m_video_display_width, m_video_display_height);
|
||||
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec.get_name(fourcc_str), info.get());
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ dirac_es_reader_c::read(generic_packetizer_c *,
|
||||
void
|
||||
dirac_es_reader_c::identify() {
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_seqhdr.pixel_width, m_seqhdr.pixel_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_seqhdr.pixel_width, m_seqhdr.pixel_height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec_c::type_e::V_DIRAC, "Dirac"), info.get());
|
||||
|
@ -308,7 +308,7 @@ flv_reader_c::identify() {
|
||||
info.add(mtx::id::packetizer, mtx::id::mpeg4_p10_video);
|
||||
|
||||
if (track->is_video())
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", track->m_v_width, track->m_v_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, track->m_v_width, track->m_v_height);
|
||||
|
||||
else if (track->is_audio()) {
|
||||
info.add(mtx::id::audio_channels, track->m_a_channels);
|
||||
|
@ -123,8 +123,8 @@ void
|
||||
hevc_es_reader_c::identify() {
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::packetizer, mtx::id::mpegh_p2_es_video);
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_width, m_height));
|
||||
info.add(mtx::id::default_duration, m_default_duration);
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_width, m_height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec_c::type_e::V_MPEGH_P2, "HEVC"), info.get());
|
||||
|
@ -132,6 +132,6 @@ ivf_reader_c::identify() {
|
||||
return;
|
||||
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_width, m_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_width, m_height);
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, m_codec.get_name(), info.get());
|
||||
}
|
||||
|
@ -2749,6 +2749,7 @@ kax_reader_c::identify() {
|
||||
info.add(mtx::id::uid, track->track_uid);
|
||||
info.add(mtx::id::codec_id, track->codec_id);
|
||||
info.set(mtx::id::codec_private_length, track->private_data ? track->private_data->get_size() : 0u);
|
||||
info.add(mtx::id::codec_private_data, track->private_data);
|
||||
info.add(mtx::id::codec_delay, track->codec_delay.to_ns(0));
|
||||
info.add(mtx::id::codec_name, track->codec_name);
|
||||
info.add(mtx::id::language, track->language.get_iso639_alpha_3_code());
|
||||
@ -2764,21 +2765,11 @@ kax_reader_c::identify() {
|
||||
info.add(mtx::id::flag_text_descriptions, track->text_descriptions_flag);
|
||||
info.add(mtx::id::flag_original, track->original_flag);
|
||||
info.add(mtx::id::flag_commentary, track->commentary_flag);
|
||||
info.add(mtx::id::display_unit, track->v_dunit);
|
||||
|
||||
if (track->private_data && (0 != track->private_data->get_size()))
|
||||
info.add(mtx::id::codec_private_data, mtx::string::to_hex(track->private_data->get_buffer(), track->private_data->get_size(), true));
|
||||
|
||||
if ((0 != track->v_width) && (0 != track->v_height))
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", track->v_width, track->v_height));
|
||||
|
||||
if ((0 != track->v_dwidth) && (0 != track->v_dheight))
|
||||
info.add(mtx::id::display_dimensions, fmt::format("{0}x{1}", track->v_dwidth, track->v_dheight));
|
||||
|
||||
if (track->v_dunit)
|
||||
info.set(mtx::id::display_unit, *track->v_dunit);
|
||||
|
||||
if ((0 != track->v_pcleft) || (0 != track->v_pctop) || (0 != track->v_pcright) || (0 != track->v_pcbottom))
|
||||
info.add(mtx::id::cropping, fmt::format("{0},{1},{2},{3}", track->v_pcleft, track->v_pctop, track->v_pcright, track->v_pcbottom));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, track->v_width, track->v_height);
|
||||
info.add_joined(mtx::id::display_dimensions, "x"s, track->v_dwidth, track->v_dheight);
|
||||
info.add_joined(mtx::id::cropping, ","s, track->v_pcleft, track->v_pctop, track->v_pcright, track->v_pcbottom);
|
||||
|
||||
if (track->codec.is(codec_c::type_e::V_MPEG4_P10))
|
||||
info.add(mtx::id::packetizer, track->ms_compat ? mtx::id::mpeg4_p10_es_video : mtx::id::mpeg4_p10_video);
|
||||
|
@ -217,7 +217,7 @@ void
|
||||
mpeg_es_reader_c::identify() {
|
||||
auto codec = fmt::format("mpg{0}", version);
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", width, height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, width, height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec, codec), info.get());
|
||||
|
@ -1406,9 +1406,7 @@ mpeg_ps_reader_c::identify() {
|
||||
info.set(mtx::id::number, (static_cast<uint64_t>(track->id.sub_id) << 32) | static_cast<uint64_t>(track->id.id));
|
||||
info.add(mtx::id::stream_id, track->id.id);
|
||||
info.add(mtx::id::sub_stream_id, track->id.sub_id);
|
||||
|
||||
if ((0 != track->v_dwidth) && (0 != track->v_dheight))
|
||||
info.add(mtx::id::display_dimensions, fmt::format("{0}x{1}", track->v_dwidth, track->v_dheight));
|
||||
info.add_joined(mtx::id::display_dimensions, "x"s, track->v_dwidth, track->v_dheight);
|
||||
|
||||
if ('a' == track->type) {
|
||||
info.add(mtx::id::audio_channels, track->a_channels);
|
||||
@ -1416,7 +1414,7 @@ mpeg_ps_reader_c::identify() {
|
||||
info.add(mtx::id::audio_bits_per_sample, track->a_bits_per_sample);
|
||||
|
||||
} else if ('v' == track->type)
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", track->v_width, track->v_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, track->v_width, track->v_height);
|
||||
|
||||
id_result_track(i, 'a' == track->type ? ID_RESULT_TRACK_AUDIO : ID_RESULT_TRACK_VIDEO, track->codec.get_name(), info.get());
|
||||
}
|
||||
|
@ -1384,12 +1384,10 @@ reader_c::identify() {
|
||||
|
||||
for (auto const &track : m_tracks) {
|
||||
info = mtx::id::info_c{};
|
||||
info.add(mtx::id::language, track->language.get_iso639_alpha_3_code());
|
||||
info.set(mtx::id::stream_id, track->pid);
|
||||
info.set(mtx::id::number, track->pid);
|
||||
|
||||
if (track->program_number)
|
||||
info.set(mtx::id::program_number, track->program_number.value());
|
||||
info.add(mtx::id::language, track->language.get_iso639_alpha_3_code());
|
||||
info.set(mtx::id::stream_id, track->pid);
|
||||
info.set(mtx::id::number, track->pid);
|
||||
info.add(mtx::id::program_number, track->program_number);
|
||||
|
||||
if (pid_type_e::audio == track->type) {
|
||||
info.add(mtx::id::audio_channels, track->a_channels);
|
||||
@ -1397,12 +1395,11 @@ reader_c::identify() {
|
||||
info.add(mtx::id::audio_bits_per_sample, track->a_bits_per_sample);
|
||||
|
||||
} else if (pid_type_e::video == track->type)
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", track->v_width, track->v_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, track->v_width, track->v_height);
|
||||
|
||||
else if (pid_type_e::subtitles == track->type) {
|
||||
info.set(mtx::id::text_subtitles, track->codec.is(codec_c::type_e::S_SRT));
|
||||
if (track->m_ttx_wanted_page)
|
||||
info.set(mtx::id::teletext_page, *track->m_ttx_wanted_page);
|
||||
info.add(mtx::id::teletext_page, track->m_ttx_wanted_page);
|
||||
}
|
||||
|
||||
auto multiplexed_track_ids = std::vector<uint64_t>{};
|
||||
|
@ -84,7 +84,7 @@ obu_reader_c::read(generic_packetizer_c *,
|
||||
void
|
||||
obu_reader_c::identify() {
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_width, m_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_width, m_height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec_c::type_e::V_AV1, {}), info.get());
|
||||
|
@ -689,8 +689,7 @@ ogm_reader_c::identify() {
|
||||
if (!dmx->title.empty() && !dmx->ms_compat)
|
||||
info.add(mtx::id::track_name, dmx->title);
|
||||
|
||||
if ((0 != dmx->display_width) && (0 != dmx->display_height))
|
||||
info.add(mtx::id::display_dimensions, fmt::format("{0}x{1}", dmx->display_width, dmx->display_height));
|
||||
info.add_joined(mtx::id::display_dimensions, "x"s, dmx->display_width, dmx->display_height);
|
||||
|
||||
if (dynamic_cast<ogm_s_text_demuxer_c *>(dmx.get()) || dynamic_cast<ogm_s_kate_demuxer_c *>(dmx.get())) {
|
||||
info.add(mtx::id::text_subtitles, true);
|
||||
@ -698,8 +697,7 @@ ogm_reader_c::identify() {
|
||||
}
|
||||
|
||||
auto pixel_dimensions = dmx->get_pixel_dimensions();
|
||||
if (pixel_dimensions.first && pixel_dimensions.second)
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", pixel_dimensions.first, pixel_dimensions.second));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, pixel_dimensions.first, pixel_dimensions.second);
|
||||
|
||||
info.add(mtx::id::audio_channels, dmx->channels);
|
||||
info.add(mtx::id::audio_sampling_frequency, dmx->sample_rate);
|
||||
|
@ -2029,7 +2029,7 @@ qtmp4_reader_c::identify() {
|
||||
info.add(mtx::id::language, dmx.language.get_iso639_alpha_3_code());
|
||||
|
||||
if (dmx.is_video())
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", dmx.v_width, dmx.v_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, dmx.v_width, dmx.v_height);
|
||||
|
||||
else if (dmx.is_audio()) {
|
||||
info.add(mtx::id::audio_channels, dmx.a_channels);
|
||||
|
@ -566,7 +566,7 @@ real_reader_c::identify() {
|
||||
info.set(mtx::id::number, demuxer->track->id);
|
||||
|
||||
if (RMFF_TRACK_TYPE_VIDEO == demuxer->track->type)
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", demuxer->width, demuxer->height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, demuxer->width, demuxer->height);
|
||||
|
||||
else if (RMFF_TRACK_TYPE_AUDIO == demuxer->track->type) {
|
||||
info.add(mtx::id::audio_channels, demuxer->channels);
|
||||
|
@ -96,7 +96,7 @@ vc1_es_reader_c::read(generic_packetizer_c *,
|
||||
void
|
||||
vc1_es_reader_c::identify() {
|
||||
auto info = mtx::id::info_c{};
|
||||
info.add(mtx::id::pixel_dimensions, fmt::format("{0}x{1}", m_seqhdr.pixel_width, m_seqhdr.pixel_height));
|
||||
info.add_joined(mtx::id::pixel_dimensions, "x"s, m_seqhdr.pixel_width, m_seqhdr.pixel_height);
|
||||
|
||||
id_result_container();
|
||||
id_result_track(0, ID_RESULT_TRACK_VIDEO, codec_c::get_name(codec_c::type_e::V_VC1, "VC1"), info.get());
|
||||
|
Loading…
Reference in New Issue
Block a user