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 "base/files/file_path.h" | |
6 #include "base/logging.h" | 5 #include "base/logging.h" |
7 #include "base/path_service.h" | |
8 #include "media/base/media.h" | |
9 #include "media/ffmpeg/ffmpeg_common.h" | 6 #include "media/ffmpeg/ffmpeg_common.h" |
| 7 #include "media/filters/ffmpeg_glue.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
11 | 9 |
12 using base::TimeDelta; | |
13 | |
14 namespace media { | 10 namespace media { |
15 | 11 |
16 static AVIndexEntry kIndexEntries[] = { | 12 class FFmpegCommonTest : public testing::Test { |
17 // pos, timestamp, flags, size, min_distance | 13 public: |
18 { 0, 0, AVINDEX_KEYFRAME, 0, 0 }, | 14 FFmpegCommonTest() { FFmpegGlue::InitializeFFmpeg(); } |
19 { 2000, 1000, AVINDEX_KEYFRAME, 0, 0 }, | 15 virtual ~FFmpegCommonTest() {}; |
20 { 3000, 2000, 0, 0, 0 }, | |
21 { 5000, 3000, AVINDEX_KEYFRAME, 0, 0 }, | |
22 { 6000, 4000, 0, 0, 0 }, | |
23 { 8000, 5000, AVINDEX_KEYFRAME, 0, 0 }, | |
24 { 9000, 6000, AVINDEX_KEYFRAME, 0, 0 }, | |
25 { 11500, 7000, AVINDEX_KEYFRAME, 0, 0 }, | |
26 }; | 16 }; |
27 | 17 |
28 static const AVRational kTimeBase = { 1, 1000 }; | 18 TEST_F(FFmpegCommonTest, OpusAudioDecoderConfig) { |
| 19 AVCodecContext context = {0}; |
| 20 context.codec_type = AVMEDIA_TYPE_AUDIO; |
| 21 context.codec_id = AV_CODEC_ID_OPUS; |
| 22 context.channel_layout = CHANNEL_LAYOUT_STEREO; |
| 23 context.channels = 2; |
| 24 context.sample_fmt = AV_SAMPLE_FMT_FLT; |
29 | 25 |
30 class FFmpegCommonTest : public testing::Test { | 26 // During conversion this sample rate should be changed to 48kHz. |
31 public: | 27 context.sample_rate = 44100; |
32 FFmpegCommonTest(); | |
33 virtual ~FFmpegCommonTest(); | |
34 | 28 |
35 protected: | 29 AudioDecoderConfig decoder_config; |
36 AVStream stream_; | 30 AVCodecContextToAudioDecoderConfig(&context, false, &decoder_config, false); |
37 | 31 EXPECT_EQ(48000, decoder_config.samples_per_second()); |
38 DISALLOW_COPY_AND_ASSIGN(FFmpegCommonTest); | |
39 }; | |
40 | |
41 static bool InitFFmpeg() { | |
42 static bool initialized = false; | |
43 if (initialized) { | |
44 return true; | |
45 } | |
46 base::FilePath path; | |
47 PathService::Get(base::DIR_MODULE, &path); | |
48 return media::InitializeMediaLibrary(path); | |
49 } | 32 } |
50 | 33 |
51 FFmpegCommonTest::FFmpegCommonTest() { | |
52 CHECK(InitFFmpeg()); | |
53 stream_.time_base = kTimeBase; | |
54 stream_.index_entries = kIndexEntries; | |
55 stream_.index_entries_allocated_size = sizeof(kIndexEntries); | |
56 stream_.nb_index_entries = arraysize(kIndexEntries); | |
57 } | |
58 | |
59 FFmpegCommonTest::~FFmpegCommonTest() {} | |
60 | |
61 TEST_F(FFmpegCommonTest, TimeBaseConversions) { | 34 TEST_F(FFmpegCommonTest, TimeBaseConversions) { |
62 int64 test_data[][5] = { | 35 const int64 test_data[][5] = { |
63 {1, 2, 1, 500000, 1 }, | 36 {1, 2, 1, 500000, 1 }, |
64 {1, 3, 1, 333333, 1 }, | 37 {1, 3, 1, 333333, 1 }, |
65 {1, 3, 2, 666667, 2 }, | 38 {1, 3, 2, 666667, 2 }, |
66 }; | 39 }; |
67 | 40 |
68 for (size_t i = 0; i < arraysize(test_data); ++i) { | 41 for (size_t i = 0; i < arraysize(test_data); ++i) { |
69 SCOPED_TRACE(i); | 42 SCOPED_TRACE(i); |
70 | 43 |
71 AVRational time_base; | 44 AVRational time_base; |
72 time_base.num = static_cast<int>(test_data[i][0]); | 45 time_base.num = static_cast<int>(test_data[i][0]); |
73 time_base.den = static_cast<int>(test_data[i][1]); | 46 time_base.den = static_cast<int>(test_data[i][1]); |
74 | 47 |
75 TimeDelta time_delta = ConvertFromTimeBase(time_base, test_data[i][2]); | 48 base::TimeDelta time_delta = |
| 49 ConvertFromTimeBase(time_base, test_data[i][2]); |
76 | 50 |
77 EXPECT_EQ(time_delta.InMicroseconds(), test_data[i][3]); | 51 EXPECT_EQ(time_delta.InMicroseconds(), test_data[i][3]); |
78 EXPECT_EQ(ConvertToTimeBase(time_base, time_delta), test_data[i][4]); | 52 EXPECT_EQ(ConvertToTimeBase(time_base, time_delta), test_data[i][4]); |
79 } | 53 } |
80 } | 54 } |
81 | 55 |
82 TEST_F(FFmpegCommonTest, VerifyFormatSizes) { | 56 TEST_F(FFmpegCommonTest, VerifyFormatSizes) { |
83 for (AVSampleFormat format = AV_SAMPLE_FMT_NONE; | 57 for (AVSampleFormat format = AV_SAMPLE_FMT_NONE; |
84 format < AV_SAMPLE_FMT_NB; | 58 format < AV_SAMPLE_FMT_NB; |
85 format = static_cast<AVSampleFormat>(format + 1)) { | 59 format = static_cast<AVSampleFormat>(format + 1)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 117 |
144 for (size_t i = 0; i < arraysize(invalid_date_strings); ++i) { | 118 for (size_t i = 0; i < arraysize(invalid_date_strings); ++i) { |
145 const char* date_string = invalid_date_strings[i]; | 119 const char* date_string = invalid_date_strings[i]; |
146 base::Time result; | 120 base::Time result; |
147 EXPECT_FALSE(FFmpegUTCDateToTime(date_string, &result)) | 121 EXPECT_FALSE(FFmpegUTCDateToTime(date_string, &result)) |
148 << "date_string '" << date_string << "'"; | 122 << "date_string '" << date_string << "'"; |
149 EXPECT_TRUE(result.is_null()); | 123 EXPECT_TRUE(result.is_null()); |
150 } | 124 } |
151 } | 125 } |
152 | 126 |
153 | |
154 } // namespace media | 127 } // namespace media |
OLD | NEW |