Просмотр исходного кода

Include latest MPEG-2 headers and use timestamp for references

Following upstream changes, the MPEG-2 header is now out of tree and
references are identified by their timestamp.

Bring-in conversion macros to craft a timestamp from the reference
frame index and vice-versa, which allows us to still use the
information for frame ordering.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Paul Kocialkowski 6 лет назад
Родитель
Сommit
7df14eb2d7
9 измененных файлов с 257 добавлено и 164 удалено
  1. 1 1
      Makefile
  2. 50 50
      data/bbb-happy-mpeg2/frames.h
  3. 50 50
      data/bbb-mpeg2/frames.h
  4. 50 50
      data/ed-mpeg2/frames.h
  5. 82 0
      include/mpeg2-ctrls.h
  6. 5 6
      presets.c
  7. 7 2
      v4l2-request-test.c
  8. 4 1
      v4l2-request-test.h
  9. 8 4
      v4l2.c

+ 1 - 1
Makefile

@@ -35,7 +35,7 @@ DEPS = $(SOURCES:.c=.d)
 
 # Compiler
 
-CFLAGS += -Wunused-variable
+CFLAGS += -Wunused-variable -Iinclude
 CFLAGS += $(shell pkg-config --cflags libdrm)
 LDFLAGS = $(shell pkg-config --libs libdrm)
 

+ 50 - 50
data/bbb-happy-mpeg2/frames.h

@@ -25,8 +25,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 0,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(0),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -66,8 +66,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -107,8 +107,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -148,8 +148,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -189,8 +189,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -230,8 +230,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -271,8 +271,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -312,8 +312,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -353,8 +353,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -394,8 +394,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -435,8 +435,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -476,8 +476,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 7,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(7),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -517,8 +517,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 7,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(7),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -558,8 +558,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -599,8 +599,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -640,8 +640,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -681,8 +681,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -722,8 +722,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -763,8 +763,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -804,8 +804,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -845,8 +845,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -886,8 +886,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -927,8 +927,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 22,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(22),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -968,8 +968,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 19,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(19),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -1009,8 +1009,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 19,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(19),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,

+ 50 - 50
data/bbb-mpeg2/frames.h

@@ -25,8 +25,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 4,
-			.forward_ref_index = 0,
-			.backward_ref_index = 0,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(0),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -66,8 +66,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 3,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -107,8 +107,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 2,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(2),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -148,8 +148,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 2,
-			.backward_ref_index = 3,
+			.forward_ref_ts = TS_REF_INDEX(2),
+			.backward_ref_ts = TS_REF_INDEX(3),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -189,8 +189,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 3,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(3),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -230,8 +230,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 5,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(5),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -271,8 +271,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 5,
-			.backward_ref_index = 6,
+			.forward_ref_ts = TS_REF_INDEX(5),
+			.backward_ref_ts = TS_REF_INDEX(6),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -312,8 +312,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 6,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(6),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -353,8 +353,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 7,
-			.backward_ref_index = 8,
+			.forward_ref_ts = TS_REF_INDEX(7),
+			.backward_ref_ts = TS_REF_INDEX(8),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -394,8 +394,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 8,
-			.backward_ref_index = 9,
+			.forward_ref_ts = TS_REF_INDEX(8),
+			.backward_ref_ts = TS_REF_INDEX(9),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -435,8 +435,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 9,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(9),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -476,8 +476,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 11,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(11),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -517,8 +517,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 11,
-			.backward_ref_index = 12,
+			.forward_ref_ts = TS_REF_INDEX(11),
+			.backward_ref_ts = TS_REF_INDEX(12),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -558,8 +558,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 12,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(12),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -599,8 +599,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 3,
-			.forward_ref_index = 13,
-			.backward_ref_index = 14,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(14),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -640,8 +640,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 3,
-			.forward_ref_index = 15,
-			.backward_ref_index = 15,
+			.forward_ref_ts = TS_REF_INDEX(15),
+			.backward_ref_ts = TS_REF_INDEX(15),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -681,8 +681,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 15,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(15),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -722,8 +722,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 17,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(17),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -763,8 +763,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 17,
-			.backward_ref_index = 18,
+			.forward_ref_ts = TS_REF_INDEX(17),
+			.backward_ref_ts = TS_REF_INDEX(18),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -804,8 +804,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 18,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(18),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -845,8 +845,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 19,
-			.backward_ref_index = 20,
+			.forward_ref_ts = TS_REF_INDEX(19),
+			.backward_ref_ts = TS_REF_INDEX(20),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -886,8 +886,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 20,
-			.backward_ref_index = 21,
+			.forward_ref_ts = TS_REF_INDEX(20),
+			.backward_ref_ts = TS_REF_INDEX(21),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -927,8 +927,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 21,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(21),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -968,8 +968,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 22,
-			.backward_ref_index = 23,
+			.forward_ref_ts = TS_REF_INDEX(22),
+			.backward_ref_ts = TS_REF_INDEX(23),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -1009,8 +1009,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 23,
-			.backward_ref_index = 24,
+			.forward_ref_ts = TS_REF_INDEX(23),
+			.backward_ref_ts = TS_REF_INDEX(24),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,

+ 50 - 50
data/ed-mpeg2/frames.h

@@ -25,8 +25,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 0,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(0),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -66,8 +66,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -107,8 +107,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -148,8 +148,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 0,
-			.backward_ref_index = 1,
+			.forward_ref_ts = TS_REF_INDEX(0),
+			.backward_ref_ts = TS_REF_INDEX(1),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -189,8 +189,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -230,8 +230,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -271,8 +271,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 1,
-			.backward_ref_index = 4,
+			.forward_ref_ts = TS_REF_INDEX(1),
+			.backward_ref_ts = TS_REF_INDEX(4),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -312,8 +312,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -353,8 +353,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -394,8 +394,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 4,
-			.backward_ref_index = 7,
+			.forward_ref_ts = TS_REF_INDEX(4),
+			.backward_ref_ts = TS_REF_INDEX(7),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -435,8 +435,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -476,8 +476,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 7,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(7),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -517,8 +517,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 7,
-			.backward_ref_index = 10,
+			.forward_ref_ts = TS_REF_INDEX(7),
+			.backward_ref_ts = TS_REF_INDEX(10),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -558,8 +558,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -599,8 +599,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -640,8 +640,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 10,
-			.backward_ref_index = 13,
+			.forward_ref_ts = TS_REF_INDEX(10),
+			.backward_ref_ts = TS_REF_INDEX(13),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -681,8 +681,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -722,8 +722,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -763,8 +763,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 13,
-			.backward_ref_index = 16,
+			.forward_ref_ts = TS_REF_INDEX(13),
+			.backward_ref_ts = TS_REF_INDEX(16),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -804,8 +804,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -845,8 +845,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -886,8 +886,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 16,
-			.backward_ref_index = 19,
+			.forward_ref_ts = TS_REF_INDEX(16),
+			.backward_ref_ts = TS_REF_INDEX(19),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -927,8 +927,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 22,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(22),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -968,8 +968,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 19,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(19),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,
@@ -1009,8 +1009,8 @@
 				.progressive_frame = 1,
 			},
 			.quantiser_scale_code = 2,
