Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jrtcppv committed Oct 6, 2021
2 parents 00cf8d8 + 4d3693a commit ffa1954
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 370 deletions.
61 changes: 48 additions & 13 deletions main/static/js/annotation/annotation-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class AnnotationMulti extends TatorElement {
}
});

this._videoStatus = "paused"; // Possible values: playing | paused | scrubbing

// Start out with play button disabled.
this._play._button.setAttribute("disabled","");
// Use some spaces because the tooltip z-index is wrong
Expand All @@ -275,7 +277,7 @@ class AnnotationMulti extends TatorElement {
this._zoomSliderDiv.hidden = false;
this._zoomSlider.setAttribute("min", evt.detail.minFrame);
this._zoomSlider.setAttribute("max", evt.detail.maxFrame);
this._zoomSlider.value = Number(this._currentFrameText.textContent);
this._zoomSlider.value = this._slider.value;
}
});

Expand Down Expand Up @@ -465,6 +467,9 @@ class AnnotationMulti extends TatorElement {
const frame = Number(evt.target.value);
const waitOk = now - this._lastScrub > this._scrubInterval;
if (waitOk) {

this._videoStatus = "scrubbing";

this._play.setAttribute("is-paused","");
let prime_fps = this._fps[this._longest_idx];
for (let idx = 0; idx < this._videos.length; idx++)
Expand Down Expand Up @@ -495,6 +500,8 @@ class AnnotationMulti extends TatorElement {
frame = evt.detail.frame;
}

this._videoStatus = "scrubbing";

var seekPromiseList = [];
let prime_fps = this._fps[this._longest_idx];
for (let idx = 0; idx < this._videos.length; idx++)
Expand Down Expand Up @@ -527,6 +534,8 @@ class AnnotationMulti extends TatorElement {
}
video.onDemandDownloadPrefetch(this_frame);
};

this._videoStatus = "paused";
this.handleAllNotReadyEvents();
this.dispatchEvent(new Event("hideLoading", {composed: true}));
})
Expand All @@ -540,6 +549,8 @@ class AnnotationMulti extends TatorElement {
*/
processFrameInput() {

this._videoStatus = "paused";

var frame = parseInt(this._currentFrameInput.value);
if (isNaN(frame)) {
console.log("Provided invalid frame input: " + this._currentFrameInput.value);
Expand Down Expand Up @@ -569,6 +580,8 @@ class AnnotationMulti extends TatorElement {
*/
processTimeInput() {

this._videoStatus = "paused";

var timeTokens = this._currentTimeInput.value.split(":");
if (timeTokens.length != 2)
{
Expand Down Expand Up @@ -723,9 +736,6 @@ class AnnotationMulti extends TatorElement {
}
};
this._slider.onDemandLoaded(fakeEvt);

let frame = Math.round(fakeEvt.detail.percent_complete * this._maxFrameNumber);
this._zoomSlider.setLoadProgress(frame);
};
let setup_video = (idx, video_info) => {
this._slider.setAttribute("min", 0);
Expand Down Expand Up @@ -775,6 +785,12 @@ class AnnotationMulti extends TatorElement {
(evt) => {
handle_ondemand_load(idx,evt);
});
// When a playback is stalled, pause all the videos.
this._videos[idx].addEventListener("playbackStalled",
(evt) => {
Utilities.warningAlert("Video playback stalled.");
this.pause();
});
this._videos[idx].addEventListener("frameChange",
(evt) => {
global_frame_change(idx,evt);
Expand Down Expand Up @@ -1009,7 +1025,7 @@ class AnnotationMulti extends TatorElement {
*/
setDefaultVideoSettings(idx) {

console.log(`**** Setting default video settings for: ${idx}`)
console.log(`Setting default video settings for: ${idx}`)

const seekInfo = this._videos[idx].getQuality("seek");
const scrubInfo = this._videos[idx].getQuality("scrub");
Expand Down Expand Up @@ -1363,7 +1379,7 @@ class AnnotationMulti extends TatorElement {
}
if (notReady)
{
this.handleNotReadyEvent();
this.handleAllNotReadyEvents();
}
}

Expand Down Expand Up @@ -1454,6 +1470,16 @@ class AnnotationMulti extends TatorElement {
this._last_duration = this._videos[videoIndex].playBufferDuration();

let check_ready = (checkFrame) => {

if (this._videoStatus == "scrubbing") {
console.log(`Player status == scrubbing | Cancelling check_ready for video: ${videoIndex}`);
return;
}
if (this._videoStatus == "playing") {
console.error(`Player status == playing | Cancelling check_ready for video: ${videoIndex}`);
return;
}

timeoutCounter += clock_check;

let not_ready = false;
Expand Down Expand Up @@ -1485,7 +1511,6 @@ class AnnotationMulti extends TatorElement {
timeoutIndex = 0;
}
if (timeoutIndex < timeouts[timeouts.length-1]/clock_check) {
//console.log(`Video ${videoIndex} playback check - Not ready: checking in ${500/1000} seconds [Now: ${new Date().toISOString()}]`);
this._handleNotReadyTimeout[videoIndex] = setTimeout(() => {
this._handleNotReadyTimeout[videoIndex] = null;
check_ready(checkFrame);
Expand Down Expand Up @@ -1525,7 +1550,6 @@ class AnnotationMulti extends TatorElement {
}
};

//console.log(`Video ${videoIndex} playback check - Not ready: checking in ${500/1000} seconds [Now: ${new Date().toISOString()}]`);
this._handleNotReadyTimeout[videoIndex] = setTimeout(() => {
this._handleNotReadyTimeout[videoIndex] = null;
check_ready(this._videos[videoIndex].currentFrame())
Expand Down Expand Up @@ -1559,6 +1583,7 @@ class AnnotationMulti extends TatorElement {

if (playing)
{
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
this._syncThread = setTimeout(() => {this.syncCheck()},
500);
Expand Down Expand Up @@ -1592,7 +1617,8 @@ class AnnotationMulti extends TatorElement {
}
if (playing)
{
this._play.removeAttribute("is-paused");
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
}
this.syncCheck();
}
Expand Down Expand Up @@ -1623,6 +1649,7 @@ class AnnotationMulti extends TatorElement {

if (playing)
{
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
this._syncThread = setTimeout(() => {this.syncCheck()},
500);
Expand Down Expand Up @@ -1657,6 +1684,7 @@ class AnnotationMulti extends TatorElement {
playing |= video.playBackwards();
if (playing)
{
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
}
}
Expand All @@ -1670,18 +1698,22 @@ class AnnotationMulti extends TatorElement {
this.disablePlayUI(); // Wait for playbackReady checks to enable play

const paused = this.is_paused();
var pausePromises = [];
if (paused == false) {
for (let video of this._videos)
{
video.pause();
pausePromises.push(video.pause());
}
this._play.setAttribute("is-paused", "");
}
clearTimeout(this._syncThread);
Promise.all(pausePromises).then(() => {
// If we are in focus mode, sync to the focused video.
// Otherwise, use the video with the most data.

// If we are in focus mode, sync to the focused video.
// Otherwise, use the video with the most data.
this.goToFrame(this._videos[this._primaryVideoIndex].currentFrame());
this._videoStatus = "paused";
this.goToFrame(this._videos[this._primaryVideoIndex].currentFrame());
});
}

disablePlayUI() {
Expand Down Expand Up @@ -1733,6 +1765,9 @@ class AnnotationMulti extends TatorElement {
}
else {
this._quality = quality;
if (this._qualityControl._select != null) {
this._qualityControl.quality = quality;
}
for (let video of this._videos)
{
video.setQuality(quality, buffer);
Expand Down
5 changes: 3 additions & 2 deletions main/static/js/annotation/annotation-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ class AnnotationPage extends TatorPage {
playbackQuality = Number(searchParams.get("playQuality"));
}
this._settings.quality = playbackQuality;
this._player.setQuality(playbackQuality, null, true);
this._player.setAvailableQualities(primeMediaData);
this._player.setQuality(playbackQuality, null, true);
}
);
} else if (type_data.dtype == "live") {
Expand Down Expand Up @@ -820,7 +820,8 @@ class AnnotationPage extends TatorPage {
if (localizationTypeId === null) {
throw "Could not find a localization type to use for track creation!";
}
dataType.localizationType = dataTypes.filter(type => type.id == localizationTypeId)[0];
dataType.localizationType = dataTypes.filter(type => (type.id == localizationTypeId
|| Number(type.id.split('_')[1]) == localizationTypeId))[0];
}
}
this._data.init(dataTypes, this._version, projectId, mediaId, update, !block_signals);
Expand Down
48 changes: 44 additions & 4 deletions main/static/js/annotation/annotation-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,17 @@ class AnnotationPlayer extends TatorElement {

// When a seek is complete check to make sure the display all set
this._video.addEventListener("seekComplete", evt => {
clearTimeout(this._handleNotReadyTimeout)
this._handleNotReadyTimeout = null;
this.checkReady();
});

// When a playback is stalled, pause the video
this._video.addEventListener("playbackStalled", evt => {
Utilities.warningAlert("Video playback stalled.");
this.pause();
});

this._video.addEventListener("rateChange", evt => {
this.checkReady();
});
Expand Down Expand Up @@ -283,6 +291,15 @@ class AnnotationPlayer extends TatorElement {
this.safeMode();
});

this._video.addEventListener("playbackReady", () =>{
if (this.is_paused()) {
this._play._button.removeAttribute("disabled");
this._rewind.removeAttribute("disabled")
this._fastForward.removeAttribute("disabled");
this._play.removeAttribute("tooltip");
}
});

this._timelineD3.addEventListener("zoomedTimeline", evt => {
if (evt.detail.minFrame < 1 || evt.detail.maxFrame < 1) {
// Reset the slider
Expand All @@ -294,7 +311,7 @@ class AnnotationPlayer extends TatorElement {
this._zoomSliderDiv.hidden = false;
this._zoomSlider.setAttribute("min", evt.detail.minFrame);
this._zoomSlider.setAttribute("max", evt.detail.maxFrame);
this._zoomSlider.value = Number(this._currentFrameText.textContent);
this._zoomSlider.value = this._slider.value;
}
});

Expand Down Expand Up @@ -402,9 +419,6 @@ class AnnotationPlayer extends TatorElement {
if (this._play._button.hasAttribute("disabled")) {
return;
}
if (this._playbackDisabled) {
return;
}
if (this.is_paused())
{
this.play();
Expand Down Expand Up @@ -441,6 +455,8 @@ class AnnotationPlayer extends TatorElement {
}
}
});

this._videoStatus = "paused"; // Possible values: playing | paused | scrubbing
}

static get observedAttributes() {
Expand Down Expand Up @@ -515,6 +531,9 @@ class AnnotationPlayer extends TatorElement {
const frame = Number(evt.target.value);
const waitOk = now - this._lastScrub > this._scrubInterval;
if (waitOk) {

this._videoStatus = "scrubbing";

this._play.setAttribute("is-paused","");
this._video.stopPlayerThread();
this._video.shutdownOnDemandDownload();
Expand All @@ -535,13 +554,17 @@ class AnnotationPlayer extends TatorElement {
{
frame = evt.detail.frame;
}

this._videoStatus = "scrubbing";

this._video.stopPlayerThread();
this._video.shutdownOnDemandDownload();

// Use the hq buffer when the input is finalized
this._video.seekFrame(frame, this._video.drawFrame, true).then(() => {
this._lastScrub = Date.now()
this._video.onDemandDownloadPrefetch(frame);
this._videoStatus = "paused";
this.handleNotReadyEvent();
this.dispatchEvent(new Event("hideLoading", {composed: true}));
}).catch((e) => {
Expand All @@ -556,6 +579,8 @@ class AnnotationPlayer extends TatorElement {
*/
processFrameInput() {

this._videoStatus = "paused";

var frame = parseInt(this._currentFrameInput.value);
if (isNaN(frame)) {
console.log("Provided invalid frame input: " + this._currentFrameInput.value);
Expand Down Expand Up @@ -585,6 +610,8 @@ class AnnotationPlayer extends TatorElement {
*/
processTimeInput() {

this._videoStatus = "paused";

var timeTokens = this._currentTimeInput.value.split(":");
if (timeTokens.length != 2)
{
Expand Down Expand Up @@ -776,6 +803,16 @@ class AnnotationPlayer extends TatorElement {
this._last_duration = this._video.playBufferDuration();

let check_ready = (checkFrame) => {

if (this._videoStatus == "scrubbing") {
console.log(`Player status == scrubbing | Cancelling check_ready`);
return;
}
if (this._videoStatus == "playing") {
console.error(`Player status == playing | Cancelling check_ready`);
return;
}

timeoutCounter += clock_check;

this._handleNotReadyTimeout = null;
Expand Down Expand Up @@ -868,6 +905,7 @@ class AnnotationPlayer extends TatorElement {
this._video.rateChange(this._rate);
if (this._video.play())
{
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
}
}
Expand Down Expand Up @@ -906,6 +944,7 @@ class AnnotationPlayer extends TatorElement {
this._video.rateChange(this._rate);
if (this._video.playBackwards())
{
this._videoStatus = "playing";
this._play.removeAttribute("is-paused");
}
}
Expand All @@ -922,6 +961,7 @@ class AnnotationPlayer extends TatorElement {
this._video.pause();
this._play.setAttribute("is-paused", "")
}
this._videoStatus = "paused";
this.checkReady();
}

Expand Down
Loading

0 comments on commit ffa1954

Please sign in to comment.