Skip to content

Commit 881505b

Browse files
author
Philip de Nier
committed
Fix variable size ANV/VBI alongside variables size video
The default index table entry flag is 0x80, not 0x00.
1 parent 1fdb436 commit 881505b

11 files changed

+151
-40
lines changed

src/mxf_op1a/OP1AIndexTable.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ OP1AIndexEntry::OP1AIndexEntry()
6969
{
7070
temporal_offset = 0;
7171
key_frame_offset = 0;
72-
flags = 0;
72+
flags = 0x80;
7373
can_start_partition = true;
7474
}
7575

@@ -84,13 +84,13 @@ OP1AIndexEntry::OP1AIndexEntry(int8_t temporal_offset_, int8_t key_frame_offset_
8484

8585
bool OP1AIndexEntry::IsDefault()
8686
{
87-
return temporal_offset == 0 && key_frame_offset == 0 && flags == 0;
87+
return temporal_offset == 0 && key_frame_offset == 0 && flags == 0x80;
8888
}
8989

9090
bool OP1AIndexEntry::IsCompatible(const OP1AIndexEntry &entry)
9191
{
9292
// compatible if current entry is the default entry or the new entry equals the current entry
93-
return (temporal_offset == 0 && key_frame_offset == 0 && flags == 0) ||
93+
return IsDefault() ||
9494
(temporal_offset == entry.temporal_offset && key_frame_offset == entry.key_frame_offset &&
9595
flags == entry.flags);
9696
}

src/rdd9_mxf/RDD9IndexTable.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ RDD9IndexEntry::RDD9IndexEntry()
6969
{
7070
temporal_offset = 0;
7171
key_frame_offset = 0;
72-
flags = 0;
72+
flags = 0x80;
7373
can_start_partition = true;
7474
}
7575

@@ -84,13 +84,13 @@ RDD9IndexEntry::RDD9IndexEntry(int8_t temporal_offset_, int8_t key_frame_offset_
8484

8585
bool RDD9IndexEntry::IsDefault()
8686
{
87-
return temporal_offset == 0 && key_frame_offset == 0 && flags == 0;
87+
return temporal_offset == 0 && key_frame_offset == 0 && flags == 0x80;
8888
}
8989

9090
bool RDD9IndexEntry::IsCompatible(const RDD9IndexEntry &entry)
9191
{
9292
// compatible if current entry is the default entry or the new entry equals the current entry
93-
return (temporal_offset == 0 && key_frame_offset == 0 && flags == 0) ||
93+
return IsDefault() ||
9494
(temporal_offset == entry.temporal_offset && key_frame_offset == entry.key_frame_offset &&
9595
flags == entry.flags);
9696
}

test/create_test_essence.cpp

+88-9
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ typedef enum
117117
TYPE_RDD36_422_ITU2020 = 58,
118118
TYPE_MPEG2LG_MP_ML_576I = 59,
119119
TYPE_MPEG2LG_MP_ML_576I_4_3 = 60,
120-
TYPE_END = 61,
120+
TYPE_KLV_ANC_DATA_VAR_SIZE = 61,
121+
TYPE_KLV_VBI_DATA_VAR_SIZE = 62,
122+
TYPE_END = 63,
121123
} EssenceType;
122124

123125
typedef struct
@@ -902,30 +904,96 @@ static void write_avid_alpha(FILE *file, int type, unsigned int duration)
902904
write_data(file, duration * frame_size);
903905
}
904906

905-
static void write_anc_data(FILE *file, unsigned int duration)
907+
static void write_anc_data(FILE *file, unsigned int duration, bool klv_var_size)
906908
{
907-
static const unsigned char anc_frame[24] =
909+
static const unsigned char core_anc_frame[24] =
908910
{0x00, 0x01, // single line / packet
909911
0x00, 0x09, 0x01, 0x04, 0x00, 0x07, // line 9, VANCFrame, ANC_8_BIT_COMP_LUMA, 7 samples
910912
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, // payload array header: 8 x 1 bytes
911913
0x45, 0x04, 0x04, 0x21, 0x22, 0x23, 0x24, 0x00}; // payload array: DID (1), SDID (1), DC (1), UDW (4), padding (1)
914+
// Any key will do as it is discarded when parsing the data
915+
static const unsigned char klv_key[16] = {0x41, 0x4e, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
916+
917+
// Odd and even frame data and sizes
918+
unsigned char *anc_data[2];
919+
size_t anc_data_size[2];
920+
921+
if (klv_var_size) {
922+
anc_data_size[0] = 16 + 1 + sizeof(core_anc_frame);
923+
anc_data[0] = new unsigned char[anc_data_size[0]];
924+
memcpy(anc_data[0], klv_key, 16);
925+
anc_data[0][16] = anc_data_size[0] - 17;
926+
memcpy(&anc_data[0][17], core_anc_frame, sizeof(core_anc_frame));
927+
928+
// Add an extra padding byte to the odd frame
929+
anc_data_size[1] = 16 + 1 + sizeof(core_anc_frame) + 1;
930+
anc_data[1] = new unsigned char[anc_data_size[1]];
931+
memcpy(anc_data[1], klv_key, 16);
932+
anc_data[1][16] = anc_data_size[1] - 17;
933+
memcpy(&anc_data[1][17], core_anc_frame, sizeof(core_anc_frame));
934+
anc_data[1][16 + 1 + 11] = 0x09;
935+
anc_data[1][anc_data_size[1] - 1] = 0x00;
936+
} else {
937+
anc_data[0] = const_cast<unsigned char*>(core_anc_frame);
938+
anc_data[1] = const_cast<unsigned char*>(core_anc_frame);
939+
anc_data_size[0] = sizeof(core_anc_frame);
940+
anc_data_size[1] = sizeof(core_anc_frame);
941+
}
912942

913943
unsigned int i;
914944
for (i = 0; i < duration; i++)
915-
write_buffer(file, anc_frame, sizeof(anc_frame));
945+
write_buffer(file, anc_data[i % 2], anc_data_size[i % 2]);
946+
947+
if (klv_var_size) {
948+
delete [] anc_data[0];
949+
delete [] anc_data[1];
950+
}
916951
}
917952

918-
static void write_vbi_data(FILE *file, unsigned int duration)
953+
static void write_vbi_data(FILE *file, unsigned int duration, bool klv_var_size)
919954
{
920-
static const unsigned char vbi_frame[24] =
955+
static const unsigned char core_vbi_frame[24] =
921956
{0x00, 0x01, // single line
922957
0x00, 0x15, 0x01, 0x04, 0x00, 0x08, // line 21, VBIFrame, VBI_8_BIT_COMP_LUMA, 8 samples
923958
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, // payload array header: 8 x 1 bytes
924959
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47}; // payload array
960+
// Any key will do as it is discarded when parsing the data
961+
static const unsigned char klv_key[16] = {0x56, 0x42, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
962+
963+
// Odd and even frame data and sizes
964+
unsigned char *vbi_data[2];
965+
size_t vbi_data_size[2];
966+
967+
if (klv_var_size) {
968+
vbi_data_size[0] = 16 + 1 + sizeof(core_vbi_frame);
969+
vbi_data[0] = new unsigned char[vbi_data_size[0]];
970+
memcpy(vbi_data[0], klv_key, 16);
971+
vbi_data[0][16] = vbi_data_size[0] - 17;
972+
memcpy(&vbi_data[0][17], core_vbi_frame, sizeof(core_vbi_frame));
973+
974+
// Add an extra padding byte to the odd frame
975+
vbi_data_size[1] = 16 + 1 + sizeof(core_vbi_frame) + 1;
976+
vbi_data[1] = new unsigned char[vbi_data_size[1]];
977+
memcpy(vbi_data[1], klv_key, 16);
978+
vbi_data[1][16] = vbi_data_size[1] - 17;
979+
memcpy(&vbi_data[1][17], core_vbi_frame, sizeof(core_vbi_frame));
980+
vbi_data[1][16 + 1 + 11] = 0x09;
981+
vbi_data[1][vbi_data_size[1] - 1] = 0x00;
982+
} else {
983+
vbi_data[0] = const_cast<unsigned char*>(core_vbi_frame);
984+
vbi_data[1] = const_cast<unsigned char*>(core_vbi_frame);
985+
vbi_data_size[0] = sizeof(core_vbi_frame);
986+
vbi_data_size[1] = sizeof(core_vbi_frame);
987+
}
925988

926989
unsigned int i;
927990
for (i = 0; i < duration; i++)
928-
write_buffer(file, vbi_frame, sizeof(vbi_frame));
991+
write_buffer(file, vbi_data[i % 2], vbi_data_size[i % 2]);
992+
993+
if (klv_var_size) {
994+
delete [] vbi_data[0];
995+
delete [] vbi_data[1];
996+
}
929997
}
930998

931999

@@ -990,6 +1058,11 @@ static void print_usage(const char *cmd)
9901058
fprintf(stderr, " 55: RDD-36 422 Profile\n");
9911059
fprintf(stderr, " 56: RDD-36 4444 Profile\n");
9921060
fprintf(stderr, " 57: 16-bit PCM with duration in samples\n");
1061+
fprintf(stderr, " 58: RDD-36 422 ITU 2020\n");
1062+
fprintf(stderr, " 59: MPEG-2 Long GOP MP@ML 576i\n");
1063+
fprintf(stderr, " 60: MPEG-2 Long GOP MP@ML 576i 4:3\n");
1064+
fprintf(stderr, " 61: variable size ANC data in KLV\n");
1065+
fprintf(stderr, " 62: variable size VBI data in KLV\n");
9931066
}
9941067

9951068
int main(int argc, const char **argv)
@@ -1190,10 +1263,16 @@ int main(int argc, const char **argv)
11901263
write_pcm(file, 3, duration);
11911264
break;
11921265
case TYPE_ANC_DATA:
1193-
write_anc_data(file, duration);
1266+
write_anc_data(file, duration, false);
1267+
break;
1268+
case TYPE_KLV_ANC_DATA_VAR_SIZE:
1269+
write_anc_data(file, duration, true);
11941270
break;
11951271
case TYPE_VBI_DATA:
1196-
write_vbi_data(file, duration);
1272+
write_vbi_data(file, duration, false);
1273+
break;
1274+
case TYPE_KLV_VBI_DATA_VAR_SIZE:
1275+
write_vbi_data(file, duration, true);
11971276
break;
11981277
case TYPE_16BIT_PCM_SAMPLES:
11991278
write_pcm_samples(file, 2, duration);

test/mxf_op1a/anc.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3e540ddd8608253d9b0ae75dd76e12e2
1+
730b76ff77171d65cf81cb9f776a2d54

test/mxf_op1a/anc_klv.md5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
68bb6d216edc005ee77a997dfb19159d

test/mxf_op1a/test_ancvbi.cmake

+28-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
include("${TEST_SOURCE_DIR}/test_common.cmake")
44

5-
function(run_ancvbi_test test data_type)
5+
function(run_ancvbi_test test input_type data_type klv_opt)
66
if(TEST_MODE STREQUAL "check")
77
set(output_file test_${test}.mxf)
88
elseif(TEST_MODE STREQUAL "samples")
@@ -13,31 +13,37 @@ function(run_ancvbi_test test data_type)
1313
set(output_file test_${test}.mxf)
1414
endif()
1515

16+
if(${klv_opt} STREQUAL "TRUE")
17+
set(klv_size_opt "--klv;s")
18+
else()
19+
set(klv_size_opt "--${test}-const;24")
20+
endif()
21+
1622
set(create_test_video ${CREATE_TEST_ESSENCE}
17-
-t 7
18-
-d 3
23+
-t 14
24+
-d 12
1925
video_${test}
2026
)
2127

2228
set(create_test_audio ${CREATE_TEST_ESSENCE}
2329
-t 1
24-
-d 3
30+
-d 12
2531
audio_${test}
2632
)
2733

2834
set(create_test_data ${CREATE_TEST_ESSENCE}
2935
-t ${data_type}
30-
-d 3
36+
-d 12
3137
data_${test}
3238
)
3339

3440
set(create_command ${RAW2BMX}
3541
--regtest
3642
-t op1a
3743
-o ${output_file}
38-
--avci100_1080i video_${test}
44+
--mpeg2lg_422p_hl_1080i video_${test}
3945
-q 16 --pcm audio_${test}
40-
--${test}-const 24 --${test} data_${test}
46+
${klv_size_opt} --${input_type} data_${test}
4147
)
4248

4349
run_test_a(
@@ -58,19 +64,27 @@ function(run_ancvbi_test test data_type)
5864
endfunction()
5965

6066
set(tests
61-
anc 43
62-
vbi 44
67+
anc anc 43 FALSE
68+
vbi vbi 44 FALSE
69+
anc_klv anc 61 TRUE
70+
vbi_klv vbi 62 TRUE
6371
)
6472

6573
list(LENGTH tests len_tests)
66-
math(EXPR max_index "(${len_tests} / 2) - 1")
74+
math(EXPR max_index "(${len_tests} / 4) - 1")
6775

6876
foreach(index RANGE ${max_index})
69-
math(EXPR test_index "${index} * 2")
77+
math(EXPR test_index "${index} * 4")
7078
list(GET tests ${test_index} test)
71-
72-
math(EXPR test_ess_type_index "${index} * 2 + 1")
79+
80+
math(EXPR test_input_type_index "${index} * 4 + 1")
81+
list(GET tests ${test_input_type_index} test_input_type)
82+
83+
math(EXPR test_ess_type_index "${index} * 4 + 2")
7384
list(GET tests ${test_ess_type_index} test_ess_type)
7485

75-
run_ancvbi_test(${test} ${test_ess_type})
86+
math(EXPR test_klv_opt_index "${index} * 4 + 3")
87+
list(GET tests ${test_klv_opt_index} test_klv_opt)
88+
89+
run_ancvbi_test(${test} ${test_input_type} ${test_ess_type} ${test_klv_opt})
7690
endforeach()

test/mxf_op1a/vbi.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58a8e6c0c8e31e54f796be56e2c0b75a
1+
fb2139f4d8ecdfb457737967ad5cc4cc

test/mxf_op1a/vbi_klv.md5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
92e1d604207d6628a1763516b96a3b4f

test/rdd9_mxf/anc_klv.md5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1a445e0924e22ce15e27e3c90ec70c78

test/rdd9_mxf/test_ancvbi.cmake

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
include("${TEST_SOURCE_DIR}/test_common.cmake")
44

5-
function(run_ancvbi_test test data_type)
5+
function(run_ancvbi_test test input_type data_type klv_opt)
66
if(TEST_MODE STREQUAL "check")
77
set(output_file test.mxf)
88
elseif(TEST_MODE STREQUAL "samples")
@@ -13,6 +13,12 @@ function(run_ancvbi_test test data_type)
1313
set(output_file test.mxf)
1414
endif()
1515

16+
if(${klv_opt} STREQUAL "TRUE")
17+
set(klv_size_opt "--klv;s")
18+
else()
19+
set(klv_size_opt "--${test}-const;24")
20+
endif()
21+
1622
set(create_test_video ${CREATE_TEST_ESSENCE}
1723
-t 14
1824
-d 24
@@ -38,7 +44,7 @@ function(run_ancvbi_test test data_type)
3844
--mpeg2lg_422p_hl_1080i video
3945
-q 16 --pcm audio
4046
-q 16 --pcm audio
41-
--${test}-const 24 --${test} data
47+
${klv_size_opt} --${input_type} data
4248
)
4349

4450
run_test_a(
@@ -59,19 +65,27 @@ function(run_ancvbi_test test data_type)
5965
endfunction()
6066

6167
set(tests
62-
anc 43
63-
vbi 44
68+
anc anc 43 FALSE
69+
vbi vbi 44 FALSE
70+
anc_klv anc 61 TRUE
71+
vbi_klv vbi 62 TRUE
6472
)
6573

6674
list(LENGTH tests len_tests)
67-
math(EXPR max_index "(${len_tests} / 2) - 1")
75+
math(EXPR max_index "(${len_tests} / 4) - 1")
6876

6977
foreach(index RANGE ${max_index})
70-
math(EXPR test_index "${index} * 2")
78+
math(EXPR test_index "${index} * 4")
7179
list(GET tests ${test_index} test)
72-
73-
math(EXPR test_ess_type_index "${index} * 2 + 1")
80+
81+
math(EXPR test_input_type_index "${index} * 4 + 1")
82+
list(GET tests ${test_input_type_index} test_input_type)
83+
84+
math(EXPR test_ess_type_index "${index} * 4 + 2")
7485
list(GET tests ${test_ess_type_index} test_ess_type)
7586

76-
run_ancvbi_test(${test} ${test_ess_type})
87+
math(EXPR test_klv_opt_index "${index} * 4 + 3")
88+
list(GET tests ${test_klv_opt_index} test_klv_opt)
89+
90+
run_ancvbi_test(${test} ${test_input_type} ${test_ess_type} ${test_klv_opt})
7791
endforeach()

test/rdd9_mxf/vbi_klv.md5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
210dc3cd662c9a697fdaa2313870a792

0 commit comments

Comments
 (0)