Fixed FLV MP3 audio, some fixes for live support.
This commit is contained in:
parent
6a1fee6b5b
commit
a906da6caf
3 changed files with 30 additions and 2 deletions
23
lib/dtsc.cpp
23
lib/dtsc.cpp
|
@ -173,11 +173,31 @@ bool DTSC::Stream::parsePacket(Socket::Buffer & buffer){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds a keyframe packet to all tracks, so the stream can be fully played.
|
||||||
|
void DTSC::Stream::endStream(){
|
||||||
|
if (metadata.isMember("tracks")){
|
||||||
|
for (JSON::ObjIter it = metadata["tracks"].ObjBegin(); it != metadata["tracks"].ObjEnd(); it++){
|
||||||
|
JSON::Value newPack;
|
||||||
|
newPack["time"] = it->second["lastms"];
|
||||||
|
newPack["trackid"] = it->second["trackid"];
|
||||||
|
newPack["keyframe"] = 1ll;
|
||||||
|
newPack["data"] = "";
|
||||||
|
addPacket(newPack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DTSC::Stream::addPacket(JSON::Value & newPack){
|
void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
long long unsigned int now = Util::getMS();
|
long long unsigned int now = Util::getMS();
|
||||||
livePos newPos;
|
livePos newPos;
|
||||||
newPos.trackID = newPack["trackid"].asInt();
|
newPos.trackID = newPack["trackid"].asInt();
|
||||||
newPos.seekTime = newPack["time"].asInt();
|
newPos.seekTime = newPack["time"].asInt();
|
||||||
|
if (buffers.size() > 0){
|
||||||
|
livePos lastPos = buffers.rbegin()->first;
|
||||||
|
if (newPos < lastPos){
|
||||||
|
newPos.seekTime = lastPos.seekTime+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
std::string newTrack = trackMapping[newPos.trackID];
|
std::string newTrack = trackMapping[newPos.trackID];
|
||||||
while (buffers.count(newPos) > 0){
|
while (buffers.count(newPos) > 0){
|
||||||
newPos.seekTime++;
|
newPos.seekTime++;
|
||||||
|
@ -208,8 +228,9 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
}
|
}
|
||||||
int keySize = metadata["tracks"][newTrack]["keys"].size();
|
int keySize = metadata["tracks"][newTrack]["keys"].size();
|
||||||
if (buffercount > 1){
|
if (buffercount > 1){
|
||||||
|
metadata["tracks"][newTrack]["lastms"] = newPack["time"];
|
||||||
#define prevKey metadata["tracks"][newTrack]["keys"][keySize - 1]
|
#define prevKey metadata["tracks"][newTrack]["keys"][keySize - 1]
|
||||||
if (newPack.isMember("keyframe") || !keySize || newPack["time"].asInt() - 2000 > prevKey["time"].asInt()){
|
if (newPack.isMember("keyframe") || !keySize || (datapointertype != VIDEO && newPack["time"].asInt() - 2000 > prevKey["time"].asInt())){
|
||||||
keyframes[newPos.trackID].insert(newPos);
|
keyframes[newPos.trackID].insert(newPos);
|
||||||
JSON::Value key;
|
JSON::Value key;
|
||||||
key["time"] = newPack["time"];
|
key["time"] = newPack["time"];
|
||||||
|
|
|
@ -149,6 +149,12 @@ namespace DTSC {
|
||||||
seekTime = rhs.seekTime;
|
seekTime = rhs.seekTime;
|
||||||
trackID = rhs.trackID;
|
trackID = rhs.trackID;
|
||||||
}
|
}
|
||||||
|
bool operator == (const livePos& rhs) {
|
||||||
|
return seekTime == rhs.seekTime && trackID == rhs.trackID;
|
||||||
|
}
|
||||||
|
bool operator != (const livePos& rhs) {
|
||||||
|
return seekTime != rhs.seekTime || trackID != rhs.trackID;
|
||||||
|
}
|
||||||
bool operator < (const livePos& rhs) const {
|
bool operator < (const livePos& rhs) const {
|
||||||
if (seekTime < rhs.seekTime){
|
if (seekTime < rhs.seekTime){
|
||||||
return true;
|
return true;
|
||||||
|
@ -207,6 +213,7 @@ namespace DTSC {
|
||||||
void setBufferTime(unsigned int ms);
|
void setBufferTime(unsigned int ms);
|
||||||
bool isNewest(DTSC::livePos & pos);
|
bool isNewest(DTSC::livePos & pos);
|
||||||
DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
|
DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
|
||||||
|
void endStream();
|
||||||
private:
|
private:
|
||||||
std::map<livePos,JSON::Value> buffers;
|
std::map<livePos,JSON::Value> buffers;
|
||||||
std::map<int,std::set<livePos> > keyframes;
|
std::map<int,std::set<livePos> > keyframes;
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ JSON::Value FLV::Tag::toJSON(JSON::Value & metadata){
|
||||||
metadata["tracks"]["track2"]["trackid"] = 2;
|
metadata["tracks"]["track2"]["trackid"] = 2;
|
||||||
metadata["tracks"]["track2"]["type"] = "audio";
|
metadata["tracks"]["track2"]["type"] = "audio";
|
||||||
if ( !metadata["tracks"]["track2"].isMember("codec") || metadata["tracks"]["track2"]["codec"].asString() == "?" || metadata["tracks"]["track2"]["codec"].asString() == ""){
|
if ( !metadata["tracks"]["track2"].isMember("codec") || metadata["tracks"]["track2"]["codec"].asString() == "?" || metadata["tracks"]["track2"]["codec"].asString() == ""){
|
||||||
metadata["audio"]["codec"] = getAudioCodec();
|
metadata["tracks"]["track2"]["codec"] = getAudioCodec();
|
||||||
}
|
}
|
||||||
if ( !metadata["tracks"]["track2"].isMember("rate") || metadata["tracks"]["track2"]["rate"].asInt() < 1){
|
if ( !metadata["tracks"]["track2"].isMember("rate") || metadata["tracks"]["track2"]["rate"].asInt() < 1){
|
||||||
switch (audiodata & 0x0C){
|
switch (audiodata & 0x0C){
|
||||||
|
|
Loading…
Add table
Reference in a new issue