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.
5 #include "media/base/decoder_buffer.h"
7 #include "base/logging.h"
8 #include "media/base/decrypt_config.h"
12 DecoderBuffer::DecoderBuffer(int size
)
18 DecoderBuffer::DecoderBuffer(const uint8
* data
, int size
,
19 const uint8
* side_data
, int side_data_size
)
21 side_data_size_(side_data_size
) {
29 memcpy(data_
.get(), data
, size_
);
31 memcpy(side_data_
.get(), side_data
, side_data_size_
);
34 DecoderBuffer::~DecoderBuffer() {}
36 void DecoderBuffer::Initialize() {
38 data_
.reset(reinterpret_cast<uint8
*>(
39 base::AlignedAlloc(size_
+ kPaddingSize
, kAlignmentSize
)));
40 memset(data_
.get() + size_
, 0, kPaddingSize
);
41 if (side_data_size_
> 0) {
42 side_data_
.reset(reinterpret_cast<uint8
*>(
43 base::AlignedAlloc(side_data_size_
+ kPaddingSize
, kAlignmentSize
)));
44 memset(side_data_
.get() + side_data_size_
, 0, kPaddingSize
);
49 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
51 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
53 return make_scoped_refptr(new DecoderBuffer(data
, data_size
, NULL
, 0));
57 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
59 const uint8
* side_data
,
61 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
64 return make_scoped_refptr(new DecoderBuffer(data
, data_size
,
65 side_data
, side_data_size
));
69 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CreateEOSBuffer() {
70 return make_scoped_refptr(new DecoderBuffer(NULL
, 0, NULL
, 0));
73 std::string
DecoderBuffer::AsHumanReadableString() {
74 if (end_of_stream()) {
75 return "end of stream";
79 s
<< "timestamp: " << timestamp_
.InMicroseconds()
80 << " duration: " << duration_
.InMicroseconds()
82 << " side_data_size: " << side_data_size_
83 << " encrypted: " << (decrypt_config_
!= NULL
)
84 << " discard_padding (ms): " << discard_padding_
.InMilliseconds();