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 #if !defined(OS_ANDROID) | |
| 10 #include "media/ffmpeg/ffmpeg_common.h" | |
| 11 #endif | |
| 12 | |
| 13 namespace media { | |
| 14 | |
| 15 DecoderBuffer::DecoderBuffer(int buffer_size) | |
| 16 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
| 17 buffer_size_(buffer_size) { | |
| 18 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!
| |
| 19 Initialize(); | |
| 20 } | |
| 21 | |
| 22 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) | |
| 23 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
| 24 buffer_size_(buffer_size) { | |
| 25 // Prevent invalid allocations. Also used to create end of stream buffers. | |
| 26 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.
| |
| 27 buffer_size_ = 0; | |
| 28 data_ = NULL; | |
| 29 return; | |
| 30 } | |
| 31 | |
| 32 Initialize(); | |
| 33 memcpy(data_, data, buffer_size_); | |
| 34 } | |
| 35 | |
| 36 DecoderBuffer::~DecoderBuffer() { | |
| 37 #if !defined(OS_ANDROID) | |
| 38 av_free(data_); | |
| 39 #else | |
| 40 delete[] data_; | |
| 41 #endif | |
| 42 } | |
| 43 | |
| 44 void DecoderBuffer::Initialize() { | |
| 45 #if !defined(OS_ANDROID) | |
| 46 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | |
| 47 // padded. Using av_malloc with padding ensures FFmpeg only recieves data | |
| 48 // padded and aligned to its specifications. | |
| 49 data_ = reinterpret_cast<uint8*>( | |
| 50 av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE)); | |
| 51 memset(data_ + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
| 52 #else | |
| 53 data_ = new uint8[buffer_size_]; | |
| 54 #endif | |
| 55 } | |
| 56 | |
| 57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | |
| 58 int data_size) { | |
| 59 DCHECK(data && data_size >= 0); | |
| 60 return make_scoped_refptr(new DecoderBuffer(data, data_size)); | |
| 61 } | |
| 62 | |
| 63 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | |
| 64 return make_scoped_refptr(new DecoderBuffer(NULL, 0)); | |
| 65 } | |
| 66 | |
| 67 const uint8* DecoderBuffer::GetData() const { | |
| 68 return data_; | |
| 69 } | |
| 70 | |
| 71 int DecoderBuffer::GetDataSize() const { | |
| 72 return buffer_size_; | |
| 73 } | |
| 74 | |
| 75 uint8* DecoderBuffer::GetWritableData() { | |
| 76 return data_; | |
| 77 } | |
| 78 | |
| 79 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { | |
| 80 return decrypt_config_.get(); | |
| 81 } | |
| 82 | |
| 83 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { | |
| 84 decrypt_config_ = decrypt_config.Pass(); | |
| 85 } | |
| 86 | |
| 87 } // namespace media | |
| OLD | NEW |