| 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 "media/base/buffers.h" | 8 #include "media/base/buffers.h" |
| 9 #include "media/base/decrypt_config.h" | 9 #include "media/base/decrypt_config.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 // Allocates a block of memory which is padded for use with the SIMD |
| 14 // optimizations used by FFmpeg. |
| 15 static uint8* AllocateFFmpegSafeBlock(int size) { |
| 16 uint8* const block = reinterpret_cast<uint8*>(base::AlignedAlloc( |
| 17 size + DecoderBuffer::kPaddingSize, DecoderBuffer::kAlignmentSize)); |
| 18 memset(block + size, 0, DecoderBuffer::kPaddingSize); |
| 19 return block; |
| 20 } |
| 21 |
| 13 DecoderBuffer::DecoderBuffer(int size) | 22 DecoderBuffer::DecoderBuffer(int size) |
| 14 : size_(size), | 23 : size_(size), |
| 15 side_data_size_(0), | 24 side_data_size_(0), |
| 16 is_key_frame_(false) { | 25 is_key_frame_(false) { |
| 17 Initialize(); | 26 Initialize(); |
| 18 } | 27 } |
| 19 | 28 |
| 20 DecoderBuffer::DecoderBuffer(const uint8* data, int size, | 29 DecoderBuffer::DecoderBuffer(const uint8* data, int size, |
| 21 const uint8* side_data, int side_data_size) | 30 const uint8* side_data, int side_data_size) |
| 22 : size_(size), | 31 : size_(size), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 } | 48 } |
| 40 | 49 |
| 41 DCHECK_GT(side_data_size_, 0); | 50 DCHECK_GT(side_data_size_, 0); |
| 42 memcpy(side_data_.get(), side_data, side_data_size_); | 51 memcpy(side_data_.get(), side_data, side_data_size_); |
| 43 } | 52 } |
| 44 | 53 |
| 45 DecoderBuffer::~DecoderBuffer() {} | 54 DecoderBuffer::~DecoderBuffer() {} |
| 46 | 55 |
| 47 void DecoderBuffer::Initialize() { | 56 void DecoderBuffer::Initialize() { |
| 48 CHECK_GE(size_, 0); | 57 CHECK_GE(size_, 0); |
| 49 data_.reset(reinterpret_cast<uint8*>( | 58 data_.reset(AllocateFFmpegSafeBlock(size_)); |
| 50 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); | 59 if (side_data_size_ > 0) |
| 51 memset(data_.get() + size_, 0, kPaddingSize); | 60 side_data_.reset(AllocateFFmpegSafeBlock(side_data_size_)); |
| 52 if (side_data_size_ > 0) { | |
| 53 side_data_.reset(reinterpret_cast<uint8*>( | |
| 54 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize))); | |
| 55 memset(side_data_.get() + side_data_size_, 0, kPaddingSize); | |
| 56 } | |
| 57 splice_timestamp_ = kNoTimestamp(); | 61 splice_timestamp_ = kNoTimestamp(); |
| 58 } | 62 } |
| 59 | 63 |
| 60 // static | 64 // static |
| 61 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 65 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, |
| 62 int data_size) { | 66 int data_size) { |
| 63 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. | 67 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. |
| 64 CHECK(data); | 68 CHECK(data); |
| 65 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0)); | 69 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0)); |
| 66 } | 70 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 97 << " discard_padding (ms): (" << discard_padding_.first.InMilliseconds() | 101 << " discard_padding (ms): (" << discard_padding_.first.InMilliseconds() |
| 98 << ", " << discard_padding_.second.InMilliseconds() << ")"; | 102 << ", " << discard_padding_.second.InMilliseconds() << ")"; |
| 99 return s.str(); | 103 return s.str(); |
| 100 } | 104 } |
| 101 | 105 |
| 102 void DecoderBuffer::set_timestamp(base::TimeDelta timestamp) { | 106 void DecoderBuffer::set_timestamp(base::TimeDelta timestamp) { |
| 103 DCHECK(!end_of_stream()); | 107 DCHECK(!end_of_stream()); |
| 104 timestamp_ = timestamp; | 108 timestamp_ = timestamp; |
| 105 } | 109 } |
| 106 | 110 |
| 111 void DecoderBuffer::CopySideDataFrom(const uint8* side_data, |
| 112 int side_data_size) { |
| 113 if (side_data_size > 0) { |
| 114 side_data_size_ = side_data_size; |
| 115 side_data_.reset(AllocateFFmpegSafeBlock(side_data_size_)); |
| 116 memcpy(side_data_.get(), side_data, side_data_size_); |
| 117 } else { |
| 118 side_data_.reset(); |
| 119 side_data_size_ = 0; |
| 120 } |
| 121 } |
| 122 |
| 107 } // namespace media | 123 } // namespace media |
| OLD | NEW |