OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/filters/fake_demuxer_stream.h" | 5 #include "media/filters/fake_demuxer_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const uint8 kKeyId[] = { 0x00, 0x01, 0x02, 0x03 }; | 27 const uint8 kKeyId[] = { 0x00, 0x01, 0x02, 0x03 }; |
28 const uint8 kIv[] = { | 28 const uint8 kIv[] = { |
29 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 29 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
31 }; | 31 }; |
32 | 32 |
33 FakeDemuxerStream::FakeDemuxerStream(int num_configs, | 33 FakeDemuxerStream::FakeDemuxerStream(int num_configs, |
34 int num_buffers_in_one_config, | 34 int num_buffers_in_one_config, |
35 bool is_encrypted) | 35 bool is_encrypted) |
36 : task_runner_(base::MessageLoopProxy::current()), | 36 : task_runner_(base::MessageLoopProxy::current()), |
37 num_configs_left_(num_configs), | 37 num_configs_(num_configs), |
38 num_buffers_in_one_config_(num_buffers_in_one_config), | 38 num_buffers_in_one_config_(num_buffers_in_one_config), |
39 config_changes_(num_configs > 1), | 39 config_changes_(num_configs > 1), |
40 is_encrypted_(is_encrypted), | 40 is_encrypted_(is_encrypted), |
41 num_buffers_left_in_current_config_(num_buffers_in_one_config), | |
42 num_buffers_returned_(0), | |
43 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), | |
44 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), | |
45 next_coded_size_(kStartWidth, kStartHeight), | |
46 next_read_num_(0), | |
47 read_to_hold_(-1) { | 41 read_to_hold_(-1) { |
48 DCHECK_GT(num_configs_left_, 0); | 42 DCHECK_GT(num_configs, 0); |
49 DCHECK_GT(num_buffers_in_one_config_, 0); | 43 DCHECK_GT(num_buffers_in_one_config, 0); |
| 44 Initialize(); |
50 UpdateVideoDecoderConfig(); | 45 UpdateVideoDecoderConfig(); |
51 } | 46 } |
52 | 47 |
53 FakeDemuxerStream::~FakeDemuxerStream() {} | 48 FakeDemuxerStream::~FakeDemuxerStream() {} |
54 | 49 |
| 50 void FakeDemuxerStream::Initialize() { |
| 51 DCHECK_EQ(-1, read_to_hold_); |
| 52 num_configs_left_ = num_configs_; |
| 53 num_buffers_left_in_current_config_ = num_buffers_in_one_config_; |
| 54 num_buffers_returned_ = 0; |
| 55 current_timestamp_ = base::TimeDelta::FromMilliseconds(kStartTimestampMs); |
| 56 duration_ = base::TimeDelta::FromMilliseconds(kDurationMs); |
| 57 next_coded_size_ = gfx::Size(kStartWidth, kStartHeight); |
| 58 next_read_num_ = 0; |
| 59 } |
| 60 |
55 void FakeDemuxerStream::Read(const ReadCB& read_cb) { | 61 void FakeDemuxerStream::Read(const ReadCB& read_cb) { |
56 DCHECK(task_runner_->BelongsToCurrentThread()); | 62 DCHECK(task_runner_->BelongsToCurrentThread()); |
57 DCHECK(read_cb_.is_null()); | 63 DCHECK(read_cb_.is_null()); |
58 | 64 |
59 read_cb_ = BindToCurrentLoop(read_cb); | 65 read_cb_ = BindToCurrentLoop(read_cb); |
60 | 66 |
61 if (read_to_hold_ == next_read_num_) | 67 if (read_to_hold_ == next_read_num_) |
62 return; | 68 return; |
63 | 69 |
64 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); | 70 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DoRead(); | 126 DoRead(); |
121 } | 127 } |
122 | 128 |
123 void FakeDemuxerStream::Reset() { | 129 void FakeDemuxerStream::Reset() { |
124 read_to_hold_ = -1; | 130 read_to_hold_ = -1; |
125 | 131 |
126 if (!read_cb_.is_null()) | 132 if (!read_cb_.is_null()) |
127 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 133 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
128 } | 134 } |
129 | 135 |
| 136 void FakeDemuxerStream::SeekToStart() { |
| 137 Reset(); |
| 138 Initialize(); |
| 139 } |
| 140 |
130 void FakeDemuxerStream::UpdateVideoDecoderConfig() { | 141 void FakeDemuxerStream::UpdateVideoDecoderConfig() { |
131 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); | 142 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); |
132 video_decoder_config_.Initialize( | 143 video_decoder_config_.Initialize( |
133 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, | 144 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, |
134 next_coded_size_, kVisibleRect, next_coded_size_, | 145 next_coded_size_, kVisibleRect, next_coded_size_, |
135 NULL, 0, is_encrypted_, false); | 146 NULL, 0, is_encrypted_, false); |
136 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); | 147 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); |
137 } | 148 } |
138 | 149 |
139 void FakeDemuxerStream::DoRead() { | 150 void FakeDemuxerStream::DoRead() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 184 |
174 num_buffers_left_in_current_config_--; | 185 num_buffers_left_in_current_config_--; |
175 if (num_buffers_left_in_current_config_ == 0) | 186 if (num_buffers_left_in_current_config_ == 0) |
176 num_configs_left_--; | 187 num_configs_left_--; |
177 | 188 |
178 num_buffers_returned_++; | 189 num_buffers_returned_++; |
179 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); | 190 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); |
180 } | 191 } |
181 | 192 |
182 } // namespace media | 193 } // namespace media |
OLD | NEW |