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
)
16 is_key_frame_(false) {
20 DecoderBuffer::DecoderBuffer(const uint8
* data
, int size
,
21 const uint8
* side_data
, int side_data_size
)
23 side_data_size_(side_data_size
),
24 is_key_frame_(false) {
32 memcpy(data_
.get(), data
, size_
);
34 memcpy(side_data_
.get(), side_data
, side_data_size_
);
37 DecoderBuffer::~DecoderBuffer() {}
39 void DecoderBuffer::Initialize() {
41 data_
.reset(reinterpret_cast<uint8
*>(
42 base::AlignedAlloc(size_
+ kPaddingSize
, kAlignmentSize
)));
43 memset(data_
.get() + size_
, 0, kPaddingSize
);
44 if (side_data_size_
> 0) {
45 side_data_
.reset(reinterpret_cast<uint8
*>(
46 base::AlignedAlloc(side_data_size_
+ kPaddingSize
, kAlignmentSize
)));
47 memset(side_data_
.get() + side_data_size_
, 0, kPaddingSize
);
49 splice_timestamp_
= kNoTimestamp();
53 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
55 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
57 return make_scoped_refptr(new DecoderBuffer(data
, data_size
, NULL
, 0));
61 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
63 const uint8
* side_data
,
65 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
68 return make_scoped_refptr(new DecoderBuffer(data
, data_size
,
69 side_data
, side_data_size
));
73 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CreateEOSBuffer() {
74 return make_scoped_refptr(new DecoderBuffer(NULL
, 0, NULL
, 0));
77 std::string
DecoderBuffer::AsHumanReadableString() {
78 if (end_of_stream()) {
79 return "end of stream";
83 s
<< "timestamp: " << timestamp_
.InMicroseconds()
84 << " duration: " << duration_
.InMicroseconds()
86 << " side_data_size: " << side_data_size_
87 << " is_key_frame: " << is_key_frame_
88 << " encrypted: " << (decrypt_config_
!= NULL
)
89 << " discard_padding (ms): (" << discard_padding_
.first
.InMilliseconds()
90 << ", " << discard_padding_
.second
.InMilliseconds() << ")";
94 void DecoderBuffer::set_timestamp(base::TimeDelta timestamp
) {
95 DCHECK(!end_of_stream());
96 timestamp_
= timestamp
;