1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
6 #include "base/files/memory_mapped_file.h"
7 #include "base/path_service.h"
8 #include "media/base/test_data_util.h"
9 #include "media/filters/jpeg_parser.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(JpegParserTest
, Parsing
) {
15 base::FilePath data_dir
;
16 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT
, &data_dir
));
18 // This sample frame is captured from Chromebook Pixel
19 base::FilePath file_path
= data_dir
.AppendASCII("media")
22 .AppendASCII("pixel-1280x720.jpg");
24 base::MemoryMappedFile stream
;
25 ASSERT_TRUE(stream
.Initialize(file_path
))
26 << "Couldn't open stream file: " << file_path
.MaybeAsASCII();
28 JpegParseResult result
;
29 ASSERT_TRUE(ParseJpegPicture(stream
.data(), stream
.length(), &result
));
31 // Verify selected fields
34 EXPECT_EQ(1280, result
.frame_header
.visible_width
);
35 EXPECT_EQ(720, result
.frame_header
.visible_height
);
36 EXPECT_EQ(3, result
.frame_header
.num_components
);
37 EXPECT_EQ(1, result
.frame_header
.components
[0].id
);
38 EXPECT_EQ(2, result
.frame_header
.components
[0].horizontal_sampling_factor
);
39 EXPECT_EQ(1, result
.frame_header
.components
[0].vertical_sampling_factor
);
40 EXPECT_EQ(0, result
.frame_header
.components
[0].quantization_table_selector
);
41 EXPECT_EQ(2, result
.frame_header
.components
[1].id
);
42 EXPECT_EQ(1, result
.frame_header
.components
[1].horizontal_sampling_factor
);
43 EXPECT_EQ(1, result
.frame_header
.components
[1].vertical_sampling_factor
);
44 EXPECT_EQ(1, result
.frame_header
.components
[1].quantization_table_selector
);
45 EXPECT_EQ(3, result
.frame_header
.components
[2].id
);
46 EXPECT_EQ(1, result
.frame_header
.components
[2].horizontal_sampling_factor
);
47 EXPECT_EQ(1, result
.frame_header
.components
[2].vertical_sampling_factor
);
48 EXPECT_EQ(1, result
.frame_header
.components
[2].quantization_table_selector
);
51 EXPECT_EQ(0, result
.restart_interval
);
54 EXPECT_TRUE(result
.q_table
[0].valid
);
55 EXPECT_TRUE(result
.q_table
[1].valid
);
56 EXPECT_FALSE(result
.q_table
[2].valid
);
57 EXPECT_FALSE(result
.q_table
[3].valid
);
59 // DHT fields (no DHT marker)
60 EXPECT_FALSE(result
.dc_table
[0].valid
);
61 EXPECT_FALSE(result
.ac_table
[0].valid
);
62 EXPECT_FALSE(result
.dc_table
[1].valid
);
63 EXPECT_FALSE(result
.ac_table
[1].valid
);
66 EXPECT_EQ(3, result
.scan
.num_components
);
67 EXPECT_EQ(1, result
.scan
.components
[0].component_selector
);
68 EXPECT_EQ(0, result
.scan
.components
[0].dc_selector
);
69 EXPECT_EQ(0, result
.scan
.components
[0].ac_selector
);
70 EXPECT_EQ(2, result
.scan
.components
[1].component_selector
);
71 EXPECT_EQ(1, result
.scan
.components
[1].dc_selector
);
72 EXPECT_EQ(1, result
.scan
.components
[1].ac_selector
);
73 EXPECT_EQ(3, result
.scan
.components
[2].component_selector
);
74 EXPECT_EQ(1, result
.scan
.components
[2].dc_selector
);
75 EXPECT_EQ(1, result
.scan
.components
[2].ac_selector
);
76 EXPECT_EQ(121150u, result
.data_size
);
79 TEST(JpegParserTest
, ParsingFail
) {
80 const uint8_t data
[] = {0, 1, 2, 3}; // not jpeg
81 JpegParseResult result
;
82 ASSERT_FALSE(ParseJpegPicture(data
, sizeof(data
), &result
));