From 1449e9e73e126abc19c861eac65a999059ba955b Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Thu, 6 Jun 2013 09:59:51 +0200 Subject: [PATCH] Added getTrackById() --- lib/dtsc.cpp | 24 +++++++++++++++++++++++- lib/dtsc.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 03f7888f..24c013a8 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -248,6 +248,15 @@ JSON::Value & DTSC::Stream::getPacket(unsigned int num){ return buffers[num]; } +/// Returns a track element by giving the id. +JSON::Value & DTSC::Stream::getTrackById(int trackNo){ + static JSON::Value empty; + if (trackMapping.find(trackNo) != trackMapping.end()){ + return metadata["tracks"][trackMapping[trackNo]]; + } + return empty; +} + /// Returns the type of the last received packet. DTSC::datatype DTSC::Stream::lastType(){ return datapointertype; @@ -809,6 +818,15 @@ JSON::Value & DTSC::File::getJSON(){ return jsonbuffer; } +/// Returns a track element by giving the id. +JSON::Value & DTSC::File::getTrackById(int trackNo){ + static JSON::Value empty; + if (trackMapping.find(trackNo) != trackMapping.end()){ + return metadata["tracks"][trackMapping[trackNo]]; + } + return empty; +} + bool DTSC::File::seek_time(int ms, int trackNo){ seekPos tmpPos; tmpPos.trackID = trackNo; @@ -908,8 +926,12 @@ bool DTSC::File::atKeyframe(){ } void DTSC::File::selectTracks(std::set & tracks){ - currentPositions.clear(); selectedTracks = tracks; + if ( !currentPositions.size()){ + seek_time(0); + }else{ + currentPositions.clear(); + } } /// Close the file if open diff --git a/lib/dtsc.h b/lib/dtsc.h index e83ef8fc..7c903516 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -106,6 +106,7 @@ namespace DTSC { void seekNext(); std::string & getPacket(); JSON::Value & getJSON(); + JSON::Value & getTrackById(int trackNo); bool seek_time(int seconds); bool seek_time(int seconds, int trackNo); bool seek_bpos(int bpos); @@ -154,6 +155,7 @@ namespace DTSC { Stream(unsigned int buffers, unsigned int bufferTime = 0); JSON::Value metadata; JSON::Value & getPacket(unsigned int num = 0); + JSON::Value & getTrackById(int trackNo); datatype lastType(); std::string & lastData(); bool hasVideo();