Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / media / base / decoder_buffer.cc
blobed6481b218ff746ad2e3d93c5793998ba3566323
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"
11 namespace media {
13 DecoderBuffer::DecoderBuffer(int size)
14 : size_(size),
15 side_data_size_(0),
16 is_key_frame_(false) {
17 Initialize();
20 DecoderBuffer::DecoderBuffer(const uint8* data, int size,
21 const uint8* side_data, int side_data_size)
22 : size_(size),
23 side_data_size_(side_data_size),
24 is_key_frame_(false) {
25 if (!data) {
26 CHECK_EQ(size_, 0);
27 CHECK(!side_data);
28 return;
31 Initialize();
32 memcpy(data_.get(), data, size_);
33 if (side_data)
34 memcpy(side_data_.get(), side_data, side_data_size_);
37 DecoderBuffer::~DecoderBuffer() {}
39 void DecoderBuffer::Initialize() {
40 CHECK_GE(size_, 0);
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();
52 // static
53 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
54 int data_size) {
55 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
56 CHECK(data);
57 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0));
60 // static
61 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
62 int data_size,
63 const uint8* side_data,
64 int side_data_size) {
65 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
66 CHECK(data);
67 CHECK(side_data);
68 return make_scoped_refptr(new DecoderBuffer(data, data_size,
69 side_data, side_data_size));
72 // static
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";
82 std::ostringstream s;
83 s << "timestamp: " << timestamp_.InMicroseconds()
84 << " duration: " << duration_.InMicroseconds()
85 << " size: " << size_
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() << ")";
91 return s.str();
94 void DecoderBuffer::set_timestamp(base::TimeDelta timestamp) {
95 DCHECK(!end_of_stream());
96 timestamp_ = timestamp;
99 } // namespace media