Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: media/ffmpeg/ffmpeg_common_unittest.cc

Issue 2497603003: Roll src/third_party/ffmpeg/ 3c7a09882..cdf4accee (3188 commits). (Closed)
Patch Set: Rebase (liberato@'s pipeline_integration_test_base conflicted; using liberato@'s now here) Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 = NULL && size = 0.
50 codec_context->extradata = NULL; 50 codec_parameters->extradata = NULL;
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-NULL && 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 = NULL && 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 = NULL;
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-NULL && 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 190 TEST_F(FFmpegCommonTest, UTCDateToTime_Valid) {
188 base::Time result; 191 base::Time result;
189 EXPECT_TRUE(FFmpegUTCDateToTime("2012-11-10 12:34:56", &result)); 192 EXPECT_TRUE(FFmpegUTCDateToTime("2012-11-10T12:34:56.987654Z", &result));
190 193
191 base::Time::Exploded exploded; 194 base::Time::Exploded exploded;
192 result.UTCExplode(&exploded); 195 result.UTCExplode(&exploded);
193 EXPECT_TRUE(exploded.HasValidValues()); 196 EXPECT_TRUE(exploded.HasValidValues());
194 EXPECT_EQ(2012, exploded.year); 197 EXPECT_EQ(2012, exploded.year);
195 EXPECT_EQ(11, exploded.month); 198 EXPECT_EQ(11, exploded.month);
196 EXPECT_EQ(6, exploded.day_of_week); 199 EXPECT_EQ(6, exploded.day_of_week);
197 EXPECT_EQ(10, exploded.day_of_month); 200 EXPECT_EQ(10, exploded.day_of_month);
198 EXPECT_EQ(12, exploded.hour); 201 EXPECT_EQ(12, exploded.hour);
199 EXPECT_EQ(34, exploded.minute); 202 EXPECT_EQ(34, exploded.minute);
200 EXPECT_EQ(56, exploded.second); 203 EXPECT_EQ(56, exploded.second);
201 EXPECT_EQ(0, exploded.millisecond); 204 EXPECT_EQ(987, exploded.millisecond);
205
206 // base::Time exploding operations round fractional milliseconds down, so
207 // verify fractional milliseconds using a base::TimeDelta.
208 base::Time without_fractional_ms;
209 EXPECT_TRUE(base::Time::FromUTCExploded(exploded, &without_fractional_ms));
210 base::TimeDelta delta = result - without_fractional_ms;
211 EXPECT_EQ(654, delta.InMicroseconds());
202 } 212 }
203 213
204 TEST_F(FFmpegCommonTest, UTCDateToTime_Invalid) { 214 TEST_F(FFmpegCommonTest, UTCDateToTime_Invalid) {
205 const char* invalid_date_strings[] = { 215 const char* invalid_date_strings[] = {
206 "", 216 "",
207 "2012-11-10", 217 "2012-11-10 12:34:56",
208 "12:34:56", 218 "2012-11-10 12:34:56.987654Z",
209 "-- ::", 219 "2012-11-10T12:34:56",
210 "2012-11-10 12:34:", 220 "2012-11-10T12:34:56.98765Z",
211 "2012-11-10 12::56", 221 "2012-11-10T12:34:56.98765JZ",
212 "2012-11-10 :34:56", 222 "2012-11-10T12:34:56.987654Z3",
213 "2012-11- 12:34:56", 223 "2012-11-10T12:34:56.987654ZZ",
214 "2012--10 12:34:56", 224 "2012-11-10T12:34:56.987654Z.987654Z",
215 "-11-10 12:34:56", 225 "2012-11-10",
216 "2012-11 12:34:56", 226 "12:34:56",
217 "2012-11-10-12 12:34:56", 227 "-- ::",
218 "2012-11-10 12:34", 228 "2012-11-10 12:34:",
219 "2012-11-10 12:34:56:78", 229 "2012-11-10 12::56",
220 "ABCD-11-10 12:34:56", 230 "2012-11-10 :34:56",
221 "2012-EF-10 12:34:56", 231 "2012-11- 12:34:56",
222 "2012-11-GH 12:34:56", 232 "2012--10 12:34:56",
223 "2012-11-10 IJ:34:56", 233 "-11-10 12:34:56",
224 "2012-11-10 12:JL:56", 234 "2012-11 12:34:56",
225 "2012-11-10 12:34:MN", 235 "2012-11-10-12 12:34:56",
226 "2012-11-10 12:34:56.123", 236 "2012-11-10 12:34",
227 "2012-11-1012:34:56", 237 "2012-11-10 12:34:56:78",
228 "2012-11-10 12:34:56 UTC", 238 "ABCD-11-10 12:34:56",
239 "2012-EF-10 12:34:56",
240 "2012-11-GH 12:34:56",
241 "2012-11-10 IJ:34:56",
242 "2012-11-10 12:JL:56",
243 "2012-11-10 12:34:MN",
244 "2012-11-10 12:34:56.123",
245 "2012-11-1012:34:56",
246 "2012-11-10 12:34:56 UTC",
229 }; 247 };
230 248
231 for (size_t i = 0; i < arraysize(invalid_date_strings); ++i) { 249 for (size_t i = 0; i < arraysize(invalid_date_strings); ++i) {
232 const char* date_string = invalid_date_strings[i]; 250 const char* date_string = invalid_date_strings[i];
233 base::Time result; 251 base::Time result;
234 EXPECT_FALSE(FFmpegUTCDateToTime(date_string, &result)) 252 EXPECT_FALSE(FFmpegUTCDateToTime(date_string, &result))
235 << "date_string '" << date_string << "'"; 253 << "date_string '" << date_string << "'";
236 EXPECT_TRUE(result.is_null()); 254 EXPECT_TRUE(result.is_null());
237 } 255 }
238 } 256 }
(...skipping 25 matching lines...) Expand all
264 // values; diff should verify. 282 // values; diff should verify.
265 #if 0 283 #if 0
266 printf("<enum name=\"FFmpegCodecHashes\" type=\"int\">\n"); 284 printf("<enum name=\"FFmpegCodecHashes\" type=\"int\">\n");
267 for (const auto& kv : sorted_hashes) 285 for (const auto& kv : sorted_hashes)
268 printf(" <int value=\"%d\" label=\"%s\"/>\n", kv.first, kv.second); 286 printf(" <int value=\"%d\" label=\"%s\"/>\n", kv.first, kv.second);
269 printf("</enum>\n"); 287 printf("</enum>\n");
270 #endif 288 #endif
271 } 289 }
272 290
273 } // namespace media 291 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698