intra segment seek. requires SWF update for netstream buffer action API
Showing
2 changed files
with
53 additions
and
6 deletions
... | @@ -390,6 +390,10 @@ | ... | @@ -390,6 +390,10 @@ |
390 | return true; | 390 | return true; |
391 | }; | 391 | }; |
392 | 392 | ||
393 | self.getTags = function() { | ||
394 | return h264Stream.tags; | ||
395 | }; | ||
396 | |||
393 | self.stats = { | 397 | self.stats = { |
394 | h264Tags: function() { | 398 | h264Tags: function() { |
395 | return h264Stream.tags.length; | 399 | return h264Stream.tags.length; | ... | ... |
... | @@ -113,11 +113,15 @@ var | ... | @@ -113,11 +113,15 @@ var |
113 | if(value) { | 113 | if(value) { |
114 | try { | 114 | try { |
115 | player.el().getElementsByClassName('vjs-tech')[0].vjs_setProperty('currentTime', 0); | 115 | player.el().getElementsByClassName('vjs-tech')[0].vjs_setProperty('currentTime', 0); |
116 | player.el().getElementsByClassName('vjs-tech')[0].vjs_setProperty('appendBytesAction', 'resetSeek'); | ||
117 | player.el().getElementsByClassName('vjs-tech')[0].vjs_setProperty('appendBytesAction', 'resetBegin'); | ||
116 | } catch(err) { | 118 | } catch(err) { |
117 | 119 | ||
118 | } | 120 | } |
119 | player.hls.mediaIndex = player.hls.selectSegmentByTime(value); | 121 | player.hls.sourceBuffer.appendBuffer(segmentParser.getFlvHeader()); |
120 | fillBuffer(); | 122 | player.hls.mediaIndex = player.hls.selectSegmentIndexByTime(value); |
123 | console.log(value, parseInt(value-player.hls.getSegmentByTime(value).timeRange.start,10)); | ||
124 | fillBuffer(parseInt(value-player.hls.getSegmentByTime(value).timeRange.start,10)); | ||
121 | } else { | 125 | } else { |
122 | try { | 126 | try { |
123 | return player.el().getElementsByClassName('vjs-tech')[0].vjs_getProperty('currentTime'); | 127 | return player.el().getElementsByClassName('vjs-tech')[0].vjs_getProperty('currentTime'); |
... | @@ -127,7 +131,20 @@ var | ... | @@ -127,7 +131,20 @@ var |
127 | } | 131 | } |
128 | }; | 132 | }; |
129 | 133 | ||
130 | player.hls.selectSegmentByTime = function(time) { | 134 | player.hls.getSegmentByTime = function(time) { |
135 | var index, currentSegment; | ||
136 | |||
137 | if (player.hls.media && player.hls.media.segments) { | ||
138 | for (index = 0; index < player.hls.media.segments.length; index++) { | ||
139 | currentSegment = player.hls.media.segments[index]; | ||
140 | if (time > currentSegment.timeRange.start && time <= currentSegment.timeRange.end) { | ||
141 | return currentSegment; | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | }; | ||
146 | |||
147 | player.hls.selectSegmentIndexByTime = function(time) { | ||
131 | var index, currentSegment; | 148 | var index, currentSegment; |
132 | 149 | ||
133 | if (player.hls.media && player.hls.media.segments) { | 150 | if (player.hls.media && player.hls.media.segments) { |
... | @@ -275,14 +292,20 @@ var | ... | @@ -275,14 +292,20 @@ var |
275 | * Determines whether there is enough video data currently in the buffer | 292 | * Determines whether there is enough video data currently in the buffer |
276 | * and downloads a new segment if the buffered time is less than the goal. | 293 | * and downloads a new segment if the buffered time is less than the goal. |
277 | */ | 294 | */ |
278 | fillBuffer = function() { | 295 | fillBuffer = function(intrasegmentSecond) { |
279 | var | 296 | var |
280 | buffered = player.buffered(), | 297 | buffered = player.buffered(), |
281 | bufferedTime = 0, | 298 | bufferedTime = 0, |
282 | segment = player.hls.media.segments[player.hls.mediaIndex], | 299 | segment = player.hls.media.segments[player.hls.mediaIndex], |
283 | segmentUri, | 300 | segmentUri, |
301 | gotoSecond, | ||
284 | startTime; | 302 | startTime; |
285 | 303 | ||
304 | if(intrasegmentSecond) | ||
305 | { | ||
306 | gotoSecond = intrasegmentSecond; | ||
307 | } | ||
308 | |||
286 | // if there is a request already in flight, do nothing | 309 | // if there is a request already in flight, do nothing |
287 | if (segmentXhr) { | 310 | if (segmentXhr) { |
288 | return; | 311 | return; |
... | @@ -320,9 +343,28 @@ var | ... | @@ -320,9 +343,28 @@ var |
320 | 343 | ||
321 | // transmux the segment data from MP2T to FLV | 344 | // transmux the segment data from MP2T to FLV |
322 | segmentParser.parseSegmentBinaryData(new Uint8Array(segmentXhr.response)); | 345 | segmentParser.parseSegmentBinaryData(new Uint8Array(segmentXhr.response)); |
346 | |||
347 | if(gotoSecond!==null && gotoSecond>0) | ||
348 | { | ||
349 | /* | ||
350 | console.log(segmentParser.getTags().length, 'total'); | ||
351 | console.log(gotoSecond, 'you want second'); | ||
352 | console.log(player.hls.selectPlaylist().segments[player.hls.mediaIndex].duration); | ||
353 | console.log((segmentParser.getTags().length/player.hls.selectPlaylist().segments[player.hls.mediaIndex].duration)*gotoSecond); | ||
354 | */ | ||
355 | var segmentCount = 100; //(segmentParser.getTags().length/player.hls.selectPlaylist().segments[player.hls.mediaIndex].duration)*gotoSecond; | ||
356 | var xx = 0; | ||
357 | |||
358 | //drain until where you want in the buffer | ||
359 | while(xx<segmentCount) | ||
360 | { | ||
361 | segmentParser.getNextTag(); | ||
362 | xx++; | ||
363 | } | ||
364 | } | ||
365 | |||
323 | while (segmentParser.tagsAvailable()) { | 366 | while (segmentParser.tagsAvailable()) { |
324 | player.hls.sourceBuffer.appendBuffer(segmentParser.getNextTag().bytes, | 367 | player.hls.sourceBuffer.appendBuffer(segmentParser.getNextTag().bytes, player); |
325 | player); | ||
326 | } | 368 | } |
327 | 369 | ||
328 | segmentXhr = null; | 370 | segmentXhr = null; |
... | @@ -339,6 +381,7 @@ var | ... | @@ -339,6 +381,7 @@ var |
339 | } | 381 | } |
340 | }; | 382 | }; |
341 | startTime = +new Date(); | 383 | startTime = +new Date(); |
384 | console.log('getting segment', segmentUri); | ||
342 | segmentXhr.send(null); | 385 | segmentXhr.send(null); |
343 | }; | 386 | }; |
344 | 387 | ... | ... |
-
Please register or sign in to post a comment