-
Notifications
You must be signed in to change notification settings - Fork 6
/
hlsplaylist.hpp
executable file
·149 lines (119 loc) · 3.19 KB
/
hlsplaylist.hpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file hlsplaylist.hpp
* @brief Parsers and containers for HLS playlists.
*
* @copyright Copyright 2015 Samir Sinha. All rights reserved.
* @license This project is released under the ISC license. See LICENSE
* for the full text.
*/
#ifndef CINEK_AVLIB_HLSPLAYLIST_HPP
#define CINEK_AVLIB_HLSPLAYLIST_HPP
#include "avstream.hpp"
#include <array>
#include <vector>
#include <string>
namespace cinekav {
namespace mpegts {
class ElementaryStream;
}
}
namespace cinekav {
class HLSPlaylistParser;
class HLSPlaylist
{
public:
struct Segment
{
std::string uri;
float duration;
Segment() = default;
Segment(Segment&& other) :
uri(std::move(other.uri)),
duration(other.duration)
{
other.duration = 0.f;
}
Segment& operator=(Segment&& other)
{
uri = std::move(other.uri);
duration = other.duration;
other.duration = 0.f;
return *this;
}
};
HLSPlaylist();
HLSPlaylist(const std::string& uri, const Memory& memory=Memory());
HLSPlaylist(HLSPlaylist&& other);
HLSPlaylist& operator=(HLSPlaylist&& other);
void addSegment(Segment&& segment);
int segmentCount() const { return _segments.size(); }
Segment* segmentAt(int index);
const Segment* segmentAt(int index) const;
const std::string& uri() const { return _uri; }
private:
friend class HLSPlaylistParser;
std::string _uri;
int _seqNo;
float _targetDuration;
int _version;
std::vector<Segment, std_allocator<Segment>> _segments;
};
class HLSPlaylistParser
{
public:
HLSPlaylistParser();
bool parse(HLSPlaylist& playlist, const std::string& line);
private:
enum { kInit, kInputLine, kPlaylistLine } _state;
HLSPlaylist::Segment _info;
};
class HLSMasterPlaylistParser;
class HLSMasterPlaylist
{
public:
struct PlaylistInfo
{
uint32_t frameWidth = 0;
uint32_t frameHeight = 0;
uint32_t bandwidth = 0;
std::array<uint32_t, 4> codecs; // more?
bool available = false;
};
struct StreamInfo
{
PlaylistInfo info;
HLSPlaylist playlist;
};
using Playlists = std::vector<StreamInfo, std_allocator<StreamInfo>>;
HLSMasterPlaylist(const Memory& memory=Memory());
StreamInfo* addStream(const PlaylistInfo& info, const std::string& uri);
Playlists::const_iterator begin() const {
return _playlists.begin();
}
Playlists::const_iterator end() const {
return _playlists.end();
}
Playlists::iterator begin() {
return _playlists.begin();
}
Playlists::iterator end() {
return _playlists.end();
}
private:
friend class HLSMasterPlaylistParser;
Memory _memory;
Playlists _playlists;
};
class HLSMasterPlaylistParser
{
public:
HLSMasterPlaylistParser();
bool parse(HLSMasterPlaylist& playlist, const std::string& line);
private:
void parseCodecs(const std::string& line);
enum { kInit, kInputLine, kPlaylistLine } _state;
HLSMasterPlaylist::PlaylistInfo _info;
int _version;
};
} /* namespace cinekav */
#endif