Improved selectDefaultTracks function to give feedback on selection changes.
This commit is contained in:
parent
a984243d56
commit
9723159592
4 changed files with 35 additions and 9 deletions
|
@ -255,16 +255,31 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
|
||||
void Output::selectDefaultTracks(){
|
||||
/// Automatically selects the tracks that are possible and/or wanted.
|
||||
/// Returns true if the track selection changed in any way.
|
||||
bool Output::selectDefaultTracks(){
|
||||
if (!isInitialized){
|
||||
initialize();
|
||||
if (!isInitialized){return;}
|
||||
if (!isInitialized){return false;}
|
||||
}
|
||||
|
||||
//First, back up and wipe the existing selections, if any.
|
||||
std::set<unsigned long> oldSel = selectedTracks;
|
||||
selectedTracks.clear();
|
||||
|
||||
bool autoSeek = buffer.size();
|
||||
uint64_t seekTarget = currentTime();
|
||||
|
||||
//check which tracks don't actually exist
|
||||
std::set<unsigned long> toRemove;
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
if (!myMeta.tracks.count(*it)){
|
||||
toRemove.insert(*it);
|
||||
continue;
|
||||
}
|
||||
//autoSeeking and target not in bounds? Drop it too.
|
||||
if (autoSeek && myMeta.tracks[*it].lastms < seekTarget - 6000){
|
||||
toRemove.insert(*it);
|
||||
}
|
||||
}
|
||||
//remove those from selectedtracks
|
||||
|
@ -344,6 +359,7 @@ namespace Mist{
|
|||
if (myMeta.live){
|
||||
for (std::map<unsigned int, DTSC::Track>::reverse_iterator trit = myMeta.tracks.rbegin(); trit != myMeta.tracks.rend(); trit++){
|
||||
if ((!byType && trit->second.codec == strRef.substr(shift)) || (byType && trit->second.type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
if (autoSeek && trit->second.lastms < seekTarget - 6000){continue;}
|
||||
selectedTracks.insert(trit->first);
|
||||
found = true;
|
||||
if (!multiSel){break;}
|
||||
|
@ -352,6 +368,7 @@ namespace Mist{
|
|||
}else{
|
||||
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
|
||||
if ((!byType && trit->second.codec == strRef.substr(shift)) || (byType && trit->second.type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
if (autoSeek && trit->second.lastms < seekTarget - 6000){continue;}
|
||||
selectedTracks.insert(trit->first);
|
||||
found = true;
|
||||
if (!multiSel){break;}
|
||||
|
@ -381,6 +398,12 @@ namespace Mist{
|
|||
if (!selectedTracks.size() && myMeta.tracks.size() && capa["codecs"][bestSoFar].size()){
|
||||
WARN_MSG("No tracks selected (%u total) for stream %s!", myMeta.tracks.size(), streamName.c_str());
|
||||
}
|
||||
bool madeChange = (oldSel != selectedTracks);
|
||||
if (autoSeek && madeChange){
|
||||
INFO_MSG("Automatically seeking to position %llu to resume playback", seekTarget);
|
||||
seek(seekTarget);
|
||||
}
|
||||
return madeChange;
|
||||
}
|
||||
|
||||
/// Clears the buffer, sets parseData to false, and generally makes not very much happen at all.
|
||||
|
@ -825,7 +848,7 @@ namespace Mist{
|
|||
if (buffer.size() != selectedTracks.size()){
|
||||
std::set<uint32_t> dropTracks;
|
||||
if (buffer.size() < selectedTracks.size()){
|
||||
//prepare to drop any selectedTrack without buffe entry
|
||||
//prepare to drop any selectedTrack without buffer entry
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); ++it){
|
||||
bool found = false;
|
||||
for (std::set<sortedPageInfo>::iterator bi = buffer.begin(); bi != buffer.end(); ++bi){
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Mist {
|
|||
uint64_t endTime();
|
||||
void setBlocking(bool blocking);
|
||||
void updateMeta();
|
||||
void selectDefaultTracks();
|
||||
bool selectDefaultTracks();
|
||||
bool connectToFile(std::string file);
|
||||
static bool listenMode(){return true;}
|
||||
uint32_t currTrackCount() const;
|
||||
|
|
|
@ -28,6 +28,12 @@ namespace Mist {
|
|||
}
|
||||
|
||||
void OutJSON::sendNext(){
|
||||
if (keepReselecting){
|
||||
//If we can select more tracks, do it and continue.
|
||||
if (selectDefaultTracks()){
|
||||
return;//After a seek, the current packet is invalid. Do nothing and return here.
|
||||
}
|
||||
}
|
||||
JSON::Value jPack = thisPacket.toJSON();
|
||||
if (dupcheck){
|
||||
if (jPack.compareExcept(lastVal, nodup)){
|
||||
|
|
|
@ -160,12 +160,9 @@ namespace Mist {
|
|||
lastMeta = Util::epoch();
|
||||
updateMeta();
|
||||
if (myMeta.tracks.size() > 1){
|
||||
size_t prevTrackCount = selectedTracks.size();
|
||||
selectDefaultTracks();
|
||||
if (selectedTracks.size() > prevTrackCount){
|
||||
INFO_MSG("Picked up new track - selecting it and resetting state.");
|
||||
if (selectDefaultTracks()){
|
||||
INFO_MSG("Track selection changed - resending headers and continuing");
|
||||
sentHeader = false;
|
||||
initialSeek();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue