OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/decoder_buffer.h" | 5 #include "media/base/decoder_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/pickle.h" |
8 #include "media/base/decrypt_config.h" | 9 #include "media/base/decrypt_config.h" |
| 10 #include "media/base/video_decoder_config.h" |
9 | 11 |
10 namespace media { | 12 namespace media { |
11 | 13 |
12 DecoderBuffer::DecoderBuffer(int size) | 14 DecoderBuffer::DecoderBuffer(int size) |
13 : size_(size), | 15 : size_(size), |
14 side_data_size_(0) { | 16 side_data_size_(0) { |
15 Initialize(); | 17 Initialize(); |
16 } | 18 } |
17 | 19 |
18 DecoderBuffer::DecoderBuffer(const uint8* data, int size, | 20 DecoderBuffer::DecoderBuffer(const uint8* data, int size, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 CHECK(side_data); | 65 CHECK(side_data); |
64 return make_scoped_refptr(new DecoderBuffer(data, data_size, | 66 return make_scoped_refptr(new DecoderBuffer(data, data_size, |
65 side_data, side_data_size)); | 67 side_data, side_data_size)); |
66 } | 68 } |
67 | 69 |
68 // static | 70 // static |
69 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | 71 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { |
70 return make_scoped_refptr(new DecoderBuffer(NULL, 0, NULL, 0)); | 72 return make_scoped_refptr(new DecoderBuffer(NULL, 0, NULL, 0)); |
71 } | 73 } |
72 | 74 |
| 75 // static |
| 76 const char DecoderBuffer::kFakeVideoBufferHeader[] = "FakeVideoBufferForTest"; |
| 77 |
| 78 // static |
| 79 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateFakeVideoBufferForTest( |
| 80 const VideoDecoderConfig& config, |
| 81 base::TimeDelta timestamp, base::TimeDelta duration) { |
| 82 Pickle pickle; |
| 83 pickle.WriteString(kFakeVideoBufferHeader); |
| 84 pickle.WriteInt(config.coded_size().width()); |
| 85 pickle.WriteInt(config.coded_size().height()); |
| 86 pickle.WriteInt64(timestamp.InMilliseconds()); |
| 87 |
| 88 scoped_refptr<DecoderBuffer> buffer = DecoderBuffer::CopyFrom( |
| 89 static_cast<const uint8*>(pickle.data()), pickle.size()); |
| 90 buffer->SetTimestamp(timestamp); |
| 91 buffer->SetDuration(duration); |
| 92 |
| 93 return buffer; |
| 94 } |
| 95 |
| 96 // static |
| 97 bool DecoderBuffer::VerifyFakeVideoBufferForTest( |
| 98 const scoped_refptr<DecoderBuffer>& buffer, |
| 99 const VideoDecoderConfig& config) { |
| 100 // Check if the input |buffer| matches the |config|. |
| 101 PickleIterator pickle(Pickle(reinterpret_cast<const char*>(buffer->GetData()), |
| 102 buffer->GetDataSize())); |
| 103 std::string header; |
| 104 int width = 0; |
| 105 int height = 0; |
| 106 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && |
| 107 pickle.ReadInt(&height); |
| 108 return (success && header == DecoderBuffer::kFakeVideoBufferHeader && |
| 109 width == config.coded_size().width() && |
| 110 height == config.coded_size().height()); |
| 111 } |
| 112 |
73 base::TimeDelta DecoderBuffer::GetTimestamp() const { | 113 base::TimeDelta DecoderBuffer::GetTimestamp() const { |
74 DCHECK(!IsEndOfStream()); | 114 DCHECK(!IsEndOfStream()); |
75 return timestamp_; | 115 return timestamp_; |
76 } | 116 } |
77 | 117 |
78 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { | 118 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { |
79 DCHECK(!IsEndOfStream()); | 119 DCHECK(!IsEndOfStream()); |
80 timestamp_ = timestamp; | 120 timestamp_ = timestamp; |
81 } | 121 } |
82 | 122 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 std::ostringstream s; | 177 std::ostringstream s; |
138 s << "timestamp: " << timestamp_.InMicroseconds() | 178 s << "timestamp: " << timestamp_.InMicroseconds() |
139 << " duration: " << duration_.InMicroseconds() | 179 << " duration: " << duration_.InMicroseconds() |
140 << " size: " << size_ | 180 << " size: " << size_ |
141 << " side_data_size: " << side_data_size_ | 181 << " side_data_size: " << side_data_size_ |
142 << " encrypted: " << (decrypt_config_ != NULL); | 182 << " encrypted: " << (decrypt_config_ != NULL); |
143 return s.str(); | 183 return s.str(); |
144 } | 184 } |
145 | 185 |
146 } // namespace media | 186 } // namespace media |
OLD | NEW |