| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SetTimestampOffset(base::TimeDelta new_offset) { | 94 void SetTimestampOffset(base::TimeDelta new_offset) { |
| 95 timestamp_offset_ = new_offset; | 95 timestamp_offset_ = new_offset; |
| 96 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset_); | 96 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 BufferQueue StringToBufferQueue(const std::string& buffers_to_append, | 99 BufferQueue StringToBufferQueue(const std::string& buffers_to_append, |
| 100 const TrackId track_id, | 100 const TrackId track_id, |
| 101 const DemuxerStream::Type type) { | 101 const DemuxerStream::Type type) { |
| 102 std::vector<std::string> timestamps = base::SplitString( | 102 std::vector<std::string> timestamps; |
| 103 buffers_to_append, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 103 base::SplitString(buffers_to_append, ' ', ×tamps); |
| 104 | 104 |
| 105 BufferQueue buffers; | 105 BufferQueue buffers; |
| 106 for (size_t i = 0; i < timestamps.size(); i++) { | 106 for (size_t i = 0; i < timestamps.size(); i++) { |
| 107 bool is_keyframe = false; | 107 bool is_keyframe = false; |
| 108 if (base::EndsWith(timestamps[i], "K", base::CompareCase::SENSITIVE)) { | 108 if (base::EndsWith(timestamps[i], "K", base::CompareCase::SENSITIVE)) { |
| 109 is_keyframe = true; | 109 is_keyframe = true; |
| 110 // Remove the "K" off of the token. | 110 // Remove the "K" off of the token. |
| 111 timestamps[i] = timestamps[i].substr(0, timestamps[i].length() - 1); | 111 timestamps[i] = timestamps[i].substr(0, timestamps[i].length() - 1); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Use custom decode timestamp if included. | 114 // Use custom decode timestamp if included. |
| 115 std::vector<std::string> buffer_timestamps = base::SplitString( | 115 std::vector<std::string> buffer_timestamps; |
| 116 timestamps[i], "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 116 base::SplitString(timestamps[i], '|', &buffer_timestamps); |
| 117 if (buffer_timestamps.size() == 1) | 117 if (buffer_timestamps.size() == 1) |
| 118 buffer_timestamps.push_back(buffer_timestamps[0]); | 118 buffer_timestamps.push_back(buffer_timestamps[0]); |
| 119 CHECK_EQ(2u, buffer_timestamps.size()); | 119 CHECK_EQ(2u, buffer_timestamps.size()); |
| 120 | 120 |
| 121 double time_in_ms, decode_time_in_ms; | 121 double time_in_ms, decode_time_in_ms; |
| 122 CHECK(base::StringToDouble(buffer_timestamps[0], &time_in_ms)); | 122 CHECK(base::StringToDouble(buffer_timestamps[0], &time_in_ms)); |
| 123 CHECK(base::StringToDouble(buffer_timestamps[1], &decode_time_in_ms)); | 123 CHECK(base::StringToDouble(buffer_timestamps[1], &decode_time_in_ms)); |
| 124 | 124 |
| 125 // Create buffer. Encode the original time_in_ms as the buffer's data to | 125 // Create buffer. Encode the original time_in_ms as the buffer's data to |
| 126 // enable later verification of possible buffer relocation in presentation | 126 // enable later verification of possible buffer relocation in presentation |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 << "2 kAborted reads in a row. Giving up."; | 186 << "2 kAborted reads in a row. Giving up."; |
| 187 EXPECT_FALSE(read_callback_called_); | 187 EXPECT_FALSE(read_callback_called_); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Format of |expected| is a space-delimited sequence of | 190 // Format of |expected| is a space-delimited sequence of |
| 191 // timestamp_in_ms:original_timestamp_in_ms | 191 // timestamp_in_ms:original_timestamp_in_ms |
| 192 // original_timestamp_in_ms (and the colon) must be omitted if it is the same | 192 // original_timestamp_in_ms (and the colon) must be omitted if it is the same |
| 193 // as timestamp_in_ms. | 193 // as timestamp_in_ms. |
| 194 void CheckReadsThenReadStalls(ChunkDemuxerStream* stream, | 194 void CheckReadsThenReadStalls(ChunkDemuxerStream* stream, |
| 195 const std::string& expected) { | 195 const std::string& expected) { |
| 196 std::vector<std::string> timestamps = base::SplitString( | 196 std::vector<std::string> timestamps; |
| 197 expected, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 197 base::SplitString(expected, ' ', ×tamps); |
| 198 std::stringstream ss; | 198 std::stringstream ss; |
| 199 for (size_t i = 0; i < timestamps.size(); ++i) { | 199 for (size_t i = 0; i < timestamps.size(); ++i) { |
| 200 int loop_count = 0; | 200 int loop_count = 0; |
| 201 | 201 |
| 202 do { | 202 do { |
| 203 read_callback_called_ = false; | 203 read_callback_called_ = false; |
| 204 stream->Read(base::Bind(&FrameProcessorTest::StoreStatusAndBuffer, | 204 stream->Read(base::Bind(&FrameProcessorTest::StoreStatusAndBuffer, |
| 205 base::Unretained(this))); | 205 base::Unretained(this))); |
| 206 message_loop_.RunUntilIdle(); | 206 message_loop_.RunUntilIdle(); |
| 207 EXPECT_TRUE(read_callback_called_); | 207 EXPECT_TRUE(read_callback_called_); |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 CheckExpectedRangesByTimestamp(audio_.get(), "{ [0,5) }"); | 736 CheckExpectedRangesByTimestamp(audio_.get(), "{ [0,5) }"); |
| 737 CheckExpectedRangesByTimestamp(video_.get(), "{ [0,20) }"); | 737 CheckExpectedRangesByTimestamp(video_.get(), "{ [0,20) }"); |
| 738 CheckReadsThenReadStalls(audio_.get(), "0:-5"); | 738 CheckReadsThenReadStalls(audio_.get(), "0:-5"); |
| 739 CheckReadsThenReadStalls(video_.get(), "0 10"); | 739 CheckReadsThenReadStalls(video_.get(), "0 10"); |
| 740 } | 740 } |
| 741 | 741 |
| 742 INSTANTIATE_TEST_CASE_P(SequenceMode, FrameProcessorTest, Values(true)); | 742 INSTANTIATE_TEST_CASE_P(SequenceMode, FrameProcessorTest, Values(true)); |
| 743 INSTANTIATE_TEST_CASE_P(SegmentsMode, FrameProcessorTest, Values(false)); | 743 INSTANTIATE_TEST_CASE_P(SegmentsMode, FrameProcessorTest, Values(false)); |
| 744 | 744 |
| 745 } // namespace media | 745 } // namespace media |
| OLD | NEW |