123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: flash-worker.js</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
- </head>
- <body>
- <div id="main">
- <h1 class="page-title">Source: flash-worker.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>/**
- * @file flash-worker.js
- */
- /**
- * videojs-contrib-media-sources
- *
- * Copyright (c) 2015 Brightcove
- * All rights reserved.
- *
- * Handles communication between the browser-world and the mux.js
- * transmuxer running inside of a WebWorker by exposing a simple
- * message-based interface to a Transmuxer object.
- */
- import window from 'global/window';
- import flv from 'mux.js/lib/flv';
- const orderTags = function(tags) {
- let videoTags = tags.videoTags;
- let audioTags = tags.audioTags;
- let ordered = [];
- let tag;
- while (videoTags.length || audioTags.length) {
- if (!videoTags.length) {
- // only audio tags remain
- tag = audioTags.shift();
- } else if (!audioTags.length) {
- // only video tags remain
- tag = videoTags.shift();
- } else if (audioTags[0].dts < videoTags[0].dts) {
- // audio should be decoded next
- tag = audioTags.shift();
- } else {
- // video should be decoded next
- tag = videoTags.shift();
- }
- ordered.push(tag);
- }
- return ordered;
- }
- /**
- * Re-emits tranmsuxer events by converting them into messages to the
- * world outside the worker.
- *
- * @param {Object} transmuxer the transmuxer to wire events on
- * @private
- */
- const wireTransmuxerEvents = function(transmuxer) {
- transmuxer.on('data', function(segment) {
- segment.tags = orderTags(segment.tags);
- window.postMessage({
- action: 'data',
- segment
- });
- });
- transmuxer.on('done', function(data) {
- window.postMessage({ action: 'done' });
- });
- };
- /**
- * All incoming messages route through this hash. If no function exists
- * to handle an incoming message, then we ignore the message.
- *
- * @class MessageHandlers
- * @param {Object} options the options to initialize with
- */
- class MessageHandlers {
- constructor(options) {
- this.options = options || {};
- this.init();
- }
- /**
- * initialize our web worker and wire all the events.
- */
- init() {
- if (this.transmuxer) {
- this.transmuxer.dispose();
- }
- this.transmuxer = new flv.Transmuxer(this.options);
- wireTransmuxerEvents(this.transmuxer);
- }
- /**
- * Adds data (a ts segment) to the start of the transmuxer pipeline for
- * processing.
- *
- * @param {ArrayBuffer} data data to push into the muxer
- */
- push(data) {
- // Cast array buffer to correct type for transmuxer
- let segment = new Uint8Array(data.data, data.byteOffset, data.byteLength);
- this.transmuxer.push(segment);
- }
- /**
- * Recreate the transmuxer so that the next segment added via `push`
- * start with a fresh transmuxer.
- */
- reset() {
- this.init();
- }
- /**
- * Forces the pipeline to finish processing the last segment and emit it's
- * results.
- *
- * @param {Object} data event data, not really used
- */
- flush(data) {
- this.transmuxer.flush();
- }
- }
- /**
- * Our web wroker interface so that things can talk to mux.js
- * that will be running in a web worker. the scope is passed to this by
- * webworkify.
- *
- * @param {Object} self the scope for the web worker
- */
- const Worker = function(self) {
- self.onmessage = function(event) {
- if (event.data.action === 'init' && event.data.options) {
- this.messageHandlers = new MessageHandlers(event.data.options);
- return;
- }
- if (!this.messageHandlers) {
- this.messageHandlers = new MessageHandlers();
- }
- if (event.data && event.data.action && event.data.action !== 'init') {
- if (this.messageHandlers[event.data.action]) {
- this.messageHandlers[event.data.action](event.data);
- }
- }
- };
- };
- export default (self) => {
- return new Worker(self);
- };
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FlashMediaSource.html">FlashMediaSource</a></li><li><a href="FlashSourceBuffer.html">FlashSourceBuffer</a></li><li><a href="HtmlMediaSource.html">HtmlMediaSource</a></li><li><a href="MessageHandlers.html">MessageHandlers</a></li><li><a href="VirtualSourceBuffer.html">VirtualSourceBuffer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#abort">abort</a></li><li><a href="global.html#addSourceBuffer">addSourceBuffer</a></li><li><a href="global.html#appendBuffer">appendBuffer</a></li><li><a href="global.html#endOfStream">endOfStream</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#MediaSource">MediaSource</a></li><li><a href="global.html#open">open</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#supportsNativeMediaSources">supportsNativeMediaSources</a></li><li><a href="global.html#URL">URL</a></li><li><a href="global.html#Worker">Worker</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Dec 02 2016 19:56:59 GMT-0500 (EST)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|