| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "media/base/buffer_queue.h" | 8 #include "media/base/buffer_queue.h" |
| 9 #include "media/base/data_buffer.h" | 9 #include "media/base/data_buffer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 queue_.Consume(kDataSize); | 120 queue_.Consume(kDataSize); |
| 121 | 121 |
| 122 EXPECT_EQ(kNewDataSize, queue_.Copy(dataBig, kNewDataSize)); | 122 EXPECT_EQ(kNewDataSize, queue_.Copy(dataBig, kNewDataSize)); |
| 123 EXPECT_EQ(0, memcmp(dataBig, | 123 EXPECT_EQ(0, memcmp(dataBig, |
| 124 kNewData + kDataSize, | 124 kNewData + kDataSize, |
| 125 kNewDataSize - kDataSize)); | 125 kNewDataSize - kDataSize)); |
| 126 dataBig += (kNewDataSize - kDataSize); | 126 dataBig += (kNewDataSize - kDataSize); |
| 127 EXPECT_EQ(0, memcmp(dataBig, kData, kDataSize)); | 127 EXPECT_EQ(0, memcmp(dataBig, kData, kDataSize)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 |
| 130 TEST_F(BufferQueueTest, GetTime) { | 131 TEST_F(BufferQueueTest, GetTime) { |
| 131 const struct { | 132 const struct { |
| 132 int64 first_time_seconds; | 133 int64 first_time_useconds; |
| 134 int64 duration_useconds; |
| 133 size_t consume_bytes; | 135 size_t consume_bytes; |
| 134 double bytes_to_seconds; | |
| 135 } tests[] = { | 136 } tests[] = { |
| 136 { 0, 0, 0.5 }, | 137 // Timestamps of 0 are treated as garbage. |
| 137 { 0, 0, 1 }, | 138 { 0, 1000000, 0 }, |
| 138 { 0, 0, 1.75 }, | 139 { 0, 4000000, 0 }, |
| 139 { 0, 4, 0.5 }, | 140 { 0, 8000000, 0 }, |
| 140 { 0, 4, 1 }, | 141 // { 0, 1000000, 4 }, |
| 141 { 0, 4, 1.75 }, | 142 // { 0, 4000000, 4 }, |
| 142 { 5, 0, 0.5 }, | 143 // { 0, 8000000, 4 }, |
| 143 { 5, 0, 1 }, | 144 // { 0, 1000000, kNewDataSize }, |
| 144 { 5, 0, 1.75 }, | 145 // { 0, 4000000, kNewDataSize }, |
| 145 { 5, 4, 0.5 }, | 146 // { 0, 8000000, kNewDataSize }, |
| 146 { 5, 4, 1 }, | 147 { 5, 1000000, 0 }, |
| 147 { 5, 4, 1.75 }, | 148 { 5, 4000000, 0 }, |
| 149 { 5, 8000000, 0 }, |
| 150 { 5, 1000000, 4 }, |
| 151 { 5, 4000000, 4 }, |
| 152 { 5, 8000000, 4 }, |
| 153 { 5, 1000000, kNewDataSize }, |
| 154 { 5, 4000000, kNewDataSize }, |
| 155 { 5, 8000000, kNewDataSize }, |
| 148 }; | 156 }; |
| 149 | 157 |
| 150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 158 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 151 buffer2->SetTimestamp(base::TimeDelta::FromSeconds( | 159 buffer2->SetTimestamp(base::TimeDelta::FromMicroseconds( |
| 152 tests[i].first_time_seconds)); | 160 tests[i].first_time_useconds)); |
| 161 buffer2->SetDuration(base::TimeDelta::FromMicroseconds( |
| 162 tests[i].duration_useconds)); |
| 153 queue_.Enqueue(buffer2.get()); | 163 queue_.Enqueue(buffer2.get()); |
| 154 queue_.Consume(tests[i].consume_bytes); | 164 queue_.Consume(tests[i].consume_bytes); |
| 155 | 165 |
| 156 int64 expected = base::TimeDelta::FromSeconds(static_cast<int64>( | 166 int64 expected = base::TimeDelta::FromMicroseconds(static_cast<int64>( |
| 157 tests[i].first_time_seconds + (tests[i].consume_bytes * | 167 tests[i].first_time_useconds + (tests[i].consume_bytes * |
| 158 tests[i].bytes_to_seconds))).ToInternalValue(); | 168 tests[i].duration_useconds) / kNewDataSize)).ToInternalValue(); |
| 159 | 169 |
| 160 int64 actual = queue_.GetTime(tests[i].bytes_to_seconds).ToInternalValue(); | 170 int64 actual = queue_.GetTime().ToInternalValue(); |
| 161 | 171 |
| 162 EXPECT_EQ(expected, actual) << "With test = {" | 172 EXPECT_EQ(expected, actual) << "With test = { start:" |
| 163 << tests[i].first_time_seconds << ", " << tests[i].consume_bytes | 173 << tests[i].first_time_useconds << ", duration:" |
| 164 << ", " << tests[i].bytes_to_seconds << "}\n"; | 174 << tests[i].duration_useconds << ", consumed:" |
| 175 << tests[i].consume_bytes << "}\n"; |
| 165 | 176 |
| 166 queue_.Clear(); | 177 queue_.Clear(); |
| 167 } | 178 } |
| 168 } | 179 } |
| 169 | 180 |
| 170 } // namespace media | 181 } // namespace media |
| OLD | NEW |