Update Frames component to use ffprobe-worker.

This commit is contained in:
Alf
2020-12-21 23:26:31 -08:00
parent 60cb243a42
commit 16d930c36e
4 changed files with 100 additions and 64 deletions

View File

@@ -1,6 +1,11 @@
onmessage = (e) => { onmessage = (e) => {
const file = e.data[0]; const type = e.data[0];
const file = e.data[1];
let data;
switch (type) {
case 'get_file_info':
// Mount FS for files. // Mount FS for files.
if (!FS.analyzePath('/work').exists) { if (!FS.analyzePath('/work').exists) {
FS.mkdir('/work'); FS.mkdir('/work');
@@ -23,7 +28,7 @@ onmessage = (e) => {
}; };
// Send back data response. // Send back data response.
const data = { data = {
...info, ...info,
streams: s, streams: s,
versions, versions,
@@ -32,5 +37,36 @@ onmessage = (e) => {
// Cleanup mount. // Cleanup mount.
FS.unmount('/work'); FS.unmount('/work');
break;
case 'get_frames':
if (!FS.analyzePath('/work').exists) {
FS.mkdir('/work');
}
FS.mount(WORKERFS, { files: [file] }, '/work');
const offset = e.data[2];
const frames = Module.get_frames('/work/' + file.name, offset);
// Remap frames into collection.
const f = [];
for (let i = 0; i < frames.frames.size(); i++) {
f.push(frames.frames.get(i));
}
data = {
...frames,
frames: f,
}
postMessage(data);
// Cleanup mount.
FS.unmount('/work');
break;
default:
break;
}
} }
self.importScripts('ffprobe-wasm.js'); // Load ffprobe into worker context. self.importScripts('ffprobe-wasm.js'); // Load ffprobe into worker context.

View File

@@ -28,7 +28,7 @@
</div> </div>
</b-tab> </b-tab>
<b-tab title="Frames" class="mt-2" lazy> <b-tab title="Frames" class="mt-2" lazy>
<Frames /> <Frames :file="file" />
</b-tab> </b-tab>
</b-tabs> </b-tabs>
</div> </div>
@@ -39,8 +39,6 @@
import Overview from './Overview.vue'; import Overview from './Overview.vue';
import Frames from './Frames.vue'; import Frames from './Frames.vue';
const worker = new Worker('ffprobe-worker.js');
export default { export default {
name: 'File', name: 'File',
components: { components: {
@@ -57,7 +55,7 @@ export default {
} }
}, },
created() { created() {
worker.onmessage = (e) => { this.$worker.onmessage = (e) => {
this.info = e.data; this.info = e.data;
} }
}, },
@@ -68,7 +66,7 @@ export default {
this.showProgress = true; this.showProgress = true;
const file = event.dataTransfer ? event.dataTransfer.files[0] : event.target.files[0]; const file = event.dataTransfer ? event.dataTransfer.files[0] : event.target.files[0];
worker.postMessage([ file ]); this.$worker.postMessage([ 'get_file_info', file ]);
} }
} }
} }

View File

@@ -1,6 +1,8 @@
<template> <template>
<div> <div>
<h4>Frames</h4> <h4>Frames</h4>
<div v-if="!data">Loading...</div>
<div v-if="data">
<p class="text-right">Total: {{ data.nb_frames }}</p> <p class="text-right">Total: {{ data.nb_frames }}</p>
<b-pagination <b-pagination
@@ -11,7 +13,7 @@
align="right" align="right"
></b-pagination> ></b-pagination>
<b-table striped hover :items="frames"> <b-table striped hover :items="data.frames">
<template #cell(pict_type)="data"> <template #cell(pict_type)="data">
{{ String.fromCharCode(data.value) }} {{ String.fromCharCode(data.value) }}
</template> </template>
@@ -25,11 +27,13 @@
align="right" align="right"
></b-pagination> ></b-pagination>
</div> </div>
</div>
</template> </template>
<script> <script>
export default { export default {
name: 'Frames', name: 'Frames',
props: ['file'],
data() { data() {
return { return {
data: null, data: null,
@@ -41,22 +45,17 @@ export default {
pages() { pages() {
return this.data.nb_frames; return this.data.nb_frames;
}, },
frames() {
if (!this.data) return [];
const s = [];
for (let i = 0; i < this.data.frames.size(); i++) {
s.push(this.data.frames.get(i));
}
return s;
},
}, },
created() { created() {
this.data = window.Module.get_frames(0); this.$worker.onmessage = (e) => {
this.data = e.data;
}
this.$worker.postMessage([ 'get_frames', this.file, 0 ]);
}, },
methods: { methods: {
onPageChanged(page) { onPageChanged(page) {
this.data = window.Module.get_frames(this.perPage * (page - 1)); this.$worker.postMessage([ 'get_frames', this.file, this.perPage * (page - 1) ]);
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, },
} }

View File

@@ -5,6 +5,9 @@ import App from './App.vue'
import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css'; import 'bootstrap-vue/dist/bootstrap-vue.css';
const worker = new Worker('ffprobe-worker.js');
Vue.prototype.$worker = worker;
Vue.use(BootstrapVue); Vue.use(BootstrapVue);
Vue.config.productionTip = false Vue.config.productionTip = false