[FFmpeg-devel,26/37] avformat/matroskadec: Combine arrays

Submitted by Andreas Rheinhardt on May 16, 2019, 10:30 p.m.

Details

Message ID 20190516223018.30827-27-andreas.rheinhardt@gmail.com
State Accepted
Commit 38255cdcf815ff44bb0ab10cb16b96e409f2eeed
Headers show

Commit Message

Andreas Rheinhardt May 16, 2019, 10:30 p.m.
By including SimpleBlocks and BlockGroups 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@gmail.com>
---
 libavformat/matroskadec.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 727d438481..fdd6c4b86b 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -716,26 +716,21 @@  static const EbmlSyntax matroska_blockgroup[] = {
     CHILD_OF(matroska_cluster_parsing)
 };
 
+// The following array contains SimpleBlock and BlockGroup twice
+// in order to reuse the other values for matroska_cluster_enter.
 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 },
-    CHILD_OF(matroska_segment)
-};
-
-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 },
     CHILD_OF(matroska_segment)
 };
 
 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] } },
     { 0 }
 };
 
@@ -1059,6 +1054,9 @@  static int ebml_parse(MatroskaDemuxContext *matroska,
 static EbmlSyntax *ebml_parse_id(EbmlSyntax *syntax, uint32_t id)
 {
     int i;
+
+    // Whoever touches this should be aware of the duplication
+    // existing in matroska_cluster_parsing.
     for (i = 0; syntax[i].id; i++)
         if (id == syntax[i].id)
             break;