Skip to content

Commit 1e34e8c

Browse files
committed
head request updates for arbiter and bba
1 parent 005ca39 commit 1e34e8c

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

algorithms/arbiterPlus.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func CalculateSelectedIndexArbiter(newThr int, lastDuration int, lastIndex int,
4848
lastRate int, thrList *[]int, mpdDuration int, currentMPD http.MPD, currentURL string,
4949
currentMPDRepAdaptSet int, segmentNumber int, baseURL string, debugLog bool, downloadTime int, bufferLevel int,
5050
highestMPDrepRateIndex int, lowestMPDrepRateIndex int, bandwithList []int,
51-
segmentSize int) int {
51+
segmentSize int, quicBool bool, useTestbedBool bool) int {
5252

5353
//Does not work if repRatesReversed
5454
//the typical default buffer should be 60 seconds, however this is set in the config json files
@@ -119,6 +119,8 @@ func CalculateSelectedIndexArbiter(newThr int, lastDuration int, lastIndex int,
119119
//segHeadValues := http.GetNSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, true)
120120
//fmt.Println("test", http.SegHeadValues)
121121

122+
_, client, _ := http.GetHTTPClient(quicBool, glob.DebugFile, debugLog, useTestbedBool)
123+
122124
if actualRateQuality {
123125
videoChunks := mpdDuration / lastDuration
124126
//fmt.Println("vidchunks", videoChunks)
@@ -127,7 +129,7 @@ func CalculateSelectedIndexArbiter(newThr int, lastDuration int, lastIndex int,
127129

128130
//fmt.Println("videoWindow", videoWindow)
129131
if http.SegHeadValues == nil {
130-
for targetIndex < lowestMPDrepRateIndex && !SmartConvHelper(targetIndex, videoWindow, targetRate, currentMPD, currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber, baseURL, debugLog, lastDuration) {
132+
for targetIndex < lowestMPDrepRateIndex && !SmartConvHelper(targetIndex, videoWindow, targetRate, currentMPD, currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber, baseURL, debugLog, lastDuration, client) {
131133
targetIndex++
132134
}
133135
} else {

algorithms/bba2.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
func CalculateSelectedIndexBba(newThr int, lastDuration int, lastIndex int, maxBufferLevel int,
3636
lastRate int, thrList *[]int, mpdDuration int, currentMPD http.MPD, currentURL string,
3737
currentMPDRepAdaptSet int, segmentNumber int, baseURL string, debugLog bool, downloadTime int, bufferLevel int,
38-
highestMPDrepRateIndex int, lowestMPDrepRateIndex int, bandwithList []int) int {
38+
highestMPDrepRateIndex int, lowestMPDrepRateIndex int, bandwithList []int, quicBool bool, useTestbedBool bool) int {
3939

4040
*thrList = append(*thrList, newThr)
4141

@@ -68,7 +68,7 @@ func CalculateSelectedIndexBba(newThr int, lastDuration int, lastIndex int, maxB
6868
//fmt.Println("lowest bitrate...: ", lowest)
6969

7070
reservoir := bba1UpdateReservoir(lastRate, lastIndex, mpdDuration, lastDuration, maxBufferLevel,
71-
currentMPD, currentURL, currentMPDRepAdaptSet, segmentNumber, baseURL, debugLog, bandwithList)
71+
currentMPD, currentURL, currentMPDRepAdaptSet, segmentNumber, baseURL, debugLog, bandwithList, quicBool, useTestbedBool)
7272

7373
//fmt.Println("reservoir: ", reservoir)
7474
//fmt.Println("ret1:", retVal)
@@ -168,7 +168,7 @@ func CalculateSelectedIndexBba(newThr int, lastDuration int, lastIndex int, maxB
168168

169169
func bba1UpdateReservoir(lastRate int, lastRateIndex int, mpdDuration int,
170170
lastSegmentDuration int, maxBufferLevel int, currentMPD http.MPD, currentURL string, currentMPDRepAdaptSet int,
171-
segmentNumber int, baseURL string, debugLog bool, bandwithList []int) int {
171+
segmentNumber int, baseURL string, debugLog bool, bandwithList []int, quicBool bool, useTestbedBool bool) int {
172172
//we need to convert the maxBufferLevel to milliseconds
173173
//otherwise the comparison is between seconds and milliseconds
174174

@@ -186,16 +186,18 @@ func bba1UpdateReservoir(lastRate int, lastRateIndex int, mpdDuration int,
186186
// fmt.Println("contlenght", http.GetContentLengthHeader(currentMPD,
187187
// currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+1, baseURL, debugLog))
188188

189+
_, client, _ := http.GetHTTPClient(quicBool, glob.DebugFile, debugLog, useTestbedBool)
190+
189191
for i := 0; i < resvWin; i++ {
190192
//do a func getSegBySize(lastSegNumber+i, lastRateIndex) and return the size of the segment
191193
if http.GetContentLengthHeader(currentMPD,
192-
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog) > avgSegSize {
194+
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog, client) > avgSegSize {
193195

194196
largeSeg += http.GetContentLengthHeader(currentMPD,
195-
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog)
197+
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog, client)
196198
} else {
197199
smallSeg += http.GetContentLengthHeader(currentMPD,
198-
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog)
200+
currentURL, currentMPDRepAdaptSet, lastRate, segmentNumber+i, baseURL, debugLog, client)
199201
}
200202
}
201203

algorithms/helperFunctions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package algorithms
2323

2424
import (
2525
"math"
26+
otherhttp "net/http"
2627

2728
glob "github.com/uccmisl/godash/global"
2829
"github.com/uccmisl/godash/http"
@@ -136,13 +137,13 @@ func ThroughputSamples(window int, thrList []int) []int {
136137
/*
137138
* Checks next "videoWindow" of segments and makes sure the average rate is less than the estimated rate
138139
*/
139-
func SmartConvHelper(qIndex int, videoWindow int, estRate float64, currentMPD http.MPD, currentURL string, currentMPDRepAdaptSet int, lastRate int, segmentNumber int, baseURL string, debugLog bool, lastDuration int) bool {
140+
func SmartConvHelper(qIndex int, videoWindow int, estRate float64, currentMPD http.MPD, currentURL string, currentMPDRepAdaptSet int, lastRate int, segmentNumber int, baseURL string, debugLog bool, lastDuration int, client *otherhttp.Client) bool {
140141
var totSegSize int
141142

142143
for i := 0; i < videoWindow; i++ {
143144

144145
totSegSize += 8 * http.GetContentLengthHeader(currentMPD,
145-
currentURL, currentMPDRepAdaptSet, qIndex, segmentNumber+i, baseURL, debugLog)
146+
currentURL, currentMPDRepAdaptSet, qIndex, segmentNumber+i, baseURL, debugLog, client)
146147

147148
}
148149
actualAvgRate := float64(float64(totSegSize) / (float64(lastDuration) / 1000 * float64(videoWindow)))

config/configure.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"adapt" : "conventional",
2+
"adapt" : "arbiter",
33
"codec" : "h264",
44
"debug" : "on",
55
"initBuffer" : 2,
66
"maxBuffer" : 60,
77
"maxHeight" : 1080,
8-
"streamDuration" : 8,
8+
"streamDuration" : 20,
99
"storeDash" : "off",
1010
"outputFolder" : "123456",
1111
"logFile" : "log_file_2",
1212
"getHeaders" : "off",
1313
"terminalPrint" : "on",
14-
"printHeader" : "{\"Algorithm\":\"off\",\"Seg_Dur\":\"off\",\"Codec\":\"off\",\"Width\":\"on\",\"Height\":\"on\",\"FPS\":\"off\",\"Play_Pos\":\"off\",\"RTT\":\"off\",\"Seg_Repl\":\"off\",\"Protocol\":\"on\",\"P.1203\":\"on\",\"Clae\":\"on\",\"Duanmu\":\"on\",\"Yin\":\"on\",\"Yu\":\"on\"}",
14+
"printHeader" : "{\"Algorithm\":\"on\",\"Seg_Dur\":\"off\",\"Codec\":\"off\",\"Width\":\"on\",\"Height\":\"on\",\"FPS\":\"off\",\"Play_Pos\":\"off\",\"RTT\":\"off\",\"Seg_Repl\":\"off\",\"Protocol\":\"on\",\"P.1203\":\"on\",\"Clae\":\"on\",\"Duanmu\":\"on\",\"Yin\":\"on\",\"Yu\":\"on\"}",
1515
"expRatio": 0.2,
1616
"quic" : "off",
1717
"useTestbed" : "off",
1818
"url" : "[http://cs1dev.ucc.ie/misl/4K_non_copyright_dataset/4_sec/x264/bbb/DASH_Files/full/dash_video_audio.mpd]",
1919
"QoE" : "on",
20-
"serveraddr" : "on"
20+
"serveraddr" : "off"
2121
}

http/mpdParsing.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func GetAllSegmentHeaders(mpdList []MPD, codecIndexList [][]int,
355355
segmentNumber int, streamDuration int,
356356
isByteRangeMPD bool,
357357
maxBuffer int,
358-
headerURL string, codec string, urlInput []string, debugLog bool, printToFile bool) map[int]map[int][]int {
358+
headerURL string, codec string, urlInput []string, debugLog bool, printToFile bool, client *http.Client) map[int]map[int][]int {
359359

360360
// store the seg header maps
361361
var segHeadValues map[int]map[int][]int
@@ -383,7 +383,7 @@ func GetAllSegmentHeaders(mpdList []MPD, codecIndexList [][]int,
383383
currentURL := strings.TrimSpace(urlInput[mpdListIndex])
384384

385385
// get the segment headers for this MPD url
386-
segHeadValues[mpdListIndex] = getSegmentHeaders(mpdList, mpdListIndex, currentMPDRepAdaptSet, maxHeight, segmentNumber, streamDuration, isByteRangeMPD, maxBuffer, currentURL, headerURL, debugLog, printToFile)
386+
segHeadValues[mpdListIndex] = getSegmentHeaders(mpdList, mpdListIndex, currentMPDRepAdaptSet, maxHeight, segmentNumber, streamDuration, isByteRangeMPD, maxBuffer, currentURL, headerURL, debugLog, printToFile, client)
387387
}
388388
return segHeadValues
389389
}
@@ -395,7 +395,7 @@ func GetNSegmentHeaders(mpdList []MPD, codecIndexList [][]int,
395395
segmentNumber int, streamDuration int,
396396
isByteRangeMPD bool,
397397
maxBuffer int,
398-
headerURL string, codec string, urlInput []string, debugLog bool, useHeaderFile bool) map[int]map[int][]int {
398+
headerURL string, codec string, urlInput []string, debugLog bool, useHeaderFile bool, client *http.Client) map[int]map[int][]int {
399399

400400
// store the seg header maps
401401
var segHeadValues map[int]map[int][]int
@@ -427,7 +427,7 @@ func GetNSegmentHeaders(mpdList []MPD, codecIndexList [][]int,
427427
if useHeaderFile {
428428
segHeadValues[mpdListIndex] = getNSegmentHeadersFromFile(mpdList, mpdListIndex, currentMPDRepAdaptSet, maxHeight, segmentNumber, streamDuration, isByteRangeMPD, maxBuffer, currentURL, headerURL, debugLog)
429429
} else {
430-
segHeadValues[mpdListIndex] = getSegmentHeaders(mpdList, mpdListIndex, currentMPDRepAdaptSet, maxHeight, segmentNumber, streamDuration, isByteRangeMPD, maxBuffer, currentURL, headerURL, debugLog, useHeaderFile)
430+
segHeadValues[mpdListIndex] = getSegmentHeaders(mpdList, mpdListIndex, currentMPDRepAdaptSet, maxHeight, segmentNumber, streamDuration, isByteRangeMPD, maxBuffer, currentURL, headerURL, debugLog, useHeaderFile, client)
431431
}
432432
}
433433
SegHeadValues = segHeadValues
@@ -559,7 +559,7 @@ func getNSegmentHeadersFromFile(mpdList []MPD, mpdListIndex int, currentMPDRepAd
559559

560560
// GetContentLengthHeader :
561561
// get the header of the next segment to have the informations about it
562-
func GetContentLengthHeader(currentMPD MPD, currentURL string, currentMPDRepAdaptSet int, repRate int, segmentNumber int, adaptationSetBaseURL string, debugLog bool) int {
562+
func GetContentLengthHeader(currentMPD MPD, currentURL string, currentMPDRepAdaptSet int, repRate int, segmentNumber int, adaptationSetBaseURL string, debugLog bool, client *http.Client) int {
563563

564564
// get the base url
565565
baseURL := GetNextSegment(currentMPD, segmentNumber, repRate, currentMPDRepAdaptSet)
@@ -573,7 +573,7 @@ func GetContentLengthHeader(currentMPD MPD, currentURL string, currentMPDRepAdap
573573
}
574574

575575
//Get the header of the url
576-
resp, err := http.Head(url)
576+
resp, err := client.Head(url)
577577
if err != nil {
578578
panic(err)
579579
}
@@ -602,7 +602,7 @@ func getSegmentHeaders(mpdList []MPD, mpdListIndex int, currentMPDRepAdaptSet in
602602
segmentNumber int, streamDuration int,
603603
isByteRangeMPD bool,
604604
maxBuffer int, currentURL string,
605-
headerURL string, debugLog bool, printToFile bool) map[int][]int {
605+
headerURL string, debugLog bool, printToFile bool, client *http.Client) map[int][]int {
606606

607607
var fileName string
608608

@@ -755,7 +755,7 @@ func getSegmentHeaders(mpdList []MPD, mpdListIndex int, currentMPDRepAdaptSet in
755755
*/
756756
for j := highestMPDrepRateIndex; j <= lowestMPDrepRateIndex; j++ {
757757
// get the content length of the next segment that will be downloaded
758-
contentLength := GetContentLengthHeader(mpdList[mpdListIndex], currentURL, currentMPDRepAdaptSet, j, i, baseURL, debugLog)
758+
contentLength := GetContentLengthHeader(mpdList[mpdListIndex], currentURL, currentMPDRepAdaptSet, j, i, baseURL, debugLog, client)
759759
// save this value in a dictionary
760760
contentLengthDictionary[j] = append(contentLengthDictionary[j], contentLength)
761761
if printToFile {

http/urlParsing.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,13 @@ func SetNoden(node P2Pconsul.NodeUrl) {
5858
Noden = node
5959
}
6060

61-
// getURLBody :
62-
// * get the response body of the url
63-
// * calculate the rtt
64-
// * return the response body and the rtt
65-
func getURLBody(url string, isByteRangeMPD bool, startRange int, endRange int, quicBool bool, debugFile string, debugLog bool, useTestbedBool bool) (io.ReadCloser, time.Duration, string) {
61+
// getHTTPClient:
62+
func GetHTTPClient(quicBool bool, debugFile string, debugLog bool, useTestbedBool bool) (*http.Transport, *http.Client, *http3.RoundTripper) {
6663

6764
var client *http.Client
6865
var cert tls.Certificate
6966
var caCertPool = x509.NewCertPool()
7067
var caCert []byte
71-
var err error
7268
var config *tls.Config
7369
var quicConfig *tls.Config
7470
var tr *http.Transport
@@ -171,6 +167,25 @@ func getURLBody(url string, isByteRangeMPD bool, startRange int, endRange int, q
171167
}
172168
}
173169

170+
return tr, client, trQuic
171+
172+
}
173+
174+
// getURLBody :
175+
// * get the response body of the url
176+
// * calculate the rtt
177+
// * return the response body and the rtt
178+
func getURLBody(url string, isByteRangeMPD bool, startRange int, endRange int, quicBool bool, debugFile string, debugLog bool, useTestbedBool bool, returnContentLengthOnly bool) (io.ReadCloser, time.Duration, string, int) {
179+
180+
var client *http.Client
181+
var err error
182+
var tr *http.Transport
183+
var trQuic *http3.RoundTripper
184+
var contentLen = 0
185+
186+
// assign the protocols for this client
187+
tr, client, trQuic = GetHTTPClient(quicBool, debugFile, debugLog, useTestbedBool)
188+
174189
// request the url
175190
logging.DebugPrint(debugFile, debugLog, "DEBUG: ", "Get the url "+url)
176191
req, err := http.NewRequest("GET", url, nil)
@@ -181,6 +196,7 @@ func getURLBody(url string, isByteRangeMPD bool, startRange int, endRange int, q
181196
// stop the app
182197
utils.StopApp()
183198
}
199+
184200
logging.DebugPrint(debugFile, debugLog, "DEBUG: ", "get the rtt "+url)
185201
// determine the rtt for this segment
186202
start := time.Now()
@@ -300,7 +316,7 @@ func getURLBody(url string, isByteRangeMPD bool, startRange int, endRange int, q
300316
//fmt.Println("len : ", resp.ContentLength)
301317

302318
// return the response body
303-
return resp.Body, rtt, protocol
319+
return resp.Body, rtt, protocol, contentLen
304320

305321
}
306322

@@ -449,7 +465,7 @@ func GetURLByteRangeBody(url string, startRange int, endRange int) (io.ReadClose
449465
func GetURL(url string, isByteRangeMPD bool, startRange int, endRange int, quicBool bool, debugFile string, debugLog bool, useTestbedBool bool) ([]byte, time.Duration, string) {
450466

451467
// get the response body and rtt for this url
452-
responseBody, rtt, protocol := getURLBody(url, isByteRangeMPD, startRange, endRange, quicBool, debugFile, debugLog, useTestbedBool)
468+
responseBody, rtt, protocol, _ := getURLBody(url, isByteRangeMPD, startRange, endRange, quicBool, debugFile, debugLog, useTestbedBool, false)
453469

454470
// Lets read from the http stream and not create a file to store the body
455471
body, err := ioutil.ReadAll(responseBody)
@@ -538,7 +554,7 @@ func GetFile(currentURL string, fileBaseURL string, fileLocation string, isByteR
538554
}
539555

540556
//request the URL with GET
541-
body, rtt, protocol := getURLBody(urlHeaderString, isByteRangeMPD, startRange, endRange, quicBool, debugFile, debugLog, useTestbedBool)
557+
body, rtt, protocol, _ := getURLBody(urlHeaderString, isByteRangeMPD, startRange, endRange, quicBool, debugFile, debugLog, useTestbedBool, false)
542558

543559
// read from the buffer
544560
var buf bytes.Buffer

player/player.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,12 @@ func Stream(mpdList []http.MPD, debugFile string, debugLog bool, codec string, c
396396
startTime = time.Now()
397397
nextRunTime = time.Now()
398398

399+
_, client, _ := http.GetHTTPClient(quicBool, glob.DebugFile, debugLog, useTestbedBool)
400+
399401
// get the segment headers and stop this run
400402
if getHeaderBool {
401403
// get the segment headers for all MPD url passed as arguments - print to file
402-
http.GetAllSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, true)
404+
http.GetAllSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, true, client)
403405

404406
// print error message
405407
fmt.Printf("*** - All segment header have been downloaded to " + glob.DebugFolder + " - ***\n")
@@ -408,12 +410,12 @@ func Stream(mpdList []http.MPD, debugFile string, debugLog bool, codec string, c
408410
} else {
409411
if getHeaderReadFromFile == glob.GetHeaderOnline {
410412
// get the segment headers for all MPD url passed as arguments - not from file
411-
segHeadValues = http.GetAllSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, false)
413+
segHeadValues = http.GetAllSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, false, client)
412414
} else if getHeaderReadFromFile == glob.GetHeaderOffline {
413415
// get the segment headers for all MPD url passed as arguments - yes from file
414416
// get headers from file for a given number of seconds of stream time
415417
// let's assume every n seconds
416-
segHeadValues = http.GetNSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, true)
418+
segHeadValues = http.GetNSegmentHeaders(mpdList, codecIndexList, maxHeight, 1, streamDuration, isByteRangeMPD, maxBuffer, headerURL, codec, urlInput, debugLog, true, client)
417419

418420
}
419421
}
@@ -1051,7 +1053,7 @@ func streamLoop(streamStructs []http.StreamStruct, Noden P2Pconsul.NodeUrl) (int
10511053
repRate, &thrList, streamDuration, mpdList[mpdListIndex], currentURL,
10521054
mimeTypes[mimeTypeIndex], segmentNumber, baseURL, debugLog, deliveryTime, bufferLevel,
10531055
highestMPDrepRateIndex, lowestMPDrepRateIndex, bandwithList,
1054-
segSize)
1056+
segSize, quicBool, useTestbedBool)
10551057
//fmt.Println("new: ", repRate)
10561058
case glob.BBAAlg:
10571059
//fmt.Println("segDur: ", segmentDuration*1000)
@@ -1065,7 +1067,7 @@ func streamLoop(streamStructs []http.StreamStruct, Noden P2Pconsul.NodeUrl) (int
10651067
repRate = algo.CalculateSelectedIndexBba(thr, segmentDuration*1000, segmentNumber, maxBufferLevel,
10661068
repRate, &thrList, streamDuration, mpdList[mpdListIndex], currentURL,
10671069
mimeTypes[mimeTypeIndex], segmentNumber, baseURL, debugLog, deliveryTime, bufferLevel,
1068-
highestMPDrepRateIndex, lowestMPDrepRateIndex, bandwithList)
1070+
highestMPDrepRateIndex, lowestMPDrepRateIndex, bandwithList, quicBool, useTestbedBool)
10691071

10701072
case glob.TestAlg:
10711073
//fmt.Println("")

0 commit comments

Comments
 (0)