-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolved intermittent crash while seeking, added support for manifest files with CR-LF line breaks #492
Resolved intermittent crash while seeking, added support for manifest files with CR-LF line breaks #492
Changes from 15 commits
ecdfbb5
8e5b818
aceaa5b
6537c95
96bb1d4
a8559cd
8f1a16c
0eb69e5
fd2814f
b32d9bb
b51a6ad
158513a
c3704df
60ff4d7
a9f90cb
ccae651
ca2a5ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ crashlytics-build.properties | |
|
||
# Flash Builder | ||
/bin/flashls.swc | ||
/bin-temp |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ package org.mangui.hls.playlist { | |
import org.mangui.hls.model.Level; | ||
import org.mangui.hls.utils.DateUtil; | ||
import org.mangui.hls.utils.Hex; | ||
import org.mangui.hls.utils.StringUtil; | ||
|
||
CONFIG::LOGGING { | ||
import org.mangui.hls.utils.Log; | ||
|
@@ -127,7 +128,7 @@ package org.mangui.hls.playlist { | |
/** loading complete handler **/ | ||
private function _loadCompleteHandler(event : Event) : void { | ||
_metrics.loading_end_time = getTimer(); | ||
onLoadedData(String(_urlloader.data)); | ||
onLoadedData(StringUtil.toLF(String(_urlloader.data))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have a sample playlist which is not parsed correctly with current Manifest parser ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We faced a number of issues. but the primary problem was directives, such as Converting line breaks to LF and trimming whitespace resolved the issues and enabled the parser to parse as normal. I'm not able to share URLs on a public forum, but here's a problematic playlist: sample.m3u8 |
||
}; | ||
|
||
private function onLoadedData(data : String) : void { | ||
|
@@ -144,7 +145,7 @@ package org.mangui.hls.playlist { | |
/** Extract fragments from playlist data. **/ | ||
public static function getFragments(data : String, base : String, level : int) : Vector.<Fragment> { | ||
var fragments : Vector.<Fragment> = new Vector.<Fragment>(); | ||
var lines : Array = data.split("\n"); | ||
var lines : Vector.<String> = StringUtil.toLines(data); | ||
// fragment seqnum | ||
var seqnum : int = 0; | ||
// fragment start time (in sec) | ||
|
@@ -313,7 +314,7 @@ package org.mangui.hls.playlist { | |
var levels : Vector.<Level> = new Vector.<Level>(); | ||
var bitrateDictionary : Dictionary = new Dictionary(); | ||
var level : Level; | ||
var lines : Array = data.split("\n"); | ||
var lines : Vector.<String> = StringUtil.toLines(data); | ||
var level_found : Boolean = false; | ||
var i : int = 0; | ||
while (i < lines.length) { | ||
|
@@ -387,7 +388,7 @@ package org.mangui.hls.playlist { | |
/** Extract Alternate Audio Tracks from manifest data. **/ | ||
public static function extractAltAudioTracks(data : String, base : String = '') : Vector.<AltAudioTrack> { | ||
var altAudioTracks : Vector.<AltAudioTrack> = new Vector.<AltAudioTrack>(); | ||
var lines : Array = data.split("\n"); | ||
var lines : Vector.<String> = StringUtil.toLines(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't this trim the Level / Alt Audio track name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No: it trims whitespace characters from the ends of the lines, but has now affect on anything else, including labels There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok got it |
||
var i : int = 0; | ||
while (i < lines.length) { | ||
var line : String = lines[i++]; | ||
|
@@ -490,7 +491,7 @@ package org.mangui.hls.playlist { | |
}; | ||
|
||
public static function getTargetDuration(data : String) : Number { | ||
var lines : Array = data.split("\n"); | ||
var lines : Vector.<String> = StringUtil.toLines(data); | ||
var i : int = 0; | ||
var targetduration : Number = 0; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.mangui.hls.utils | ||
{ | ||
public class StringUtil | ||
{ | ||
/** | ||
* Returns <code>true</code> if the specified string is | ||
* a single space, tab, carriage return, newline, or formfeed character. | ||
* | ||
* @param str The String that is is being queried. | ||
* | ||
* @return <code>true</code> if the specified string is | ||
* a single space, tab, carriage return, newline, or formfeed character. | ||
*/ | ||
public static function isWhitespace(character:String):Boolean | ||
{ | ||
switch (character) | ||
{ | ||
case " ": | ||
case "\t": | ||
case "\r": | ||
case "\n": | ||
case "\f": | ||
case "\u00A0": // non breaking space | ||
case "\u2028": // line seperator | ||
case "\u2029": // paragraph seperator | ||
case "\u3000": // ideographic space | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Removes all whitespace characters from the beginning and end | ||
* of the specified string. | ||
* | ||
* @param str The String whose whitespace should be trimmed. | ||
* | ||
* @return Updated String where whitespace was removed from the | ||
* beginning and end. | ||
*/ | ||
public static function trim(str:String):String | ||
{ | ||
if (str == null) return ''; | ||
|
||
var startIndex:int = 0; | ||
while (isWhitespace(str.charAt(startIndex))) | ||
++startIndex; | ||
|
||
var endIndex:int = str.length - 1; | ||
while (isWhitespace(str.charAt(endIndex))) | ||
--endIndex; | ||
|
||
if (endIndex >= startIndex) | ||
return str.slice(startIndex, endIndex + 1); | ||
else | ||
return ""; | ||
} | ||
|
||
/** | ||
* Splits a String into an Vector of nicely trimmed strings, where each | ||
* item represents a single line of the original String data | ||
* | ||
* @param str The String to be split into an Array | ||
* @return Vector of type String | ||
*/ | ||
public static function toLines(str:String):Vector.<String> | ||
{ | ||
var lines:Array = toLF(str).split("\n"); | ||
var i:uint; | ||
var length:uint = lines.length; | ||
|
||
for (i=0; i<length; ++i) | ||
{ | ||
lines[i] = trim(lines[i]); | ||
} | ||
|
||
return Vector.<String>(lines); | ||
} | ||
|
||
/** | ||
* Converts strings containing Windows (CR-LF), MacOS (CR) and other | ||
* non-standard line breaks (LF-CR) into strings using only Linux-style | ||
* line breaks (LF). | ||
* | ||
* @param str String containing non-Linux line breaks | ||
* @returns String containly only Linux-style line breaks | ||
*/ | ||
public static function toLF(str:String):String | ||
{ | ||
return (str || "").replace(/\r\n|\n\r|\r/g, "\n"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I am a bit pedantic, but there are some useless whitespace there :-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not any more.