Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/decoder_buffer.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "media/base/decrypt_config.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 DecoderBuffer::DecoderBuffer(int buffer_size) | |
| 13 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
| 14 buffer_size_(buffer_size) { | |
| 15 Initialize(); | |
| 16 } | |
| 17 | |
| 18 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) | |
| 19 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
| 20 buffer_size_(buffer_size) { | |
| 21 Initialize(); | |
| 22 // If Initialize fails buffer_size_ == 0 and this becomes a no-op. | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
not needed
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 23 memcpy(data_.get(), data, buffer_size_); | |
| 24 } | |
| 25 | |
| 26 DecoderBuffer::~DecoderBuffer() {} | |
| 27 | |
| 28 void DecoderBuffer::Initialize() { | |
| 29 // Prevent arbitrary pointers. | |
| 30 if (buffer_size_ <= 0) { | |
| 31 buffer_size_ = 0; | |
| 32 data_.reset(NULL); | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 #if !defined(OS_ANDROID) | |
| 37 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | |
| 38 // padded. Using av_malloc with padding ensures FFmpeg only recieves data | |
| 39 // padded and aligned to its specifications. | |
| 40 data_.reset(reinterpret_cast<uint8*>( | |
| 41 av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE))); | |
| 42 #else | |
| 43 data_.reset(new uint8[buffer_size_]); | |
| 44 #endif | |
| 45 CHECK(data_.get()) << "DecoderBuffer ctor failed to allocate memory"; | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
not needed
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 46 | |
| 47 #if !defined(OS_ANDROID) | |
| 48 // Padding data should always be zeroed to prevent uninitialized reads. | |
| 49 memset(data_.get() + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
can move this up into other #if section
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 50 #endif | |
| 51 } | |
| 52 | |
| 53 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | |
| 54 int data_size) { | |
| 55 return make_scoped_refptr(new DecoderBuffer(data, data_size)); | |
| 56 } | |
| 57 | |
| 58 const uint8* DecoderBuffer::GetData() const { | |
| 59 return data_.get(); | |
| 60 } | |
| 61 | |
| 62 int DecoderBuffer::GetDataSize() const { | |
| 63 return buffer_size_; | |
| 64 } | |
| 65 | |
| 66 uint8* DecoderBuffer::GetWritableData() { | |
| 67 return data_.get(); | |
| 68 } | |
| 69 | |
| 70 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { | |
| 71 return decrypt_config_.get(); | |
| 72 } | |
| 73 | |
| 74 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { | |
| 75 decrypt_config_ = decrypt_config.Pass(); | |
| 76 } | |
| 77 | |
| 78 } // namespace media | |
| OLD | NEW |