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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "media/base/bind_to_loop.h" | 12 #include "media/base/bind_to_loop.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/base/test_helpers.h" | 14 #include "media/base/test_helpers.h" |
15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 const int kStartTimestampMs = 0; | 21 const int kStartTimestampMs = 0; |
22 const int kDurationMs = 30; | 22 const int kDurationMs = 30; |
23 const int kStartWidth = 320; | 23 const int kStartWidth = 320; |
24 const int kStartHeight = 240; | 24 const int kStartHeight = 240; |
25 const int kWidthDelta = 4; | 25 const int kWidthDelta = 4; |
26 const int kHeightDelta = 3; | 26 const int kHeightDelta = 3; |
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 : message_loop_(base::MessageLoopProxy::current()), | 36 : task_runner_(base::MessageLoopProxy::current()), |
37 num_configs_left_(num_configs), | 37 num_configs_left_(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 is_encrypted_(is_encrypted), | 39 is_encrypted_(is_encrypted), |
40 num_buffers_left_in_current_config_(num_buffers_in_one_config), | 40 num_buffers_left_in_current_config_(num_buffers_in_one_config), |
41 num_buffers_returned_(0), | 41 num_buffers_returned_(0), |
42 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), | 42 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), |
43 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), | 43 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), |
44 next_coded_size_(kStartWidth, kStartHeight), | 44 next_coded_size_(kStartWidth, kStartHeight), |
45 next_read_num_(0), | 45 next_read_num_(0), |
46 read_to_hold_(-1) { | 46 read_to_hold_(-1) { |
47 DCHECK_GT(num_configs_left_, 0); | 47 DCHECK_GT(num_configs_left_, 0); |
48 DCHECK_GT(num_buffers_in_one_config_, 0); | 48 DCHECK_GT(num_buffers_in_one_config_, 0); |
49 UpdateVideoDecoderConfig(); | 49 UpdateVideoDecoderConfig(); |
50 } | 50 } |
51 | 51 |
52 FakeDemuxerStream::~FakeDemuxerStream() {} | 52 FakeDemuxerStream::~FakeDemuxerStream() {} |
53 | 53 |
54 void FakeDemuxerStream::Read(const ReadCB& read_cb) { | 54 void FakeDemuxerStream::Read(const ReadCB& read_cb) { |
55 DCHECK(message_loop_->BelongsToCurrentThread()); | 55 DCHECK(task_runner_->BelongsToCurrentThread()); |
56 DCHECK(read_cb_.is_null()); | 56 DCHECK(read_cb_.is_null()); |
57 | 57 |
58 read_cb_ = BindToCurrentLoop(read_cb); | 58 read_cb_ = BindToCurrentLoop(read_cb); |
59 | 59 |
60 if (read_to_hold_ == next_read_num_) | 60 if (read_to_hold_ == next_read_num_) |
61 return; | 61 return; |
62 | 62 |
63 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); | 63 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); |
64 DoRead(); | 64 DoRead(); |
65 } | 65 } |
66 | 66 |
67 AudioDecoderConfig FakeDemuxerStream::audio_decoder_config() { | 67 AudioDecoderConfig FakeDemuxerStream::audio_decoder_config() { |
68 DCHECK(message_loop_->BelongsToCurrentThread()); | 68 DCHECK(task_runner_->BelongsToCurrentThread()); |
69 NOTREACHED(); | 69 NOTREACHED(); |
70 return AudioDecoderConfig(); | 70 return AudioDecoderConfig(); |
71 } | 71 } |
72 | 72 |
73 VideoDecoderConfig FakeDemuxerStream::video_decoder_config() { | 73 VideoDecoderConfig FakeDemuxerStream::video_decoder_config() { |
74 DCHECK(message_loop_->BelongsToCurrentThread()); | 74 DCHECK(task_runner_->BelongsToCurrentThread()); |
75 return video_decoder_config_; | 75 return video_decoder_config_; |
76 } | 76 } |
77 | 77 |
78 // TODO(xhwang): Support audio if needed. | 78 // TODO(xhwang): Support audio if needed. |
79 DemuxerStream::Type FakeDemuxerStream::type() { | 79 DemuxerStream::Type FakeDemuxerStream::type() { |
80 DCHECK(message_loop_->BelongsToCurrentThread()); | 80 DCHECK(task_runner_->BelongsToCurrentThread()); |
81 return VIDEO; | 81 return VIDEO; |
82 } | 82 } |
83 | 83 |
84 void FakeDemuxerStream::EnableBitstreamConverter() { | 84 void FakeDemuxerStream::EnableBitstreamConverter() { |
85 DCHECK(message_loop_->BelongsToCurrentThread()); | 85 DCHECK(task_runner_->BelongsToCurrentThread()); |
86 } | 86 } |
87 | 87 |
88 void FakeDemuxerStream::HoldNextRead() { | 88 void FakeDemuxerStream::HoldNextRead() { |
89 DCHECK(message_loop_->BelongsToCurrentThread()); | 89 DCHECK(task_runner_->BelongsToCurrentThread()); |
90 read_to_hold_ = next_read_num_; | 90 read_to_hold_ = next_read_num_; |
91 } | 91 } |
92 | 92 |
93 void FakeDemuxerStream::HoldNextConfigChangeRead() { | 93 void FakeDemuxerStream::HoldNextConfigChangeRead() { |
94 DCHECK(message_loop_->BelongsToCurrentThread()); | 94 DCHECK(task_runner_->BelongsToCurrentThread()); |
95 // Set |read_to_hold_| to be the next config change read. | 95 // Set |read_to_hold_| to be the next config change read. |
96 read_to_hold_ = next_read_num_ + num_buffers_in_one_config_ - | 96 read_to_hold_ = next_read_num_ + num_buffers_in_one_config_ - |
97 next_read_num_ % (num_buffers_in_one_config_ + 1); | 97 next_read_num_ % (num_buffers_in_one_config_ + 1); |
98 } | 98 } |
99 | 99 |
100 void FakeDemuxerStream::SatisfyRead() { | 100 void FakeDemuxerStream::SatisfyRead() { |
101 DCHECK(message_loop_->BelongsToCurrentThread()); | 101 DCHECK(task_runner_->BelongsToCurrentThread()); |
102 DCHECK_EQ(read_to_hold_, next_read_num_); | 102 DCHECK_EQ(read_to_hold_, next_read_num_); |
103 DCHECK(!read_cb_.is_null()); | 103 DCHECK(!read_cb_.is_null()); |
104 | 104 |
105 read_to_hold_ = -1; | 105 read_to_hold_ = -1; |
106 DoRead(); | 106 DoRead(); |
107 } | 107 } |
108 | 108 |
109 void FakeDemuxerStream::Reset() { | 109 void FakeDemuxerStream::Reset() { |
110 read_to_hold_ = -1; | 110 read_to_hold_ = -1; |
111 | 111 |
112 if (!read_cb_.is_null()) | 112 if (!read_cb_.is_null()) |
113 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 113 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
114 } | 114 } |
115 | 115 |
116 void FakeDemuxerStream::UpdateVideoDecoderConfig() { | 116 void FakeDemuxerStream::UpdateVideoDecoderConfig() { |
117 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); | 117 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); |
118 video_decoder_config_.Initialize( | 118 video_decoder_config_.Initialize( |
119 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, | 119 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, |
120 next_coded_size_, kVisibleRect, next_coded_size_, | 120 next_coded_size_, kVisibleRect, next_coded_size_, |
121 NULL, 0, is_encrypted_, false); | 121 NULL, 0, is_encrypted_, false); |
122 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); | 122 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); |
123 } | 123 } |
124 | 124 |
125 void FakeDemuxerStream::DoRead() { | 125 void FakeDemuxerStream::DoRead() { |
126 DCHECK(message_loop_->BelongsToCurrentThread()); | 126 DCHECK(task_runner_->BelongsToCurrentThread()); |
127 DCHECK(!read_cb_.is_null()); | 127 DCHECK(!read_cb_.is_null()); |
128 | 128 |
129 next_read_num_++; | 129 next_read_num_++; |
130 | 130 |
131 if (num_buffers_left_in_current_config_ == 0) { | 131 if (num_buffers_left_in_current_config_ == 0) { |
132 // End of stream. | 132 // End of stream. |
133 if (num_configs_left_ == 0) { | 133 if (num_configs_left_ == 0) { |
134 base::ResetAndReturn(&read_cb_).Run(kOk, | 134 base::ResetAndReturn(&read_cb_).Run(kOk, |
135 DecoderBuffer::CreateEOSBuffer()); | 135 DecoderBuffer::CreateEOSBuffer()); |
136 return; | 136 return; |
(...skipping 23 matching lines...) Expand all Loading... |
160 | 160 |
161 num_buffers_left_in_current_config_--; | 161 num_buffers_left_in_current_config_--; |
162 if (num_buffers_left_in_current_config_ == 0) | 162 if (num_buffers_left_in_current_config_ == 0) |
163 num_configs_left_--; | 163 num_configs_left_--; |
164 | 164 |
165 num_buffers_returned_++; | 165 num_buffers_returned_++; |
166 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); | 166 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); |
167 } | 167 } |
168 | 168 |
169 } // namespace media | 169 } // namespace media |
OLD | NEW |