1*09537850SAkhilesh Sanikop /*
2*09537850SAkhilesh Sanikop * Copyright 2021 The libgav1 Authors
3*09537850SAkhilesh Sanikop *
4*09537850SAkhilesh Sanikop * Licensed under the Apache License, Version 2.0 (the "License");
5*09537850SAkhilesh Sanikop * you may not use this file except in compliance with the License.
6*09537850SAkhilesh Sanikop * You may obtain a copy of the License at
7*09537850SAkhilesh Sanikop *
8*09537850SAkhilesh Sanikop * http://www.apache.org/licenses/LICENSE-2.0
9*09537850SAkhilesh Sanikop *
10*09537850SAkhilesh Sanikop * Unless required by applicable law or agreed to in writing, software
11*09537850SAkhilesh Sanikop * distributed under the License is distributed on an "AS IS" BASIS,
12*09537850SAkhilesh Sanikop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*09537850SAkhilesh Sanikop * See the License for the specific language governing permissions and
14*09537850SAkhilesh Sanikop * limitations under the License.
15*09537850SAkhilesh Sanikop */
16*09537850SAkhilesh Sanikop
17*09537850SAkhilesh Sanikop #ifdef __cplusplus
18*09537850SAkhilesh Sanikop #error Do not compile this file with a C++ compiler
19*09537850SAkhilesh Sanikop #endif
20*09537850SAkhilesh Sanikop
21*09537850SAkhilesh Sanikop // clang-format off
22*09537850SAkhilesh Sanikop #include "src/gav1/decoder.h"
23*09537850SAkhilesh Sanikop
24*09537850SAkhilesh Sanikop // Import the test frame #defines.
25*09537850SAkhilesh Sanikop #include "src/decoder_test_data.h"
26*09537850SAkhilesh Sanikop // clang-format on
27*09537850SAkhilesh Sanikop
28*09537850SAkhilesh Sanikop #include <stddef.h>
29*09537850SAkhilesh Sanikop #include <stdint.h>
30*09537850SAkhilesh Sanikop #include <stdio.h>
31*09537850SAkhilesh Sanikop #include <stdlib.h>
32*09537850SAkhilesh Sanikop
33*09537850SAkhilesh Sanikop #define ASSERT_EQ(a, b) \
34*09537850SAkhilesh Sanikop do { \
35*09537850SAkhilesh Sanikop if ((a) != (b)) { \
36*09537850SAkhilesh Sanikop fprintf(stderr, "Assertion failure: (%s) == (%s), at %s:%d\n", #a, #b, \
37*09537850SAkhilesh Sanikop __FILE__, __LINE__); \
38*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest failed\n"); \
39*09537850SAkhilesh Sanikop exit(1); \
40*09537850SAkhilesh Sanikop } \
41*09537850SAkhilesh Sanikop } while (0)
42*09537850SAkhilesh Sanikop
43*09537850SAkhilesh Sanikop #define ASSERT_NE(a, b) \
44*09537850SAkhilesh Sanikop do { \
45*09537850SAkhilesh Sanikop if ((a) == (b)) { \
46*09537850SAkhilesh Sanikop fprintf(stderr, "Assertion failure: (%s) != (%s), at %s:%d\n", #a, #b, \
47*09537850SAkhilesh Sanikop __FILE__, __LINE__); \
48*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest failed\n"); \
49*09537850SAkhilesh Sanikop exit(1); \
50*09537850SAkhilesh Sanikop } \
51*09537850SAkhilesh Sanikop } while (0)
52*09537850SAkhilesh Sanikop
53*09537850SAkhilesh Sanikop #define ASSERT_TRUE(a) \
54*09537850SAkhilesh Sanikop do { \
55*09537850SAkhilesh Sanikop if (!(a)) { \
56*09537850SAkhilesh Sanikop fprintf(stderr, "Assertion failure: %s, at %s:%d\n", #a, __FILE__, \
57*09537850SAkhilesh Sanikop __LINE__); \
58*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest failed\n"); \
59*09537850SAkhilesh Sanikop exit(1); \
60*09537850SAkhilesh Sanikop } \
61*09537850SAkhilesh Sanikop } while (0)
62*09537850SAkhilesh Sanikop
63*09537850SAkhilesh Sanikop #define ASSERT_FALSE(a) \
64*09537850SAkhilesh Sanikop do { \
65*09537850SAkhilesh Sanikop if (a) { \
66*09537850SAkhilesh Sanikop fprintf(stderr, "Assertion failure: !(%s), at %s:%d\n", #a, __FILE__, \
67*09537850SAkhilesh Sanikop __LINE__); \
68*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest failed\n"); \
69*09537850SAkhilesh Sanikop exit(1); \
70*09537850SAkhilesh Sanikop } \
71*09537850SAkhilesh Sanikop } while (0)
72*09537850SAkhilesh Sanikop
73*09537850SAkhilesh Sanikop static const uint8_t kFrame1[] = {OBU_TEMPORAL_DELIMITER, OBU_SEQUENCE_HEADER,
74*09537850SAkhilesh Sanikop OBU_FRAME_1};
75*09537850SAkhilesh Sanikop
76*09537850SAkhilesh Sanikop static const uint8_t kFrame2[] = {OBU_TEMPORAL_DELIMITER, OBU_FRAME_2};
77*09537850SAkhilesh Sanikop
78*09537850SAkhilesh Sanikop static const uint8_t kFrame1WithHdrCllAndHdrMdcv[] = {
79*09537850SAkhilesh Sanikop OBU_TEMPORAL_DELIMITER, OBU_SEQUENCE_HEADER, OBU_METADATA_HDR_CLL,
80*09537850SAkhilesh Sanikop OBU_METADATA_HDR_MDCV, OBU_FRAME_1};
81*09537850SAkhilesh Sanikop
82*09537850SAkhilesh Sanikop static const uint8_t kFrame2WithItutT35[] = {
83*09537850SAkhilesh Sanikop OBU_TEMPORAL_DELIMITER, OBU_METADATA_ITUT_T35, OBU_FRAME_2};
84*09537850SAkhilesh Sanikop
85*09537850SAkhilesh Sanikop typedef struct DecoderTest {
86*09537850SAkhilesh Sanikop Libgav1Decoder* decoder;
87*09537850SAkhilesh Sanikop int frames_in_use;
88*09537850SAkhilesh Sanikop void* buffer_private_data;
89*09537850SAkhilesh Sanikop void* released_input_buffer;
90*09537850SAkhilesh Sanikop } DecoderTest;
91*09537850SAkhilesh Sanikop
DecoderTestInit(DecoderTest * test)92*09537850SAkhilesh Sanikop static void DecoderTestInit(DecoderTest* test) {
93*09537850SAkhilesh Sanikop test->decoder = NULL;
94*09537850SAkhilesh Sanikop test->frames_in_use = 0;
95*09537850SAkhilesh Sanikop test->buffer_private_data = NULL;
96*09537850SAkhilesh Sanikop test->released_input_buffer = NULL;
97*09537850SAkhilesh Sanikop }
98*09537850SAkhilesh Sanikop
DecoderTestIncrementFramesInUse(DecoderTest * test)99*09537850SAkhilesh Sanikop static void DecoderTestIncrementFramesInUse(DecoderTest* test) {
100*09537850SAkhilesh Sanikop ++test->frames_in_use;
101*09537850SAkhilesh Sanikop }
102*09537850SAkhilesh Sanikop
DecoderTestDecrementFramesInUse(DecoderTest * test)103*09537850SAkhilesh Sanikop static void DecoderTestDecrementFramesInUse(DecoderTest* test) {
104*09537850SAkhilesh Sanikop --test->frames_in_use;
105*09537850SAkhilesh Sanikop }
106*09537850SAkhilesh Sanikop
DecoderTestSetReleasedInputBuffer(DecoderTest * test,void * released_input_buffer)107*09537850SAkhilesh Sanikop static void DecoderTestSetReleasedInputBuffer(DecoderTest* test,
108*09537850SAkhilesh Sanikop void* released_input_buffer) {
109*09537850SAkhilesh Sanikop test->released_input_buffer = released_input_buffer;
110*09537850SAkhilesh Sanikop }
111*09537850SAkhilesh Sanikop
DecoderTestSetBufferPrivateData(DecoderTest * test,void * buffer_private_data)112*09537850SAkhilesh Sanikop static void DecoderTestSetBufferPrivateData(DecoderTest* test,
113*09537850SAkhilesh Sanikop void* buffer_private_data) {
114*09537850SAkhilesh Sanikop test->buffer_private_data = buffer_private_data;
115*09537850SAkhilesh Sanikop }
116*09537850SAkhilesh Sanikop
117*09537850SAkhilesh Sanikop typedef struct FrameBufferPrivate {
118*09537850SAkhilesh Sanikop uint8_t* data[3];
119*09537850SAkhilesh Sanikop } FrameBufferPrivate;
120*09537850SAkhilesh Sanikop
GetFrameBuffer(void * callback_private_data,int bitdepth,Libgav1ImageFormat image_format,int width,int height,int left_border,int right_border,int top_border,int bottom_border,int stride_alignment,Libgav1FrameBuffer * frame_buffer)121*09537850SAkhilesh Sanikop static Libgav1StatusCode GetFrameBuffer(
122*09537850SAkhilesh Sanikop void* callback_private_data, int bitdepth, Libgav1ImageFormat image_format,
123*09537850SAkhilesh Sanikop int width, int height, int left_border, int right_border, int top_border,
124*09537850SAkhilesh Sanikop int bottom_border, int stride_alignment, Libgav1FrameBuffer* frame_buffer) {
125*09537850SAkhilesh Sanikop Libgav1FrameBufferInfo info;
126*09537850SAkhilesh Sanikop Libgav1StatusCode status = Libgav1ComputeFrameBufferInfo(
127*09537850SAkhilesh Sanikop bitdepth, image_format, width, height, left_border, right_border,
128*09537850SAkhilesh Sanikop top_border, bottom_border, stride_alignment, &info);
129*09537850SAkhilesh Sanikop if (status != kLibgav1StatusOk) return status;
130*09537850SAkhilesh Sanikop
131*09537850SAkhilesh Sanikop FrameBufferPrivate* buffer_private =
132*09537850SAkhilesh Sanikop (FrameBufferPrivate*)malloc(sizeof(FrameBufferPrivate));
133*09537850SAkhilesh Sanikop if (buffer_private == NULL) return kLibgav1StatusOutOfMemory;
134*09537850SAkhilesh Sanikop
135*09537850SAkhilesh Sanikop for (int i = 0; i < 3; ++i) {
136*09537850SAkhilesh Sanikop const size_t size = (i == 0) ? info.y_buffer_size : info.uv_buffer_size;
137*09537850SAkhilesh Sanikop buffer_private->data[i] = (uint8_t*)malloc(sizeof(uint8_t) * size);
138*09537850SAkhilesh Sanikop if (buffer_private->data[i] == NULL) {
139*09537850SAkhilesh Sanikop for (int j = 0; j < i; j++) {
140*09537850SAkhilesh Sanikop free(buffer_private->data[j]);
141*09537850SAkhilesh Sanikop }
142*09537850SAkhilesh Sanikop free(buffer_private);
143*09537850SAkhilesh Sanikop return kLibgav1StatusOutOfMemory;
144*09537850SAkhilesh Sanikop }
145*09537850SAkhilesh Sanikop }
146*09537850SAkhilesh Sanikop
147*09537850SAkhilesh Sanikop uint8_t* const y_buffer = buffer_private->data[0];
148*09537850SAkhilesh Sanikop uint8_t* const u_buffer =
149*09537850SAkhilesh Sanikop (info.uv_buffer_size != 0) ? buffer_private->data[1] : NULL;
150*09537850SAkhilesh Sanikop uint8_t* const v_buffer =
151*09537850SAkhilesh Sanikop (info.uv_buffer_size != 0) ? buffer_private->data[2] : NULL;
152*09537850SAkhilesh Sanikop
153*09537850SAkhilesh Sanikop status = Libgav1SetFrameBuffer(&info, y_buffer, u_buffer, v_buffer,
154*09537850SAkhilesh Sanikop buffer_private, frame_buffer);
155*09537850SAkhilesh Sanikop if (status != kLibgav1StatusOk) return status;
156*09537850SAkhilesh Sanikop
157*09537850SAkhilesh Sanikop DecoderTest* const decoder_test = (DecoderTest*)callback_private_data;
158*09537850SAkhilesh Sanikop DecoderTestIncrementFramesInUse(decoder_test);
159*09537850SAkhilesh Sanikop DecoderTestSetBufferPrivateData(decoder_test, frame_buffer->private_data);
160*09537850SAkhilesh Sanikop return kLibgav1StatusOk;
161*09537850SAkhilesh Sanikop }
162*09537850SAkhilesh Sanikop
ReleaseFrameBuffer(void * callback_private_data,void * buffer_private_data)163*09537850SAkhilesh Sanikop static void ReleaseFrameBuffer(void* callback_private_data,
164*09537850SAkhilesh Sanikop void* buffer_private_data) {
165*09537850SAkhilesh Sanikop FrameBufferPrivate* buffer_private = (FrameBufferPrivate*)buffer_private_data;
166*09537850SAkhilesh Sanikop for (int i = 0; i < 3; ++i) {
167*09537850SAkhilesh Sanikop free(buffer_private->data[i]);
168*09537850SAkhilesh Sanikop }
169*09537850SAkhilesh Sanikop free(buffer_private);
170*09537850SAkhilesh Sanikop DecoderTest* const decoder_test = (DecoderTest*)callback_private_data;
171*09537850SAkhilesh Sanikop DecoderTestDecrementFramesInUse(decoder_test);
172*09537850SAkhilesh Sanikop }
173*09537850SAkhilesh Sanikop
ReleaseInputBuffer(void * private_data,void * input_buffer)174*09537850SAkhilesh Sanikop static void ReleaseInputBuffer(void* private_data, void* input_buffer) {
175*09537850SAkhilesh Sanikop DecoderTestSetReleasedInputBuffer((DecoderTest*)private_data, input_buffer);
176*09537850SAkhilesh Sanikop }
177*09537850SAkhilesh Sanikop
DecoderTestSetUp(DecoderTest * test)178*09537850SAkhilesh Sanikop static void DecoderTestSetUp(DecoderTest* test) {
179*09537850SAkhilesh Sanikop Libgav1DecoderSettings settings;
180*09537850SAkhilesh Sanikop Libgav1DecoderSettingsInitDefault(&settings);
181*09537850SAkhilesh Sanikop settings.frame_parallel = 0; // false
182*09537850SAkhilesh Sanikop settings.get_frame_buffer = GetFrameBuffer;
183*09537850SAkhilesh Sanikop settings.release_frame_buffer = ReleaseFrameBuffer;
184*09537850SAkhilesh Sanikop settings.callback_private_data = test;
185*09537850SAkhilesh Sanikop settings.release_input_buffer = ReleaseInputBuffer;
186*09537850SAkhilesh Sanikop ASSERT_EQ(test->decoder, NULL);
187*09537850SAkhilesh Sanikop ASSERT_EQ(Libgav1DecoderCreate(&settings, &test->decoder), kLibgav1StatusOk);
188*09537850SAkhilesh Sanikop ASSERT_NE(test->decoder, NULL);
189*09537850SAkhilesh Sanikop }
190*09537850SAkhilesh Sanikop
DecoderTestAPIFlowForNonFrameParallelMode(void)191*09537850SAkhilesh Sanikop static void DecoderTestAPIFlowForNonFrameParallelMode(void) {
192*09537850SAkhilesh Sanikop DecoderTest test;
193*09537850SAkhilesh Sanikop DecoderTestInit(&test);
194*09537850SAkhilesh Sanikop DecoderTestSetUp(&test);
195*09537850SAkhilesh Sanikop
196*09537850SAkhilesh Sanikop Libgav1StatusCode status;
197*09537850SAkhilesh Sanikop const Libgav1DecoderBuffer* buffer;
198*09537850SAkhilesh Sanikop
199*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
200*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1, sizeof(kFrame1), 0,
201*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1);
202*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
203*09537850SAkhilesh Sanikop
204*09537850SAkhilesh Sanikop // In non-frame-parallel mode, decoding happens only in the DequeueFrame call.
205*09537850SAkhilesh Sanikop // So there should be no frames in use yet.
206*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
207*09537850SAkhilesh Sanikop
208*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
209*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
210*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
211*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
212*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1);
213*09537850SAkhilesh Sanikop
214*09537850SAkhilesh Sanikop // libgav1 has decoded frame1 and is holding a reference to it.
215*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
216*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
217*09537850SAkhilesh Sanikop
218*09537850SAkhilesh Sanikop // Enqueue frame2 for decoding.
219*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2, sizeof(kFrame2), 0,
220*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2);
221*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
222*09537850SAkhilesh Sanikop
223*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
224*09537850SAkhilesh Sanikop
225*09537850SAkhilesh Sanikop // Dequeue the output of frame2.
226*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
227*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
228*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
229*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame2);
230*09537850SAkhilesh Sanikop
231*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 2);
232*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
233*09537850SAkhilesh Sanikop
234*09537850SAkhilesh Sanikop // Signal end of stream (method 1). This should ensure that all the references
235*09537850SAkhilesh Sanikop // are released.
236*09537850SAkhilesh Sanikop status = Libgav1DecoderSignalEOS(test.decoder);
237*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
238*09537850SAkhilesh Sanikop
239*09537850SAkhilesh Sanikop // libgav1 should have released all the reference frames now.
240*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
241*09537850SAkhilesh Sanikop
242*09537850SAkhilesh Sanikop // Now, the decoder is ready to accept a new coded video sequence.
243*09537850SAkhilesh Sanikop
244*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
245*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1, sizeof(kFrame1), 0,
246*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1);
247*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
248*09537850SAkhilesh Sanikop
249*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
250*09537850SAkhilesh Sanikop
251*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
252*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
253*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
254*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
255*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1);
256*09537850SAkhilesh Sanikop
257*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
258*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
259*09537850SAkhilesh Sanikop
260*09537850SAkhilesh Sanikop // Enqueue frame2 for decoding.
261*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2, sizeof(kFrame2), 0,
262*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2);
263*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
264*09537850SAkhilesh Sanikop
265*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
266*09537850SAkhilesh Sanikop
267*09537850SAkhilesh Sanikop // Dequeue the output of frame2.
268*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
269*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
270*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
271*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame2);
272*09537850SAkhilesh Sanikop
273*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 2);
274*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
275*09537850SAkhilesh Sanikop
276*09537850SAkhilesh Sanikop // Signal end of stream (method 2). This should ensure that all the references
277*09537850SAkhilesh Sanikop // are released.
278*09537850SAkhilesh Sanikop Libgav1DecoderDestroy(test.decoder);
279*09537850SAkhilesh Sanikop test.decoder = NULL;
280*09537850SAkhilesh Sanikop
281*09537850SAkhilesh Sanikop // libgav1 should have released all the frames now.
282*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
283*09537850SAkhilesh Sanikop }
284*09537850SAkhilesh Sanikop
285*09537850SAkhilesh Sanikop static void
DecoderTestNonFrameParallelModeEnqueueMultipleFramesWithoutDequeuing(void)286*09537850SAkhilesh Sanikop DecoderTestNonFrameParallelModeEnqueueMultipleFramesWithoutDequeuing(void) {
287*09537850SAkhilesh Sanikop DecoderTest test;
288*09537850SAkhilesh Sanikop DecoderTestInit(&test);
289*09537850SAkhilesh Sanikop DecoderTestSetUp(&test);
290*09537850SAkhilesh Sanikop
291*09537850SAkhilesh Sanikop Libgav1StatusCode status;
292*09537850SAkhilesh Sanikop const Libgav1DecoderBuffer* buffer;
293*09537850SAkhilesh Sanikop
294*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
295*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1, sizeof(kFrame1), 0,
296*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1);
297*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
298*09537850SAkhilesh Sanikop
299*09537850SAkhilesh Sanikop // Until the output of frame1 is dequeued, no other frames can be enqueued.
300*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2, sizeof(kFrame2), 0,
301*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2);
302*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusTryAgain);
303*09537850SAkhilesh Sanikop
304*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
305*09537850SAkhilesh Sanikop
306*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
307*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
308*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
309*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
310*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1);
311*09537850SAkhilesh Sanikop
312*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
313*09537850SAkhilesh Sanikop
314*09537850SAkhilesh Sanikop // Delete the decoder instance.
315*09537850SAkhilesh Sanikop Libgav1DecoderDestroy(test.decoder);
316*09537850SAkhilesh Sanikop test.decoder = NULL;
317*09537850SAkhilesh Sanikop
318*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
319*09537850SAkhilesh Sanikop }
320*09537850SAkhilesh Sanikop
DecoderTestNonFrameParallelModeEOSBeforeDequeuingLastFrame(void)321*09537850SAkhilesh Sanikop static void DecoderTestNonFrameParallelModeEOSBeforeDequeuingLastFrame(void) {
322*09537850SAkhilesh Sanikop DecoderTest test;
323*09537850SAkhilesh Sanikop DecoderTestInit(&test);
324*09537850SAkhilesh Sanikop DecoderTestSetUp(&test);
325*09537850SAkhilesh Sanikop
326*09537850SAkhilesh Sanikop Libgav1StatusCode status;
327*09537850SAkhilesh Sanikop const Libgav1DecoderBuffer* buffer;
328*09537850SAkhilesh Sanikop
329*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
330*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1, sizeof(kFrame1), 0,
331*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1);
332*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
333*09537850SAkhilesh Sanikop
334*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
335*09537850SAkhilesh Sanikop
336*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
337*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
338*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
339*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
340*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1);
341*09537850SAkhilesh Sanikop
342*09537850SAkhilesh Sanikop // Enqueue frame2 for decoding.
343*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2, sizeof(kFrame2), 0,
344*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2);
345*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
346*09537850SAkhilesh Sanikop
347*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
348*09537850SAkhilesh Sanikop
349*09537850SAkhilesh Sanikop // Signal end of stream before dequeuing the output of frame2.
350*09537850SAkhilesh Sanikop status = Libgav1DecoderSignalEOS(test.decoder);
351*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
352*09537850SAkhilesh Sanikop
353*09537850SAkhilesh Sanikop // In this case, the output of the last frame that was enqueued is lost (which
354*09537850SAkhilesh Sanikop // is intentional since end of stream was signaled without dequeueing it).
355*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
356*09537850SAkhilesh Sanikop
357*09537850SAkhilesh Sanikop Libgav1DecoderDestroy(test.decoder);
358*09537850SAkhilesh Sanikop test.decoder = NULL;
359*09537850SAkhilesh Sanikop }
360*09537850SAkhilesh Sanikop
DecoderTestNonFrameParallelModeInvalidFrameAfterEOS(void)361*09537850SAkhilesh Sanikop static void DecoderTestNonFrameParallelModeInvalidFrameAfterEOS(void) {
362*09537850SAkhilesh Sanikop DecoderTest test;
363*09537850SAkhilesh Sanikop DecoderTestInit(&test);
364*09537850SAkhilesh Sanikop DecoderTestSetUp(&test);
365*09537850SAkhilesh Sanikop
366*09537850SAkhilesh Sanikop Libgav1StatusCode status;
367*09537850SAkhilesh Sanikop const Libgav1DecoderBuffer* buffer = NULL;
368*09537850SAkhilesh Sanikop
369*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
370*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1, sizeof(kFrame1), 0,
371*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1);
372*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
373*09537850SAkhilesh Sanikop
374*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
375*09537850SAkhilesh Sanikop
376*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
377*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
378*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
379*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
380*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1);
381*09537850SAkhilesh Sanikop
382*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
383*09537850SAkhilesh Sanikop
384*09537850SAkhilesh Sanikop // Signal end of stream.
385*09537850SAkhilesh Sanikop status = Libgav1DecoderSignalEOS(test.decoder);
386*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
387*09537850SAkhilesh Sanikop
388*09537850SAkhilesh Sanikop // libgav1 should have released all the reference frames now.
389*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
390*09537850SAkhilesh Sanikop
391*09537850SAkhilesh Sanikop // Now, the decoder is ready to accept a new coded video sequence. But, we
392*09537850SAkhilesh Sanikop // try to enqueue a frame that does not have a sequence header (which is not
393*09537850SAkhilesh Sanikop // allowed).
394*09537850SAkhilesh Sanikop
395*09537850SAkhilesh Sanikop // Enqueue frame2 for decoding.
396*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2, sizeof(kFrame2), 0,
397*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2);
398*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
399*09537850SAkhilesh Sanikop
400*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
401*09537850SAkhilesh Sanikop
402*09537850SAkhilesh Sanikop // Dequeue the output of frame2 (this will fail since no sequence header has
403*09537850SAkhilesh Sanikop // been seen since the last EOS signal).
404*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
405*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusBitstreamError);
406*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame2);
407*09537850SAkhilesh Sanikop
408*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
409*09537850SAkhilesh Sanikop
410*09537850SAkhilesh Sanikop Libgav1DecoderDestroy(test.decoder);
411*09537850SAkhilesh Sanikop test.decoder = NULL;
412*09537850SAkhilesh Sanikop }
413*09537850SAkhilesh Sanikop
DecoderTestMetadataObu(void)414*09537850SAkhilesh Sanikop static void DecoderTestMetadataObu(void) {
415*09537850SAkhilesh Sanikop DecoderTest test;
416*09537850SAkhilesh Sanikop DecoderTestInit(&test);
417*09537850SAkhilesh Sanikop DecoderTestSetUp(&test);
418*09537850SAkhilesh Sanikop
419*09537850SAkhilesh Sanikop Libgav1StatusCode status;
420*09537850SAkhilesh Sanikop const Libgav1DecoderBuffer* buffer;
421*09537850SAkhilesh Sanikop
422*09537850SAkhilesh Sanikop // Enqueue frame1 for decoding.
423*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame1WithHdrCllAndHdrMdcv,
424*09537850SAkhilesh Sanikop sizeof(kFrame1WithHdrCllAndHdrMdcv), 0,
425*09537850SAkhilesh Sanikop (uint8_t*)&kFrame1WithHdrCllAndHdrMdcv);
426*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
427*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
428*09537850SAkhilesh Sanikop
429*09537850SAkhilesh Sanikop // Dequeue the output of frame1.
430*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
431*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
432*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
433*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_hdr_cll, 1);
434*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_hdr_mdcv, 1);
435*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_itut_t35, 0);
436*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame1WithHdrCllAndHdrMdcv);
437*09537850SAkhilesh Sanikop
438*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
439*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
440*09537850SAkhilesh Sanikop
441*09537850SAkhilesh Sanikop // Enqueue frame2 for decoding.
442*09537850SAkhilesh Sanikop status = Libgav1DecoderEnqueueFrame(test.decoder, kFrame2WithItutT35,
443*09537850SAkhilesh Sanikop sizeof(kFrame2WithItutT35), 0,
444*09537850SAkhilesh Sanikop (uint8_t*)&kFrame2WithItutT35);
445*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
446*09537850SAkhilesh Sanikop
447*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 1);
448*09537850SAkhilesh Sanikop
449*09537850SAkhilesh Sanikop // Dequeue the output of frame2.
450*09537850SAkhilesh Sanikop status = Libgav1DecoderDequeueFrame(test.decoder, &buffer);
451*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
452*09537850SAkhilesh Sanikop ASSERT_NE(buffer, NULL);
453*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_hdr_cll, 0);
454*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_hdr_mdcv, 0);
455*09537850SAkhilesh Sanikop ASSERT_EQ(buffer->has_itut_t35, 1);
456*09537850SAkhilesh Sanikop ASSERT_NE(buffer->itut_t35.payload_bytes, NULL);
457*09537850SAkhilesh Sanikop ASSERT_NE(buffer->itut_t35.payload_size, 0);
458*09537850SAkhilesh Sanikop ASSERT_EQ(test.released_input_buffer, &kFrame2WithItutT35);
459*09537850SAkhilesh Sanikop
460*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 2);
461*09537850SAkhilesh Sanikop ASSERT_EQ(test.buffer_private_data, buffer->buffer_private_data);
462*09537850SAkhilesh Sanikop
463*09537850SAkhilesh Sanikop status = Libgav1DecoderSignalEOS(test.decoder);
464*09537850SAkhilesh Sanikop ASSERT_EQ(status, kLibgav1StatusOk);
465*09537850SAkhilesh Sanikop ASSERT_EQ(test.frames_in_use, 0);
466*09537850SAkhilesh Sanikop
467*09537850SAkhilesh Sanikop Libgav1DecoderDestroy(test.decoder);
468*09537850SAkhilesh Sanikop }
469*09537850SAkhilesh Sanikop
main(void)470*09537850SAkhilesh Sanikop int main(void) {
471*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest started\n");
472*09537850SAkhilesh Sanikop DecoderTestAPIFlowForNonFrameParallelMode();
473*09537850SAkhilesh Sanikop DecoderTestNonFrameParallelModeEnqueueMultipleFramesWithoutDequeuing();
474*09537850SAkhilesh Sanikop DecoderTestNonFrameParallelModeEOSBeforeDequeuingLastFrame();
475*09537850SAkhilesh Sanikop DecoderTestNonFrameParallelModeInvalidFrameAfterEOS();
476*09537850SAkhilesh Sanikop DecoderTestMetadataObu();
477*09537850SAkhilesh Sanikop fprintf(stderr, "C DecoderTest passed\n");
478*09537850SAkhilesh Sanikop return 0;
479*09537850SAkhilesh Sanikop }
480