blob: 3cfb2549d0a878a7c3e3a87c46942053799a859c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "media/base/data_buffer.h"
#include "media/base/decrypt_config.h"
#if !defined(OS_ANDROID)
#include "media/ffmpeg/ffmpeg_common.h"
#endif
namespace media {
DataBuffer::DataBuffer(scoped_array<uint8> buffer, size_t buffer_size)
: data_(buffer.Pass()),
buffer_size_(buffer_size),
data_size_(buffer_size) {
}
DataBuffer::DataBuffer(size_t buffer_size)
: data_(new uint8[buffer_size]),
buffer_size_(buffer_size),
data_size_(0) {
CHECK(data_.get()) << "DataBuffer ctor failed to allocate memory";
// Prevent arbitrary pointers.
if (buffer_size == 0)
data_.reset(NULL);
}
DataBuffer::~DataBuffer() {
}
scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data,
size_t data_size) {
size_t padding_size = 0;
#if !defined(OS_ANDROID)
// Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
// padded with this value.
padding_size = FF_INPUT_BUFFER_PADDING_SIZE;
#endif
scoped_refptr<DataBuffer> data_buffer(
new DataBuffer(data_size + padding_size));
memcpy(data_buffer->data_.get(), data, data_size);
memset(data_buffer->data_.get() + data_size, 0, padding_size);
data_buffer->SetDataSize(data_size);
return data_buffer;
}
const uint8* DataBuffer::GetData() const {
return data_.get();
}
size_t DataBuffer::GetDataSize() const {
return data_size_;
}
const DecryptConfig* DataBuffer::GetDecryptConfig() const {
return decrypt_config_.get();
}
uint8* DataBuffer::GetWritableData() {
return data_.get();
}
void DataBuffer::SetDataSize(size_t data_size) {
DCHECK_LE(data_size, buffer_size_);
data_size_ = data_size;
}
size_t DataBuffer::GetBufferSize() const {
return buffer_size_;
}
void DataBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
decrypt_config_ = decrypt_config.Pass();
}
} // namespace media
|