WIP: flash and HTML, working together
Showing
1 changed file
with
15 additions
and
89 deletions
... | @@ -91,25 +91,14 @@ videojs.getComponent('Html5').registerSourceHandler({ | ... | @@ -91,25 +91,14 @@ videojs.getComponent('Html5').registerSourceHandler({ |
91 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; | 91 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; |
92 | 92 | ||
93 | videojs.Hls.prototype.src = function(src) { | 93 | videojs.Hls.prototype.src = function(src) { |
94 | var | 94 | var oldMediaPlaylist; |
95 | mediaSource, | ||
96 | oldMediaPlaylist, | ||
97 | source; | ||
98 | 95 | ||
99 | // do nothing if the src is falsey | 96 | // do nothing if the src is falsey |
100 | if (!src) { | 97 | if (!src) { |
101 | return; | 98 | return; |
102 | } | 99 | } |
103 | 100 | ||
104 | // mediaSource = new videojs.MediaSource(); | 101 | this.mediaSource = new videojs.MediaSource(); |
105 | mediaSource = new MediaSource(); | ||
106 | source = { | ||
107 | src: URL.createObjectURL(mediaSource), | ||
108 | //src: videojs.URL.createObjectURL(mediaSource), | ||
109 | type: 'audio/mp4;codecs=mp4a.40.2' // "video/flv" | ||
110 | }; | ||
111 | this.mediaSource = mediaSource; | ||
112 | |||
113 | this.segmentBuffer_ = []; | 102 | this.segmentBuffer_ = []; |
114 | this.segmentParser_ = new videojs.Hls.SegmentParser(); | 103 | this.segmentParser_ = new videojs.Hls.SegmentParser(); |
115 | 104 | ||
... | @@ -231,8 +220,8 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -231,8 +220,8 @@ videojs.Hls.prototype.src = function(src) { |
231 | if (!this.tech_.el()) { | 220 | if (!this.tech_.el()) { |
232 | return; | 221 | return; |
233 | } | 222 | } |
234 | this.tech_.el().src = source.src; | 223 | |
235 | //this.tech_.el().vjs_src(source.src); | 224 | this.tech_.src(videojs.URL.createObjectURL(this.mediaSource)); |
236 | }; | 225 | }; |
237 | 226 | ||
238 | /* Returns the media index for the live point in the current playlist, and updates | 227 | /* Returns the media index for the live point in the current playlist, and updates |
... | @@ -256,8 +245,7 @@ videojs.Hls.getMediaIndexForLive_ = function(selectedPlaylist) { | ... | @@ -256,8 +245,7 @@ videojs.Hls.getMediaIndexForLive_ = function(selectedPlaylist) { |
256 | }; | 245 | }; |
257 | 246 | ||
258 | videojs.Hls.prototype.handleSourceOpen = function() { | 247 | videojs.Hls.prototype.handleSourceOpen = function() { |
259 | this.audioSourceBuffer = this.mediaSource.addSourceBuffer('audio/mp4;codecs=mp4a.40.2'); | 248 | this.sourceBuffer = this.mediaSource.addSourceBuffer('video/mp2t'); |
260 | this.videoSourceBuffer = this.mediaSource.addSourceBuffer('video/mp4;codecs=avc1.4d400d'); | ||
261 | 249 | ||
262 | // if autoplay is enabled, begin playback. This is duplicative of | 250 | // if autoplay is enabled, begin playback. This is duplicative of |
263 | // code in video.js but is required because play() must be invoked | 251 | // code in video.js but is required because play() must be invoked |
... | @@ -371,8 +359,7 @@ videojs.Hls.prototype.setupFirstPlay = function() { | ... | @@ -371,8 +359,7 @@ videojs.Hls.prototype.setupFirstPlay = function() { |
371 | // check that everything is ready to begin buffering | 359 | // check that everything is ready to begin buffering |
372 | if (this.duration() === Infinity && | 360 | if (this.duration() === Infinity && |
373 | this.tech_.played().length === 0 && | 361 | this.tech_.played().length === 0 && |
374 | this.audioSourceBuffer && | 362 | this.sourceBuffer && |
375 | this.videoSourceBuffer && | ||
376 | media) { | 363 | media) { |
377 | 364 | ||
378 | // seek to the latest media position for live videos | 365 | // seek to the latest media position for live videos |
... | @@ -423,9 +410,8 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { | ... | @@ -423,9 +410,8 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { |
423 | this.mediaIndex = this.playlists.getMediaIndexForTime_(currentTime); | 410 | this.mediaIndex = this.playlists.getMediaIndexForTime_(currentTime); |
424 | 411 | ||
425 | // abort any segments still being decoded | 412 | // abort any segments still being decoded |
426 | if (this.audioSourceBuffer) { | 413 | if (this.sourceBuffer) { |
427 | this.audioSourceBuffer.abort(); | 414 | this.sourceBuffer.abort(); |
428 | this.videoSourceBuffer.abort(); | ||
429 | } | 415 | } |
430 | 416 | ||
431 | // cancel outstanding requests and buffer appends | 417 | // cancel outstanding requests and buffer appends |
... | @@ -481,7 +467,6 @@ videojs.Hls.prototype.seekable = function() { | ... | @@ -481,7 +467,6 @@ videojs.Hls.prototype.seekable = function() { |
481 | */ | 467 | */ |
482 | videojs.Hls.prototype.updateDuration = function(playlist) { | 468 | videojs.Hls.prototype.updateDuration = function(playlist) { |
483 | var oldDuration = this.mediaSource.duration, | 469 | var oldDuration = this.mediaSource.duration, |
484 | // oldDuration = this.mediaSource.duration(), | ||
485 | newDuration = videojs.Hls.Playlist.duration(playlist), | 470 | newDuration = videojs.Hls.Playlist.duration(playlist), |
486 | setDuration = function() { | 471 | setDuration = function() { |
487 | this.mediaSource.duration = newDuration; | 472 | this.mediaSource.duration = newDuration; |
... | @@ -492,7 +477,6 @@ videojs.Hls.prototype.updateDuration = function(playlist) { | ... | @@ -492,7 +477,6 @@ videojs.Hls.prototype.updateDuration = function(playlist) { |
492 | // if the duration has changed, invalidate the cached value | 477 | // if the duration has changed, invalidate the cached value |
493 | if (oldDuration !== newDuration) { | 478 | if (oldDuration !== newDuration) { |
494 | if (this.mediaSource.readyState === 'open') { | 479 | if (this.mediaSource.readyState === 'open') { |
495 | // this.mediaSource.duration(newDuration); | ||
496 | this.mediaSource.duration = newDuration; | 480 | this.mediaSource.duration = newDuration; |
497 | this.tech_.trigger('durationchange'); | 481 | this.tech_.trigger('durationchange'); |
498 | } else { | 482 | } else { |
... | @@ -510,9 +494,8 @@ videojs.Hls.prototype.resetSrc_ = function() { | ... | @@ -510,9 +494,8 @@ videojs.Hls.prototype.resetSrc_ = function() { |
510 | this.cancelSegmentXhr(); | 494 | this.cancelSegmentXhr(); |
511 | this.cancelKeyXhr(); | 495 | this.cancelKeyXhr(); |
512 | 496 | ||
513 | if (this.audioSourceBuffer) { | 497 | if (this.sourceBuffer) { |
514 | this.audioSourceBuffer.abort(); | 498 | this.sourceBuffer.abort(); |
515 | this.videoSourceBuffer.abort(); | ||
516 | } | 499 | } |
517 | }; | 500 | }; |
518 | 501 | ||
... | @@ -850,8 +833,6 @@ videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { | ... | @@ -850,8 +833,6 @@ videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { |
850 | }); | 833 | }); |
851 | }; | 834 | }; |
852 | 835 | ||
853 | var initialized = false; | ||
854 | |||
855 | videojs.Hls.prototype.drainBuffer = function(event) { | 836 | videojs.Hls.prototype.drainBuffer = function(event) { |
856 | var | 837 | var |
857 | i = 0, | 838 | i = 0, |
... | @@ -870,13 +851,13 @@ videojs.Hls.prototype.drainBuffer = function(event) { | ... | @@ -870,13 +851,13 @@ videojs.Hls.prototype.drainBuffer = function(event) { |
870 | 851 | ||
871 | // if the buffer is empty or the source buffer hasn't been created | 852 | // if the buffer is empty or the source buffer hasn't been created |
872 | // yet, do nothing | 853 | // yet, do nothing |
873 | if (!segmentBuffer.length || !this.audioSourceBuffer) { | 854 | if (!segmentBuffer.length || !this.sourceBuffer) { |
874 | return; | 855 | return; |
875 | } | 856 | } |
876 | 857 | ||
877 | // we can't append more data if the source buffer is busy processing | 858 | // we can't append more data if the source buffer is busy processing |
878 | // what we've already sent | 859 | // what we've already sent |
879 | if (this.audioSourceBuffer.updating || this.videoSourceBuffer.updating) { | 860 | if (this.sourceBuffer.updating) { |
880 | return; | 861 | return; |
881 | } | 862 | } |
882 | 863 | ||
... | @@ -931,14 +912,6 @@ videojs.Hls.prototype.drainBuffer = function(event) { | ... | @@ -931,14 +912,6 @@ videojs.Hls.prototype.drainBuffer = function(event) { |
931 | 912 | ||
932 | event = event || {}; | 913 | event = event || {}; |
933 | 914 | ||
934 | var transmuxer = new videojs.mp2t.Transmuxer(); | ||
935 | var segments = []; | ||
936 | transmuxer.on('data', function(segment) { | ||
937 | segments.push(segment); | ||
938 | }); | ||
939 | transmuxer.push(bytes); | ||
940 | transmuxer.end(); | ||
941 | |||
942 | // // transmux the segment data from MP2T to FLV | 915 | // // transmux the segment data from MP2T to FLV |
943 | // this.segmentParser_.parseSegmentBinaryData(bytes); | 916 | // this.segmentParser_.parseSegmentBinaryData(bytes); |
944 | // this.segmentParser_.flushTags(); | 917 | // this.segmentParser_.flushTags(); |
... | @@ -995,57 +968,10 @@ videojs.Hls.prototype.drainBuffer = function(event) { | ... | @@ -995,57 +968,10 @@ videojs.Hls.prototype.drainBuffer = function(event) { |
995 | // this.tech_.el().vjs_discontinuity(); | 968 | // this.tech_.el().vjs_discontinuity(); |
996 | // } | 969 | // } |
997 | 970 | ||
998 | // (function() { | 971 | if (this.sourceBuffer.buffered.length) { |
999 | // var segmentByteLength = 0, j, segment; | 972 | this.sourceBuffer.timestampOffset = this.sourceBuffer.buffered.end(0); |
1000 | // for (i = 0; i < tags.length; i++) { | ||
1001 | // segmentByteLength += tags[i].bytes.byteLength; | ||
1002 | // } | ||
1003 | // segment = new Uint8Array(segmentByteLength); | ||
1004 | // for (i = 0, j = 0; i < tags.length; i++) { | ||
1005 | // segment.set(tags[i].bytes, j); | ||
1006 | // j += tags[i].bytes.byteLength; | ||
1007 | // } | ||
1008 | // this.sourceBuffer.appendBuffer(segment); | ||
1009 | // }).call(this); | ||
1010 | |||
1011 | (function() { | ||
1012 | var audioByteLength = 0, videoByteLength = 0, j, audioSegment, videoSegment; | ||
1013 | if (initialized) { | ||
1014 | segments = segments.slice(2); | ||
1015 | } | 973 | } |
1016 | for (i = 0; i < segments.length; i++) { | 974 | this.sourceBuffer.appendBuffer(bytes); |
1017 | if (segments[i].type === 'audio') { | ||
1018 | audioByteLength += segments[i].data.byteLength; | ||
1019 | } else { | ||
1020 | videoByteLength += segments[i].data.byteLength; | ||
1021 | } | ||
1022 | } | ||
1023 | audioSegment = new Uint8Array(audioByteLength); | ||
1024 | for (i = 0, j = 0; i < segments.length; i++) { | ||
1025 | if (segments[i].type === 'audio') { | ||
1026 | audioSegment.set(segments[i].data, j); | ||
1027 | j += segments[i].data.byteLength; | ||
1028 | } | ||
1029 | } | ||
1030 | if (this.audioSourceBuffer.buffered.length) { | ||
1031 | this.audioSourceBuffer.timestampOffset = this.audioSourceBuffer.buffered.end(0); | ||
1032 | } | ||
1033 | this.audioSourceBuffer.appendBuffer(audioSegment); | ||
1034 | |||
1035 | videoSegment = new Uint8Array(videoByteLength); | ||
1036 | for (i = 0, j = 0; i < segments.length; i++) { | ||
1037 | if (segments[i].type === 'video') { | ||
1038 | videoSegment.set(segments[i].data, j); | ||
1039 | j += segments[i].data.byteLength; | ||
1040 | } | ||
1041 | } | ||
1042 | if (this.videoSourceBuffer.buffered.length) { | ||
1043 | this.videoSourceBuffer.timestampOffset = this.videoSourceBuffer.buffered.end(0); | ||
1044 | } | ||
1045 | this.videoSourceBuffer.appendBuffer(videoSegment); | ||
1046 | |||
1047 | initialized = true; | ||
1048 | }).call(this); | ||
1049 | 975 | ||
1050 | // we're done processing this segment | 976 | // we're done processing this segment |
1051 | segmentBuffer.shift(); | 977 | segmentBuffer.shift(); | ... | ... |
-
Please register or sign in to post a comment