2012-05-07 22:22:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-04-30 07:11:19 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-01-26 05:49:01 +03:00
|
|
|
#include "StreamTracks.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-04-30 07:11:19 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern LazyLogModule gMediaStreamGraphLog;
|
2015-05-21 23:22:04 +03:00
|
|
|
#define STREAM_LOG(type, msg) MOZ_LOG(gMediaStreamGraphLog, type, msg)
|
2013-03-07 12:53:45 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::DumpTrackInfo() const
|
2013-03-07 12:53:45 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
STREAM_LOG(LogLevel::Info, ("DumpTracks: mTracksKnownTime %lld", mTracksKnownTime));
|
2013-03-07 12:53:45 +04:00
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
Track* track = mTracks[i];
|
|
|
|
if (track->IsEnded()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
STREAM_LOG(LogLevel::Info, ("Track[%d] %d: ended", i, track->GetID()));
|
2013-03-07 12:53:45 +04:00
|
|
|
} else {
|
2015-06-04 01:25:57 +03:00
|
|
|
STREAM_LOG(LogLevel::Info, ("Track[%d] %d: %lld", i, track->GetID(),
|
2014-09-18 09:13:13 +04:00
|
|
|
track->GetEnd()));
|
2013-03-07 12:53:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-30 07:11:19 +04:00
|
|
|
StreamTime
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::GetEnd() const
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
|
|
|
StreamTime t = mTracksKnownTime;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
2012-04-30 07:11:19 +04:00
|
|
|
Track* track = mTracks[i];
|
|
|
|
if (!track->IsEnded()) {
|
2014-09-18 09:13:13 +04:00
|
|
|
t = std::min(t, track->GetEnd());
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:08:12 +04:00
|
|
|
StreamTime
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::GetAllTracksEnd() const
|
2013-12-04 05:08:12 +04:00
|
|
|
{
|
2014-05-19 00:26:54 +04:00
|
|
|
if (mTracksKnownTime < STREAM_TIME_MAX) {
|
|
|
|
// A track might be added.
|
|
|
|
return STREAM_TIME_MAX;
|
|
|
|
}
|
2013-12-04 05:08:12 +04:00
|
|
|
StreamTime t = 0;
|
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
|
|
|
Track* track = mTracks[i];
|
|
|
|
if (!track->IsEnded()) {
|
|
|
|
return STREAM_TIME_MAX;
|
|
|
|
}
|
2014-09-18 09:13:13 +04:00
|
|
|
t = std::max(t, track->GetEnd());
|
2013-12-04 05:08:12 +04:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::Track*
|
|
|
|
StreamTracks::FindTrack(TrackID aID)
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
2015-05-13 16:35:10 +03:00
|
|
|
if (aID == TRACK_NONE || mTracks.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-05-13 16:35:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The tracks are sorted by ID. We can use a binary search.
|
|
|
|
|
|
|
|
uint32_t left = 0, right = mTracks.Length() - 1;
|
|
|
|
while (left <= right) {
|
|
|
|
uint32_t middle = (left + right) / 2;
|
|
|
|
if (mTracks[middle]->GetID() == aID) {
|
|
|
|
return mTracks[middle];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTracks[middle]->GetID() > aID) {
|
2015-05-13 18:07:16 +03:00
|
|
|
if (middle == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-13 16:35:10 +03:00
|
|
|
right = middle - 1;
|
|
|
|
} else {
|
|
|
|
left = middle + 1;
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-13 16:35:10 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-04-30 07:11:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-26 05:49:01 +03:00
|
|
|
StreamTracks::ForgetUpTo(StreamTime aTime)
|
2012-04-30 07:11:19 +04:00
|
|
|
{
|
2014-06-12 08:44:59 +04:00
|
|
|
// Only prune if there is a reasonable chunk (50ms @ 48kHz) to forget, so we
|
|
|
|
// don't spend too much time pruning segments.
|
|
|
|
const StreamTime minChunkSize = 2400;
|
|
|
|
if (aTime < mForgottenTime + minChunkSize) {
|
2012-04-30 07:11:19 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-06-12 08:44:59 +04:00
|
|
|
mForgottenTime = aTime;
|
2012-04-30 07:11:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
|
2012-04-30 07:11:19 +04:00
|
|
|
Track* track = mTracks[i];
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime forgetTo = std::min(track->GetEnd() - 1, aTime);
|
2012-04-30 07:11:19 +04:00
|
|
|
track->ForgetUpTo(forgetTo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 14:45:29 +03:00
|
|
|
void
|
|
|
|
StreamTracks::Clear()
|
|
|
|
{
|
|
|
|
mTracks.Clear();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|