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

Side by Side Diff: media/filters/ffmpeg_h264_to_annex_b_bitstream_converter_unittest.cc

Issue 2534193003: To M56: Roll src/third_party/ffmpeg/ 3c7a09882..cdf4accee (3188 commits). (Closed)
Patch Set: Created 4 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "media/ffmpeg/ffmpeg_common.h" 8 #include "media/ffmpeg/ffmpeg_common.h"
9 #include "media/filters/ffmpeg_demuxer.h" 9 #include "media/filters/ffmpeg_demuxer.h"
10 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h" 10 #include "media/filters/ffmpeg_h264_to_annex_b_bitstream_converter.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 0xBD, 0xF7, 0xFA, 0xE3, 0x8A, 0x76, 0xCB, 0x6C, 0xC8, 0x13, 0xC4, 0x53, 275 0xBD, 0xF7, 0xFA, 0xE3, 0x8A, 0x76, 0xCB, 0x6C, 0xC8, 0x13, 0xC4, 0x53,
276 0x53, 0xDB, 0xAD, 0x37, 0x1A, 0xEB, 0xE0}; 276 0x53, 0xDB, 0xAD, 0x37, 0x1A, 0xEB, 0xE0};
277 277
278 // Class for testing the FFmpegH264ToAnnexBBitstreamConverter. 278 // Class for testing the FFmpegH264ToAnnexBBitstreamConverter.
279 class FFmpegH264ToAnnexBBitstreamConverterTest : public testing::Test { 279 class FFmpegH264ToAnnexBBitstreamConverterTest : public testing::Test {
280 protected: 280 protected:
281 FFmpegH264ToAnnexBBitstreamConverterTest() { 281 FFmpegH264ToAnnexBBitstreamConverterTest() {
282 // Set up AVCConfigurationRecord correctly for tests. 282 // Set up AVCConfigurationRecord correctly for tests.
283 // It's ok to do const cast here as data in kHeaderDataOkWithFieldLen4 is 283 // It's ok to do const cast here as data in kHeaderDataOkWithFieldLen4 is
284 // never written to. 284 // never written to.
285 memset(&test_context_, 0, sizeof(AVCodecContext)); 285 memset(&test_parameters_, 0, sizeof(AVCodecParameters));
286 test_context_.extradata = const_cast<uint8_t*>(kHeaderDataOkWithFieldLen4); 286 test_parameters_.extradata =
287 test_context_.extradata_size = sizeof(kHeaderDataOkWithFieldLen4); 287 const_cast<uint8_t*>(kHeaderDataOkWithFieldLen4);
288 test_parameters_.extradata_size = sizeof(kHeaderDataOkWithFieldLen4);
288 } 289 }
289 290
290 void CreatePacket(AVPacket* packet, const uint8_t* data, uint32_t data_size) { 291 void CreatePacket(AVPacket* packet, const uint8_t* data, uint32_t data_size) {
291 // Create new packet sized of |data_size| from |data|. 292 // Create new packet sized of |data_size| from |data|.
292 EXPECT_EQ(av_new_packet(packet, data_size), 0); 293 EXPECT_EQ(av_new_packet(packet, data_size), 0);
293 memcpy(packet->data, data, data_size); 294 memcpy(packet->data, data, data_size);
294 } 295 }
295 296
296 // Variable to hold valid dummy context for testing. 297 // Variable to hold valid dummy parameters for testing.
297 AVCodecContext test_context_; 298 AVCodecParameters test_parameters_;
298 299
299 private: 300 private:
300 DISALLOW_COPY_AND_ASSIGN(FFmpegH264ToAnnexBBitstreamConverterTest); 301 DISALLOW_COPY_AND_ASSIGN(FFmpegH264ToAnnexBBitstreamConverterTest);
301 }; 302 };
302 303
303 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_Success) { 304 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_Success) {
304 FFmpegH264ToAnnexBBitstreamConverter converter(&test_context_); 305 FFmpegH264ToAnnexBBitstreamConverter converter(&test_parameters_);
305 306
306 ScopedAVPacket test_packet(new AVPacket()); 307 ScopedAVPacket test_packet(new AVPacket());
307 CreatePacket(test_packet.get(), kPacketDataOkWithFieldLen4, 308 CreatePacket(test_packet.get(), kPacketDataOkWithFieldLen4,
308 sizeof(kPacketDataOkWithFieldLen4)); 309 sizeof(kPacketDataOkWithFieldLen4));
309 310
310 // Try out the actual conversion (should be successful and allocate new 311 // Try out the actual conversion (should be successful and allocate new
311 // packet and destroy the old one). 312 // packet and destroy the old one).
312 EXPECT_TRUE(converter.ConvertPacket(test_packet.get())); 313 EXPECT_TRUE(converter.ConvertPacket(test_packet.get()));
313 314
314 // Converter will be automatically cleaned up. 315 // Converter will be automatically cleaned up.
315 } 316 }
316 317
317 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_SuccessBigPacket) { 318 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_SuccessBigPacket) {
318 FFmpegH264ToAnnexBBitstreamConverter converter(&test_context_); 319 FFmpegH264ToAnnexBBitstreamConverter converter(&test_parameters_);
319 320
320 // Create new packet with 1000 excess bytes. 321 // Create new packet with 1000 excess bytes.
321 ScopedAVPacket test_packet(new AVPacket()); 322 ScopedAVPacket test_packet(new AVPacket());
322 static uint8_t excess_data[sizeof(kPacketDataOkWithFieldLen4) + 1000] = {0}; 323 static uint8_t excess_data[sizeof(kPacketDataOkWithFieldLen4) + 1000] = {0};
323 memcpy(excess_data, kPacketDataOkWithFieldLen4, 324 memcpy(excess_data, kPacketDataOkWithFieldLen4,
324 sizeof(kPacketDataOkWithFieldLen4)); 325 sizeof(kPacketDataOkWithFieldLen4));
325 CreatePacket(test_packet.get(), excess_data, sizeof(excess_data)); 326 CreatePacket(test_packet.get(), excess_data, sizeof(excess_data));
326 327
327 // Try out the actual conversion (should be successful and allocate new 328 // Try out the actual conversion (should be successful and allocate new
328 // packet and destroy the old one as we do NOT support in place transform). 329 // packet and destroy the old one as we do NOT support in place transform).
329 EXPECT_TRUE(converter.ConvertPacket(test_packet.get())); 330 EXPECT_TRUE(converter.ConvertPacket(test_packet.get()));
330 331
331 // Converter will be automatically cleaned up. 332 // Converter will be automatically cleaned up.
332 } 333 }
333 334
334 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_FailureNullParams) { 335 TEST_F(FFmpegH264ToAnnexBBitstreamConverterTest, Conversion_FailureNullParams) {
335 // Set up AVCConfigurationRecord to represent NULL data. 336 // Set up AVCConfigurationRecord to represent NULL data.
336 AVCodecContext dummy_context; 337 AVCodecParameters dummy_parameters;
337 dummy_context.extradata = NULL; 338 dummy_parameters.extradata = nullptr;
338 dummy_context.extradata_size = 0; 339 dummy_parameters.extradata_size = 0;
339 FFmpegH264ToAnnexBBitstreamConverter converter(&dummy_context); 340 FFmpegH264ToAnnexBBitstreamConverter converter(&dummy_parameters);
340 341
341 // Try out the actual conversion with NULL parameter. 342 // Try out the actual conversion with NULL parameter.
342 EXPECT_FALSE(converter.ConvertPacket(NULL)); 343 EXPECT_FALSE(converter.ConvertPacket(nullptr));
343 344
344 // Create new packet to test actual conversion. 345 // Create new packet to test actual conversion.
345 ScopedAVPacket test_packet(new AVPacket()); 346 ScopedAVPacket test_packet(new AVPacket());
346 CreatePacket(test_packet.get(), kPacketDataOkWithFieldLen4, 347 CreatePacket(test_packet.get(), kPacketDataOkWithFieldLen4,
347 sizeof(kPacketDataOkWithFieldLen4)); 348 sizeof(kPacketDataOkWithFieldLen4));
348 349
349 // Try out the actual conversion. This should fail due to missing extradata. 350 // Try out the actual conversion. This should fail due to missing extradata.
350 EXPECT_FALSE(converter.ConvertPacket(test_packet.get())); 351 EXPECT_FALSE(converter.ConvertPacket(test_packet.get()));
351 352
352 // Converted will be automatically cleaned up. 353 // Converter will be automatically cleaned up.
353 } 354 }
354 355
355 } // namespace media 356 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698