[FFmpeg-devel] [PATCH 18/21] avformat/matroskadec: Combine two arrays

Andreas Rheinhardt andreas.rheinhardt at googlemail.com
Sun Apr 7 20:30:00 EEST 2019


Steve Lhomme:
> On 3/27/2019 12:18 PM, Andreas Rheinhardt via ffmpeg-devel wrote:
>> By including SimpleBlocks and Blocksgroups twice in the same EbmlSyntax
>> array (with different semantics), one can reduce the duplication of the
>> other values.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at googlemail.com>
>> ---
>>   libavformat/matroskadec.c | 13 +++----------
>>   1 file changed, 3 insertions(+), 10 deletions(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 3adcb3e86d..60f58cefa9 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -704,25 +704,18 @@ static const EbmlSyntax matroska_blockgroup[] = {
>>   };
>>     static const EbmlSyntax matroska_cluster_parsing[] = {
>> -    { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0,
>> offsetof(MatroskaCluster, timecode) },
>> -    { MATROSKA_ID_BLOCKGROUP,      EBML_NEST, 0, 0, { .n =
>> matroska_blockgroup } },
>>       { MATROSKA_ID_SIMPLEBLOCK,     EBML_BIN,  0,
>> offsetof(MatroskaBlock, bin) },
>> -    { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE },
>> -    { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE },
>> -    { 0 }
>> -};
>> -
>> -static const EbmlSyntax matroska_cluster_initial[] = {
>> +    { MATROSKA_ID_BLOCKGROUP,      EBML_NEST, 0, 0, { .n =
>> matroska_blockgroup } },
>>       { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0,
>> offsetof(MatroskaCluster, timecode) },
>> -    { MATROSKA_ID_BLOCKGROUP,      EBML_STOP },
>>       { MATROSKA_ID_SIMPLEBLOCK,     EBML_STOP },
>> +    { MATROSKA_ID_BLOCKGROUP,      EBML_STOP },
>>       { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE },
>>       { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE },
>>       { 0 }
>>   };
>>     static const EbmlSyntax matroska_cluster_enter[] = {
>> -    { MATROSKA_ID_CLUSTER,     EBML_NEST, 0, 0, { .n =
>> matroska_cluster_initial } },
>> +    { MATROSKA_ID_CLUSTER,     EBML_NEST, 0, 0, { .n =
>> &matroska_cluster_parsing[2] } },
> 
> To avoid breaking this optimisation when the code is changed you might
> use some static_assert to make sure that
> matroska_cluster_parsing[2].id is MATROSKA_ID_CLUSTERTIMECODE

static_assert is actually C11, not C90 (as FFmpeg is), so I think a
comment should suffice.


More information about the ffmpeg-devel mailing list