Restyle
This commit is contained in:
parent
5b79f296d6
commit
fccf66fba2
280 changed files with 56975 additions and 71885 deletions
|
@ -1,16 +1,16 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <inttypes.h>
|
||||
#include <mist/stream.h>
|
||||
#include <mist/flv_tag.h>
|
||||
#include <mist/defines.h>
|
||||
#include <mist/h264.h>
|
||||
#include <iostream>
|
||||
#include <mist/bitfields.h>
|
||||
#include <mist/defines.h>
|
||||
#include <mist/flv_tag.h>
|
||||
#include <mist/h264.h>
|
||||
#include <mist/stream.h>
|
||||
#include <string>
|
||||
|
||||
#include "input_mp4.h"
|
||||
|
||||
|
@ -34,13 +34,11 @@ namespace Mist{
|
|||
stco64 = false;
|
||||
}
|
||||
|
||||
uint64_t mp4TrackHeader::size(){
|
||||
return (stszBox.asBox() ? stszBox.getSampleCount() : 0);
|
||||
}
|
||||
uint64_t mp4TrackHeader::size(){return (stszBox.asBox() ? stszBox.getSampleCount() : 0);}
|
||||
|
||||
void mp4TrackHeader::read(MP4::TRAK & trakBox){
|
||||
void mp4TrackHeader::read(MP4::TRAK &trakBox){
|
||||
initialised = false;
|
||||
std::string tmp;//temporary string for copying box data
|
||||
std::string tmp; // temporary string for copying box data
|
||||
MP4::Box trakLoopPeek;
|
||||
timeScale = 1;
|
||||
|
||||
|
@ -60,26 +58,26 @@ namespace Mist{
|
|||
hasCTTS = cttsBox.isType("ctts");
|
||||
}
|
||||
|
||||
void mp4TrackHeader::getPart(uint64_t index, uint64_t & offset, uint32_t & size, uint64_t & timestamp, int32_t & timeOffset, uint64_t & duration){
|
||||
void mp4TrackHeader::getPart(uint64_t index, uint64_t &offset, uint32_t &size,
|
||||
uint64_t ×tamp, int32_t &timeOffset, uint64_t &duration){
|
||||
if (index < sampleIndex){
|
||||
sampleIndex = 0;
|
||||
stscStart = 0;
|
||||
}
|
||||
|
||||
|
||||
uint64_t stscCount = stscBox.getEntryCount();
|
||||
MP4::STSCEntry stscEntry;
|
||||
while (stscStart < stscCount){
|
||||
stscEntry = stscBox.getSTSCEntry(stscStart);
|
||||
//check where the next index starts
|
||||
// check where the next index starts
|
||||
uint64_t nextSampleIndex;
|
||||
if (stscStart + 1 < stscCount){
|
||||
nextSampleIndex = sampleIndex + (stscBox.getSTSCEntry(stscStart+1).firstChunk - stscEntry.firstChunk) * stscEntry.samplesPerChunk;
|
||||
nextSampleIndex = sampleIndex + (stscBox.getSTSCEntry(stscStart + 1).firstChunk - stscEntry.firstChunk) *
|
||||
stscEntry.samplesPerChunk;
|
||||
}else{
|
||||
nextSampleIndex = stszBox.getSampleCount();
|
||||
}
|
||||
if (nextSampleIndex > index){
|
||||
break;
|
||||
}
|
||||
if (nextSampleIndex > index){break;}
|
||||
sampleIndex = nextSampleIndex;
|
||||
++stscStart;
|
||||
}
|
||||
|
@ -88,13 +86,11 @@ namespace Mist{
|
|||
FAIL_MSG("Could not complete seek - not in file (%" PRIu64 " > %" PRIu64 ")", sampleIndex, index);
|
||||
}
|
||||
|
||||
uint64_t stcoPlace = (stscEntry.firstChunk - 1 ) + ((index - sampleIndex) / stscEntry.samplesPerChunk);
|
||||
uint64_t stcoPlace = (stscEntry.firstChunk - 1) + ((index - sampleIndex) / stscEntry.samplesPerChunk);
|
||||
uint64_t stszStart = sampleIndex + (stcoPlace - (stscEntry.firstChunk - 1)) * stscEntry.samplesPerChunk;
|
||||
|
||||
offset = (stco64 ? co64Box.getChunkOffset(stcoPlace) : stcoBox.getChunkOffset(stcoPlace));
|
||||
for (int j = stszStart; j < index; j++){
|
||||
offset += stszBox.getEntrySize(j);
|
||||
}
|
||||
for (int j = stszStart; j < index; j++){offset += stszBox.getEntrySize(j);}
|
||||
|
||||
if (index < deltaPos){
|
||||
deltaIndex = 0;
|
||||
|
@ -106,24 +102,22 @@ namespace Mist{
|
|||
uint64_t sttsCount = sttsBox.getEntryCount();
|
||||
while (deltaIndex < sttsCount){
|
||||
tmpSTTS = sttsBox.getSTTSEntry(deltaIndex);
|
||||
if ((index - deltaPos) < tmpSTTS.sampleCount){
|
||||
break;
|
||||
}
|
||||
if ((index - deltaPos) < tmpSTTS.sampleCount){break;}
|
||||
deltaTotal += tmpSTTS.sampleCount * tmpSTTS.sampleDelta;
|
||||
deltaPos += tmpSTTS.sampleCount;
|
||||
++deltaIndex;
|
||||
}
|
||||
timestamp = ((deltaTotal + ((index-deltaPos) * tmpSTTS.sampleDelta))*1000) / timeScale;
|
||||
timestamp = ((deltaTotal + ((index - deltaPos) * tmpSTTS.sampleDelta)) * 1000) / timeScale;
|
||||
duration = 0;
|
||||
|
||||
|
||||
{
|
||||
uint64_t tmpIndex = deltaIndex;
|
||||
uint64_t tmpPos = deltaPos;
|
||||
uint64_t tmpTotal = deltaTotal;
|
||||
while (tmpIndex < sttsCount){
|
||||
tmpSTTS = sttsBox.getSTTSEntry(tmpIndex);
|
||||
if ((index+1 - tmpPos) < tmpSTTS.sampleCount){
|
||||
duration = (((tmpTotal + ((index+1-tmpPos) * tmpSTTS.sampleDelta))*1000) / timeScale) - timestamp;
|
||||
if ((index + 1 - tmpPos) < tmpSTTS.sampleCount){
|
||||
duration = (((tmpTotal + ((index + 1 - tmpPos) * tmpSTTS.sampleDelta)) * 1000) / timeScale) - timestamp;
|
||||
break;
|
||||
}
|
||||
tmpTotal += tmpSTTS.sampleCount * tmpSTTS.sampleDelta;
|
||||
|
@ -144,7 +138,7 @@ namespace Mist{
|
|||
while (offsetIndex < cttsCount){
|
||||
tmpCTTS = cttsBox.getCTTSEntry(offsetIndex);
|
||||
if ((index - offsetPos) < tmpCTTS.sampleCount){
|
||||
timeOffset = (tmpCTTS.sampleOffset*1000)/timeScale;
|
||||
timeOffset = (tmpCTTS.sampleOffset * 1000) / timeScale;
|
||||
break;
|
||||
}
|
||||
offsetPos += tmpCTTS.sampleCount;
|
||||
|
@ -153,10 +147,10 @@ namespace Mist{
|
|||
}
|
||||
size = stszBox.getEntrySize(index);
|
||||
}
|
||||
|
||||
inputMP4::inputMP4(Util::Config * cfg) : Input(cfg){
|
||||
malSize = 4;//initialise data read buffer to 0;
|
||||
data = (char*)malloc(malSize);
|
||||
|
||||
inputMP4::inputMP4(Util::Config *cfg) : Input(cfg){
|
||||
malSize = 4; // initialise data read buffer to 0;
|
||||
data = (char *)malloc(malSize);
|
||||
capa["name"] = "MP4";
|
||||
capa["desc"] = "This input allows streaming of MP4 files as Video on Demand.";
|
||||
capa["source_match"] = "/*.mp4";
|
||||
|
@ -170,11 +164,9 @@ namespace Mist{
|
|||
capa["codecs"][0u][1u].append("AC3");
|
||||
capa["codecs"][0u][1u].append("MP3");
|
||||
}
|
||||
|
||||
inputMP4::~inputMP4(){
|
||||
free(data);
|
||||
}
|
||||
|
||||
|
||||
inputMP4::~inputMP4(){free(data);}
|
||||
|
||||
bool inputMP4::checkArguments(){
|
||||
if (config->getString("input") == "-"){
|
||||
std::cerr << "Input from stdin not yet supported" << std::endl;
|
||||
|
@ -194,15 +186,12 @@ namespace Mist{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool inputMP4::preRun(){
|
||||
//open File
|
||||
// open File
|
||||
inFile = fopen(config->getString("input").c_str(), "r");
|
||||
if (!inFile){
|
||||
return false;
|
||||
}
|
||||
if (!inFile){return false;}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool inputMP4::readHeader(){
|
||||
|
@ -210,19 +199,17 @@ namespace Mist{
|
|||
INFO_MSG("inFile failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint32_t trackNo = 0;
|
||||
|
||||
//first we get the necessary header parts
|
||||
while(!feof(inFile)){
|
||||
|
||||
// first we get the necessary header parts
|
||||
while (!feof(inFile)){
|
||||
std::string boxType = MP4::readBoxType(inFile);
|
||||
if (boxType == "erro"){
|
||||
break;
|
||||
}
|
||||
if (boxType=="moov"){
|
||||
if (boxType == "erro"){break;}
|
||||
if (boxType == "moov"){
|
||||
MP4::MOOV moovBox;
|
||||
moovBox.read(inFile);
|
||||
//for all box in moov
|
||||
// for all box in moov
|
||||
|
||||
std::deque<MP4::TRAK> trak = moovBox.getChildren<MP4::TRAK>();
|
||||
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
|
||||
|
@ -230,25 +217,23 @@ namespace Mist{
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (!MP4::skipBox(inFile)){//moving on to next box
|
||||
if (!MP4::skipBox(inFile)){// moving on to next box
|
||||
FAIL_MSG("Error in skipping box, exiting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fseeko(inFile,0,SEEK_SET);
|
||||
|
||||
//See whether a separate header file exists.
|
||||
fseeko(inFile, 0, SEEK_SET);
|
||||
|
||||
// See whether a separate header file exists.
|
||||
if (readExistingHeader()){return true;}
|
||||
HIGH_MSG("Not read existing header");
|
||||
|
||||
trackNo = 0;
|
||||
//Create header file from MP4 data
|
||||
while(!feof(inFile)){
|
||||
// Create header file from MP4 data
|
||||
while (!feof(inFile)){
|
||||
std::string boxType = MP4::readBoxType(inFile);
|
||||
if (boxType=="erro"){
|
||||
break;
|
||||
}
|
||||
if (boxType=="moov"){
|
||||
if (boxType == "erro"){break;}
|
||||
if (boxType == "moov"){
|
||||
MP4::MOOV moovBox;
|
||||
moovBox.read(inFile);
|
||||
|
||||
|
@ -256,7 +241,7 @@ namespace Mist{
|
|||
HIGH_MSG("Obtained %zu trak Boxes", trak.size());
|
||||
|
||||
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
|
||||
uint64_t trackNo = myMeta.tracks.size()+1;
|
||||
uint64_t trackNo = myMeta.tracks.size() + 1;
|
||||
myMeta.tracks[trackNo].trackID = trackNo;
|
||||
|
||||
MP4::TKHD tkhdBox = trakIt->getChild<MP4::TKHD>();
|
||||
|
@ -283,10 +268,10 @@ namespace Mist{
|
|||
MP4::STSD stsdBox = stblBox.getChild<MP4::STSD>();
|
||||
MP4::Box sEntryBox = stsdBox.getEntry(0);
|
||||
std::string sType = sEntryBox.getType();
|
||||
HIGH_MSG("Found track %zu of type %s", trackNo, sType.c_str());
|
||||
HIGH_MSG("Found track %zu of type %s", trackNo, sType.c_str());
|
||||
|
||||
if (sType == "avc1" || sType == "h264" || sType == "mp4v"){
|
||||
MP4::VisualSampleEntry & vEntryBox = (MP4::VisualSampleEntry&)sEntryBox;
|
||||
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
|
||||
myMeta.tracks[trackNo].type = "video";
|
||||
myMeta.tracks[trackNo].codec = "H264";
|
||||
|
||||
|
@ -301,7 +286,7 @@ namespace Mist{
|
|||
if (initBox.isType("avcC")){
|
||||
myMeta.tracks[trackNo].init.assign(initBox.payload(), initBox.payloadSize());
|
||||
}
|
||||
///this is a hacky way around invalid FLV data (since it gets ignored nearly everywhere, but we do need correct data...
|
||||
/// this is a hacky way around invalid FLV data (since it gets ignored nearly everywhere, but we do need correct data...
|
||||
if (!myMeta.tracks[trackNo].width){
|
||||
h264::sequenceParameterSet sps;
|
||||
sps.fromDTSCInit(myMeta.tracks[trackNo].init);
|
||||
|
@ -311,7 +296,7 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
if (sType == "hev1" || sType == "hvc1"){
|
||||
MP4::VisualSampleEntry & vEntryBox = (MP4::VisualSampleEntry&)sEntryBox;
|
||||
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
|
||||
myMeta.tracks[trackNo].type = "video";
|
||||
myMeta.tracks[trackNo].codec = "HEVC";
|
||||
if (!myMeta.tracks[trackNo].width){
|
||||
|
@ -328,7 +313,7 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
if (sType == "mp4a" || sType == "aac " || sType == "ac-3"){
|
||||
MP4::AudioSampleEntry & aEntryBox = (MP4::AudioSampleEntry&)sEntryBox;
|
||||
MP4::AudioSampleEntry &aEntryBox = (MP4::AudioSampleEntry &)sEntryBox;
|
||||
myMeta.tracks[trackNo].type = "audio";
|
||||
myMeta.tracks[trackNo].channels = aEntryBox.getChannelCount();
|
||||
myMeta.tracks[trackNo].rate = aEntryBox.getSampleRate();
|
||||
|
@ -336,14 +321,14 @@ namespace Mist{
|
|||
if (sType == "ac-3"){
|
||||
myMeta.tracks[trackNo].codec = "AC3";
|
||||
}else{
|
||||
MP4::ESDS esdsBox = (MP4::ESDS&)(aEntryBox.getCodecBox());
|
||||
MP4::ESDS esdsBox = (MP4::ESDS &)(aEntryBox.getCodecBox());
|
||||
myMeta.tracks[trackNo].codec = esdsBox.getCodec();
|
||||
myMeta.tracks[trackNo].init = esdsBox.getInitData();
|
||||
}
|
||||
myMeta.tracks[trackNo].size = 16;///\todo this might be nice to calculate from mp4 file;
|
||||
myMeta.tracks[trackNo].size = 16; ///\todo this might be nice to calculate from mp4 file;
|
||||
}
|
||||
|
||||
if (sType == "tx3g"){//plain text subtitles
|
||||
if (sType == "tx3g"){// plain text subtitles
|
||||
myMeta.tracks[trackNo].type = "meta";
|
||||
myMeta.tracks[trackNo].codec = "subtitle";
|
||||
}
|
||||
|
@ -354,12 +339,12 @@ namespace Mist{
|
|||
MP4::STCO stcoBox = stblBox.getChild<MP4::STCO>();
|
||||
MP4::CO64 co64Box = stblBox.getChild<MP4::CO64>();
|
||||
MP4::STSC stscBox = stblBox.getChild<MP4::STSC>();
|
||||
MP4::CTTS cttsBox = stblBox.getChild<MP4::CTTS>();//optional ctts box
|
||||
MP4::CTTS cttsBox = stblBox.getChild<MP4::CTTS>(); // optional ctts box
|
||||
|
||||
bool stco64 = co64Box.isType("co64");
|
||||
bool hasCTTS = cttsBox.isType("ctts");
|
||||
|
||||
uint64_t totaldur = 0;///\todo note: set this to begin time
|
||||
uint64_t totaldur = 0; ///\todo note: set this to begin time
|
||||
mp4PartBpos BsetPart;
|
||||
|
||||
uint64_t entryNo = 0;
|
||||
|
@ -368,8 +353,8 @@ namespace Mist{
|
|||
uint64_t stssIndex = 0;
|
||||
uint64_t stcoIndex = 0;
|
||||
uint64_t stscIndex = 0;
|
||||
uint64_t cttsIndex = 0;//current ctts Index we are reading
|
||||
uint64_t cttsEntryRead = 0;//current part of ctts we are reading
|
||||
uint64_t cttsIndex = 0; // current ctts Index we are reading
|
||||
uint64_t cttsEntryRead = 0; // current part of ctts we are reading
|
||||
|
||||
uint64_t stssCount = stssBox.getEntryCount();
|
||||
uint64_t stscCount = stscBox.getEntryCount();
|
||||
|
@ -386,35 +371,33 @@ namespace Mist{
|
|||
for (uint64_t stszIndex = 0; stszIndex < stszCount; ++stszIndex){
|
||||
if (stcoIndex >= nextFirstChunk){
|
||||
++stscIndex;
|
||||
nextFirstChunk = (stscIndex + 1 < stscCount ? stscBox.getSTSCEntry(stscIndex + 1).firstChunk - 1 : stcoCount);
|
||||
nextFirstChunk =
|
||||
(stscIndex + 1 < stscCount ? stscBox.getSTSCEntry(stscIndex + 1).firstChunk - 1 : stcoCount);
|
||||
}
|
||||
BsetPart.keyframe = (myMeta.tracks[trackNo].type == "video" && stssIndex < stssCount && stszIndex + 1 == stssBox.getSampleNumber(stssIndex));
|
||||
if (BsetPart.keyframe){
|
||||
++stssIndex;
|
||||
}
|
||||
//in bpos set
|
||||
BsetPart.keyframe = (myMeta.tracks[trackNo].type == "video" && stssIndex < stssCount &&
|
||||
stszIndex + 1 == stssBox.getSampleNumber(stssIndex));
|
||||
if (BsetPart.keyframe){++stssIndex;}
|
||||
// in bpos set
|
||||
BsetPart.stcoNr = stcoIndex;
|
||||
//bpos = chunkoffset[samplenr] in stco
|
||||
// bpos = chunkoffset[samplenr] in stco
|
||||
BsetPart.bpos = tmpOffset;
|
||||
++fromSTCOinSTSC;
|
||||
if (fromSTCOinSTSC < stscBox.getSTSCEntry(stscIndex).samplesPerChunk){//as long as we are still in this chunk
|
||||
if (fromSTCOinSTSC < stscBox.getSTSCEntry(stscIndex).samplesPerChunk){// as long as we are still in this chunk
|
||||
tmpOffset += stszBox.getEntrySize(stszIndex);
|
||||
}else{
|
||||
++stcoIndex;
|
||||
fromSTCOinSTSC = 0;
|
||||
tmpOffset = (stco64 ? co64Box.getChunkOffset(stcoIndex) : stcoBox.getChunkOffset(stcoIndex));
|
||||
}
|
||||
BsetPart.time = (totaldur*1000)/timescale;
|
||||
BsetPart.time = (totaldur * 1000) / timescale;
|
||||
totaldur += sttsEntry.sampleDelta;
|
||||
sampleNo++;
|
||||
if (sampleNo >= sttsEntry.sampleCount){
|
||||
++entryNo;
|
||||
sampleNo = 0;
|
||||
if (entryNo < sttsBox.getEntryCount()){
|
||||
sttsEntry = sttsBox.getSTTSEntry(entryNo);
|
||||
}
|
||||
if (entryNo < sttsBox.getEntryCount()){sttsEntry = sttsBox.getSTTSEntry(entryNo);}
|
||||
}
|
||||
|
||||
|
||||
if (hasCTTS){
|
||||
MP4::CTTSEntry cttsEntry = cttsBox.getCTTSEntry(cttsIndex);
|
||||
cttsEntryRead++;
|
||||
|
@ -422,71 +405,74 @@ namespace Mist{
|
|||
++cttsIndex;
|
||||
cttsEntryRead = 0;
|
||||
}
|
||||
BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000)/timescale;
|
||||
BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000) / timescale;
|
||||
}else{
|
||||
BsetPart.timeOffset = 0;
|
||||
}
|
||||
|
||||
if(sType == "tx3g"){
|
||||
if(stszBox.getEntrySize(stszIndex) <=2 && false){
|
||||
if (sType == "tx3g"){
|
||||
if (stszBox.getEntrySize(stszIndex) <= 2 && false){
|
||||
FAIL_MSG("size <=2");
|
||||
}else{
|
||||
long long packSendSize = 0;
|
||||
packSendSize = 24 + (BsetPart.timeOffset ? 17 : 0) + (BsetPart.bpos ? 15 : 0) + 19 +
|
||||
stszBox.getEntrySize(stszIndex) + 11-2 + 19;
|
||||
stszBox.getEntrySize(stszIndex) + 11 - 2 + 19;
|
||||
myMeta.update(BsetPart.time, BsetPart.timeOffset, trackNo,
|
||||
stszBox.getEntrySize(stszIndex) -2 , BsetPart.bpos, true,
|
||||
packSendSize);
|
||||
stszBox.getEntrySize(stszIndex) - 2, BsetPart.bpos, true, packSendSize);
|
||||
}
|
||||
}else{
|
||||
myMeta.update(BsetPart.time, BsetPart.timeOffset, trackNo, stszBox.getEntrySize(stszIndex), BsetPart.bpos, BsetPart.keyframe);
|
||||
myMeta.update(BsetPart.time, BsetPart.timeOffset, trackNo,
|
||||
stszBox.getEntrySize(stszIndex), BsetPart.bpos, BsetPart.keyframe);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!MP4::skipBox(inFile)){//moving on to next box
|
||||
if (!MP4::skipBox(inFile)){// moving on to next box
|
||||
FAIL_MSG("Error in Skipping box, exiting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
clearerr(inFile);
|
||||
|
||||
//outputting dtsh file
|
||||
|
||||
// outputting dtsh file
|
||||
myMeta.toFile(config->getString("input") + ".dtsh");
|
||||
return true;
|
||||
}
|
||||
|
||||
void inputMP4::getNext(bool smart){//get next part from track in stream
|
||||
|
||||
void inputMP4::getNext(bool smart){// get next part from track in stream
|
||||
if (curPositions.empty()){
|
||||
thisPacket.null();
|
||||
return;
|
||||
}
|
||||
//pop uit set
|
||||
// pop uit set
|
||||
mp4PartTime curPart = *curPositions.begin();
|
||||
curPositions.erase(curPositions.begin());
|
||||
|
||||
|
||||
bool isKeyframe = false;
|
||||
if(nextKeyframe[curPart.trackID] < myMeta.tracks[curPart.trackID].keys.size()){
|
||||
//checking if this is a keyframe
|
||||
if (myMeta.tracks[curPart.trackID].type == "video" && (long long int) curPart.time == myMeta.tracks[curPart.trackID].keys[(nextKeyframe[curPart.trackID])].getTime()){
|
||||
if (nextKeyframe[curPart.trackID] < myMeta.tracks[curPart.trackID].keys.size()){
|
||||
// checking if this is a keyframe
|
||||
if (myMeta.tracks[curPart.trackID].type == "video" &&
|
||||
(long long int)curPart.time ==
|
||||
myMeta.tracks[curPart.trackID].keys[(nextKeyframe[curPart.trackID])].getTime()){
|
||||
isKeyframe = true;
|
||||
}
|
||||
//if a keyframe has passed, we find the next keyframe
|
||||
if (myMeta.tracks[curPart.trackID].keys[(nextKeyframe[curPart.trackID])].getTime() <= (long long int)curPart.time){
|
||||
nextKeyframe[curPart.trackID] ++;
|
||||
// if a keyframe has passed, we find the next keyframe
|
||||
if (myMeta.tracks[curPart.trackID].keys[(nextKeyframe[curPart.trackID])].getTime() <=
|
||||
(long long int)curPart.time){
|
||||
nextKeyframe[curPart.trackID]++;
|
||||
}
|
||||
}
|
||||
if (fseeko(inFile,curPart.bpos,SEEK_SET)){
|
||||
FAIL_MSG("seek unsuccessful @bpos %" PRIu64 ": %s",curPart.bpos, strerror(errno));
|
||||
if (fseeko(inFile, curPart.bpos, SEEK_SET)){
|
||||
FAIL_MSG("seek unsuccessful @bpos %" PRIu64 ": %s", curPart.bpos, strerror(errno));
|
||||
thisPacket.null();
|
||||
return;
|
||||
}
|
||||
if (curPart.size > malSize){
|
||||
data = (char*)realloc(data, curPart.size);
|
||||
data = (char *)realloc(data, curPart.size);
|
||||
malSize = curPart.size;
|
||||
}
|
||||
if (fread(data, curPart.size, 1, inFile)!=1){
|
||||
if (fread(data, curPart.size, 1, inFile) != 1){
|
||||
FAIL_MSG("read unsuccessful at %" PRIu64, ftell(inFile));
|
||||
thisPacket.null();
|
||||
return;
|
||||
|
@ -494,44 +480,44 @@ namespace Mist{
|
|||
|
||||
if (myMeta.tracks[curPart.trackID].codec == "subtitle"){
|
||||
unsigned int txtLen = Bit::btohs(data);
|
||||
if (!txtLen && false ){
|
||||
curPart.index ++;
|
||||
if (!txtLen && false){
|
||||
curPart.index++;
|
||||
return getNext(smart);
|
||||
//thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, " ", 1, 0/*Note: no bpos*/, isKeyframe);
|
||||
// thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, " ", 1, 0/*Note: no bpos*/, isKeyframe);
|
||||
}else{
|
||||
|
||||
static JSON::Value thisPack;
|
||||
thisPack.null();
|
||||
thisPack["trackid"] = (uint64_t)curPart.trackID;
|
||||
thisPack["bpos"] = curPart.bpos; //(long long)fileSource.tellg();
|
||||
thisPack["data"] = std::string(data+2,txtLen);
|
||||
thisPack["data"] = std::string(data + 2, txtLen);
|
||||
thisPack["time"] = curPart.time;
|
||||
if (curPart.duration){
|
||||
thisPack["duration"] = curPart.duration;
|
||||
}
|
||||
thisPack["keyframe"] = true;
|
||||
if (curPart.duration){thisPack["duration"] = curPart.duration;}
|
||||
thisPack["keyframe"] = true;
|
||||
// Write the json value to lastpack
|
||||
std::string tmpStr = thisPack.toNetPacked();
|
||||
thisPacket.reInit(tmpStr.data(), tmpStr.size());
|
||||
//return;
|
||||
// return;
|
||||
|
||||
//thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, data+2, txtLen, 0/*Note: no bpos*/, isKeyframe);
|
||||
// thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, data+2, txtLen, 0/*Note: no bpos*/, isKeyframe);
|
||||
}
|
||||
}else{
|
||||
thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, data, curPart.size, 0/*Note: no bpos*/, isKeyframe);
|
||||
thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, data, curPart.size,
|
||||
0 /*Note: no bpos*/, isKeyframe);
|
||||
}
|
||||
|
||||
//get the next part for this track
|
||||
curPart.index ++;
|
||||
// get the next part for this track
|
||||
curPart.index++;
|
||||
if (curPart.index < headerData[curPart.trackID].size()){
|
||||
headerData[curPart.trackID].getPart(curPart.index, curPart.bpos, curPart.size, curPart.time, curPart.offset, curPart.duration);
|
||||
headerData[curPart.trackID].getPart(curPart.index, curPart.bpos, curPart.size, curPart.time,
|
||||
curPart.offset, curPart.duration);
|
||||
curPositions.insert(curPart);
|
||||
}
|
||||
}
|
||||
|
||||
void inputMP4::seek(int seekTime){//seek to a point
|
||||
void inputMP4::seek(int seekTime){// seek to a point
|
||||
nextKeyframe.clear();
|
||||
//for all tracks
|
||||
// for all tracks
|
||||
curPositions.clear();
|
||||
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
nextKeyframe[*it] = 0;
|
||||
|
@ -540,23 +526,23 @@ namespace Mist{
|
|||
addPart.size = 0;
|
||||
addPart.time = 0;
|
||||
addPart.trackID = *it;
|
||||
//for all indexes in those tracks
|
||||
// for all indexes in those tracks
|
||||
for (unsigned int i = 0; i < headerData[*it].size(); i++){
|
||||
//if time > seekTime
|
||||
// if time > seekTime
|
||||
headerData[*it].getPart(i, addPart.bpos, addPart.size, addPart.time, addPart.offset, addPart.duration);
|
||||
//check for keyframe time in myMeta and update nextKeyframe
|
||||
// check for keyframe time in myMeta and update nextKeyframe
|
||||
//
|
||||
if (myMeta.tracks[*it].keys[(nextKeyframe[*it])].getTime() < addPart.time){
|
||||
nextKeyframe[*it] ++;
|
||||
nextKeyframe[*it]++;
|
||||
}
|
||||
if (addPart.time >= seekTime){
|
||||
addPart.index = i;
|
||||
//use addPart thingy in time set and break
|
||||
// use addPart thingy in time set and break
|
||||
curPositions.insert(addPart);
|
||||
break;
|
||||
}//end if time > seektime
|
||||
}//end for all indexes
|
||||
}//rof all tracks
|
||||
}// end if time > seektime
|
||||
}// end for all indexes
|
||||
}// rof all tracks
|
||||
}
|
||||
|
||||
void inputMP4::trackSelect(std::string trackSpec){
|
||||
|
@ -565,7 +551,8 @@ namespace Mist{
|
|||
while (trackSpec != ""){
|
||||
index = trackSpec.find(' ');
|
||||
selectedTracks.insert(atoi(trackSpec.substr(0, index).c_str()));
|
||||
VERYHIGH_MSG("Added track %d, index = %lld, (index == npos) = %d", atoi(trackSpec.substr(0, index).c_str()), index, index == std::string::npos);
|
||||
VERYHIGH_MSG("Added track %d, index = %lld, (index == npos) = %d",
|
||||
atoi(trackSpec.substr(0, index).c_str()), index, index == std::string::npos);
|
||||
if (index != std::string::npos){
|
||||
trackSpec.erase(0, index + 1);
|
||||
}else{
|
||||
|
@ -573,5 +560,4 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}// namespace Mist
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue