std::string AFRT::toPrettyString(uint32_t indent) { std::stringstream r; r << std::string(indent, ' ') << "[afrt] Fragment Run Table (" << boxedSize() << ")" << std::endl; r << std::string(indent + 1, ' ') << "Version " << (int)getVersion() << std::endl; if (getUpdate()) { r << std::string(indent + 1, ' ') << "Update" << std::endl; } else { r << std::string(indent + 1, ' ') << "Replacement or new table" << std::endl; } r << std::string(indent + 1, ' ') << "Timescale " << getTimeScale() << std::endl; r << std::string(indent + 1, ' ') << "QualitySegmentUrlModifiers (" << getQualityEntryCount() << ")" << std::endl; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { r << std::string(indent + 2, ' ') << i << ": " << getQualityEntry(i) << std::endl; } r << std::string(indent + 1, ' ') << "FragmentRunEntryTable (" << getFragmentRunCount() << ")" << std::endl; for (unsigned int i = 0; i < getFragmentRunCount(); i++) { afrt_runtable myRun = getFragmentRun(i); if (myRun.duration) { r << std::string(indent + 2, ' ') << i << ": " << myRun.firstFragment << " is at " << ((double)myRun.firstTimestamp / (double)getTimeScale()) << "s, " << ((double)myRun.duration / (double)getTimeScale()) << "s per fragment." << std::endl; } else { r << std::string(indent + 2, ' ') << i << ": " << myRun.firstFragment << " is at " << ((double)myRun.firstTimestamp / (double)getTimeScale()) << "s, discontinuity type " << myRun.discontinuity << std::endl; } } return r.str(); }
std::string AFRA::toPrettyString(uint32_t indent) { std::stringstream r; r << std::string(indent, ' ') << "[afra] Fragment Random Access (" << boxedSize() << ")" << std::endl; r << std::string(indent + 1, ' ') << "Version " << getVersion() << std::endl; r << std::string(indent + 1, ' ') << "Flags " << getFlags() << std::endl; r << std::string(indent + 1, ' ') << "Long IDs " << getLongIDs() << std::endl; r << std::string(indent + 1, ' ') << "Long Offsets " << getLongOffsets() << std::endl; r << std::string(indent + 1, ' ') << "Global Entries " << getGlobalEntries() << std::endl; r << std::string(indent + 1, ' ') << "TimeScale " << getTimeScale() << std::endl; uint32_t count = getEntryCount(); r << std::string(indent + 1, ' ') << "Entries (" << count << ") " << std::endl; for (uint32_t i = 0; i < count; ++i) { afraentry tmpent = getEntry(i); r << std::string(indent + 1, ' ') << i << ": Time " << tmpent.time << ", Offset " << tmpent.offset << std::endl; } if (getGlobalEntries()) { count = getGlobalEntryCount(); r << std::string(indent + 1, ' ') << "Global Entries (" << count << ") " << std::endl; for (uint32_t i = 0; i < count; ++i) { globalafraentry tmpent = getGlobalEntry(i); r << std::string(indent + 1, ' ') << i << ": T " << tmpent.time << ", S" << tmpent.segment << "F" << tmpent.fragment << ", " << tmpent.afraoffset << "/" << tmpent.offsetfromafra << std::endl; } } return r.str(); }
void setTimestamp(const double *arr, epicsUInt32 count) { const double tmult = getTimeScale(); times_t times(count); // check for monotonic // TODO: not handling overflow (HW supports controlled rollover w/ special 0xffffffff times) for(epicsUInt32 i=0; i<count; i++) { if(!finite(arr[i]) || arr[i]<0.0) throw std::runtime_error("times must be finite >=0"); times[i] = (arr[i]*tmult)+0.5; if(i>0 && times[i]<=times[i-1]) throw std::runtime_error("Non-monotonic timestamp array"); else if(times[i]==0xffffffff) throw std::runtime_error("Time overflow, rollover not supported"); } { SCOPED_LOCK(mutex); scratch.times.swap(times); is_committed = false; } DEBUG(4, ("Set times\n")); scanIoRequest(changed); }
// in movie fragment mode set the actual duration of // last sample void PVA_FF_TrackHeaderAtom::updateLastTSEntry(uint32 ts) { uint32 duration = (uint32)((getTimeScale() / 1000.0f) * ts); setDuration(duration); _deltaTS = 0; // this will not increase the total duration // in movie fragmement mode as done before rendering }
float ElapsedTimer::getTime() const { assert(m_startTime != YAM_TIME_TYPE(-1) ); // You must call reset atleast once before first call to getTime. YAM_TIME_TYPE curTime = getTotalTime(); float deltaTime = float(curTime-m_startTime)/float(getTimeScale()); assert( deltaTime >= 0.0f ); // WTF? return deltaTime; }
epicsUInt32 getTimestamp(double* arr, epicsUInt32 count) const { SCOPED_LOCK(mutex); const double tmult = getTimeScale(); epicsUInt32 ret = std::min(size_t(count), committed.times.size()); for(epicsUInt32 i=0; i<ret; i++) { arr[i] = committed.times[i]/tmult; } return ret; }
void AudioItem::calculateWidth() { int newWidth = 0; qint64 audio_duration = m_audio->totalDuration(); if (audio_duration != 0) newWidth = ((50/(float)getTimeScale()) * (float)audio_duration) / 1000; else newWidth = 100; if (newWidth < (50 / m_timeScale)) newWidth = 50 / m_timeScale; setWidth(newWidth); }
void RGBMatrixItem::calculateWidth() { int newWidth = 0; qint64 matrixDuration = getDuration(); if (matrixDuration != 0) newWidth = ((50 / float(getTimeScale())) * float(matrixDuration)) / 1000; else newWidth = 100; if (newWidth < (50 / m_timeScale)) newWidth = 50 / m_timeScale; setWidth(newWidth); }
void RGBMatrixItem::calculateWidth() { int newWidth = 0; qint64 matrix_duration = m_matrix->totalDuration(); if (matrix_duration != 0) newWidth = ((50/(float)getTimeScale()) * (float)matrix_duration) / 1000; else newWidth = 100; if (newWidth < (50 / m_timeScale)) newWidth = 50 / m_timeScale; setWidth(newWidth); }
void PVA_FF_TrackHeaderAtom::addSample(uint32 ts) { // Need to verify that this fp in the movie timescale // Currenly ts for the media samples fp in terms of milliseconds // For rounding uint32 duration = (uint32)((getTimeScale() / 1000.0f) * ts + 0.5f); _deltaTS = duration - _prevTS; setDuration(duration); _prevTS = duration; }
void EFXItem::calculateWidth() { int newWidth = 0; qint64 efxDuration = getDuration(); if (efxDuration != 0) newWidth = ((50.0 / float(getTimeScale())) * float(efxDuration)) / 1000.0; else newWidth = 100; if (newWidth < (50 / m_timeScale)) newWidth = 50 / m_timeScale; setWidth(newWidth); }
std::string ABST::toPrettyString(uint32_t indent) { std::stringstream r; r << std::string(indent, ' ') << "[abst] Bootstrap Info (" << boxedSize() << ")" << std::endl; r << std::string(indent + 1, ' ') << "Version " << (int)getVersion() << std::endl; r << std::string(indent + 1, ' ') << "BootstrapinfoVersion " << getBootstrapinfoVersion() << std::endl; r << std::string(indent + 1, ' ') << "Profile " << (int)getProfile() << std::endl; if (getLive()) { r << std::string(indent + 1, ' ') << "Live" << std::endl; } else { r << std::string(indent + 1, ' ') << "Recorded" << std::endl; } if (getUpdate()) { r << std::string(indent + 1, ' ') << "Update" << std::endl; } else { r << std::string(indent + 1, ' ') << "Replacement or new table" << std::endl; } r << std::string(indent + 1, ' ') << "Timescale " << getTimeScale() << std::endl; r << std::string(indent + 1, ' ') << "CurrMediaTime " << getCurrentMediaTime() << std::endl; r << std::string(indent + 1, ' ') << "SmpteTimeCodeOffset " << getSmpteTimeCodeOffset() << std::endl; r << std::string(indent + 1, ' ') << "MovieIdentifier " << getMovieIdentifier() << std::endl; r << std::string(indent + 1, ' ') << "ServerEntryTable (" << getServerEntryCount() << ")" << std::endl; for (unsigned int i = 0; i < getServerEntryCount(); i++) { r << std::string(indent + 2, ' ') << i << ": " << getServerEntry(i) << std::endl; } r << std::string(indent + 1, ' ') << "QualityEntryTable (" << getQualityEntryCount() << ")" << std::endl; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { r << std::string(indent + 2, ' ') << i << ": " << getQualityEntry(i) << std::endl; } r << std::string(indent + 1, ' ') << "DrmData " << getDrmData() << std::endl; r << std::string(indent + 1, ' ') << "MetaData " << getMetaData() << std::endl; r << std::string(indent + 1, ' ') << "SegmentRunTableEntries (" << getSegmentRunTableCount() << ")" << std::endl; for (uint32_t i = 0; i < getSegmentRunTableCount(); i++) { r << ((Box)getSegmentRunTable(i)).toPrettyString(indent + 2); } r << std::string(indent + 1, ' ') + "FragmentRunTableEntries (" << getFragmentRunTableCount() << ")" << std::endl; for (uint32_t i = 0; i < getFragmentRunTableCount(); i++) { r << ((Box)getFragmentRunTable(i)).toPrettyString(indent + 2); } return r.str(); }
// Render atom to a file stream bool PVA_FF_MovieHeaderAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp) { int32 rendered = 0; // Keep track of number of bytes rendered // Render PVA_FF_Atom type and size if (!renderAtomBaseMembers(fp)) { return false; } rendered += getDefaultSize(); if (!PVA_FF_AtomUtils::render32(fp, getCreationTime())) { return false; } if (!PVA_FF_AtomUtils::render32(fp, getModificationTime())) { return false; } if (!PVA_FF_AtomUtils::render32(fp, getTimeScale())) { return false; } /* * To ensure that the total track duration includes the duration of the * last sample as well, which in our case fp same as the last but one. */ //uint32 totalDuration = getDuration() + _deltaTS; uint32 totalDuration = getDuration(); if (!PVA_FF_AtomUtils::render32(fp, totalDuration)) { return false; } rendered += 16; uint32 reserved = 0x00010000; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 4; reserved = 0x0100; if (!PVA_FF_AtomUtils::render16(fp, (uint16)(reserved))) { return false; } rendered += 2; // const bit(32)[2] reserved = 0; if (!PVA_FF_AtomUtils::render16(fp, (uint16)(reserved))) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 10; // const bit(32)[9] reserved = 0x00010000; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 4; reserved = 0; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 12; reserved = 0x00010000; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 4; reserved = 0; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 12; reserved = 0x40000000; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 4; // const bit(32)[6] reserved = 0 reserved = 0; if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } if (!PVA_FF_AtomUtils::render32(fp, reserved)) { return false; } rendered += 24; // _nextTrackID if (!PVA_FF_AtomUtils::render32(fp, _nextTrackID)) { return false; } rendered += 4; return true; }
int CheckMedia(const int wid, const int hei, const std::string mp4_file) { mediaInfo.video_width = wid; mediaInfo.video_height = hei; mediaInfo.audio_codec = -1; mediaInfo.video_frame_rate = -1; std::deque<unsigned char> mdat; std::deque<unsigned char> avcC; std::deque<unsigned char> stts; for(int i = 0; i < 4; i++) { mdat.push_back(0); avcC.push_back(0); stts.push_back(0); } avcC.push_back(0); mediaInfo.begin_skip = -1; FILE *fp = fopen( mp4_file.c_str(), "rb"); unsigned char c; // 0. find av data(mdat) start position int pos = 0; while( !feof(fp) ) { c = fgetc(fp); pos ++; mdat.push_back(c); mdat.pop_front(); if ( mdat[0] == 'm' && mdat[1] == 'd' && mdat[2] == 'a' && mdat[3] == 't') { mediaInfo.begin_skip = pos; std::cout << "Found MDAT skipped = "<< pos << std::endl; break; } } if ( mediaInfo.begin_skip < 0) return 0; mediaInfo.sps_data.clear(); mediaInfo.pps_data.clear(); fseek(fp, 0l, SEEK_SET); unsigned int time_scale = 0; unsigned int frame_duration = 0; bool avcFind = false; // 1. get sps&pps and time scale while( !feof(fp) ) { c = fgetc(fp); avcC.push_back(c); avcC.pop_front(); if ( avcC[0] == 'a' && avcC[1] == 'v' && avcC[2] == 'c' && avcC[3] == 'C' && avcC[4] == 0x01) { avcFind = true; getHeader(fp); break; } else if (avcC[0] == 'm' && avcC[1] == 'd' && avcC[2] == 'h' && avcC[3] == 'd') { time_scale = getTimeScale(fp, avcC[4]); } } if ( !avcFind ) { return 0; } std::cout << "time_scale = " << time_scale << std::endl; // 2. trying to find the stss atom while( !feof(fp) ) { c = fgetc(fp); stts.push_back(c); stts.pop_front(); if ( stts[0] == 's' && stts[1] == 't' && stts[2] == 't' && stts[3] == 's') { frame_duration = getFrameRate(fp, time_scale); break; } } std::cout << "frame rate = " << mediaInfo.video_frame_rate << std::endl; { char temp[512]; sprintf(temp, "skip = %d, time_scale = %d, duration = %d, frame_rate = %d\n", mediaInfo.begin_skip, time_scale, frame_duration, mediaInfo.video_frame_rate); LOGD(temp); } return 1; }
void AnimTimeSensor::frame(Time oTime, UInt32 uiFrame) { Time startT = _sfStartTime .getValue(); Time stopT = _sfStopTime .getValue(); Time currT = _sfTime .getValue(); Time length = _sfCycleLength.getValue(); Time deltaT = 0.0; setTime(oTime); if(getEnabled() == false) { if(getIsActive() == true) { setIsActive(false); } return; } if(startT < stopT) { if(oTime < startT) { if(getIsActive() == true) { SLOG << "ATS: start < stop, BEFORE startT, deactivating" << std::endl; setFraction(0.f ); setAnimTime(0.f ); setIsActive(false); } return; } else if(oTime > stopT) { if(getIsActive() == true) { SLOG << "ATS: start < stop, AFTER stopT"; setFraction(1.f ); setAnimTime(length); // only deactivate the second time oTime > stopT // to propagate the final state if(currT > stopT) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } return; } else { if(currT <= 0.0) { deltaT = oTime - startT; } else { deltaT = oTime - currT; } } } else { if(oTime < startT) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, BEFORE startT, deactivating" << std::endl; setFraction(0.f ); setAnimTime(0.f ); setIsActive(false); } return; } else { if(currT <= 0.0) { deltaT = oTime - startT; } else { deltaT = oTime - currT; } } } // use deltaT to update Real32 oldAnimT = getAnimTime(); Real32 newAnimT = getAnimTime(); if(getForward() == true) { newAnimT += getTimeScale() * deltaT; } else { newAnimT -= getTimeScale() * deltaT; } if(getLoop() == true) { newAnimT = osgMod<Real64>(newAnimT, length); while(newAnimT < 0.f) newAnimT += length; setAnimTime(newAnimT ); setFraction(newAnimT / length); if(getIsActive() == false) setIsActive(true); } else { if(newAnimT < 0.f) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, newAnimT < 0"; setAnimTime(0.f); setFraction(0.f); // only deactivate the second time newAnimT < 0.f // to propagate the final state if(oldAnimT <= 0.f) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } } else if(newAnimT > length) { if(getIsActive() == true) { SLOG << "ATS: start >= stop, newAnimT > length"; setAnimTime(length); setFraction(1.f ); // only deactivate the second time newAnimT > length // to propagate the final state if(oldAnimT >= length) { PLOG << ", deactivating"; setIsActive(false); } PLOG << std::endl; } } else { setAnimTime(newAnimT ); setFraction(newAnimT / length); if(getIsActive() == false) setIsActive(true); } } }