1 /* Gstreamer
2  * Copyright (C) 2013-2014 Intel Corporation
3  *    Author: Halley Zhao <halley.zhao@intel.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <gst/check/gstcheck.h>
22 #include <gst/codecparsers/gstvp8parser.h>
23 
24 /* A key frame data */
25 static const guint8 vp8_frame_data_0[] = {
26   0x50, 0x1d, 0x00, 0x9d, 0x01, 0x2a, 0xb0, 0x00, 0x90, 0x00, 0x00, 0x07,
27   0x08, 0x85, 0x85, 0x88, 0x85, 0x84, 0x88, 0x02, 0x02, 0x03, 0x55, 0xd2,
28   0x82, 0xf1, 0x8e, 0xd1, 0x00, 0x13, 0xee, 0x83, 0x17, 0x70, 0xd0, 0xf8,
29   0x34, 0xdc, 0x9e, 0x9a, 0x6f, 0x7a, 0x6b, 0xb0, 0x26, 0x33, 0xf7, 0xe1,
30   0xba, 0x59, 0xef, 0x1e, 0x97, 0xe6, 0xc4, 0x4e, 0x49, 0x72, 0x22, 0x6d,
31   0x72, 0x1a, 0xeb, 0x53, 0x48, 0x32, 0x3a, 0x22, 0x44, 0x5a, 0x61, 0xc5,
32   0x1f, 0xd8, 0xb2, 0xf3, 0x3c, 0xb6, 0x40, 0x7b, 0x7b, 0x83, 0x74, 0xb8,
33   0x56, 0xfb, 0xdc, 0xac, 0x00, 0x01, 0x55, 0xfc, 0x9d, 0xda, 0x9c, 0x5f,
34   0xf0, 0xfe, 0x7a, 0xf1, 0xc4, 0x9a, 0xa9, 0x04, 0x0a, 0xfd, 0x51, 0xe2,
35   0xca, 0x64, 0x57, 0xda, 0x5c, 0x0c, 0x16, 0x95, 0x54, 0x79, 0x48, 0xdc,
36   0x2c, 0x26, 0xf9, 0x27, 0x52, 0x1f, 0xc2, 0xd6, 0x6e, 0xdc, 0xa6, 0xae,
37   0x95, 0x02, 0xff, 0xaf, 0xa7, 0xdd, 0xa1, 0xb1, 0x7e, 0x03, 0x8d, 0x98,
38   0x14, 0x6c, 0x80, 0x39, 0x86, 0x65, 0x13, 0x33, 0xad, 0xdc, 0x2e, 0x84,
39   0xaa, 0xa8, 0xaa, 0xe4, 0x93, 0x10, 0x18, 0xca, 0x31, 0xe8, 0xa2, 0x1b,
40   0x49, 0x9e, 0xc0, 0xe2, 0x94, 0xc6, 0x80, 0x70, 0xe0, 0xf8, 0x41, 0x91,
41   0x92, 0xc4, 0xab, 0xf1, 0x46, 0xde, 0x8b, 0xfe, 0x3c, 0x3e, 0x2d, 0xc0,
42   0xb4, 0x90, 0xc3, 0x62, 0xef, 0xc7, 0xfb, 0x8f, 0xe0, 0x13, 0x79, 0x0f,
43   0x52, 0x64, 0xfb, 0x2b, 0x65, 0x17, 0x6f, 0x25, 0x2a, 0x9c, 0xfb, 0x98,
44   0x86, 0xb4, 0x09, 0x8b, 0x37, 0x67, 0x54, 0x32, 0x7e, 0xcc, 0x07, 0xff,
45   0xb4, 0x15, 0xd0, 0x11, 0x30, 0x2e, 0x0f, 0x12, 0xc9, 0xff, 0xfd, 0x9b,
46   0x69, 0x44, 0x65, 0x60, 0xfe, 0xff, 0xab, 0x52, 0x8a, 0x9a, 0x31, 0xbd,
47   0xcc, 0x8d, 0x1e, 0x31, 0x35, 0x8a, 0x27, 0x32, 0x9d, 0xd2, 0xca, 0xc8,
48   0x26, 0x0a, 0xe2, 0x4a, 0x12, 0xba, 0x3b, 0x8b, 0x89, 0xa1, 0x3b, 0x05,
49   0x54, 0x96, 0xcc, 0xe6, 0x6a, 0x56, 0x3e, 0xcd, 0xd6, 0x13, 0x46, 0x40,
50   0x21, 0x64, 0x0b, 0xa3, 0xf9, 0x0a, 0x9a, 0xb4, 0x66, 0xe3, 0x5b, 0x36,
51   0xea, 0x0a, 0x56, 0xbf, 0xf3, 0xac, 0x42, 0xcd, 0x7a, 0x36, 0xce, 0xc3,
52   0x4b, 0x15, 0x6b, 0xdb, 0x6e, 0x23, 0x94, 0x69, 0x44, 0xd4, 0x42, 0x51,
53   0x8f, 0x21, 0x41, 0x4a, 0x24, 0x15, 0x0d, 0xea, 0x3b, 0x5f, 0xdd, 0xc2,
54   0xf1, 0x0f, 0x9b, 0x73, 0x49, 0x3e, 0x82, 0x16, 0x44, 0x77, 0x0f, 0x80,
55   0x35, 0x04, 0x1a, 0x7f, 0xb3, 0x17, 0xac, 0xf9, 0x38, 0xc9, 0x57, 0x74,
56   0xcd, 0x03, 0x95, 0xbb, 0xec, 0xe4, 0x53, 0x2a, 0x6f, 0xf1, 0x51, 0x12,
57   0xd7, 0x78, 0xaf, 0x3a, 0x77, 0x86, 0x21, 0xfa, 0xa8, 0x05, 0x99, 0x9a,
58   0xc8, 0x9b, 0x4e, 0x72, 0xc9, 0xd5, 0x75, 0x7e, 0x7f, 0x09, 0xdf, 0x02,
59   0x70, 0x59, 0xc4, 0x28, 0x04, 0x88, 0x4f, 0x59, 0xe8, 0x30, 0xc9, 0x66,
60   0xa2, 0x51, 0xef, 0x40, 0xc5, 0xbc, 0xac, 0x74, 0x03, 0xff, 0x6a, 0xb2,
61   0xd4, 0x1a, 0x3b, 0x2c, 0x4a, 0x66, 0xa8, 0xed, 0x18, 0x62, 0x93, 0x4a,
62   0xcb, 0x07, 0x86, 0x7b, 0x70, 0x0f, 0xb0, 0x5e, 0xa6, 0xdd, 0xe1, 0x1a,
63   0x99, 0xd3, 0x2a, 0xf7, 0x98, 0x06, 0x93, 0xbf, 0xa7, 0x8e, 0x13, 0x50,
64   0x44, 0xbc, 0xce, 0x36, 0x17, 0x1b, 0x1f, 0x15, 0xb3, 0x22, 0x3e, 0xd9,
65   0x88, 0xe3, 0xa4, 0xa1, 0x60, 0xde, 0x37, 0x53, 0x0b, 0xbe, 0x0c, 0xe8,
66   0xd0, 0xfa, 0xdd, 0x1f, 0xa6, 0xda, 0xf7, 0xb3, 0x97, 0x44, 0xf1, 0x23,
67   0x29, 0xee, 0xbf, 0xf6, 0xf2, 0x1d, 0xd8, 0x58, 0x20, 0xd7, 0x77, 0xa6,
68   0xf9, 0xb0, 0x6b, 0xcd, 0xda, 0x06, 0xc0, 0x2f, 0x50, 0x95, 0xc6, 0x07,
69   0x2a, 0xbf, 0x46, 0x27, 0x59, 0x52, 0xc3, 0xc7, 0xe6, 0xd7, 0xcb, 0x00,
70   0x53, 0x76, 0x3e, 0x44, 0x4f, 0xab, 0x4d, 0xbd, 0xff, 0x5d, 0xea, 0xf3,
71   0xa9, 0x14, 0x0e, 0x4d, 0xb9, 0xe4, 0xde, 0x9e, 0xb0, 0xa7, 0xf1, 0x41,
72   0x79, 0x30, 0xa4, 0xa8, 0x2e, 0xb5, 0x42, 0x40, 0x08, 0xf8, 0x00, 0xbf,
73   0xdc, 0xe4, 0xe0, 0xff, 0x54, 0x1b, 0x34, 0xe2, 0xed, 0x2c, 0x03, 0x96,
74   0x9e, 0xb9, 0xea, 0x6d, 0x46, 0xa9, 0x51, 0x6c, 0xff, 0xa2, 0xd1, 0x84,
75   0x0b, 0xa9, 0xd5, 0xd2, 0xb5, 0x08, 0x62, 0x17, 0x7f, 0x5c, 0xcc, 0xdb,
76   0x5c, 0x2b, 0xe1, 0x2a, 0x6d, 0x45, 0xf8, 0xf0, 0x32, 0x58, 0xb4, 0xc8,
77   0x36, 0x2c, 0xa6, 0x1b, 0xc4, 0x87, 0x4d, 0x29, 0xe6, 0x2f, 0x3b, 0x2e,
78   0xd2, 0x80, 0x75, 0xf9, 0x81, 0x22, 0x2e, 0x5e, 0x61, 0xf7, 0xac, 0xb0,
79   0xb6, 0x35, 0xd8, 0x38, 0xa8, 0xf4, 0xef, 0xac, 0xe7, 0x3a, 0x87, 0xff,
80   0x0d, 0x84, 0x94, 0x4c, 0x6d, 0x81, 0x01, 0xd0, 0x83, 0x65, 0x16, 0x57,
81   0xb4, 0x6c, 0x8e, 0x00,
82 };
83 
84 /* An inter frame data */
85 static const guint8 vp8_frame_data_1[] = {
86   0x51, 0x0c, 0x00, 0x00, 0x10, 0x10, 0x00, 0x1e, 0xcb, 0x03, 0xdc, 0xc3,
87   0xed, 0xef, 0x1d, 0x30, 0xe3, 0x45, 0xc8, 0x86, 0xa6, 0xa4, 0x9c, 0x8e,
88   0x72, 0xee, 0xae, 0x46, 0x79, 0x53, 0x58, 0x0b, 0x01, 0xb1, 0xf4, 0x06,
89   0x5c, 0xc0, 0x18, 0xb8, 0x2b, 0xa0, 0x00, 0x3f, 0x06, 0x9a, 0x28, 0x55,
90   0x3b, 0x5f, 0x2b, 0x02, 0x14, 0x03, 0x93, 0xdf, 0x09, 0xe3, 0x22, 0x23,
91   0x53, 0xd3, 0xa8, 0x84, 0x34, 0x05, 0x0d, 0xec, 0xa9, 0x49, 0x72, 0xee,
92   0x9f, 0x4a, 0x0e, 0xbe, 0x98, 0xbc, 0x01, 0x08, 0x9e, 0xd5, 0x6a, 0xb2,
93   0x47, 0x0c, 0x19, 0xe0, 0x60, 0x3e, 0x3c, 0x75, 0xef, 0x65, 0xc6, 0x6c,
94   0x4f, 0xdb, 0x05, 0x38, 0x40, 0xfd, 0xe0, 0x05, 0x6b, 0xb5, 0x02, 0xc3,
95   0xeb, 0x8e, 0x18, 0x64, 0xf9, 0xe7, 0x7c, 0x98, 0x43, 0x2a, 0x5a, 0x80,
96   0xfb, 0xea, 0x20, 0x08, 0x98, 0x56, 0x73, 0x16, 0x26, 0x38, 0x5f, 0x3a,
97   0x7b, 0x7e, 0xf3, 0x0f, 0xe3, 0xbb, 0xa8, 0x76, 0x58, 0xbc, 0xb6, 0xfd,
98   0xa2, 0x66, 0xdb, 0xff, 0x84, 0x61, 0x29, 0xf4, 0x93, 0x23, 0x7e, 0x78,
99   0x4c, 0x1c, 0x31, 0x45, 0xb4, 0x1a, 0xa7, 0x0e, 0x1c, 0xaa, 0x7a, 0xdd,
100   0x85, 0xda, 0xe5, 0xa8, 0x92, 0xca, 0x81, 0xac, 0x72, 0x5d, 0xa1, 0x12,
101   0x18, 0xf9, 0xee, 0xfd, 0x31, 0xf3, 0xdf, 0x4b, 0x87, 0x75, 0x80, 0x2c,
102   0x12, 0x03, 0xb6, 0x1f, 0x08, 0x3c, 0x7b, 0x32, 0x89, 0xe1, 0xae, 0xa6,
103   0x41, 0x43, 0x4d, 0xd6, 0xbb, 0x0d, 0x9c, 0x9d, 0x36, 0x35, 0xc5, 0xa7,
104   0xf8, 0xec, 0x18, 0xd2, 0x12, 0x9b, 0x90, 0x84, 0x9c, 0xd8, 0x92, 0x7e,
105   0xe9, 0xba, 0x97, 0x53, 0x53, 0xcb, 0x07, 0xda, 0x81, 0xd0, 0x5f, 0xd6,
106   0x87, 0x94, 0x64, 0xb9, 0xca, 0x33, 0x2c, 0xb8, 0x14, 0x04, 0x13, 0xe4,
107   0x1b, 0xe3, 0xb5, 0x1f, 0xcb, 0xfc, 0xf1, 0x79, 0xc6, 0xc6, 0x32, 0xcf,
108   0x28, 0x2e, 0x05, 0x8a, 0xe4, 0x57, 0x08, 0x23, 0xd7, 0x31, 0xef, 0x81,
109   0x8a, 0x0a, 0xab, 0x2e, 0x80, 0x1e, 0x4a, 0x95, 0x78, 0x69, 0xed, 0xf6,
110   0x00, 0x55, 0x5c, 0x38, 0x1f, 0x8c, 0xd9, 0x6e, 0x6c, 0x1e, 0xce, 0x1c,
111   0xa4, 0xf9, 0x1d, 0xff, 0xe6, 0xcd, 0x66, 0xc3, 0x35, 0xe8, 0x84, 0xd7,
112   0xe4, 0xac, 0xbf, 0x5b, 0x6f, 0x32, 0x7e, 0x55, 0x66, 0xb2, 0xa8, 0x1e,
113   0x8b, 0xcb, 0x70, 0xcf, 0xa1, 0x63, 0xd4, 0xa8, 0xb1, 0xc0, 0x1f, 0xa6,
114   0xbf, 0xcf, 0x6b, 0xaf, 0xb4, 0xbc, 0x38, 0x12, 0xbc, 0x1e, 0x72, 0x48,
115   0x7d, 0xc9, 0xc9, 0xe9, 0x28, 0xd0, 0xcd, 0xe3, 0xf5, 0x45, 0x91, 0xad,
116   0x7b, 0xba, 0x5b, 0x10, 0xd3, 0x85, 0xad, 0x49, 0x15, 0xf6, 0x89, 0x3e,
117   0x50, 0x21, 0x18, 0xdc, 0x4e, 0xce, 0xbd, 0x6c, 0xe9, 0xa9, 0x40, 0xf3,
118   0x78, 0x97, 0xf9, 0x71, 0xe0, 0x18, 0x32, 0xad, 0xac, 0xf8, 0x3f, 0x42,
119   0xa7, 0x43, 0x2b, 0x32, 0xbd, 0xad, 0x77, 0xb5, 0x87, 0xf8, 0xe0, 0xfe,
120   0x7e, 0x93, 0xb7, 0xfe, 0x40, 0x19, 0x29, 0x4e, 0x4b, 0x80, 0x77, 0x0f,
121   0xa8, 0xc0, 0x17, 0xa1, 0xf1, 0xb8, 0x4f, 0x6c, 0xee, 0x08, 0xe6, 0x78,
122   0x98, 0x45, 0x71, 0xbf, 0xea, 0xe9, 0x34, 0x3a, 0x49, 0x44, 0xc8, 0xb1,
123   0x79, 0x5c, 0x14, 0x37, 0xf4, 0x77, 0xf8, 0x8f, 0xda, 0xe6, 0x8e, 0x6c,
124   0x20, 0xf7, 0x75, 0x35, 0x8c, 0x43, 0x49, 0x21, 0x34, 0xb0, 0x19, 0x16,
125   0x2f, 0x2b, 0x9a, 0x64, 0x8f, 0x39, 0x45, 0x9b, 0x7a, 0x27, 0x96, 0xc6,
126   0x4d, 0x95, 0xdc, 0x03, 0x6c, 0xea, 0xea, 0x60, 0xa8, 0x16, 0xb4, 0x24,
127   0xa6, 0x9a, 0x68, 0x49, 0xcb, 0xf2, 0x22, 0xb5, 0xda, 0x2d, 0xd2, 0x0c,
128   0xad, 0x57, 0xba, 0x5a, 0x8d, 0xa0, 0x0a, 0x98, 0x31, 0x64, 0xad, 0x9a,
129   0xa0, 0x6b, 0x40, 0xcd, 0x90, 0xba, 0x16, 0xc5, 0x22, 0x92, 0x70, 0x00,
130   0x0e, 0xfd, 0x70, 0x4a, 0x48, 0x58, 0xa7, 0xe6, 0x1c, 0x4a, 0xc3, 0x07,
131   0xe9, 0xe0, 0x39, 0x1e, 0x96, 0x38, 0x8c, 0x5e, 0xc1, 0x5b, 0x26, 0x43,
132   0xd9, 0xc0,
133 };
134 
GST_START_TEST(test_vp8_parse_key_frame)135 GST_START_TEST (test_vp8_parse_key_frame)
136 {
137   GstVp8Parser parser;
138   GstVp8FrameHdr frame_hdr;
139   GstVp8MbLfAdjustments *const adj = &parser.mb_lf_adjust;
140 
141   gst_vp8_parser_init (&parser);
142 
143   memset (&frame_hdr, 0, sizeof (frame_hdr));
144   assert_equals_int (gst_vp8_parser_parse_frame_header (&parser, &frame_hdr,
145           vp8_frame_data_0, sizeof (vp8_frame_data_0)), GST_VP8_PARSER_OK);
146 
147   assert_equals_int (frame_hdr.key_frame, 1);
148 
149   assert_equals_int (frame_hdr.first_part_size, 234);
150   assert_equals_int (frame_hdr.width, 176);
151   assert_equals_int (frame_hdr.height, 144);
152 
153   assert_equals_int (adj->loop_filter_adj_enable, 1);
154   assert_equals_int (adj->mode_ref_lf_delta_update, 1);
155 
156   assert_equals_int (adj->ref_frame_delta[0], 2);
157   assert_equals_int (adj->ref_frame_delta[1], 0);
158   assert_equals_int (adj->ref_frame_delta[2], -2);
159   assert_equals_int (adj->ref_frame_delta[3], -2);
160 
161   assert_equals_int (adj->mb_mode_delta[0], 4);
162   assert_equals_int (adj->mb_mode_delta[1], -2);
163   assert_equals_int (adj->mb_mode_delta[2], 2);
164   assert_equals_int (adj->mb_mode_delta[3], 4);
165 
166   assert_equals_int (frame_hdr.quant_indices.y_ac_qi, 4);
167   assert_equals_int (frame_hdr.mb_no_skip_coeff, 1);
168 
169   assert_equals_int (frame_hdr.rd_range, 0xe8);
170   assert_equals_int (frame_hdr.rd_value, 0x68);
171   assert_equals_int (frame_hdr.rd_count, 1);
172 }
173 
174 GST_END_TEST;
175 
GST_START_TEST(test_vp8_parse_inter_frame)176 GST_START_TEST (test_vp8_parse_inter_frame)
177 {
178   GstVp8Parser parser;
179   GstVp8FrameHdr frame_hdr;
180 
181   gst_vp8_parser_init (&parser);
182 
183   memset (&frame_hdr, 0, sizeof (frame_hdr));
184   assert_equals_int (gst_vp8_parser_parse_frame_header (&parser, &frame_hdr,
185           vp8_frame_data_0, sizeof (vp8_frame_data_0)), GST_VP8_PARSER_OK);
186 
187   memset (&frame_hdr, 0, sizeof (frame_hdr));
188   assert_equals_int (gst_vp8_parser_parse_frame_header (&parser, &frame_hdr,
189           vp8_frame_data_1, sizeof (vp8_frame_data_1)), GST_VP8_PARSER_OK);
190 
191   assert_equals_int (frame_hdr.key_frame, 0);
192 
193   assert_equals_int (frame_hdr.first_part_size, 98);
194 
195   assert_equals_int (parser.mb_lf_adjust.loop_filter_adj_enable, 1);
196   assert_equals_int (frame_hdr.quant_indices.y_ac_qi, 4);
197 
198   assert_equals_int (frame_hdr.refresh_entropy_probs, 1);
199   assert_equals_int (frame_hdr.refresh_last, 1);
200   assert_equals_int (frame_hdr.mb_no_skip_coeff, 1);
201 
202   assert_equals_int (frame_hdr.prob_skip_false, 131);
203   assert_equals_int (frame_hdr.prob_intra, 224);
204   assert_equals_int (frame_hdr.prob_last, 233);
205   assert_equals_int (frame_hdr.prob_gf, 1);
206 
207   assert_equals_int (frame_hdr.rd_range, 0x8e);
208   assert_equals_int (frame_hdr.rd_value, 0x85);
209   assert_equals_int (frame_hdr.rd_count, 5);
210 }
211 
212 GST_END_TEST;
213 
214 static Suite *
vp8parsers_suite(void)215 vp8parsers_suite (void)
216 {
217   Suite *s = suite_create ("VP8 Parser library");
218 
219   TCase *tc_chain = tcase_create ("general");
220 
221   suite_add_tcase (s, tc_chain);
222   tcase_add_test (tc_chain, test_vp8_parse_key_frame);
223   tcase_add_test (tc_chain, test_vp8_parse_inter_frame);
224 
225   return s;
226 }
227 
228 GST_CHECK_MAIN (vp8parsers);
229