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

Side by Side Diff: media/test/mock_media_source.cc

Issue 2920243002: Declare kAppendWholeFile as constexpr (Closed)
Patch Set: Created 3 years, 6 months 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
« no previous file with comments | « media/test/mock_media_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/test/mock_media_source.h" 5 #include "media/test/mock_media_source.h"
6 6
7 #include "base/threading/thread_task_runner_handle.h" 7 #include "base/threading/thread_task_runner_handle.h"
8 #include "media/base/test_data_util.h" 8 #include "media/base/test_data_util.h"
9 #include "media/base/timestamp_constants.h" 9 #include "media/base/timestamp_constants.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 constexpr char kSourceId[] = "SourceId"; 13 constexpr char kSourceId[] = "SourceId";
14 const size_t kAppendWholeFile = std::numeric_limits<size_t>::max();
15 14
16 MockMediaSource::MockMediaSource(const std::string& filename, 15 MockMediaSource::MockMediaSource(const std::string& filename,
17 const std::string& mimetype, 16 const std::string& mimetype,
18 size_t initial_append_size) 17 size_t initial_append_size)
19 : current_position_(0), 18 : current_position_(0),
20 initial_append_size_(initial_append_size), 19 initial_append_size_(initial_append_size),
21 mimetype_(mimetype), 20 mimetype_(mimetype),
22 chunk_demuxer_(new ChunkDemuxer( 21 chunk_demuxer_(new ChunkDemuxer(
23 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)), 22 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)),
24 base::Bind(&MockMediaSource::OnEncryptedMediaInitData, 23 base::Bind(&MockMediaSource::OnEncryptedMediaInitData,
25 base::Unretained(this)), 24 base::Unretained(this)),
26 &media_log_)), 25 &media_log_)),
27 owned_chunk_demuxer_(chunk_demuxer_) { 26 owned_chunk_demuxer_(chunk_demuxer_) {
28 file_data_ = ReadTestDataFile(filename); 27 file_data_ = ReadTestDataFile(filename);
29 28
30 if (initial_append_size_ == kAppendWholeFile) 29 if (initial_append_size_ == kAppendWholeFile)
31 initial_append_size_ = file_data_->data_size(); 30 initial_append_size_ = file_data_->data_size();
32 31
33 DCHECK_GT(initial_append_size_, 0u); 32 CHECK_GT(initial_append_size_, 0u);
34 DCHECK_LE(initial_append_size_, file_data_->data_size()); 33 CHECK_LE(initial_append_size_, file_data_->data_size());
35 } 34 }
36 35
37 MockMediaSource::~MockMediaSource() {} 36 MockMediaSource::~MockMediaSource() {}
38 37
39 std::unique_ptr<Demuxer> MockMediaSource::GetDemuxer() { 38 std::unique_ptr<Demuxer> MockMediaSource::GetDemuxer() {
40 return std::move(owned_chunk_demuxer_); 39 return std::move(owned_chunk_demuxer_);
41 } 40 }
42 41
43 void MockMediaSource::Seek(base::TimeDelta seek_time, 42 void MockMediaSource::Seek(base::TimeDelta seek_time,
44 size_t new_position, 43 size_t new_position,
45 size_t seek_append_size) { 44 size_t seek_append_size) {
46 chunk_demuxer_->StartWaitingForSeek(seek_time); 45 chunk_demuxer_->StartWaitingForSeek(seek_time);
47 46
48 chunk_demuxer_->ResetParserState(kSourceId, base::TimeDelta(), 47 chunk_demuxer_->ResetParserState(kSourceId, base::TimeDelta(),
49 kInfiniteDuration, &last_timestamp_offset_); 48 kInfiniteDuration, &last_timestamp_offset_);
50 49
51 DCHECK_LT(new_position, file_data_->data_size()); 50 CHECK_LT(new_position, file_data_->data_size());
52 current_position_ = new_position; 51 current_position_ = new_position;
53 52
54 AppendData(seek_append_size); 53 AppendData(seek_append_size);
55 } 54 }
56 55
57 void MockMediaSource::Seek(base::TimeDelta seek_time) { 56 void MockMediaSource::Seek(base::TimeDelta seek_time) {
58 chunk_demuxer_->StartWaitingForSeek(seek_time); 57 chunk_demuxer_->StartWaitingForSeek(seek_time);
59 } 58 }
60 59
61 void MockMediaSource::AppendData(size_t size) { 60 void MockMediaSource::AppendData(size_t size) {
62 DCHECK(chunk_demuxer_); 61 CHECK(chunk_demuxer_);
63 DCHECK_LT(current_position_, file_data_->data_size()); 62 CHECK_LT(current_position_, file_data_->data_size());
64 DCHECK_LE(current_position_ + size, file_data_->data_size()); 63 CHECK_LE(current_position_ + size, file_data_->data_size());
65 64
66 ASSERT_TRUE(chunk_demuxer_->AppendData( 65 ASSERT_TRUE(chunk_demuxer_->AppendData(
67 kSourceId, file_data_->data() + current_position_, size, 66 kSourceId, file_data_->data() + current_position_, size,
68 base::TimeDelta(), kInfiniteDuration, &last_timestamp_offset_)); 67 base::TimeDelta(), kInfiniteDuration, &last_timestamp_offset_));
69 current_position_ += size; 68 current_position_ += size;
70 } 69 }
71 70
72 bool MockMediaSource::AppendAtTime(base::TimeDelta timestamp_offset, 71 bool MockMediaSource::AppendAtTime(base::TimeDelta timestamp_offset,
73 const uint8_t* pData, 72 const uint8_t* pData,
74 int size) { 73 int size) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 codecs_param = mimetype_.substr(codecs_param_start, 162 codecs_param = mimetype_.substr(codecs_param_start,
164 codecs_param_end - codecs_param_start); 163 codecs_param_end - codecs_param_start);
165 } 164 }
166 165
167 return chunk_demuxer_->AddId(kSourceId, type, codecs_param); 166 return chunk_demuxer_->AddId(kSourceId, type, codecs_param);
168 } 167 }
169 168
170 void MockMediaSource::OnEncryptedMediaInitData( 169 void MockMediaSource::OnEncryptedMediaInitData(
171 EmeInitDataType init_data_type, 170 EmeInitDataType init_data_type,
172 const std::vector<uint8_t>& init_data) { 171 const std::vector<uint8_t>& init_data) {
173 DCHECK(!init_data.empty()); 172 CHECK(!init_data.empty());
174 CHECK(!encrypted_media_init_data_cb_.is_null()); 173 CHECK(!encrypted_media_init_data_cb_.is_null());
175 encrypted_media_init_data_cb_.Run(init_data_type, init_data); 174 encrypted_media_init_data_cb_.Run(init_data_type, init_data);
176 } 175 }
177 176
178 void MockMediaSource::InitSegmentReceived(std::unique_ptr<MediaTracks> tracks) { 177 void MockMediaSource::InitSegmentReceived(std::unique_ptr<MediaTracks> tracks) {
179 CHECK(tracks.get()); 178 CHECK(tracks.get());
180 EXPECT_GT(tracks->tracks().size(), 0u); 179 EXPECT_GT(tracks->tracks().size(), 0u);
181 CHECK(chunk_demuxer_); 180 CHECK(chunk_demuxer_);
182 // Verify that track ids are unique. 181 // Verify that track ids are unique.
183 std::set<MediaTrack::Id> track_ids; 182 std::set<MediaTrack::Id> track_ids;
184 for (const auto& track : tracks->tracks()) { 183 for (const auto& track : tracks->tracks()) {
185 EXPECT_EQ(track_ids.end(), track_ids.find(track->id())); 184 EXPECT_EQ(track_ids.end(), track_ids.find(track->id()));
186 track_ids.insert(track->id()); 185 track_ids.insert(track->id());
187 } 186 }
188 InitSegmentReceivedMock(tracks); 187 InitSegmentReceivedMock(tracks);
189 } 188 }
190 189
191 } // namespace media 190 } // namespace media
OLDNEW
« no previous file with comments | « media/test/mock_media_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698