forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_buffer.cc
67 lines (52 loc) · 1.46 KB
/
data_buffer.cc
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
// 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 "media/base/data_buffer.h"
#include "base/logging.h"
namespace media {
DataBuffer::DataBuffer(scoped_array<uint8> buffer, int buffer_size)
: Buffer(base::TimeDelta(), base::TimeDelta()),
data_(buffer.Pass()),
buffer_size_(buffer_size),
data_size_(buffer_size) {
}
DataBuffer::DataBuffer(int buffer_size)
: Buffer(base::TimeDelta(), base::TimeDelta()),
buffer_size_(buffer_size),
data_size_(0) {
Initialize();
}
DataBuffer::DataBuffer(const uint8* data, int data_size)
: Buffer(base::TimeDelta(), base::TimeDelta()),
buffer_size_(data_size),
data_size_(data_size) {
Initialize();
memcpy(data_.get(), data, data_size_);
}
DataBuffer::~DataBuffer() {}
void DataBuffer::Initialize() {
// Prevent arbitrary pointers.
if (buffer_size_ <= 0) {
buffer_size_ = data_size_ = 0;
data_.reset();
return;
}
data_.reset(new uint8[buffer_size_]);
}
const uint8* DataBuffer::GetData() const {
return data_.get();
}
int DataBuffer::GetDataSize() const {
return data_size_;
}
uint8* DataBuffer::GetWritableData() {
return data_.get();
}
void DataBuffer::SetDataSize(int data_size) {
DCHECK_LE(data_size, buffer_size_);
data_size_ = data_size;
}
int DataBuffer::GetBufferSize() const {
return buffer_size_;
}
} // namespace media