-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhlstream.hpp
executable file
·128 lines (101 loc) · 3.3 KB
/
hlstream.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
/**
* @file hlstream.hpp
* @brief Ingests HLS playlists and transport streams, and outputs
* encoded elementary stream data.
*
* @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_HLSTREAM_HPP
#define CINEK_AVLIB_HLSTREAM_HPP
#include "avstream.hpp"
#include "hlsplaylist.hpp"
#include "mpegts.hpp"
namespace cinekav {
namespace mpegts {
class ElementaryStream;
}
}
namespace cinekav {
class HLStream : public Stream
{
public:
HLStream(const StreamInputCallbacks& inputCbs,
Buffer&& videoBuffer,
Buffer&& audioBuffer,
const char* url,
const Memory& memory=Memory());
virtual ~HLStream();
virtual void update() override;
// Obtain encoded data from our current read buffer. This method advances
// may advance the read pointer as needed
int pullEncodedData(ESAccessUnit* vau, ESAccessUnit* aau);
private:
cinekav::ElementaryStream* createES(cinekav::ElementaryStream::Type,
uint16_t programId);
cinekav::ElementaryStream* getES(uint16_t programId, uint16_t index);
void finalizeES(uint16_t programId, uint16_t index);
cinekav::ElementaryStream* handleOverflowES(uint16_t programId,
uint16_t index,
uint32_t len);
private:
Memory _memory;
StreamInputCallbacks _inputCbs;
enum
{
kOpenRootList,
kReadRootList,
kOpenMediaList,
kReadMediaList,
kDownloadSegment,
kOpenSegment,
kReadSegment,
kNoStreamError,
kInStreamError,
kMemoryError,
kInternalError
}
_state;
uint32_t _inputRequestHandle;
uintptr_t _inputResourceHandle;
Buffer _inputBuffer;
HLSMasterPlaylist _masterPlaylist;
HLSMasterPlaylist::Playlists::iterator _toParsePlaylist;
HLSMasterPlaylist::Playlists::const_iterator _toPlayPlaylist;
std::string _rootUrl;
int _playlistSegmentIndex;
Buffer _videoBuffer;
Buffer _audioBuffer;
cinekav::mpegts::Demuxer _demuxer;
uint8_t _audioESIndex; // 0x1 - 0x7f
uint8_t _videoESIndex; // 0x80 - 0xff
int _bufferCount;
using EStreams = std::vector<cinekav::ElementaryStream,
std_allocator<cinekav::ElementaryStream>>;
EStreams _audioStreams;
EStreams _videoStreams;
// identifies which stream buffer within the index array marks the current
// read and writeindices.
struct StreamPosition
{
int readFromIdx; // read from buffer index
int readDoneIdx;
int readAUIdx; // read access unit within buffer
int writeToIdx; // write to buffer index
int writeDoneIdx;
int bufferCnt;
void reset(int bufferCnt);
bool hasWriteSpace() const;
bool hasReadSpace() const;
bool advanceWrite();
bool advanceRead();
};
StreamPosition _audioPos;
StreamPosition _videoPos;
void resetStreams();
void startStreams();
void stopStreams();
};
} /* namespace cinekav */
#endif