Performance: Only hold one of clips/snapshots.
This commit is contained in:
+38
-36
@@ -58,8 +58,7 @@ interface FrigateCardGroupData {
|
|||||||
}
|
}
|
||||||
interface FrigateCardTimelineItem extends TimelineItem {
|
interface FrigateCardTimelineItem extends TimelineItem {
|
||||||
event: FrigateEvent;
|
event: FrigateEvent;
|
||||||
clip?: FrigateBrowseMediaSource;
|
source?: FrigateBrowseMediaSource;
|
||||||
snapshot?: FrigateBrowseMediaSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TimelineViewContext extends ViewContext {
|
interface TimelineViewContext extends ViewContext {
|
||||||
@@ -127,11 +126,19 @@ class TimelineEventManager {
|
|||||||
* @param camera The id the camera this object is from.
|
* @param camera The id the camera this object is from.
|
||||||
* @param target The FrigateBrowseMediaSource to add.
|
* @param target The FrigateBrowseMediaSource to add.
|
||||||
*/
|
*/
|
||||||
protected _addMediaSource(camera: string, target: FrigateBrowseMediaSource): void {
|
protected _addMediaSource(
|
||||||
|
camera: string,
|
||||||
|
mediaPriority: TimelineMediaType,
|
||||||
|
target: FrigateBrowseMediaSource,
|
||||||
|
): void {
|
||||||
const items: FrigateCardTimelineItem[] = [];
|
const items: FrigateCardTimelineItem[] = [];
|
||||||
target.children?.forEach((child) => {
|
target.children?.forEach((child) => {
|
||||||
const event = child.frigate?.event;
|
const event = child.frigate?.event;
|
||||||
if (event && ['video', 'image'].includes(child.media_content_type)) {
|
if (
|
||||||
|
event &&
|
||||||
|
BrowseMediaUtil.isTrueMedia(child) &&
|
||||||
|
['video', 'image'].includes(child.media_content_type)
|
||||||
|
) {
|
||||||
let item = this._dataset.get(event.id);
|
let item = this._dataset.get(event.id);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
item = {
|
item = {
|
||||||
@@ -143,17 +150,21 @@ class TimelineEventManager {
|
|||||||
event: event,
|
event: event,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
(child.media_content_type === 'video' &&
|
||||||
|
['all', 'clips'].includes(mediaPriority)) ||
|
||||||
|
(!item.source &&
|
||||||
|
child.media_content_type === 'image' &&
|
||||||
|
['all', 'snapshots'].includes(mediaPriority))
|
||||||
|
) {
|
||||||
|
item.source = child;
|
||||||
|
}
|
||||||
if (event.end_time) {
|
if (event.end_time) {
|
||||||
item['end'] = event.end_time * 1000;
|
item['end'] = event.end_time * 1000;
|
||||||
item['type'] = 'range';
|
item['type'] = 'range';
|
||||||
} else {
|
} else {
|
||||||
item['type'] = 'point';
|
item['type'] = 'point';
|
||||||
}
|
}
|
||||||
if (child.media_content_type === 'video') {
|
|
||||||
item['clip'] = child;
|
|
||||||
} else if (child.media_content_type === 'image') {
|
|
||||||
item['snapshot'] = child;
|
|
||||||
}
|
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -264,7 +275,7 @@ class TimelineEventManager {
|
|||||||
|
|
||||||
const fetchCameraEvents = async (
|
const fetchCameraEvents = async (
|
||||||
camera: string,
|
camera: string,
|
||||||
mediaType: 'clips' | 'snapshots',
|
fetchMedia: 'clips' | 'snapshots',
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const cameraConfig = cameras.get(camera);
|
const cameraConfig = cameras.get(camera);
|
||||||
if (!cameraConfig || !this._dateStart || !this._dateEnd) {
|
if (!cameraConfig || !this._dateStart || !this._dateEnd) {
|
||||||
@@ -278,6 +289,7 @@ class TimelineEventManager {
|
|||||||
try {
|
try {
|
||||||
this._addMediaSource(
|
this._addMediaSource(
|
||||||
camera,
|
camera,
|
||||||
|
media,
|
||||||
await BrowseMediaUtil.browseMediaQuery(hass, {
|
await BrowseMediaUtil.browseMediaQuery(hass, {
|
||||||
...browseMediaQueryParametersBase,
|
...browseMediaQueryParametersBase,
|
||||||
|
|
||||||
@@ -287,7 +299,7 @@ class TimelineEventManager {
|
|||||||
before: this._dateEnd.getTime() / 1000,
|
before: this._dateEnd.getTime() / 1000,
|
||||||
after: this._dateStart.getTime() / 1000,
|
after: this._dateStart.getTime() / 1000,
|
||||||
unlimited: true,
|
unlimited: true,
|
||||||
mediaType: mediaType,
|
mediaType: fetchMedia,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -527,7 +539,10 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
* @param b The second item.
|
* @param b The second item.
|
||||||
* @returns -1, 0, 1 (standard array sort function configuration).
|
* @returns -1, 0, 1 (standard array sort function configuration).
|
||||||
*/
|
*/
|
||||||
const sortEvent = (a: FrigateCardTimelineItem, b: FrigateCardTimelineItem): number => {
|
const sortEvent = (
|
||||||
|
a: FrigateCardTimelineItem,
|
||||||
|
b: FrigateCardTimelineItem,
|
||||||
|
): number => {
|
||||||
if (a.start < b.start) {
|
if (a.start < b.start) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -535,31 +550,15 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
const selected = this._timeline.getSelection();
|
const selected = this._timeline.getSelection();
|
||||||
let childIndex = -1;
|
let childIndex = -1;
|
||||||
const children: FrigateBrowseMediaSource[] = [];
|
const children: FrigateBrowseMediaSource[] = [];
|
||||||
this._events.dataset.get({ order: sortEvent }).forEach((item) => {
|
this._events.dataset.get({ order: sortEvent }).forEach((item) => {
|
||||||
if (this.timelineConfig) {
|
if (item.source) {
|
||||||
let added = false;
|
children.push(item.source);
|
||||||
if (
|
if (selected.includes(item.event.id)) {
|
||||||
item.clip &&
|
|
||||||
['all', 'clips'].includes(this.timelineConfig.media) &&
|
|
||||||
BrowseMediaUtil.isTrueMedia(item.clip)
|
|
||||||
) {
|
|
||||||
added = true;
|
|
||||||
children.push(item.clip);
|
|
||||||
} else if (
|
|
||||||
item.snapshot &&
|
|
||||||
['all', 'snapshots'].includes(this.timelineConfig.media) &&
|
|
||||||
BrowseMediaUtil.isTrueMedia(item.snapshot)
|
|
||||||
) {
|
|
||||||
added = true;
|
|
||||||
children.push(item.snapshot);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (added && selected.includes(item.event.id)) {
|
|
||||||
childIndex = children.length - 1;
|
childIndex = children.length - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -620,7 +619,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
// recent portion of the event that fits in the window.
|
// recent portion of the event that fits in the window.
|
||||||
return [
|
return [
|
||||||
sub(fromUnixTime(event.end_time), { seconds: windowSeconds }),
|
sub(fromUnixTime(event.end_time), { seconds: windowSeconds }),
|
||||||
fromUnixTime(event.end_time)
|
fromUnixTime(event.end_time),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
// If the event is shorter than the configured window, center the event
|
// If the event is shorter than the configured window, center the event
|
||||||
@@ -629,7 +628,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
return [
|
return [
|
||||||
sub(fromUnixTime(event.start_time), { seconds: gap / 2 }),
|
sub(fromUnixTime(event.start_time), { seconds: gap / 2 }),
|
||||||
add(fromUnixTime(event.end_time), { seconds: gap / 2 }),
|
add(fromUnixTime(event.end_time), { seconds: gap / 2 }),
|
||||||
]
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If there's no end-time yet, place the start-time in the center of the
|
// If there's no end-time yet, place the start-time in the center of the
|
||||||
@@ -644,7 +643,10 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
* Get the configured window length in seconds.
|
* Get the configured window length in seconds.
|
||||||
*/
|
*/
|
||||||
protected _getConfiguredWindowSeconds(): number {
|
protected _getConfiguredWindowSeconds(): number {
|
||||||
return this.timelineConfig?.window_seconds ?? frigateCardConfigDefaults.timeline.window_seconds;
|
return (
|
||||||
|
this.timelineConfig?.window_seconds ??
|
||||||
|
frigateCardConfigDefaults.timeline.window_seconds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -658,7 +660,7 @@ export class FrigateCardTimelineCore extends LitElement {
|
|||||||
}
|
}
|
||||||
const end = new Date();
|
const end = new Date();
|
||||||
const start = sub(end, {
|
const start = sub(end, {
|
||||||
seconds: this._getConfiguredWindowSeconds()
|
seconds: this._getConfiguredWindowSeconds(),
|
||||||
});
|
});
|
||||||
return [start, end];
|
return [start, end];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user