Style enforcement
This commit is contained in:
parent
6811b54186
commit
56c21b5ba6
4 changed files with 939 additions and 1151 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,14 @@
|
|||
#include "ts_packet.h"
|
||||
#include "adts.h"
|
||||
#include "h265.h"
|
||||
#include "ts_packet.h"
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <deque>
|
||||
#include "h265.h"
|
||||
|
||||
#include "shared_memory.h"
|
||||
|
||||
namespace TS{
|
||||
enum codecType {
|
||||
H264 = 0x1B,
|
||||
AAC = 0x0F,
|
||||
AC3 = 0x81,
|
||||
MP3 = 0x03,
|
||||
H265 = 0x24,
|
||||
ID3 = 0x15
|
||||
};
|
||||
enum codecType{H264 = 0x1B, AAC = 0x0F, AC3 = 0x81, MP3 = 0x03, H265 = 0x24, ID3 = 0x15};
|
||||
|
||||
class ADTSRemainder{
|
||||
private:
|
||||
|
@ -24,8 +17,10 @@ namespace TS {
|
|||
uint32_t now;
|
||||
uint32_t len;
|
||||
uint32_t bpos;
|
||||
|
||||
public:
|
||||
void setRemainder(const aac::adts & p, const void * source, const uint32_t avail, const uint32_t bPos);
|
||||
void setRemainder(const aac::adts &p, const void *source, const uint32_t avail,
|
||||
const uint32_t bPos);
|
||||
|
||||
ADTSRemainder();
|
||||
~ADTSRemainder();
|
||||
|
@ -60,8 +55,10 @@ namespace TS {
|
|||
void finish();
|
||||
void eraseTrack(unsigned long tid);
|
||||
bool isDataTrack(unsigned long tid);
|
||||
void parseBitstream(uint32_t tid, const char * pesPayload, uint32_t realPayloadSize,uint64_t timeStamp, int64_t timeOffset, uint64_t bPos);
|
||||
void parseBitstream(uint32_t tid, const char *pesPayload, uint32_t realPayloadSize,
|
||||
uint64_t timeStamp, int64_t timeOffset, uint64_t bPos);
|
||||
std::set<unsigned long> getActiveTracks();
|
||||
|
||||
private:
|
||||
unsigned long long lastPAT;
|
||||
ProgramAssociationTable associationTable;
|
||||
|
@ -92,3 +89,4 @@ namespace TS {
|
|||
void parsePES(unsigned long tid, bool finished = false);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,36 +1,32 @@
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <mist/stream.h>
|
||||
#include <mist/flv_tag.h>
|
||||
#include <mist/defines.h>
|
||||
#include <mist/ts_packet.h>
|
||||
#include <mist/timing.h>
|
||||
#include <mist/mp4_generic.h>
|
||||
#include "input_hls.h"
|
||||
#include <mist/bitfields.h>
|
||||
#include <mist/tinythread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <mist/http_parser.h>
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <mist/bitfields.h>
|
||||
#include <mist/defines.h>
|
||||
#include <mist/flv_tag.h>
|
||||
#include <mist/http_parser.h>
|
||||
#include <mist/mp4_generic.h>
|
||||
#include <mist/stream.h>
|
||||
#include <mist/timing.h>
|
||||
#include <mist/tinythread.h>
|
||||
#include <mist/ts_packet.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
|
||||
#define SEM_TS_CLAIM "/MstTSIN%s"
|
||||
|
||||
|
||||
namespace Mist{
|
||||
// remove trailing \r for windows generated playlist files
|
||||
int cleanLine(std::string &s){
|
||||
if (s.length() > 0 && s.at(s.length() - 1) == '\r') {
|
||||
s.erase(s.size() - 1);
|
||||
if (s.length() > 0 && s.at(s.length() - 1) == '\r'){s.erase(s.size() - 1);}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Playlist::Playlist(const std::string &uriSrc){
|
||||
lastFileIndex = 0;
|
||||
|
@ -75,13 +71,9 @@ namespace Mist {
|
|||
key = line.substr(7, pos - 7);
|
||||
val = line.c_str() + pos + 1;
|
||||
|
||||
if (key == "VERSION") {
|
||||
version = atoi(val.c_str());
|
||||
}
|
||||
if (key == "VERSION"){version = atoi(val.c_str());}
|
||||
|
||||
if (key == "TARGETDURATION") {
|
||||
waitTime = atoi(val.c_str());
|
||||
}
|
||||
if (key == "TARGETDURATION"){waitTime = atoi(val.c_str());}
|
||||
|
||||
if (key == "MEDIA-SEQUENCE"){
|
||||
media_sequence = atoi(val.c_str());
|
||||
|
@ -124,9 +116,7 @@ namespace Mist {
|
|||
initDone = true;
|
||||
}
|
||||
|
||||
bool Playlist::atEnd() const {
|
||||
return (packetPtr - source.data() + 188) > source.size();
|
||||
}
|
||||
bool Playlist::atEnd() const{return (packetPtr - source.data() + 188) > source.size();}
|
||||
|
||||
bool Playlist::isUrl() const{
|
||||
return (uri_root.size() ? uri_root.find("http://") == 0 : uri.find("http://") == 0);
|
||||
|
@ -171,9 +161,7 @@ namespace Mist {
|
|||
}
|
||||
|
||||
FAIL_MSG("Failed to load %s: %s", loadUrl.c_str(), conn ? "timeout" : "connection closed");
|
||||
if (conn) {
|
||||
conn.close();
|
||||
}
|
||||
if (conn){conn.close();}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -208,9 +196,7 @@ namespace Mist {
|
|||
skip = (lastFileIndex - media_sequence);
|
||||
continue;
|
||||
}
|
||||
if (line.compare(0, 7, "#EXTINF") != 0) {
|
||||
continue;
|
||||
}
|
||||
if (line.compare(0, 7, "#EXTINF") != 0){continue;}
|
||||
float f = atof(line.c_str() + 8);
|
||||
// next line belongs to this item
|
||||
std::string filename;
|
||||
|
@ -226,9 +212,7 @@ namespace Mist {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isUrl()) {
|
||||
fileSource.close();
|
||||
}
|
||||
if (!isUrl()){fileSource.close();}
|
||||
|
||||
ret = (count > 0);
|
||||
|
||||
|
@ -236,9 +220,7 @@ namespace Mist {
|
|||
noChangeCount = 0;
|
||||
}else{
|
||||
++noChangeCount;
|
||||
if (noChangeCount > 3) {
|
||||
VERYHIGH_MSG("enough!");
|
||||
}
|
||||
if (noChangeCount > 3){VERYHIGH_MSG("enough!");}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -265,9 +247,7 @@ namespace Mist {
|
|||
|
||||
entry.bytePos = totalBytes;
|
||||
entry.duration = duration;
|
||||
if (!isUrl()) {
|
||||
totalBytes += fileSource.tellg();
|
||||
}
|
||||
if (!isUrl()){totalBytes += fileSource.tellg();}
|
||||
|
||||
if (initDone){
|
||||
lastTimestamp += duration;
|
||||
|
@ -279,7 +259,6 @@ namespace Mist {
|
|||
++entryCount;
|
||||
entries.push_back(entry);
|
||||
++lastFileIndex;
|
||||
|
||||
}
|
||||
|
||||
/// Constructor of HLS Input
|
||||
|
@ -301,26 +280,23 @@ namespace Mist {
|
|||
}
|
||||
|
||||
inputHLS::~inputHLS(){
|
||||
if (inFile) {
|
||||
fclose(inFile);
|
||||
}
|
||||
if (inFile){fclose(inFile);}
|
||||
}
|
||||
|
||||
bool inputHLS::setup(){
|
||||
if (config->getString("input") == "-") {
|
||||
return false;
|
||||
}
|
||||
if (config->getString("input") == "-"){return false;}
|
||||
|
||||
if (!initPlaylist(config->getString("input"))) {
|
||||
return false;
|
||||
}
|
||||
if (!initPlaylist(config->getString("input"))){return false;}
|
||||
|
||||
if (Util::Config::printDebugLevel >= DLVL_HIGH){
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end(); pListIt++){
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end();
|
||||
pListIt++){
|
||||
std::cout << pListIt->id << ": " << pListIt->uri << std::endl;
|
||||
int j = 0;
|
||||
for (std::deque<playListEntries>::iterator entryIt = pListIt->entries.begin(); entryIt != pListIt->entries.end(); entryIt++){
|
||||
std::cout << " " << j++ << ": " << entryIt->filename << " bytePos: " << entryIt->bytePos << std::endl;
|
||||
for (std::deque<playListEntries>::iterator entryIt = pListIt->entries.begin();
|
||||
entryIt != pListIt->entries.end(); entryIt++){
|
||||
std::cout << " " << j++ << ": " << entryIt->filename
|
||||
<< " bytePos: " << entryIt->bytePos << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -343,9 +319,7 @@ namespace Mist {
|
|||
|
||||
void inputHLS::parseStreamHeader(){
|
||||
bool hasHeader = false;
|
||||
if (!hasHeader) {
|
||||
myMeta = DTSC::Meta();
|
||||
}
|
||||
if (!hasHeader){myMeta = DTSC::Meta();}
|
||||
|
||||
TS::Packet packet; // to analyse and extract data
|
||||
int counter = 1;
|
||||
|
@ -355,10 +329,9 @@ namespace Mist {
|
|||
unsigned int dataLen;
|
||||
bool keepReading = false;
|
||||
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end(); pListIt++){
|
||||
if (!pListIt->entries.size()) {
|
||||
continue;
|
||||
}
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end();
|
||||
pListIt++){
|
||||
if (!pListIt->entries.size()){continue;}
|
||||
std::deque<playListEntries>::iterator entryIt = pListIt->entries.begin();
|
||||
|
||||
tsStream.clear();
|
||||
|
@ -393,7 +366,9 @@ namespace Mist {
|
|||
pidMapping[(pListIt->id << 16) + headerPack.getTrackId()] = counter;
|
||||
pidMappingR[counter] = (pListIt->id << 16) + headerPack.getTrackId();
|
||||
packetId = counter;
|
||||
HIGH_MSG("Added file %s, trackid: %d, mapped to: %d", (pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(), counter);
|
||||
HIGH_MSG("Added file %s, trackid: %d, mapped to: %d",
|
||||
(pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(),
|
||||
counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
@ -406,7 +381,8 @@ namespace Mist {
|
|||
myMeta.live = false;
|
||||
myMeta.vod = true;
|
||||
|
||||
if (!hasHeader && (!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())) {
|
||||
if (!hasHeader &&
|
||||
(!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())){
|
||||
tsStream.initializeMetadata(myMeta, tmpTrackId, packetId);
|
||||
}
|
||||
}
|
||||
|
@ -427,9 +403,7 @@ namespace Mist {
|
|||
tsStream.clear();
|
||||
|
||||
INFO_MSG("end stream header tracks: %d", myMeta.tracks.size());
|
||||
if (hasHeader) {
|
||||
return;
|
||||
}
|
||||
if (hasHeader){return;}
|
||||
|
||||
// myMeta.live = true;
|
||||
// myMeta.vod = false;
|
||||
|
@ -437,9 +411,7 @@ namespace Mist {
|
|||
}
|
||||
|
||||
bool inputHLS::readHeader(){
|
||||
if (playlists.size() && playlists[0].playlistType == LIVE) {
|
||||
return true;
|
||||
}
|
||||
if (playlists.size() && playlists[0].playlistType == LIVE){return true;}
|
||||
|
||||
std::istringstream urlSource;
|
||||
std::ifstream fileSource;
|
||||
|
@ -451,14 +423,10 @@ namespace Mist {
|
|||
DTSC::File tmp(config->getString("input") + ".dtsh");
|
||||
if (tmp){
|
||||
myMeta = tmp.getMeta();
|
||||
if (myMeta) {
|
||||
hasHeader = true;
|
||||
}
|
||||
if (myMeta){hasHeader = true;}
|
||||
}
|
||||
|
||||
if (!hasHeader) {
|
||||
myMeta = DTSC::Meta();
|
||||
}
|
||||
if (!hasHeader){myMeta = DTSC::Meta();}
|
||||
|
||||
TS::Packet packet; // to analyse and extract data
|
||||
|
||||
|
@ -468,11 +436,13 @@ namespace Mist {
|
|||
char *data;
|
||||
unsigned int dataLen;
|
||||
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end(); pListIt++){
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end();
|
||||
pListIt++){
|
||||
tsStream.clear();
|
||||
uint32_t entId = 0;
|
||||
|
||||
for (std::deque<playListEntries>::iterator entryIt = pListIt->entries.begin(); entryIt != pListIt->entries.end(); entryIt++) {
|
||||
for (std::deque<playListEntries>::iterator entryIt = pListIt->entries.begin();
|
||||
entryIt != pListIt->entries.end(); entryIt++){
|
||||
// WORK
|
||||
tsStream.partialClear();
|
||||
endOfFile = false;
|
||||
|
@ -482,9 +452,7 @@ namespace Mist {
|
|||
urlSource.str(pListIt->source);
|
||||
|
||||
endOfFile = !pListIt->atEnd();
|
||||
if (!endOfFile){
|
||||
packet.FromPointer(pListIt->packetPtr);
|
||||
}
|
||||
if (!endOfFile){packet.FromPointer(pListIt->packetPtr);}
|
||||
pListIt->packetPtr += 188;
|
||||
}else{
|
||||
in.close();
|
||||
|
@ -515,11 +483,14 @@ namespace Mist {
|
|||
pidMapping[(pListIt->id << 16) + headerPack.getTrackId()] = counter;
|
||||
pidMappingR[counter] = (pListIt->id << 16) + headerPack.getTrackId();
|
||||
packetId = counter;
|
||||
INFO_MSG("Added file %s, trackid: %d, mapped to: %d", (pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(), counter);
|
||||
INFO_MSG("Added file %s, trackid: %d, mapped to: %d",
|
||||
(pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(),
|
||||
counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (!hasHeader && (!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())) {
|
||||
if (!hasHeader &&
|
||||
(!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())){
|
||||
tsStream.initializeMetadata(myMeta, tmpTrackId, packetId);
|
||||
}
|
||||
|
||||
|
@ -528,9 +499,12 @@ namespace Mist {
|
|||
uint64_t pBPos = headerPack.getInt("bpos");
|
||||
|
||||
// keyframe data exists, so always add 19 bytes keyframedata.
|
||||
long long packOffset = headerPack.hasMember("offset") ? headerPack.getInt("offset") : 0;
|
||||
long long packSendSize = 24 + (packOffset ? 17 : 0) + (entId >= 0 ? 15 : 0) + 19 + dataLen + 11;
|
||||
myMeta.update(headerPack.getTime(), packOffset, packetId, dataLen, entId, headerPack.hasMember("keyframe"), packSendSize);
|
||||
long long packOffset =
|
||||
headerPack.hasMember("offset") ? headerPack.getInt("offset") : 0;
|
||||
long long packSendSize =
|
||||
24 + (packOffset ? 17 : 0) + (entId >= 0 ? 15 : 0) + 19 + dataLen + 11;
|
||||
myMeta.update(headerPack.getTime(), packOffset, packetId, dataLen, entId,
|
||||
headerPack.hasMember("keyframe"), packSendSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,11 +531,14 @@ namespace Mist {
|
|||
pidMapping[(pListIt->id << 16) + headerPack.getTrackId()] = counter;
|
||||
pidMappingR[counter] = (pListIt->id << 16) + headerPack.getTrackId();
|
||||
packetId = counter;
|
||||
INFO_MSG("Added file %s, trackid: %d, mapped to: %d", (pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(), counter);
|
||||
INFO_MSG("Added file %s, trackid: %d, mapped to: %d",
|
||||
(pListIt->uri_root + entryIt->filename).c_str(), headerPack.getTrackId(),
|
||||
counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (!hasHeader && (!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())) {
|
||||
if (!hasHeader &&
|
||||
(!myMeta.tracks.count(packetId) || !myMeta.tracks[packetId].codec.size())){
|
||||
tsStream.initializeMetadata(myMeta, tmpTrackId, packetId);
|
||||
}
|
||||
|
||||
|
@ -571,26 +548,21 @@ namespace Mist {
|
|||
|
||||
// keyframe data exists, so always add 19 bytes keyframedata.
|
||||
long long packOffset = headerPack.hasMember("offset") ? headerPack.getInt("offset") : 0;
|
||||
long long packSendSize = 24 + (packOffset ? 17 : 0) + (entId >= 0 ? 15 : 0) + 19 + dataLen + 11;
|
||||
myMeta.update(headerPack.getTime(), packOffset, packetId, dataLen, entId, headerPack.hasMember("keyframe"), packSendSize);
|
||||
long long packSendSize =
|
||||
24 + (packOffset ? 17 : 0) + (entId >= 0 ? 15 : 0) + 19 + dataLen + 11;
|
||||
myMeta.update(headerPack.getTime(), packOffset, packetId, dataLen, entId,
|
||||
headerPack.hasMember("keyframe"), packSendSize);
|
||||
}
|
||||
tsStream.getEarliestPacket(headerPack);
|
||||
}
|
||||
|
||||
if (!pListIt->isUrl()) {
|
||||
in.close();
|
||||
}
|
||||
if (!pListIt->isUrl()){in.close();}
|
||||
|
||||
if (hasHeader) {
|
||||
break;
|
||||
}
|
||||
if (hasHeader){break;}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasHeader || (playlists.size() && playlists[0].isUrl())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasHeader || (playlists.size() && playlists[0].isUrl())){return true;}
|
||||
|
||||
INFO_MSG("write header file...");
|
||||
std::ofstream oFile((config->getString("input") + ".dtsh").c_str());
|
||||
|
@ -603,18 +575,16 @@ namespace Mist {
|
|||
}
|
||||
|
||||
bool inputHLS::needsLock(){
|
||||
if (playlists.size() && playlists[0].isUrl()) {
|
||||
return false;
|
||||
}
|
||||
return (playlists.size() <= currentPlaylist) || !(playlists[currentPlaylist].playlistType == LIVE);
|
||||
if (playlists.size() && playlists[0].isUrl()){return false;}
|
||||
return (playlists.size() <= currentPlaylist) ||
|
||||
!(playlists[currentPlaylist].playlistType == LIVE);
|
||||
}
|
||||
|
||||
bool inputHLS::openStreamSource() {
|
||||
return true;
|
||||
}
|
||||
bool inputHLS::openStreamSource(){return true;}
|
||||
|
||||
int inputHLS::getFirstPlaylistToReload(){
|
||||
//at this point, we need to check which playlist we need to reload, and keep reading from that playlist until EndOfPlaylist
|
||||
// at this point, we need to check which playlist we need to reload, and keep reading from that
|
||||
// playlist until EndOfPlaylist
|
||||
std::vector<int>::iterator result = std::min_element(reloadNext.begin(), reloadNext.end());
|
||||
return std::distance(reloadNext.begin(), result);
|
||||
}
|
||||
|
@ -643,19 +613,14 @@ namespace Mist {
|
|||
endOfFile = in.eof();
|
||||
}
|
||||
|
||||
|
||||
// eof flag is set after unsuccesful read, so check again
|
||||
if (endOfFile) {
|
||||
tsStream.finish();
|
||||
}
|
||||
if (endOfFile){tsStream.finish();}
|
||||
|
||||
if (playlists[currentPlaylist].playlistType == LIVE){
|
||||
hasPacket = tsStream.hasPacketOnEachTrack() || (endOfFile && tsStream.hasPacket());
|
||||
}else{
|
||||
|
||||
if (!selectedTracks.size()) {
|
||||
return;
|
||||
}
|
||||
if (!selectedTracks.size()){return;}
|
||||
|
||||
tid = *selectedTracks.begin();
|
||||
hasPacket = tsStream.hasPacket(getMappedTrackId(tid));
|
||||
|
@ -669,9 +634,7 @@ namespace Mist {
|
|||
HIGH_MSG("need to reload playlist %d, time: %d", a, reloadNext[a] - Util::bootSecs());
|
||||
|
||||
int f = firstSegment();
|
||||
if (f >= 0) {
|
||||
segmentTime = playlists[f].entries.front().timestamp - Util::bootSecs();
|
||||
}
|
||||
if (f >= 0){segmentTime = playlists[f].entries.front().timestamp - Util::bootSecs();}
|
||||
|
||||
int playlistTime = reloadNext.at(currentPlaylist) - Util::bootSecs() - 1;
|
||||
|
||||
|
@ -694,23 +657,25 @@ namespace Mist {
|
|||
|
||||
if (!readNextFile()){
|
||||
|
||||
if (playlists[currentPlaylist].playlistType != LIVE) {
|
||||
return;
|
||||
}
|
||||
//need to reload all available playlists. update the map with the amount of ms to wait before the next check.
|
||||
if (playlists[currentPlaylist].playlistType != LIVE){return;}
|
||||
// need to reload all available playlists. update the map with the amount of ms to wait
|
||||
// before the next check.
|
||||
|
||||
// set specific elements with the correct bootsecs()
|
||||
reloadNext.at(currentPlaylist) = b + playlists[currentPlaylist].waitTime;
|
||||
|
||||
int timeToWait = reloadNext.at(currentPlaylist) - Util::bootSecs();
|
||||
|
||||
//at this point, we need to check which playlist we need to reload, and keep reading from that playlist until EndOfPlaylist
|
||||
std::vector<int>::iterator result = std::min_element(reloadNext.begin(), reloadNext.end());
|
||||
// at this point, we need to check which playlist we need to reload, and keep reading from
|
||||
// that playlist until EndOfPlaylist
|
||||
std::vector<int>::iterator result =
|
||||
std::min_element(reloadNext.begin(), reloadNext.end());
|
||||
int playlistToReload = std::distance(reloadNext.begin(), result);
|
||||
currentPlaylist = playlistToReload;
|
||||
|
||||
// dont wait the first time.
|
||||
if (timeToWait > 0 && playlists[currentPlaylist].initDone && playlists[currentPlaylist].noChangeCount > 0) {
|
||||
if (timeToWait > 0 && playlists[currentPlaylist].initDone &&
|
||||
playlists[currentPlaylist].noChangeCount > 0){
|
||||
if (timeToWait > playlists[currentPlaylist].waitTime){
|
||||
WARN_MSG("something is not right...");
|
||||
return;
|
||||
|
@ -726,7 +691,6 @@ namespace Mist {
|
|||
thisPacket.null();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (playlists[currentPlaylist].isUrl()){
|
||||
|
@ -767,14 +731,15 @@ namespace Mist {
|
|||
Bit::htobl(thisPacket.getData() + 8, tid);
|
||||
}
|
||||
|
||||
|
||||
void inputHLS::readPMT(){
|
||||
if (playlists[currentPlaylist].isUrl()){
|
||||
size_t bpos;
|
||||
TS::Packet tsBuffer;
|
||||
const char *tmpPtr = playlists[currentPlaylist].source.data();
|
||||
|
||||
while (!tsStream.hasPacketOnEachTrack() && (tmpPtr - playlists[currentPlaylist].source.c_str() + 188 <= playlists[currentPlaylist].source.size())) {
|
||||
while (!tsStream.hasPacketOnEachTrack() &&
|
||||
(tmpPtr - playlists[currentPlaylist].source.c_str() + 188 <=
|
||||
playlists[currentPlaylist].source.size())){
|
||||
tsBuffer.FromPointer(tmpPtr);
|
||||
tsStream.parse(tsBuffer, 0);
|
||||
tmpPtr += 188;
|
||||
|
@ -804,12 +769,12 @@ namespace Mist {
|
|||
int trackId = 0;
|
||||
|
||||
unsigned long plistEntry = 0xFFFFFFFFull;
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++) {
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end();
|
||||
it++){
|
||||
unsigned long thisBPos = 0;
|
||||
for (std::deque<DTSC::Key>::iterator keyIt = myMeta.tracks[*it].keys.begin(); keyIt != myMeta.tracks[*it].keys.end(); keyIt++) {
|
||||
if (keyIt->getTime() > seekTime) {
|
||||
break;
|
||||
}
|
||||
for (std::deque<DTSC::Key>::iterator keyIt = myMeta.tracks[*it].keys.begin();
|
||||
keyIt != myMeta.tracks[*it].keys.end(); keyIt++){
|
||||
if (keyIt->getTime() > seekTime){break;}
|
||||
thisBPos = keyIt->getBpos();
|
||||
}
|
||||
if (thisBPos < plistEntry){
|
||||
|
@ -818,7 +783,6 @@ namespace Mist {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (plistEntry < 1){
|
||||
WARN_MSG("attempted to seek outside the file");
|
||||
return;
|
||||
|
@ -838,14 +802,10 @@ namespace Mist {
|
|||
}
|
||||
|
||||
int inputHLS::getEntryId(int playlistId, uint64_t bytePos){
|
||||
if (bytePos == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (bytePos == 0){return 0;}
|
||||
|
||||
for (int i = 0; i < playlists[playlistId].entries.size(); i++){
|
||||
if (playlists[playlistId].entries.at(i).bytePos > bytePos) {
|
||||
return i - 1;
|
||||
}
|
||||
if (playlists[playlistId].entries.at(i).bytePos > bytePos){return i - 1;}
|
||||
}
|
||||
|
||||
return playlists[playlistId].entries.size() - 1;
|
||||
|
@ -855,13 +815,9 @@ namespace Mist {
|
|||
return pidMapping[(playlistId << 16) + id];
|
||||
}
|
||||
|
||||
int inputHLS::getMappedTrackId(int id) {
|
||||
return (pidMappingR[id] & 0xFFFF);
|
||||
}
|
||||
int inputHLS::getMappedTrackId(int id){return (pidMappingR[id] & 0xFFFF);}
|
||||
|
||||
int inputHLS::getMappedTrackPlaylist(int id) {
|
||||
return (pidMappingR[id] >> 16);
|
||||
}
|
||||
int inputHLS::getMappedTrackPlaylist(int id){return (pidMappingR[id] >> 16);}
|
||||
|
||||
/// Very first function to be called on a regular playlist or variant playlist.
|
||||
bool inputHLS::initPlaylist(const std::string &uri){
|
||||
|
@ -919,9 +875,7 @@ namespace Mist {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isUrl){
|
||||
fileSource.close();
|
||||
}
|
||||
if (!isUrl){fileSource.close();}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -933,9 +887,7 @@ namespace Mist {
|
|||
// set size of reloadNext to playlist count with default value 0
|
||||
playlists.push_back(p);
|
||||
|
||||
if (reloadNext.size() < playlists.size()) {
|
||||
reloadNext.resize(playlists.size());
|
||||
}
|
||||
if (reloadNext.size() < playlists.size()){reloadNext.resize(playlists.size());}
|
||||
|
||||
reloadNext.at(p.id) = Util::bootSecs() + p.waitTime;
|
||||
return true;
|
||||
|
@ -979,12 +931,14 @@ namespace Mist {
|
|||
return true;
|
||||
}
|
||||
|
||||
///return the playlist id from which we need to read the first upcoming segment by timestamp. this will keep the playlists in sync while reading segments.
|
||||
/// return the playlist id from which we need to read the first upcoming segment by timestamp.
|
||||
/// this will keep the playlists in sync while reading segments.
|
||||
int inputHLS::firstSegment(){
|
||||
uint64_t firstTimeStamp = 0;
|
||||
int tmpId = -1;
|
||||
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end(); pListIt++){
|
||||
for (std::vector<Playlist>::iterator pListIt = playlists.begin(); pListIt != playlists.end();
|
||||
pListIt++){
|
||||
if (pListIt->entries.size()){
|
||||
if (pListIt->entries.front().timestamp < firstTimeStamp || tmpId < 0){
|
||||
firstTimeStamp = pListIt->entries.front().timestamp;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
#include "input.h"
|
||||
#include <fstream>
|
||||
#include <mist/dtsc.h>
|
||||
#include <mist/nal.h>
|
||||
#include <mist/ts_packet.h>
|
||||
#include <mist/ts_stream.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
//#include <stdint.h>
|
||||
|
||||
|
@ -16,9 +16,7 @@ namespace Mist {
|
|||
|
||||
enum PlaylistType{VOD, LIVE, EVENT};
|
||||
|
||||
|
||||
struct playListEntries
|
||||
{
|
||||
struct playListEntries{
|
||||
std::string filename;
|
||||
uint64_t bytePos;
|
||||
float duration;
|
||||
|
@ -49,7 +47,6 @@ namespace Mist {
|
|||
uint64_t media_sequence;
|
||||
int lastFileIndex;
|
||||
|
||||
|
||||
int waitTime;
|
||||
PlaylistType playlistType;
|
||||
std::deque<playListEntries> entries;
|
||||
|
@ -58,9 +55,7 @@ namespace Mist {
|
|||
unsigned int startTime;
|
||||
};
|
||||
|
||||
|
||||
struct entryBuffer
|
||||
{
|
||||
struct entryBuffer{
|
||||
int timestamp;
|
||||
playListEntries entry;
|
||||
int playlistIndex;
|
||||
|
@ -72,6 +67,7 @@ namespace Mist {
|
|||
~inputHLS();
|
||||
bool needsLock();
|
||||
bool openStreamSource();
|
||||
|
||||
protected:
|
||||
// Private Functions
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue