2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef MCS_VIDEO_BUFFER_H_
19
#define MCS_VIDEO_BUFFER_H_
23
#include "mcs/non_copyable.h"
24
#include "mcs/utils.h"
29
class BufferOutputTarget;
31
class Buffer : public std::enable_shared_from_this<Buffer> {
33
typedef std::shared_ptr<Buffer> Ptr;
35
class Delegate : public mcs::NonCopyable {
37
virtual void OnBufferFinished(const mcs::video::Buffer::Ptr &buffer) = 0;
42
static Buffer::Ptr Create(uint32_t capacity = 0, mcs::TimestampUs timestamp = 0ll);
43
static Buffer::Ptr Create(uint8_t *data, uint32_t length);
44
static Buffer::Ptr Create(void *native_handle);
46
void SetRange(uint32_t offset, uint32_t length);
47
void SetTimestamp(int64_t timestamp);
49
virtual uint32_t Capacity() const { return capacity_; }
50
virtual uint32_t Offset() const { return offset_; }
51
virtual uint32_t Length() const { return length_; }
52
virtual uint8_t* Data() { return data_ + offset_; }
53
// Timestamp of the buffer in micro-seconds
54
virtual mcs::TimestampUs Timestamp() const { return timestamp_; }
56
virtual bool IsValid() const { return data_ != nullptr || native_handle_ != nullptr; }
58
virtual void *NativeHandle() const { return native_handle_; }
60
void SetDelegate(const std::weak_ptr<Delegate> &delegate);
66
Buffer(mcs::TimestampUs timestamp);
68
void Allocate(uint32_t size);
71
std::weak_ptr<Delegate> delegate_;
79
friend class BufferOutputTarget;