| 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 static const char kFakeBufferHeader[] = "Fake Buffer"; | 27 static const char kFakeBufferHeader[] = "Fake Buffer"; |
| 28 | 28 |
| 29 FakeDemuxerStream::FakeDemuxerStream(int num_configs, | 29 FakeDemuxerStream::FakeDemuxerStream(int num_configs, |
| 30 int num_buffers_in_one_config, | 30 int num_buffers_in_one_config, |
| 31 bool is_encrypted) | 31 bool is_encrypted) |
| 32 : message_loop_(base::MessageLoopProxy::current()), | 32 : message_loop_(base::MessageLoopProxy::current()), |
| 33 num_configs_left_(num_configs), | 33 num_configs_left_(num_configs), |
| 34 num_buffers_in_one_config_(num_buffers_in_one_config), | 34 num_buffers_in_one_config_(num_buffers_in_one_config), |
| 35 is_encrypted_(is_encrypted), | 35 is_encrypted_(is_encrypted), |
| 36 num_buffers_left_in_current_config_(num_buffers_in_one_config), | 36 num_buffers_left_in_current_config_(num_buffers_in_one_config), |
| 37 num_buffers_returned_(0), |
| 37 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), | 38 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), |
| 38 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), | 39 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), |
| 39 next_coded_size_(kStartWidth, kStartHeight), | 40 next_coded_size_(kStartWidth, kStartHeight), |
| 40 hold_next_read_(false) { | 41 next_read_num_(0), |
| 42 read_to_hold_(-1) { |
| 41 DCHECK_GT(num_configs_left_, 0); | 43 DCHECK_GT(num_configs_left_, 0); |
| 42 DCHECK_GT(num_buffers_in_one_config_, 0); | 44 DCHECK_GT(num_buffers_in_one_config_, 0); |
| 43 UpdateVideoDecoderConfig(); | 45 UpdateVideoDecoderConfig(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 FakeDemuxerStream::~FakeDemuxerStream() {} | 48 FakeDemuxerStream::~FakeDemuxerStream() {} |
| 47 | 49 |
| 48 void FakeDemuxerStream::Read(const ReadCB& read_cb) { | 50 void FakeDemuxerStream::Read(const ReadCB& read_cb) { |
| 49 DCHECK(message_loop_->BelongsToCurrentThread()); | 51 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 50 DCHECK(read_cb_.is_null()); | 52 DCHECK(read_cb_.is_null()); |
| 51 | 53 |
| 52 read_cb_ = BindToCurrentLoop(read_cb); | 54 read_cb_ = BindToCurrentLoop(read_cb); |
| 53 | 55 |
| 54 if (!hold_next_read_) | 56 if (read_to_hold_ == next_read_num_) |
| 55 DoRead(); | 57 return; |
| 58 |
| 59 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); |
| 60 DoRead(); |
| 56 } | 61 } |
| 57 | 62 |
| 58 const AudioDecoderConfig& FakeDemuxerStream::audio_decoder_config() { | 63 const AudioDecoderConfig& FakeDemuxerStream::audio_decoder_config() { |
| 59 DCHECK(message_loop_->BelongsToCurrentThread()); | 64 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 60 NOTREACHED(); | 65 NOTREACHED(); |
| 61 return audio_decoder_config_; | 66 return audio_decoder_config_; |
| 62 } | 67 } |
| 63 | 68 |
| 64 const VideoDecoderConfig& FakeDemuxerStream::video_decoder_config() { | 69 const VideoDecoderConfig& FakeDemuxerStream::video_decoder_config() { |
| 65 DCHECK(message_loop_->BelongsToCurrentThread()); | 70 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 66 return video_decoder_config_; | 71 return video_decoder_config_; |
| 67 } | 72 } |
| 68 | 73 |
| 69 // TODO(xhwang): Support audio if needed. | 74 // TODO(xhwang): Support audio if needed. |
| 70 DemuxerStream::Type FakeDemuxerStream::type() { | 75 DemuxerStream::Type FakeDemuxerStream::type() { |
| 71 DCHECK(message_loop_->BelongsToCurrentThread()); | 76 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 72 return VIDEO; | 77 return VIDEO; |
| 73 } | 78 } |
| 74 | 79 |
| 75 void FakeDemuxerStream::EnableBitstreamConverter() { | 80 void FakeDemuxerStream::EnableBitstreamConverter() { |
| 76 DCHECK(message_loop_->BelongsToCurrentThread()); | 81 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 77 } | 82 } |
| 78 | 83 |
| 79 void FakeDemuxerStream::HoldNextRead() { | 84 void FakeDemuxerStream::HoldNextRead() { |
| 80 DCHECK(message_loop_->BelongsToCurrentThread()); | 85 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 81 hold_next_read_ = true; | 86 read_to_hold_ = next_read_num_; |
| 87 } |
| 88 |
| 89 void FakeDemuxerStream::HoldNextConfigChangeRead() { |
| 90 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 91 // Set |read_to_hold_| to be the next config change read. |
| 92 read_to_hold_ = next_read_num_ + num_buffers_in_one_config_ - |
| 93 next_read_num_ % (num_buffers_in_one_config_ + 1); |
| 82 } | 94 } |
| 83 | 95 |
| 84 void FakeDemuxerStream::SatisfyRead() { | 96 void FakeDemuxerStream::SatisfyRead() { |
| 85 DCHECK(message_loop_->BelongsToCurrentThread()); | 97 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 86 DCHECK(hold_next_read_); | 98 DCHECK_EQ(read_to_hold_, next_read_num_); |
| 87 DCHECK(!read_cb_.is_null()); | 99 DCHECK(!read_cb_.is_null()); |
| 88 | 100 |
| 101 read_to_hold_ = -1; |
| 89 DoRead(); | 102 DoRead(); |
| 90 } | 103 } |
| 91 | 104 |
| 92 void FakeDemuxerStream::Reset() { | 105 void FakeDemuxerStream::Reset() { |
| 93 hold_next_read_ = false; | 106 read_to_hold_ = -1; |
| 94 | 107 |
| 95 if (!read_cb_.is_null()) | 108 if (!read_cb_.is_null()) |
| 96 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 109 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 97 } | 110 } |
| 98 | 111 |
| 99 void FakeDemuxerStream::UpdateVideoDecoderConfig() { | 112 void FakeDemuxerStream::UpdateVideoDecoderConfig() { |
| 100 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); | 113 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); |
| 101 video_decoder_config_.Initialize( | 114 video_decoder_config_.Initialize( |
| 102 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, | 115 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, |
| 103 next_coded_size_, kVisibleRect, next_coded_size_, | 116 next_coded_size_, kVisibleRect, next_coded_size_, |
| 104 NULL, 0, is_encrypted_, false); | 117 NULL, 0, is_encrypted_, false); |
| 105 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); | 118 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); |
| 106 } | 119 } |
| 107 | 120 |
| 108 void FakeDemuxerStream::DoRead() { | 121 void FakeDemuxerStream::DoRead() { |
| 109 DCHECK(message_loop_->BelongsToCurrentThread()); | 122 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 110 DCHECK(!read_cb_.is_null()); | 123 DCHECK(!read_cb_.is_null()); |
| 111 | 124 |
| 125 next_read_num_++; |
| 126 |
| 112 if (num_buffers_left_in_current_config_ == 0) { | 127 if (num_buffers_left_in_current_config_ == 0) { |
| 113 // End of stream. | 128 // End of stream. |
| 114 if (num_configs_left_ == 0) { | 129 if (num_configs_left_ == 0) { |
| 115 base::ResetAndReturn(&read_cb_).Run(kOk, | 130 base::ResetAndReturn(&read_cb_).Run(kOk, |
| 116 DecoderBuffer::CreateEOSBuffer()); | 131 DecoderBuffer::CreateEOSBuffer()); |
| 117 return; | 132 return; |
| 118 } | 133 } |
| 119 | 134 |
| 120 // Config change. | 135 // Config change. |
| 121 num_buffers_left_in_current_config_ = num_buffers_in_one_config_; | 136 num_buffers_left_in_current_config_ = num_buffers_in_one_config_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 | 151 |
| 137 // TODO(xhwang): Output out-of-order buffers if needed. | 152 // TODO(xhwang): Output out-of-order buffers if needed. |
| 138 buffer->SetTimestamp(current_timestamp_); | 153 buffer->SetTimestamp(current_timestamp_); |
| 139 buffer->SetDuration(duration_); | 154 buffer->SetDuration(duration_); |
| 140 current_timestamp_ += duration_; | 155 current_timestamp_ += duration_; |
| 141 | 156 |
| 142 num_buffers_left_in_current_config_--; | 157 num_buffers_left_in_current_config_--; |
| 143 if (num_buffers_left_in_current_config_ == 0) | 158 if (num_buffers_left_in_current_config_ == 0) |
| 144 num_configs_left_--; | 159 num_configs_left_--; |
| 145 | 160 |
| 161 num_buffers_returned_++; |
| 146 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); | 162 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); |
| 147 } | 163 } |
| 148 | 164 |
| 149 } // namespace media | 165 } // namespace media |
| OLD | NEW |