Skip to content

Commit

Permalink
Fix bugs in HLS plugin (#18)
Browse files Browse the repository at this point in the history
* Import websocket plugin

* Import http2 plugin

* Import HLS plugin

* Move HLS files into right packages

* Move http2 files around

* Fix misprint

* Fix Readme
Automatic formatting
Remove shade

* Added unit test

* New tests

* New unit test

* Update pom.xml removing libs that were not used

* fix resolution selection issue

* fix max resolution selection

* Add modules to parent

* use default

* switch to Java 8

* fix max bandwidth resolution

* HTTP2 Plugin:

- Fix README.md
- Remove shaded jar
- Remove libs that were not used in pom.xml
- Extend and inherit code of JMeter instead of copying it.
- Create Unit tests.

* HTTP2 Plugin:

Add unit Tests

* Import 3 plugins (#3)

* Fix Readme
Automatic formatting
Remove shade

* Added unit test

* New tests

* New unit test

* Update pom.xml removing libs that were not used

* fix resolution selection issue

* fix max resolution selection

* fix max bandwidth resolution

* HTTP2 Plugin:

- Fix README.md
- Remove shaded jar
- Remove libs that were not used in pom.xml
- Extend and inherit code of JMeter instead of copying it.
- Create Unit tests.

* HTTP2 Plugin:

Add unit Tests

* HTTP2StreamHandler Tests

* HTTP2 Plugin:
Unit tests for HTTP2 Sampler

* Unit Tests of HTTP/2 Plugin

* make class Parser serializable

* Resolve conflicts on pom.xml

* merge mqtt

* Fix HLS pom.xml

* Fix HLS conflicts

* Add files via upload

Files to include in the HLS Readme manual:
- plugin images
- .jmx example

* Update documentation of HTTP/2

* Update README.md

HLS Readme file updated.

* added before_install to .travis.yml

* Fix bugs in HLS plugin
-Remove unused code
-Remove duplicated playlist that were shown in the View Result Tree
-Fix infinite loop in Live Stream
-Update unit test according to modifications

* Fix bug in HLS plugin
-Fix problem occurred when selecting radiobutton 'Whole Video' that didn't bring all the fragments.
  • Loading branch information
egabrielcastro authored and undera committed Aug 11, 2017
1 parent 5115997 commit db0b99c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 170 deletions.
2 changes: 1 addition & 1 deletion hls/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.blazemeter.jmeter</groupId>
<artifactId>jmeter-hls</artifactId>
<version>1.1</version>
<version>1.0.2</version>

<build>
<plugins>
Expand Down
35 changes: 23 additions & 12 deletions hls/src/main/java/com/blazemeter/jmeter/hls/logic/HlsSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;


public class HlsSampler extends AbstractSampler {
private static final Logger log = LoggingManager.getLoggerForClass();
private String playlistUri;
Expand Down Expand Up @@ -77,9 +78,11 @@ private DataRequest getMasterList(SampleResult masterResult, Parser parser) thro
private String getPlaylistPath(DataRequest respond, Parser parser) throws MalformedURLException {
URL masterURL = new URL(getURLData());
playlistUri = parser.extractUriMaster(respond.getResponse(), this.getRESDATA(), this.getNetwordData(),
this.getBandwidthType(), this.getResolutionType(), this.getUrlVideoType());
this.getBandwidthType(), this.getResolutionType());
String auxPath = masterURL.getPath().substring(0, masterURL.getPath().lastIndexOf('/') + 1);

if(playlistUri.trim().equals(""))
playlistUri = getURLData();
if (playlistUri.startsWith("http")) {
playlist = playlistUri;
} else if (playlistUri.indexOf('/') == 0) {
Expand All @@ -96,12 +99,13 @@ private String getPlaylistPath(DataRequest respond, Parser parser) throws Malfor

private DataRequest getPlayList(SampleResult playListResult, Parser parser) throws IOException {

String lastPath = "";
playListResult.sampleStart();
DataRequest subRespond = parser.getBaseUrl(new URL(playlist), playListResult, true);
playListResult.sampleEnd();

String[] urlArray = playlist.split("/");
String lastPath = urlArray[urlArray.length - 1];
lastPath = urlArray[urlArray.length - 1];

playListResult.setRequestHeaders(subRespond.getRequestHeaders() + "\n\n" + getCookieHeader(playlist) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
Expand Down Expand Up @@ -136,6 +140,8 @@ public SampleResult sample(Entry e) {
boolean isVod = getHlsVideoType().equals("vod");
boolean out = false;
boolean firstTime = true;
List<String> list = new ArrayList<>();

try {

DataRequest respond = getMasterList(masterResult, parser);
Expand All @@ -148,6 +154,7 @@ public SampleResult sample(Entry e) {
while ((playSeconds >= currenTimeseconds) && !out) {
SampleResult playListResult = new SampleResult();
DataRequest subRespond = getPlayList(playListResult, parser);

List<DataFragment> videoUri = parser.extractVideoUrl(subRespond.getResponse());
List<DataFragment> fragmentToDownload = new ArrayList<>();

Expand All @@ -168,24 +175,30 @@ public SampleResult sample(Entry e) {
boolean isPresent = false;
int length = fragmentsDownloaded.size();

if (length != 0)
isPresent = fragmentsDownloaded.contains(frag.getTsUri());
if (length != 0) {
isPresent = fragmentsDownloaded.contains(frag.getTsUri().trim());
}

if (!isPresent) {
fragmentToDownload.add(frag);
fragmentsDownloaded.add(frag.getTsUri().trim());
currenTimeseconds += Float.parseFloat(frag.getDuration());
if(getVideoDuration()) {
currenTimeseconds += Float.parseFloat(frag.getDuration());
}
}
}

List<SampleResult> videoFragment = getFragments(parser, fragmentToDownload, auxPath);
for (SampleResult sam : videoFragment) {
playListResult.addSubResult(sam);
}
masterResult.addSubResult(playListResult);

if(!list.contains(playListResult.getSampleLabel()))
{
masterResult.addSubResult(playListResult);
list.add(playListResult.getSampleLabel());
}
}
// }

} catch (IOException e1) {
e1.printStackTrace();
Expand All @@ -196,6 +209,7 @@ public SampleResult sample(Entry e) {
return masterResult;
}


public String getURLData() {
return this.getPropertyAsString("HLS.URL_DATA");
}
Expand Down Expand Up @@ -224,10 +238,6 @@ public String getResolutionType() {
return this.getPropertyAsString("HLS.RESOLUTION_TYPE");
}

public String getUrlVideoType() {
return this.getPropertyAsString("HLS.URLVIDEOTYPE");
}

public String getBandwidthType() {
return this.getPropertyAsString("HLS.BANDWIDTH_TYPE");
}
Expand Down Expand Up @@ -342,7 +352,8 @@ public List<SampleResult> getFragments(Parser parser, List<DataFragment> uris, S
uris.remove(0);
List<SampleResult> aux = getFragments(parser, uris, url);
for (SampleResult s : aux) {
res.add(s);
if(!res.contains(s))
res.add(s);
}
}
return res;
Expand Down
99 changes: 5 additions & 94 deletions hls/src/main/java/com/blazemeter/jmeter/hls/logic/Parser.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.blazemeter.jmeter.hls.logic;

//import org.apache.http.protocol.BasicHttpContext;
//import org.apache.http.protocol.HttpContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -13,28 +9,19 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.apache.http.protocol.HTTP.USER_AGENT;

public class Parser implements Serializable {
private float duration = -1;
private float actualDuration = 0;
private static final Pattern PORT_PATTERN = Pattern.compile("\\d+");
private static final String USER_TOKEN = "__jmeter.USER_TOKEN__"; //$NON-NLS-1$
private static final Logger log = LoggingManager.getLoggerForClass();
private static final String PROXY_CONNECTION = "proxy-connection"; // $NON-NLS-1$
private final Map<String, String> headers = new HashMap<>();



public Parser() {
}


// HTTP GET request
public DataRequest getBaseUrl(URL url, SampleResult sampleResult, boolean setRequest) throws IOException {

Expand Down Expand Up @@ -86,7 +73,7 @@ public DataRequest getBaseUrl(URL url, SampleResult sampleResult, boolean setReq
result.setResponseMessage(con.getResponseMessage());
result.setContentType(con.getContentType());
result.setSuccess(isSuccessCode(responseCode));
result.setSentBytes(sentBytes);// TODO consultar
result.setSentBytes(sentBytes);
result.setContentEncoding(getEncoding(con));

return result;
Expand All @@ -109,39 +96,13 @@ public String getEncoding(HttpURLConnection connection) {
return charset;
}

public String extractUriMaster(String res, String resolution, String bandwidth, String bandSelected,
String resolSelected, String urlVideoType) {

public String extractUriMaster(String res, String resolution, String bandwidth, String bandSelected, String resolSelected) {
String pattern = "(EXT-X-STREAM-INF.*)\\n(.*\\.m3u8.*)";
String bandwidthPattern = "[:|,]BANDWIDTH=(\\d*)";
String resolutionPattern = "[:|,]RESOLUTION=(\\d*x\\d*)";

String urlCandidates = "";
String secResolution = " ";
String secBandwidth = " ";

String bandwidthMax = "100000000";
String bandwidthMin = "0";
String resolutionMin = "100x100";
String resolutionMax = "5000x5000";
String uri = "";

Pattern r = Pattern.compile(pattern);
Pattern b = Pattern.compile(bandwidthPattern);
Pattern reso = Pattern.compile(resolutionPattern);

Matcher m = r.matcher(res);

boolean out = false;

if (urlVideoType.equalsIgnoreCase("Bandwidth")) {
uri = getBandwidthUrl(pattern, bandwidthPattern, resolutionPattern, res, bandwidth, bandSelected);
} else {
uri = getResolutionUrl(pattern, bandwidthPattern, resolutionPattern, res, resolution, bandwidth,
bandSelected, resolSelected);
}

return uri;

return getResolutionUrl(pattern, bandwidthPattern, resolutionPattern, res, resolution, bandwidth, bandSelected, resolSelected);
}

public List<DataFragment> extractVideoUrl(String playlistUrl) {
Expand All @@ -155,55 +116,8 @@ public List<DataFragment> extractVideoUrl(String playlistUrl) {
mediaList.add(data);
}
return mediaList;

}

public String getBandwidthUrl(String pattern, String bandwidthPattern, String resolutionPattern, String res,
String bandwidth, String bandSelected) {
String bandwidthMax = "100000000";
String secBandwidth = " ";
String urlCandidate = "";
Pattern r = Pattern.compile(pattern);
Pattern b = Pattern.compile(bandwidthPattern);
Pattern reso = Pattern.compile(resolutionPattern);
Matcher m = r.matcher(res);

while (m.find()) {
Matcher mb = b.matcher(m.group(1));
// Matcher mBandwidth = b.matcher(m.toString());
Matcher mResolution = reso.matcher(m.toString());

mb.find();
if ((bandSelected.equalsIgnoreCase("customBandwidth")) && (Integer.parseInt(mb.group(1)) <= Integer.parseInt(bandwidth)) && mResolution.find()) {
if ((Integer.parseInt(mb.group(1)) == Integer.parseInt(bandwidth)))
{
urlCandidate = m.group(2);
break;
}
else if(selectBandwidth(bandwidth, mb.group(1)))
{
urlCandidate = m.group(2);
}


} else if ((bandSelected.equalsIgnoreCase("minBandwidth")) && mResolution.find()) {
if (secBandwidth.equals(" ") && selectBandwidth(mb.group(1), bandwidthMax)
|| (!secBandwidth.equals(" ") && selectBandwidth(mb.group(1), secBandwidth))) {
secBandwidth = mb.group(1);
urlCandidate = m.group(2);
}
} else if ((bandSelected.equalsIgnoreCase("maxBandwidth"))) {
if (secBandwidth.equals(" ") && !selectBandwidth(bandwidthMax, mb.group(1))
|| (!secBandwidth.equals(" ") && selectBandwidth(secBandwidth, mb.group(1)))) {
secBandwidth = mb.group(1);
urlCandidate = m.group(2);
}
}

}
return urlCandidate;

}

public String getResolutionUrl(String pattern, String bandwidthPattern, String resolutionPattern, String res,
String resolution, String bandwidth, String bandSelected, String resolSelected) {
Expand Down Expand Up @@ -231,7 +145,6 @@ public String getResolutionUrl(String pattern, String bandwidthPattern, String r

if (resolSelected.equalsIgnoreCase("customResolution") && mResolution.find()) {
if (bandSelected.equalsIgnoreCase("customBandwidth")) {

if (mreso.group(1).equals(resolution)) {
uri = m.group(2);
break;
Expand Down Expand Up @@ -367,8 +280,6 @@ public boolean isLive(String playlistUrl) {
return !m1.find();
}

// Checks if the resolution of the video (candidate2) is closer to the
// resolution custom (target) than the one already saved (candidate1)
public boolean findResolution(String target, String candidate1, String candidate2) {
boolean ret = false;

Expand Down
Loading

0 comments on commit db0b99c

Please sign in to comment.