OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/base/android/test_data_factory.h" | 5 #include "media/base/android/test_data_factory.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "media/base/android/demuxer_stream_player_params.h" | 8 #include "media/base/android/demuxer_stream_player_params.h" |
9 #include "media/base/decoder_buffer.h" | 9 #include "media/base/decoder_buffer.h" |
10 #include "media/base/test_data_util.h" | 10 #include "media/base/test_data_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 configs.duration = duration; | 53 configs.duration = duration; |
54 | 54 |
55 return configs; | 55 return configs; |
56 } | 56 } |
57 | 57 |
58 TestDataFactory::TestDataFactory(const char* file_name_template, | 58 TestDataFactory::TestDataFactory(const char* file_name_template, |
59 base::TimeDelta duration, | 59 base::TimeDelta duration, |
60 base::TimeDelta frame_period) | 60 base::TimeDelta frame_period) |
61 : duration_(duration), | 61 : duration_(duration), |
62 frame_period_(frame_period), | 62 frame_period_(frame_period), |
63 starvation_mode_(false) { | 63 starvation_mode_(false), |
| 64 eos_reached_(false) { |
64 LoadPackets(file_name_template); | 65 LoadPackets(file_name_template); |
65 } | 66 } |
66 | 67 |
67 TestDataFactory::~TestDataFactory() {} | 68 TestDataFactory::~TestDataFactory() {} |
68 | 69 |
69 bool TestDataFactory::CreateChunk(DemuxerData* chunk, base::TimeDelta* delay) { | 70 bool TestDataFactory::CreateChunk(DemuxerData* chunk, base::TimeDelta* delay) { |
70 DCHECK(chunk); | 71 DCHECK(chunk); |
71 DCHECK(delay); | 72 DCHECK(delay); |
72 | 73 |
| 74 if (eos_reached_) |
| 75 return false; |
| 76 |
73 *delay = base::TimeDelta(); | 77 *delay = base::TimeDelta(); |
74 | 78 |
75 for (int i = 0; i < 4; ++i) { | 79 for (int i = 0; i < 4; ++i) { |
76 chunk->access_units.push_back(AccessUnit()); | 80 chunk->access_units.push_back(AccessUnit()); |
77 AccessUnit& unit = chunk->access_units.back(); | 81 AccessUnit& unit = chunk->access_units.back(); |
78 unit.status = DemuxerStream::kOk; | 82 unit.status = DemuxerStream::kOk; |
79 | 83 |
80 unit.timestamp = regular_pts_; | 84 unit.timestamp = regular_pts_; |
81 regular_pts_ += frame_period_; | 85 regular_pts_ += frame_period_; |
82 | 86 |
83 if (unit.timestamp > duration_) { | 87 if (unit.timestamp > duration_) { |
84 if (starvation_mode_) | 88 if (starvation_mode_) |
85 return false; | 89 return false; |
86 | 90 |
87 unit.is_end_of_stream = true; | 91 unit.is_end_of_stream = true; |
| 92 eos_reached_ = true; |
88 break; // EOS units have no data. | 93 break; // EOS units have no data. |
89 } | 94 } |
90 | 95 |
91 unit.data = packet_[i]; | 96 unit.data = packet_[i]; |
92 | 97 |
93 // Allow for modification by subclasses. | 98 // Allow for modification by subclasses. |
94 ModifyAccessUnit(i, &unit); | 99 ModifyAccessUnit(i, &unit); |
95 | 100 |
96 // Maintain last PTS. ModifyAccessUnit() can modify unit's PTS. | 101 // Maintain last PTS. ModifyAccessUnit() can modify unit's PTS. |
97 if (last_pts_ < unit.timestamp) | 102 if (last_pts_ < unit.timestamp) |
98 last_pts_ = unit.timestamp; | 103 last_pts_ = unit.timestamp; |
99 } | 104 } |
100 | 105 |
101 return true; | 106 return true; |
102 } | 107 } |
103 | 108 |
104 void TestDataFactory::SeekTo(const base::TimeDelta& seek_time) { | 109 void TestDataFactory::SeekTo(const base::TimeDelta& seek_time) { |
105 regular_pts_ = seek_time; | 110 regular_pts_ = seek_time; |
106 last_pts_ = base::TimeDelta(); | 111 last_pts_ = base::TimeDelta(); |
| 112 eos_reached_ = false; |
107 } | 113 } |
108 | 114 |
109 void TestDataFactory::LoadPackets(const char* file_name_template) { | 115 void TestDataFactory::LoadPackets(const char* file_name_template) { |
110 for (int i = 0; i < 4; ++i) { | 116 for (int i = 0; i < 4; ++i) { |
111 scoped_refptr<DecoderBuffer> buffer = | 117 scoped_refptr<DecoderBuffer> buffer = |
112 ReadTestDataFile(base::StringPrintf(file_name_template, i)); | 118 ReadTestDataFile(base::StringPrintf(file_name_template, i)); |
113 packet_[i] = std::vector<uint8>(buffer->data(), | 119 packet_[i] = std::vector<uint8>(buffer->data(), |
114 buffer->data() + buffer->data_size()); | 120 buffer->data() + buffer->data_size()); |
115 } | 121 } |
116 } | 122 } |
117 | 123 |
118 } // namespace media | 124 } // namespace media |
OLD | NEW |