Chromium Code Reviews| Index: media/base/decoder_buffer.cc |
| diff --git a/media/base/decoder_buffer.cc b/media/base/decoder_buffer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e12f34040c7d1a76a312d4378c684936387007da |
| --- /dev/null |
| +++ b/media/base/decoder_buffer.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/base/decoder_buffer.h" |
| + |
| +#include "base/logging.h" |
| +#include "media/base/decrypt_config.h" |
| +#if !defined(OS_ANDROID) |
| +#include "media/ffmpeg/ffmpeg_common.h" |
| +#endif |
| + |
| +namespace media { |
| + |
| +DecoderBuffer::DecoderBuffer(int buffer_size) |
| + : Buffer(base::TimeDelta(), base::TimeDelta()), |
| + buffer_size_(buffer_size) { |
| + DCHECK(buffer_size >= 0); |
|
Ami GONE FROM CHROMIUM
2012/05/30 17:38:31
FWIW, DCHECK_GE.
DaleCurtis
2012/05/30 17:56:18
Done. CQ failed seek_tester, your gain!
|
| + Initialize(); |
| +} |
| + |
| +DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) |
| + : Buffer(base::TimeDelta(), base::TimeDelta()), |
| + buffer_size_(buffer_size) { |
| + // Prevent invalid allocations. Also used to create end of stream buffers. |
| + if (data == NULL || buffer_size_ < 0) { |
|
Ami GONE FROM CHROMIUM
2012/05/30 17:38:31
In the public entry points you DCHECK non-negativi
DaleCurtis
2012/05/30 17:56:18
Good point. Fixed.
|
| + buffer_size_ = 0; |
| + data_ = NULL; |
| + return; |
| + } |
| + |
| + Initialize(); |
| + memcpy(data_, data, buffer_size_); |
| +} |
| + |
| +DecoderBuffer::~DecoderBuffer() { |
| +#if !defined(OS_ANDROID) |
| + av_free(data_); |
| +#else |
| + delete[] data_; |
| +#endif |
| +} |
| + |
| +void DecoderBuffer::Initialize() { |
| +#if !defined(OS_ANDROID) |
| + // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are |
| + // padded. Using av_malloc with padding ensures FFmpeg only recieves data |
| + // padded and aligned to its specifications. |
| + data_ = reinterpret_cast<uint8*>( |
| + av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE)); |
| + memset(data_ + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
| +#else |
| + data_ = new uint8[buffer_size_]; |
| +#endif |
| +} |
| + |
| +scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, |
| + int data_size) { |
| + DCHECK(data && data_size >= 0); |
| + return make_scoped_refptr(new DecoderBuffer(data, data_size)); |
| +} |
| + |
| +scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { |
| + return make_scoped_refptr(new DecoderBuffer(NULL, 0)); |
| +} |
| + |
| +const uint8* DecoderBuffer::GetData() const { |
| + return data_; |
| +} |
| + |
| +int DecoderBuffer::GetDataSize() const { |
| + return buffer_size_; |
| +} |
| + |
| +uint8* DecoderBuffer::GetWritableData() { |
| + return data_; |
| +} |
| + |
| +const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { |
| + return decrypt_config_.get(); |
| +} |
| + |
| +void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { |
| + decrypt_config_ = decrypt_config.Pass(); |
| +} |
| + |
| +} // namespace media |