~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to src/mcs/video/buffer.h

Add hardware encoding and video streaming support.

The hardware encoding is currently only for Android 5.x based devices. On all others encoding will simply not work. The streaming part of aethercast (MPEGTS packetizing, RTP sending) as based on some code from Android.

Approved by PS Jenkins bot, Thomas Voß, Jim Hodapp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
#ifndef MCS_VIDEO_BUFFER_H_
 
19
#define MCS_VIDEO_BUFFER_H_
 
20
 
 
21
#include <memory>
 
22
 
 
23
#include "mcs/non_copyable.h"
 
24
#include "mcs/utils.h"
 
25
 
 
26
namespace mcs {
 
27
namespace video {
 
28
 
 
29
class BufferOutputTarget;
 
30
 
 
31
class Buffer : public std::enable_shared_from_this<Buffer> {
 
32
public:
 
33
    typedef std::shared_ptr<Buffer> Ptr;
 
34
 
 
35
    class Delegate : public mcs::NonCopyable {
 
36
    public:
 
37
        virtual void OnBufferFinished(const mcs::video::Buffer::Ptr &buffer) = 0;
 
38
    };
 
39
 
 
40
    virtual ~Buffer();
 
41
 
 
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);
 
45
 
 
46
    void SetRange(uint32_t offset, uint32_t length);
 
47
    void SetTimestamp(int64_t timestamp);
 
48
 
 
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_; }
 
55
 
 
56
    virtual bool IsValid() const { return data_ != nullptr || native_handle_ != nullptr; }
 
57
 
 
58
    virtual void *NativeHandle() const { return native_handle_; }
 
59
 
 
60
    void SetDelegate(const std::weak_ptr<Delegate> &delegate);
 
61
 
 
62
    void Release();
 
63
 
 
64
protected:
 
65
    Buffer();
 
66
    Buffer(mcs::TimestampUs timestamp);
 
67
 
 
68
    void Allocate(uint32_t size);
 
69
 
 
70
private:
 
71
    std::weak_ptr<Delegate> delegate_;
 
72
    uint32_t capacity_;
 
73
    uint32_t length_;
 
74
    uint32_t offset_;
 
75
    uint8_t *data_;
 
76
    int64_t timestamp_;
 
77
    void *native_handle_;
 
78
 
 
79
    friend class BufferOutputTarget;
 
80
};
 
81
 
 
82
} // namespace video
 
83
} // namespace mcs
 
84
 
 
85
#endif