Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / media / base / decoder_buffer.cc
blobd4e75410abeba58915547062d3722439fdceb3f9
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"
10 namespace media {
12 DecoderBuffer::DecoderBuffer(int size)
13 : size_(size),
14 side_data_size_(0) {
15 Initialize();
18 DecoderBuffer::DecoderBuffer(const uint8* data, int size,
19 const uint8* side_data, int side_data_size)
20 : size_(size),
21 side_data_size_(side_data_size) {
22 if (!data) {
23 CHECK_EQ(size_, 0);
24 CHECK(!side_data);
25 return;
28 Initialize();
29 memcpy(data_.get(), data, size_);
30 if (side_data)
31 memcpy(side_data_.get(), side_data, side_data_size_);
34 DecoderBuffer::~DecoderBuffer() {}
36 void DecoderBuffer::Initialize() {
37 CHECK_GE(size_, 0);
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);
48 // static
49 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
50 int data_size) {
51 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
52 CHECK(data);
53 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0));
56 // static
57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
58 int data_size,
59 const uint8* side_data,
60 int side_data_size) {
61 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
62 CHECK(data);
63 CHECK(side_data);
64 return make_scoped_refptr(new DecoderBuffer(data, data_size,
65 side_data, side_data_size));
68 // static
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";
78 std::ostringstream s;
79 s << "timestamp: " << timestamp_.InMicroseconds()
80 << " duration: " << duration_.InMicroseconds()
81 << " size: " << size_
82 << " side_data_size: " << side_data_size_
83 << " encrypted: " << (decrypt_config_ != NULL)
84 << " discard_padding (ms): " << discard_padding_.InMilliseconds();
85 return s.str();
88 } // namespace media