mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-02-26 08:22:31 +00:00
Write CueRelativePosition for all cue entries
This commit is contained in:
parent
9a3796b08d
commit
b681b6824e
@ -69,6 +69,7 @@ cluster_helper_c::cluster_helper_c()
|
||||
, m_debug_duration{ debugging_requested("cluster_helper|cluster_helper_duration")}
|
||||
, m_debug_rendering{debugging_requested("cluster_helper|cluster_helper_rendering")}
|
||||
, m_debug_cue_duration{debugging_requested("cluster_helper|cluster_helper_cue_duration")}
|
||||
, m_debug_cue_relative_position{debugging_requested("cluster_helper|cluster_helper_cue_relative_position")}
|
||||
{
|
||||
}
|
||||
|
||||
@ -533,11 +534,43 @@ cluster_helper_c::add_to_cues_maybe(packet_cptr &pack,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<id_timecode_t, int64_t>
|
||||
cluster_helper_c::calculate_block_positions()
|
||||
const {
|
||||
|
||||
std::map<id_timecode_t, int64_t> positions;
|
||||
|
||||
for (auto child : *m_cluster) {
|
||||
auto simple_block = dynamic_cast<KaxSimpleBlock *>(child);
|
||||
if (simple_block) {
|
||||
simple_block->SetParent(*m_cluster);
|
||||
positions[ { simple_block->TrackNum(), simple_block->GlobalTimecode() } ] = simple_block->GetElementPosition();
|
||||
continue;
|
||||
}
|
||||
|
||||
auto block_group = dynamic_cast<KaxBlockGroup *>(child);
|
||||
if (!block_group)
|
||||
continue;
|
||||
|
||||
auto block = FindChild<KaxBlock>(block_group);
|
||||
if (!block)
|
||||
continue;
|
||||
|
||||
block->SetParent(*m_cluster);
|
||||
positions[ { block->TrackNum(), block->GlobalTimecode() } ] = block->GetElementPosition();
|
||||
}
|
||||
|
||||
return std::move(positions);
|
||||
}
|
||||
|
||||
void
|
||||
cluster_helper_c::postprocess_cues() {
|
||||
if (!g_kax_cues)
|
||||
return;
|
||||
|
||||
auto cluster_data_start_pos = m_cluster->GetElementPosition() + m_cluster->HeadSize();
|
||||
auto block_positions = calculate_block_positions();
|
||||
|
||||
auto &children = g_kax_cues->GetElementList();
|
||||
for (auto size = children.size(); m_num_cue_points_postprocessed < size; ++m_num_cue_points_postprocessed) {
|
||||
auto point = dynamic_cast<KaxCuePoint *>(children[m_num_cue_points_postprocessed]);
|
||||
@ -551,7 +584,18 @@ cluster_helper_c::postprocess_cues() {
|
||||
if (!positions)
|
||||
continue;
|
||||
|
||||
// Set CueRelativePosition for all cues.
|
||||
auto track_num = GetChild<KaxCueTrack>(positions).GetValue();
|
||||
auto position_itr = block_positions.find({ track_num, time });
|
||||
auto position = block_positions.end() != position_itr ? std::max<int64_t>(position_itr->second, cluster_data_start_pos) : 0ll;
|
||||
if (position)
|
||||
GetChild<KaxCueRelativePosition>(positions).SetValue(position - cluster_data_start_pos);
|
||||
|
||||
mxdebug_if(m_debug_cue_relative_position,
|
||||
boost::format("cue_relative_position: looking for <%1%:%2%>: cluster_data_start_pos %3% position %4%\n")
|
||||
% track_num % time % cluster_data_start_pos % position);
|
||||
|
||||
// Set CueDuration if the packetizer wants them.
|
||||
auto duration_itr = m_id_timecode_duration_map.find({ track_num, time });
|
||||
auto ptzr = g_packetizers_by_track_num[track_num];
|
||||
|
||||
|
@ -98,7 +98,7 @@ private:
|
||||
size_t m_num_cue_points_postprocessed;
|
||||
|
||||
bool m_discarding, m_splitting_and_processed_fully;
|
||||
bool m_debug_splitting, m_debug_packets, m_debug_duration, m_debug_rendering, m_debug_cue_duration;
|
||||
bool m_debug_splitting, m_debug_packets, m_debug_duration, m_debug_rendering, m_debug_cue_duration, m_debug_cue_relative_position;
|
||||
|
||||
public:
|
||||
cluster_helper_c();
|
||||
@ -154,6 +154,7 @@ private:
|
||||
|
||||
bool add_to_cues_maybe(packet_cptr &pack, kax_block_blob_c &block_group);
|
||||
void postprocess_cues();
|
||||
std::map<id_timecode_t, int64_t> calculate_block_positions() const;
|
||||
};
|
||||
|
||||
extern cluster_helper_c *g_cluster_helper;
|
||||
|
Loading…
Reference in New Issue
Block a user