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/buffers.h"
9 #include "media/base/decrypt_config.h"
13 DecoderBuffer::DecoderBuffer(int size
)
19 DecoderBuffer::DecoderBuffer(const uint8
* data
, int size
,
20 const uint8
* side_data
, int side_data_size
)
22 side_data_size_(side_data_size
) {
30 memcpy(data_
.get(), data
, size_
);
32 memcpy(side_data_
.get(), side_data
, side_data_size_
);
35 DecoderBuffer::~DecoderBuffer() {}
37 void DecoderBuffer::Initialize() {
39 data_
.reset(reinterpret_cast<uint8
*>(
40 base::AlignedAlloc(size_
+ kPaddingSize
, kAlignmentSize
)));
41 memset(data_
.get() + size_
, 0, kPaddingSize
);
42 if (side_data_size_
> 0) {
43 side_data_
.reset(reinterpret_cast<uint8
*>(
44 base::AlignedAlloc(side_data_size_
+ kPaddingSize
, kAlignmentSize
)));
45 memset(side_data_
.get() + side_data_size_
, 0, kPaddingSize
);
47 splice_timestamp_
= kNoTimestamp();
51 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
53 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
55 return make_scoped_refptr(new DecoderBuffer(data
, data_size
, NULL
, 0));
59 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
61 const uint8
* side_data
,
63 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
66 return make_scoped_refptr(new DecoderBuffer(data
, data_size
,
67 side_data
, side_data_size
));
71 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CreateEOSBuffer() {
72 return make_scoped_refptr(new DecoderBuffer(NULL
, 0, NULL
, 0));
75 std::string
DecoderBuffer::AsHumanReadableString() {
76 if (end_of_stream()) {
77 return "end of stream";
81 s
<< "timestamp: " << timestamp_
.InMicroseconds()
82 << " duration: " << duration_
.InMicroseconds()
84 << " side_data_size: " << side_data_size_
85 << " encrypted: " << (decrypt_config_
!= NULL
)
86 << " discard_padding (ms): (" << discard_padding_
.first
.InMilliseconds()
87 << ", " << discard_padding_
.second
.InMilliseconds() << ")";