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"
10 // Allocates a block of memory which is padded for use with the SIMD
11 // optimizations used by FFmpeg.
12 static uint8
* AllocateFFmpegSafeBlock(int size
) {
13 uint8
* const block
= reinterpret_cast<uint8
*>(base::AlignedAlloc(
14 size
+ DecoderBuffer::kPaddingSize
, DecoderBuffer::kAlignmentSize
));
15 memset(block
+ size
, 0, DecoderBuffer::kPaddingSize
);
19 DecoderBuffer::DecoderBuffer(int size
)
22 is_key_frame_(false) {
26 DecoderBuffer::DecoderBuffer(const uint8
* data
,
28 const uint8
* side_data
,
31 side_data_size_(side_data_size
),
32 is_key_frame_(false) {
42 memcpy(data_
.get(), data
, size_
);
45 CHECK_EQ(side_data_size
, 0);
49 DCHECK_GT(side_data_size_
, 0);
50 memcpy(side_data_
.get(), side_data
, side_data_size_
);
53 DecoderBuffer::~DecoderBuffer() {}
55 void DecoderBuffer::Initialize() {
57 data_
.reset(AllocateFFmpegSafeBlock(size_
));
58 if (side_data_size_
> 0)
59 side_data_
.reset(AllocateFFmpegSafeBlock(side_data_size_
));
60 splice_timestamp_
= kNoTimestamp();
64 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
66 // 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
, NULL
, 0));
72 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CopyFrom(const uint8
* data
,
74 const uint8
* side_data
,
76 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
79 return make_scoped_refptr(new DecoderBuffer(data
, data_size
,
80 side_data
, side_data_size
));
84 scoped_refptr
<DecoderBuffer
> DecoderBuffer::CreateEOSBuffer() {
85 return make_scoped_refptr(new DecoderBuffer(NULL
, 0, NULL
, 0));
88 std::string
DecoderBuffer::AsHumanReadableString() {
89 if (end_of_stream()) {
90 return "end of stream";
94 s
<< "timestamp: " << timestamp_
.InMicroseconds()
95 << " duration: " << duration_
.InMicroseconds()
97 << " side_data_size: " << side_data_size_
98 << " is_key_frame: " << is_key_frame_
99 << " encrypted: " << (decrypt_config_
!= NULL
)
100 << " discard_padding (ms): (" << discard_padding_
.first
.InMilliseconds()
101 << ", " << discard_padding_
.second
.InMilliseconds() << ")";
105 void DecoderBuffer::set_timestamp(base::TimeDelta timestamp
) {
106 DCHECK(!end_of_stream());
107 timestamp_
= timestamp
;
110 void DecoderBuffer::CopySideDataFrom(const uint8
* side_data
,
111 int side_data_size
) {
112 if (side_data_size
> 0) {
113 side_data_size_
= side_data_size
;
114 side_data_
.reset(AllocateFFmpegSafeBlock(side_data_size_
));
115 memcpy(side_data_
.get(), side_data
, side_data_size_
);