1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "StreamBuffer.h"
13 extern PRLogModuleInfo
* gMediaStreamGraphLog
;
14 #define STREAM_LOG(type, msg) PR_LOG(gMediaStreamGraphLog, type, msg)
16 #define STREAM_LOG(type, msg)
21 StreamBuffer::DumpTrackInfo() const
23 STREAM_LOG(PR_LOG_ALWAYS
, ("DumpTracks: mTracksKnownTime %lld", mTracksKnownTime
));
24 for (uint32_t i
= 0; i
< mTracks
.Length(); ++i
) {
25 Track
* track
= mTracks
[i
];
26 if (track
->IsEnded()) {
27 STREAM_LOG(PR_LOG_ALWAYS
, ("Track[%d] %d: ended", i
, track
->GetID()));
29 STREAM_LOG(PR_LOG_ALWAYS
, ("Track[%d] %d: %lld", i
, track
->GetID(),
30 track
->GetEndTimeRoundDown()));
37 StreamBuffer::GetEnd() const
39 StreamTime t
= mTracksKnownTime
;
40 for (uint32_t i
= 0; i
< mTracks
.Length(); ++i
) {
41 Track
* track
= mTracks
[i
];
42 if (!track
->IsEnded()) {
43 t
= std::min(t
, track
->GetEndTimeRoundDown());
50 StreamBuffer::FindTrack(TrackID aID
)
52 if (aID
== TRACK_NONE
)
54 for (uint32_t i
= 0; i
< mTracks
.Length(); ++i
) {
55 Track
* track
= mTracks
[i
];
56 if (track
->GetID() == aID
) {
64 StreamBuffer::ForgetUpTo(StreamTime aTime
)
66 // Round to nearest 50ms so we don't spend too much time pruning segments.
67 const MediaTime roundTo
= MillisecondsToMediaTime(50);
68 StreamTime forget
= (aTime
/roundTo
)*roundTo
;
69 if (forget
<= mForgottenTime
) {
72 mForgottenTime
= forget
;
74 for (uint32_t i
= 0; i
< mTracks
.Length(); ++i
) {
75 Track
* track
= mTracks
[i
];
76 if (track
->IsEnded() && track
->GetEndTimeRoundDown() <= forget
) {
77 mTracks
.RemoveElementAt(i
);
81 TrackTicks forgetTo
= std::min(track
->GetEnd() - 1, track
->TimeToTicksRoundDown(forget
));
82 track
->ForgetUpTo(forgetTo
);