OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 template <typename T> | 36 template <typename T> |
37 void TestConfigConvertExtraData( | 37 void TestConfigConvertExtraData( |
38 AVStream* stream, | 38 AVStream* stream, |
39 T* decoder_config, | 39 T* decoder_config, |
40 const base::Callback<bool(const AVStream*, T*)>& converter_fn) { | 40 const base::Callback<bool(const AVStream*, T*)>& converter_fn) { |
41 // Should initially convert. | 41 // Should initially convert. |
42 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); | 42 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); |
43 | 43 |
44 // Store orig to let FFmpeg free whatever it allocated. | 44 // Store orig to let FFmpeg free whatever it allocated. |
45 AVCodecContext* codec_context = stream->codec; | 45 AVCodecParameters* codec_parameters = stream->codecpar; |
46 uint8_t* orig_extradata = codec_context->extradata; | 46 uint8_t* orig_extradata = codec_parameters->extradata; |
47 int orig_extradata_size = codec_context->extradata_size; | 47 int orig_extradata_size = codec_parameters->extradata_size; |
48 | 48 |
49 // Valid combination: extra_data = NULL && size = 0. | 49 // Valid combination: extra_data = nullptr && size = 0. |
50 codec_context->extradata = NULL; | 50 codec_parameters->extradata = nullptr; |
51 codec_context->extradata_size = 0; | 51 codec_parameters->extradata_size = 0; |
52 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); | 52 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); |
53 EXPECT_EQ(static_cast<size_t>(codec_context->extradata_size), | 53 EXPECT_EQ(static_cast<size_t>(codec_parameters->extradata_size), |
54 decoder_config->extra_data().size()); | 54 decoder_config->extra_data().size()); |
55 | 55 |
56 // Valid combination: extra_data = non-NULL && size > 0. | 56 // Valid combination: extra_data = non-nullptr && size > 0. |
57 codec_context->extradata = &kExtraData[0]; | 57 codec_parameters->extradata = &kExtraData[0]; |
58 codec_context->extradata_size = arraysize(kExtraData); | 58 codec_parameters->extradata_size = arraysize(kExtraData); |
59 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); | 59 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); |
60 EXPECT_EQ(static_cast<size_t>(codec_context->extradata_size), | 60 EXPECT_EQ(static_cast<size_t>(codec_parameters->extradata_size), |
61 decoder_config->extra_data().size()); | 61 decoder_config->extra_data().size()); |
62 EXPECT_EQ(0, memcmp(codec_context->extradata, | 62 EXPECT_EQ( |
63 &decoder_config->extra_data()[0], | 63 0, memcmp(codec_parameters->extradata, &decoder_config->extra_data()[0], |
64 decoder_config->extra_data().size())); | 64 decoder_config->extra_data().size())); |
65 | 65 |
66 // Invalid combination: extra_data = NULL && size != 0. | 66 // Possible combination: extra_data = nullptr && size != 0, but the converter |
67 codec_context->extradata = NULL; | 67 // function considers this valid and having no extra_data, due to behavior of |
68 codec_context->extradata_size = 10; | 68 // avcodec_parameters_to_context(). |
69 EXPECT_FALSE(converter_fn.Run(stream, decoder_config)); | 69 codec_parameters->extradata = nullptr; |
| 70 codec_parameters->extradata_size = 10; |
| 71 EXPECT_TRUE(converter_fn.Run(stream, decoder_config)); |
| 72 EXPECT_EQ(0UL, decoder_config->extra_data().size()); |
70 | 73 |
71 // Invalid combination: extra_data = non-NULL && size = 0. | 74 // Invalid combination: extra_data = non-nullptr && size = 0. |
72 codec_context->extradata = &kExtraData[0]; | 75 codec_parameters->extradata = &kExtraData[0]; |
73 codec_context->extradata_size = 0; | 76 codec_parameters->extradata_size = 0; |
74 EXPECT_FALSE(converter_fn.Run(stream, decoder_config)); | 77 EXPECT_FALSE(converter_fn.Run(stream, decoder_config)); |
75 | 78 |
76 // Restore orig values for sane cleanup. | 79 // Restore orig values for sane cleanup. |
77 codec_context->extradata = orig_extradata; | 80 codec_parameters->extradata = orig_extradata; |
78 codec_context->extradata_size = orig_extradata_size; | 81 codec_parameters->extradata_size = orig_extradata_size; |
79 } | 82 } |
80 | 83 |
81 TEST_F(FFmpegCommonTest, AVStreamToDecoderConfig) { | 84 TEST_F(FFmpegCommonTest, AVStreamToDecoderConfig) { |
82 // Open a file to get a real AVStreams from FFmpeg. | 85 // Open a file to get a real AVStreams from FFmpeg. |
83 base::MemoryMappedFile file; | 86 base::MemoryMappedFile file; |
84 file.Initialize(GetTestDataFilePath("bear-320x240.webm")); | 87 file.Initialize(GetTestDataFilePath("bear-320x240.webm")); |
85 InMemoryUrlProtocol protocol(file.data(), file.length(), false); | 88 InMemoryUrlProtocol protocol(file.data(), file.length(), false); |
86 FFmpegGlue glue(&protocol); | 89 FFmpegGlue glue(&protocol); |
87 ASSERT_TRUE(glue.OpenContext()); | 90 ASSERT_TRUE(glue.OpenContext()); |
88 AVFormatContext* format_context = glue.format_context(); | 91 AVFormatContext* format_context = glue.format_context(); |
89 | 92 |
90 // Find the audio and video streams and test valid and invalid combinations | 93 // Find the audio and video streams and test valid and invalid combinations |
91 // for extradata and extradata_size. | 94 // for extradata and extradata_size. |
92 bool found_audio = false; | 95 bool found_audio = false; |
93 bool found_video = false; | 96 bool found_video = false; |
94 for (size_t i = 0; | 97 for (size_t i = 0; |
95 i < format_context->nb_streams && (!found_audio || !found_video); | 98 i < format_context->nb_streams && (!found_audio || !found_video); |
96 ++i) { | 99 ++i) { |
97 AVStream* stream = format_context->streams[i]; | 100 AVStream* stream = format_context->streams[i]; |
98 AVCodecContext* codec_context = stream->codec; | 101 AVCodecParameters* codec_parameters = stream->codecpar; |
99 AVMediaType codec_type = codec_context->codec_type; | 102 AVMediaType codec_type = codec_parameters->codec_type; |
100 | 103 |
101 if (codec_type == AVMEDIA_TYPE_AUDIO) { | 104 if (codec_type == AVMEDIA_TYPE_AUDIO) { |
102 if (found_audio) | 105 if (found_audio) |
103 continue; | 106 continue; |
104 found_audio = true; | 107 found_audio = true; |
105 AudioDecoderConfig audio_config; | 108 AudioDecoderConfig audio_config; |
106 TestConfigConvertExtraData(stream, &audio_config, | 109 TestConfigConvertExtraData(stream, &audio_config, |
107 base::Bind(&AVStreamToAudioDecoderConfig)); | 110 base::Bind(&AVStreamToAudioDecoderConfig)); |
108 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { | 111 } else if (codec_type == AVMEDIA_TYPE_VIDEO) { |
109 if (found_video) | 112 if (found_video) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Have FFMpeg compute the size of a buffer of 1 channel / 1 frame | 180 // Have FFMpeg compute the size of a buffer of 1 channel / 1 frame |
178 // with 1 byte alignment to make sure the sizes match. | 181 // with 1 byte alignment to make sure the sizes match. |
179 int single_buffer_size = | 182 int single_buffer_size = |
180 av_samples_get_buffer_size(NULL, 1, 1, format, 1); | 183 av_samples_get_buffer_size(NULL, 1, 1, format, 1); |
181 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format); | 184 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format); |
182 EXPECT_EQ(bytes_per_channel, single_buffer_size); | 185 EXPECT_EQ(bytes_per_channel, single_buffer_size); |
183 } | 186 } |
184 } | 187 } |
185 } | 188 } |
186 | 189 |
187 TEST_F(FFmpegCommonTest, UTCDateToTime_Valid) { | |
188 base::Time result; | |
189 EXPECT_TRUE(FFmpegUTCDateToTime("2012-11-10 12:34:56", &result)); | |
190 | |
191 base::Time::Exploded exploded; | |
192 result.UTCExplode(&exploded); | |
193 EXPECT_TRUE(exploded.HasValidValues()); | |
194 EXPECT_EQ(2012, exploded.year); | |
195 EXPECT_EQ(11, exploded.month); | |
196 EXPECT_EQ(6, exploded.day_of_week); | |
197 EXPECT_EQ(10, exploded.day_of_month); | |
198 EXPECT_EQ(12, exploded.hour); | |
199 EXPECT_EQ(34, exploded.minute); | |
200 EXPECT_EQ(56, exploded.second); | |
201 EXPECT_EQ(0, exploded.millisecond); | |
202 } | |
203 | |
204 TEST_F(FFmpegCommonTest, UTCDateToTime_Invalid) { | |
205 const char* invalid_date_strings[] = { | |
206 "", | |
207 "2012-11-10", | |
208 "12:34:56", | |
209 "-- ::", | |
210 "2012-11-10 12:34:", | |
211 "2012-11-10 12::56", | |
212 "2012-11-10 :34:56", | |
213 "2012-11- 12:34:56", | |
214 "2012--10 12:34:56", | |
215 "-11-10 12:34:56", | |
216 "2012-11 12:34:56", | |
217 "2012-11-10-12 12:34:56", | |
218 "2012-11-10 12:34", | |
219 "2012-11-10 12:34:56:78", | |
220 "ABCD-11-10 12:34:56", | |
221 "2012-EF-10 12:34:56", | |
222 "2012-11-GH 12:34:56", | |
223 "2012-11-10 IJ:34:56", | |
224 "2012-11-10 12:JL:56", | |
225 "2012-11-10 12:34:MN", | |
226 "2012-11-10 12:34:56.123", | |
227 "2012-11-1012:34:56", | |
228 "2012-11-10 12:34:56 UTC", | |
229 }; | |
230 | |
231 for (size_t i = 0; i < arraysize(invalid_date_strings); ++i) { | |
232 const char* date_string = invalid_date_strings[i]; | |
233 base::Time result; | |
234 EXPECT_FALSE(FFmpegUTCDateToTime(date_string, &result)) | |
235 << "date_string '" << date_string << "'"; | |
236 EXPECT_TRUE(result.is_null()); | |
237 } | |
238 } | |
239 | |
240 // Verifies there are no collisions of the codec name hashes used for UMA. Also | 190 // Verifies there are no collisions of the codec name hashes used for UMA. Also |
241 // includes code for updating the histograms XML. | 191 // includes code for updating the histograms XML. |
242 TEST_F(FFmpegCommonTest, VerifyUmaCodecHashes) { | 192 TEST_F(FFmpegCommonTest, VerifyUmaCodecHashes) { |
243 const AVCodecDescriptor* desc = avcodec_descriptor_next(nullptr); | 193 const AVCodecDescriptor* desc = avcodec_descriptor_next(nullptr); |
244 | 194 |
245 std::map<int32_t, const char*> sorted_hashes; | 195 std::map<int32_t, const char*> sorted_hashes; |
246 while (desc) { | 196 while (desc) { |
247 const int32_t hash = HashCodecName(desc->name); | 197 const int32_t hash = HashCodecName(desc->name); |
248 // Ensure there are no collisions. | 198 // Ensure there are no collisions. |
249 ASSERT_TRUE(sorted_hashes.find(hash) == sorted_hashes.end()); | 199 ASSERT_TRUE(sorted_hashes.find(hash) == sorted_hashes.end()); |
(...skipping 14 matching lines...) Expand all Loading... |
264 // values; diff should verify. | 214 // values; diff should verify. |
265 #if 0 | 215 #if 0 |
266 printf("<enum name=\"FFmpegCodecHashes\" type=\"int\">\n"); | 216 printf("<enum name=\"FFmpegCodecHashes\" type=\"int\">\n"); |
267 for (const auto& kv : sorted_hashes) | 217 for (const auto& kv : sorted_hashes) |
268 printf(" <int value=\"%d\" label=\"%s\"/>\n", kv.first, kv.second); | 218 printf(" <int value=\"%d\" label=\"%s\"/>\n", kv.first, kv.second); |
269 printf("</enum>\n"); | 219 printf("</enum>\n"); |
270 #endif | 220 #endif |
271 } | 221 } |
272 | 222 |
273 } // namespace media | 223 } // namespace media |
OLD | NEW |