From 4667ef856d9624981bd252cac281c563addd9ba5 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 8 Feb 2019 00:04:42 +0100 Subject: [PATCH] libmatroska2: Add variant of MATROSKA_GetBlockForTimecode The differences of MATROSKA_GetNextBlockForTimecode and the classical MATROSKA_GetBlockForTimecode are threefold: 1. The new function can return both the inner Block as well as the outer BlockGroup based upon a parameter (that is irrelevant for SimpleBlocks). 2. Consequently the return value is a pointer to an ebml_element and no longer a matroska_block*. 3. It also allows to get a matching block that is not the first matching block in a cluster. This commit is in preparation of a patch for mkvalidator. Signed-off-by: Andreas Rheinhardt --- libmatroska2/matroska/matroska.h | 1 + libmatroska2/matroskamain.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libmatroska2/matroska/matroska.h b/libmatroska2/matroska/matroska.h index 308cbc0e..6b28110c 100644 --- a/libmatroska2/matroska/matroska.h +++ b/libmatroska2/matroska/matroska.h @@ -192,6 +192,7 @@ EBML_DLL err_t MATROSKA_BlockGetFrame(const matroska_block *Block, size_t FrameN EBML_DLL err_t MATROSKA_BlockAppendFrame(matroska_block *Block, const matroska_frame *Frame, timecode_t ClusterTimecode); +EBML_DLL ebml_element *MATROSKA_GetNextBlockForTimecode(matroska_cluster *Cluster, const ebml_element *Current, timecode_t Timecode, int16_t Track, int Outer); EBML_DLL matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode_t Timecode, int16_t Track); EBML_DLL void MATROSKA_LinkClusterBlocks(matroska_cluster *Cluster, ebml_master *RSegmentInfo, ebml_master *Tracks, bool_t KeepUnmatched); diff --git a/libmatroska2/matroskamain.c b/libmatroska2/matroskamain.c index 18778cf6..ea5e0c9d 100644 --- a/libmatroska2/matroskamain.c +++ b/libmatroska2/matroskamain.c @@ -789,10 +789,10 @@ err_t MATROSKA_CuePointUpdate(matroska_cuepoint *Cue, ebml_element *Segment) return ERR_NONE; } -matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode_t Timecode, int16_t Track) +ebml_element *MATROSKA_GetNextBlockForTimecode(matroska_cluster *Cluster, const ebml_element *Current, timecode_t Timecode, int16_t Track, int Outer) { ebml_element *Block, *GBlock; - for (Block = EBML_MasterChildren(Cluster);Block;Block=EBML_MasterNext(Block)) + for (Block = Current ? EBML_MasterNext(Current) : EBML_MasterChildren(Cluster); Block; Block = EBML_MasterNext(Block)) { if (EBML_ElementIsType(Block, &MATROSKA_ContextBlockGroup)) { @@ -803,7 +803,7 @@ matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode if (MATROSKA_BlockTrackNum((matroska_block*)GBlock) == Track && MATROSKA_BlockTimecode((matroska_block*)GBlock) == Timecode) { - return (matroska_block*)GBlock; + return Outer ? Block : GBlock; } } } @@ -813,13 +813,18 @@ matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode if (MATROSKA_BlockTrackNum((matroska_block*)Block) == Track && MATROSKA_BlockTimecode((matroska_block*)Block) == Timecode) { - return (matroska_block*)Block; + return Block; } } } return NULL; } +matroska_block *MATROSKA_GetBlockForTimecode(matroska_cluster *Cluster, timecode_t Timecode, int16_t Track) +{ + return (matroska_block*)MATROSKA_GetNextBlockForTimecode(Cluster, NULL, Timecode, Track, 0); +} + void MATROSKA_LinkClusterBlocks(matroska_cluster *Cluster, ebml_master *RSegmentInfo, ebml_master *Tracks, bool_t KeepUnmatched) { ebml_element *Block, *GBlock,*NextBlock;