4bbd0d94 by Steve Mayhew Committed by David LaPalomento

Fix EXT-X-KEY processing of relative URLs

The EXT-X-KEY URI attribute is not processed to spec.  It should be
interpreted as absolute or relative to the playlist containing the
EXT-X-KEY tag.

This is in the IETF spec
(https://tools.ietf.org/html/draft-pantos-http-live-streaming-13#section
-3.1).

The fix is simple, use the same URL resolution code the TS segments are
using.

Here is a stream that only works correctly with this fix:
  http://flashls-test.s3.amazonaws.com/7_copy.m3u8
1 parent 7436e467
...@@ -472,13 +472,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) { ...@@ -472,13 +472,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
472 } 472 }
473 473
474 // resolve the segment URL relative to the playlist 474 // resolve the segment URL relative to the playlist
475 segmentUri = this.resolveSegmentUrl(segment.uri);
476
477 this.loadSegment(segmentUri, offset);
478 };
479
480 videojs.Hls.prototype.resolveSegmentUrl = function(segmentRelativeUrl) {
481 var segmentUrl;
482 // resolve the segment URL relative to the playlist
475 if (this.playlists.media().uri === this.src_) { 483 if (this.playlists.media().uri === this.src_) {
476 segmentUri = resolveUrl(this.src_, segment.uri); 484 segmentUrl = resolveUrl(this.src_, segmentRelativeUrl);
477 } else { 485 } else {
478 segmentUri = resolveUrl(resolveUrl(this.src_, this.playlists.media().uri || ''), segment.uri); 486 segmentUrl = resolveUrl(resolveUrl(this.src_, this.playlists.media().uri || ''), segmentRelativeUrl);
479 } 487 }
480 488 return segmentUrl
481 this.loadSegment(segmentUri, offset);
482 }; 489 };
483 490
484 /* 491 /*
...@@ -684,7 +691,7 @@ videojs.Hls.prototype.fetchKeys = function(playlist, index) { ...@@ -684,7 +691,7 @@ videojs.Hls.prototype.fetchKeys = function(playlist, index) {
684 key = playlist.segments[i].key; 691 key = playlist.segments[i].key;
685 if (key && !key.bytes && !keyFailed(key)) { 692 if (key && !key.bytes && !keyFailed(key)) {
686 keyXhr = videojs.Hls.xhr({ 693 keyXhr = videojs.Hls.xhr({
687 url: resolveUrl(playlist.uri, key.uri), 694 url: this.resolveSegmentUrl(key.uri),
688 responseType: 'arraybuffer', 695 responseType: 'arraybuffer',
689 withCredentials: settings.withCredentials 696 withCredentials: settings.withCredentials
690 }, function(err, url) { 697 }, function(err, url) {
......