-			.forward_ref_index = 19,
-			.backward_ref_index = 22,
+			.forward_ref_ts = TS_REF_INDEX(19),
+			.backward_ref_ts = TS_REF_INDEX(22),
 		},
 		.frame.mpeg2.quantization = {
 			.load_intra_quantiser_matrix = 1,

+ 82 - 0
include/mpeg2-ctrls.h

@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * These are the MPEG2 state controls for use with stateless MPEG-2
+ * codec drivers.
+ *
+ * It turns out that these structs are not stable yet and will undergo
+ * more changes. So keep them private until they are stable and ready to
+ * become part of the official public API.
+ */
+
+#ifndef _MPEG2_CTRLS_H_
+#define _MPEG2_CTRLS_H_
+
+#define V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS		(V4L2_CID_MPEG_BASE+250)
+#define V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION		(V4L2_CID_MPEG_BASE+251)
+
+/* enum v4l2_ctrl_type type values */
+#define V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS 0x0103
+#define	V4L2_CTRL_TYPE_MPEG2_QUANTIZATION 0x0104
+
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_I	1
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_P	2
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_B	3
+#define V4L2_MPEG2_PICTURE_CODING_TYPE_D	4
+
+struct v4l2_mpeg2_sequence {
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence header */
+	__u16	horizontal_size;
+	__u16	vertical_size;
+	__u32	vbv_buffer_size;
+
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Sequence extension */
+	__u16	profile_and_level_indication;
+	__u8	progressive_sequence;
+	__u8	chroma_format;
+};
+
+struct v4l2_mpeg2_picture {
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture header */
+	__u8	picture_coding_type;
+
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Picture coding extension */
+	__u8	f_code[2][2];
+	__u8	intra_dc_precision;
+	__u8	picture_structure;
+	__u8	top_field_first;
+	__u8	frame_pred_frame_dct;
+	__u8	concealment_motion_vectors;
+	__u8	q_scale_type;
+	__u8	intra_vlc_format;
+	__u8	alternate_scan;
+	__u8	repeat_first_field;
+	__u16	progressive_frame;
+};
+
+struct v4l2_ctrl_mpeg2_slice_params {
+	__u32	bit_size;
+	__u32	data_bit_offset;
+	__u64	backward_ref_ts;
+	__u64	forward_ref_ts;
+
+	struct v4l2_mpeg2_sequence sequence;
+	struct v4l2_mpeg2_picture picture;
+
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Slice */
+	__u32	quantiser_scale_code;
+};
+
+struct v4l2_ctrl_mpeg2_quantization {
+	/* ISO/IEC 13818-2, ITU-T Rec. H.262: Quant matrix extension */
+	__u8	load_intra_quantiser_matrix;
+	__u8	load_non_intra_quantiser_matrix;
+	__u8	load_chroma_intra_quantiser_matrix;
+	__u8	load_chroma_non_intra_quantiser_matrix;
+
+	__u8	intra_quantiser_matrix[64];
+	__u8	non_intra_quantiser_matrix[64];
+	__u8	chroma_intra_quantiser_matrix[64];
+	__u8	chroma_non_intra_quantiser_matrix[64];
+};
+
+#endif

+ 5 - 6
presets.c

@@ -22,6 +22,7 @@
 
 #include <linux/media.h>
 #include <linux/videodev2.h>
+#include <mpeg2-ctrls.h>
 
 #include "v4l2-request-test.h"
 
@@ -219,11 +220,6 @@ int frame_controls_fill(struct frame *frame, struct preset *preset,
 
 	switch (preset->type) {
 	case CODEC_TYPE_MPEG2:
-		frame->frame.mpeg2.slice_params.forward_ref_index %=
-			buffers_count;
-		frame->frame.mpeg2.slice_params.backward_ref_index %=
-			buffers_count;
-		break;
 	case CODEC_TYPE_H264:
 		break;
 #ifdef V4L2_PIX_FMT_HEVC_SLICE
@@ -297,12 +293,15 @@ unsigned int frame_poc(struct preset *preset, unsigned int index)
 
 unsigned int frame_backward_ref_index(struct preset *preset, unsigned int index)
 {
+	uint64_t ts;
+
 	if (preset == NULL)
 		return 0;
 
 	switch (preset->type) {
 	case CODEC_TYPE_MPEG2:
-		return preset->frames[index].frame.mpeg2.slice_params.backward_ref_index;
+		ts = preset->frames[index].frame.mpeg2.slice_params.backward_ref_ts;
+		return INDEX_REF_TS(ts);
 	default:
 		return 0;
 	}

+ 7 - 2
v4l2-request-test.c

@@ -32,6 +32,7 @@
 #include <drm_fourcc.h>
 #include <linux/media.h>
 #include <linux/videodev2.h>
+#include <mpeg2-ctrls.h>
 #include <xf86drm.h>
 
 #include "v4l2-request-test.h"
@@ -248,6 +249,7 @@ int main(int argc, char *argv[])
 	int video_fd = -1;
 	int media_fd = -1;
 	int drm_fd = -1;
+	uint64_t ts;
 	bool test;
 	int opt;
 	int rc;
@@ -483,11 +485,14 @@ int main(int argc, char *argv[])
 		else
 			v4l2_index = index % config.buffers_count;
 
+		ts = TS_REF_INDEX(index);
+
 		clock_gettime(CLOCK_MONOTONIC, &video_before);
 
 		rc = video_engine_decode(video_fd, v4l2_index, &frame.frame,
-					 preset->type, slice_data, slice_size,
-					 video_buffers, &video_setup);
+					 preset->type, ts, slice_data,
+					 slice_size, video_buffers,
+					 &video_setup);
 		if (rc < 0) {
 			fprintf(stderr, "Unable to decode video frame\n");
 			goto error;

+ 4 - 1
v4l2-request-test.h

@@ -23,8 +23,11 @@
 #include <linux/types.h>
 #include <linux/v4l2-controls.h>
 #include <linux/videodev2.h>
+#include <mpeg2-ctrls.h>
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define TS_REF_INDEX(index) ((index) * 1000)
+#define INDEX_REF_TS(ts) ((ts) / 1000)
 
 /*
  * Structures
@@ -226,7 +229,7 @@ int video_engine_start(int video_fd, int media_fd, unsigned int width,
 int video_engine_stop(int video_fd, struct video_buffer *buffers,
 		      unsigned int buffers_count, struct video_setup *setup);
 int video_engine_decode(int video_fd, unsigned int index, union controls *frame,
-			enum codec_type type, void *source_data,
+			enum codec_type type, uint64_t ts, void *source_data,
 			unsigned int source_size, struct video_buffer *buffers,
 			struct video_setup *setup);
 

+ 8 - 4
v4l2.c

@@ -29,6 +29,7 @@
 
 #include <linux/media.h>
 #include <linux/videodev2.h>
+#include <mpeg2-ctrls.h>
 
 #include "v4l2-request-test.h"
 
@@ -323,7 +324,7 @@ static int request_buffers(int video_fd, unsigned int type,
 }
 
 static int queue_buffer(int video_fd, int request_fd, unsigned int type,
-			unsigned int index, unsigned int size,
+			uint64_t ts, unsigned int index, unsigned int size,
 			unsigned int buffers_count)
 {
 	struct v4l2_plane planes[buffers_count];
@@ -351,6 +352,9 @@ static int queue_buffer(int video_fd, int request_fd, unsigned int type,
 		buffer.request_fd = request_fd;
 	}
 
+	buffer.timestamp.tv_usec = ts / 1000;
+	buffer.timestamp.tv_sec = ts / 1000000000ULL;
+
 	rc = ioctl(video_fd, VIDIOC_QBUF, &buffer);
 	if (rc < 0) {
 		fprintf(stderr, "Unable to queue buffer: %s\n",
@@ -863,7 +867,7 @@ int video_engine_stop(int video_fd, struct video_buffer *buffers,
 }
 
 int video_engine_decode(int video_fd, unsigned int index, union controls *frame,
-			enum codec_type type, void *source_data,
+			enum codec_type type, uint64_t ts, void *source_data,
 			unsigned int source_size, struct video_buffer *buffers,
 			struct video_setup *setup)
 {
@@ -883,14 +887,14 @@ int video_engine_decode(int video_fd, unsigned int index, union controls *frame,
 		return -1;
 	}
 
-	rc = queue_buffer(video_fd, request_fd, setup->output_type, index,
+	rc = queue_buffer(video_fd, request_fd, setup->output_type, ts, index,
 			  source_size, 1);
 	if (rc < 0) {
 		fprintf(stderr, "Unable to queue source buffer\n");
 		return -1;
 	}
 
-	rc = queue_buffer(video_fd, -1, setup->capture_type, index, 0,
+	rc = queue_buffer(video_fd, -1, setup->capture_type, 0, index, 0,
 			  buffers[index].destination_buffers_count);
 	if (rc < 0) {
 		fprintf(stderr, "Unable to queue destination buffer\n");