Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Nov 22, 2023
1 parent dd8ac1f commit af8b596
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
12 changes: 11 additions & 1 deletion src/components/mini-widgets/MiniVideoRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

<script setup lang="ts">
import { useMouseInElement, useTimestamp } from '@vueuse/core'
import { format, intervalToDuration } from 'date-fns'
import { differenceInSeconds, format, intervalToDuration } from 'date-fns'
import { saveAs } from 'file-saver'
import fixWebmDuration from 'fix-webm-duration'
import localforage from 'localforage'
Expand All @@ -64,6 +64,7 @@ import { computed, onBeforeMount, onBeforeUnmount, ref, toRefs, watch } from 'vu
import adapter from 'webrtc-adapter'
import { WebRTCManager } from '@/composables/webRTC'
import { datalogger } from '@/libs/logging'
import type { Stream } from '@/libs/webrtc/signalling_protocol'
import { useMainVehicleStore } from '@/stores/mainVehicle'
import { useMissionStore } from '@/stores/mission'
Expand Down Expand Up @@ -194,6 +195,9 @@ const startRecording = async (): Promise<SweetAlertResult | void> => {
timeRecordingStart.value = new Date()
const fileName = `${missionName || 'Cockpit'} (${format(timeRecordingStart.value, 'LLL dd, yyyy - HH꞉mm꞉ss O')})`
mediaRecorder.value = new MediaRecorder(mediaStream.value)
if (!datalogger.logging()) {
datalogger.startLogging()
}
mediaRecorder.value.start(1000)
let chunks: Blob[] = []
mediaRecorder.value.ondataavailable = async (e) => {
Expand All @@ -203,6 +207,12 @@ const startRecording = async (): Promise<SweetAlertResult | void> => {
mediaRecorder.value.onstop = () => {
const blob = new Blob(chunks, { type: 'video/webm' })
const videoTelemetryLog = datalogger.getSlice(datalogger.currentCockpitLog, timeRecordingStart.value, new Date())
const fixedVideoTelemetryLog = videoTelemetryLog.map((logPoint) => ({
...logPoint,
...{ seconds: differenceInSeconds(new Date(logPoint.epoch), timeRecordingStart.value) },
}))
console.log(fixedVideoTelemetryLog)
fixWebmDuration(blob, Date.now() - timeRecordingStart.value.getTime()).then((fixedBlob) => {
saveAs(fixedBlob, fileName)
cockpitVideoDB.removeItem(fileName)
Expand Down
51 changes: 37 additions & 14 deletions src/libs/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@ import { useMainVehicleStore } from '@/stores/mainVehicle'

import { degrees } from './utils'

/**
* Format for a standalone cockpit log
*/
export interface CockpitStandardLogPoint {
/**
* Universal Linux epoch time (milliseconds since January 1st, 1970, UTC)
*/
epoch: number
/**
* Seconds passed since the beggining of the logging
*/
seconds: number
/**
* The actual vehicle data
*/
data: Record<string, number | string>
}

/**
* Format for a standalone cockpit log
*/
export type CockpitStandardLog = CockpitStandardLogPoint[]

/**
* Manager logging vehicle data and others
*/
class DataLogger {
currentLoggerInterval: ReturnType<typeof setInterval> | undefined = undefined
currentCockpitLog: {
/**
* Universal Linux epoch time (milliseconds since January 1st, 1970, UTC)
*/
epoch: number
/**
* Seconds passed since the beggining of the logging
*/
seconds: number
/**
* The actual vehicle data
*/
data: Record<string, number | string>
}[] = []
currentCockpitLog: CockpitStandardLog = []

/**
* Start an intervaled logging
Expand Down Expand Up @@ -91,6 +101,19 @@ class DataLogger {
logging(): boolean {
return this.currentLoggerInterval !== undefined
}

/**
* Get desired part of a log based on timestamp
* @param {CockpitStandardLog} completeLog The log from which the slice should be taken from
* @param {Date} initialTime The timestamp from which the log should be started from
* @param {Date} finalTime The timestamp in which the log should be terminated
* @returns {CockpitStandardLog} The actual log
*/
getSlice(completeLog: CockpitStandardLog, initialTime: Date, finalTime: Date): CockpitStandardLog {
return completeLog.filter((logPoint) => {
return logPoint.epoch > initialTime.getTime() && logPoint.epoch < finalTime.getTime()
})
}
}

export const datalogger = new DataLogger()

0 comments on commit af8b596

Please sign in to comment.