Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.io . FileWriter; import java.io . IOException; import java.util.Timer; import java.util.TimerTask; public class DASHClient { private static final String DASH _ MANIFEST _ URL

import java.io.FileWriter;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
public class DASHClient {
private static final String DASH_MANIFEST_URL ="https://ftp.itec.aau.at/datasets/DASHDataset2014/BigBuckBunny/10sec/BigBuckBunny_10s_onDemand_2014_05_09.mpd";
private static final int BUFFER_THRESHOLD =2; // Buffer threshold for underrun detection
private double bufferDuration =0;
private int chosenRepresentation =2; // Initial representation ID (e.g.,750 kbps)
private double totalBitrate =0;
private int underrunCount =0;
private int underrunDuration =0;
public static void main(String[] args){
DASHClient client = new DASHClient();
client.startStreaming();
}
private void startStreaming(){
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
@Override
public void run(){
try {
// Fetch DASH manifest (you can use HTTP client libraries)
String manifestContent = fetchDASHManifest(DASH_MANIFEST_URL);
// Parse manifest and choose representation (simplified for demo)
// Assume representation IDs: 0(250 kbps),1(500 kbps),2(750 kbps), etc.
chosenRepresentation = getNextRepresentation(chosenRepresentation);
// Simulate downloading video segments (you'd use a library)
bufferDuration +=1;
totalBitrate += getBitrateForRepresentation(chosenRepresentation);
// Check for underrun (buffer depletion)
if (bufferDuration < BUFFER_THRESHOLD){
underrunCount++;
underrunDuration++;
}
// Record data points (write to a CSV file)
recordDataPoint(System.currentTimeMillis(), bufferDuration, chosenRepresentation,
getBitrateForRepresentation(chosenRepresentation));
} catch (IOException e){
e.printStackTrace();
}
}
},0,1000); // Run every second (simulating real-time streaming)
}
private String fetchDASHManifest(String url) throws IOException {
// Implement fetching logic (e.g., using HttpURLConnection or HttpClient)
// Return the manifest content as a string
return ""; // Placeholder for demonstration
}
private int getNextRepresentation(int currentRepId){
// Implement logic to switch to the next representation (e.g., round-robin)
// For simplicity, let's assume we cycle through representations: 0,1,2,...
return (currentRepId +1)%3; // Assuming 3 representations (250,500,750 kbps)
}
private int getBitrateForRepresentation(int repId){
// Map representation ID to actual bit rate (you can adjust this based on your data)
switch (repId){
case 0:
return 250;
case 1:
return 500;
case 2:
return 750;
// Add more cases for other representations if needed
default:
return 0;
}
}
private void recordDataPoint(long timestamp, double buffer, int repId, int bitrate){
// Create or open a CSV file for recording data points
try (FileWriter writer = new FileWriter("streaming_data.csv", true)){
// Append data to the file
writer.append(String.format("%d,%.2f,%d,%d%n", timestamp, buffer, repId, bitrate));
} catch (IOException e){
e.printStackTrace();
}
}
}
above code is just simulating the real the time streaming instead of this write a code which actualy streams the given mpd file link and records the real time data .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions