Skip to content

Commit

Permalink
libmatroska2: Add variant of MATROSKA_GetBlockForTimecode
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mkver committed Feb 7, 2019
1 parent 374b3c9 commit 4667ef8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions libmatroska2/matroska/matroska.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 9 additions & 4 deletions libmatroska2/matroskamain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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;
}
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 4667ef8

Please sign in to comment.