def get_init(mpd, hostname, sock, out, customfield): req = myhttp.HTTPRequest("GET", myhttp.URI(mpd.initialization_url), headers={'Host': hostname}) (response, raw_body) = issue_request(sock, req, customfield) out.write(raw_body) return
def get_mpd(hostname, url, sock, customfield): req = myhttp.HTTPRequest("GET", myhttp.URI(url), headers={'Host': hostname}) (response, raw_body) = issue_request(sock, req, customfield) mpdfile = mympd.MPDFile(raw_body) return mpdfile
def main(): # Parse arguments arg_parser = ArgumentParser(description='DASH client', add_help=False) arg_parser.add_argument('-u', '--url', dest='url', action='store', default='http://picard.cs.colgate.edu/dash/manifest.mpd', help='URL for MPD file') arg_parser.add_argument('-o', '--output', dest='output', action='store', default='test.mp4', help='Name of file in which to store video data') settings = arg_parser.parse_args() uri = myhttp.URI(settings.url) if settings.output is None: sink = sys.stdout else: sink = open(settings.output, 'wb') stream(uri.host, uri.abs_path, sink) if settings.output is not None: sink.close()
def get_segment(hostname, sock, representation, segment, out, reslabel, customfield): global last_buffered #retrieve information about the representatino byte_range = representation.segment_ranges[segment] #build the http request to the streaming server range_string = 'bytes=' + str(byte_range[0]) + '-' + str(byte_range[1]) req = myhttp.HTTPRequest("GET", myhttp.URI(representation.base_url), headers={ "Host": hostname, "Range": range_string }) reslabel.config(fg="green", text=str(representation._width) + "x" + str(representation._height)) #start the timer to see how long it takes to pull the segment request_start = time.time() (response, raw_body) = issue_request(sock, req, customfield) #send the http request out.write(raw_body) #write the recieved segment to the output file time_to_pull = time.time() - request_start body_size = sys.getsizeof(raw_body) number_of_frames = (representation._segment_duration / 1000) * fps segment_pack = { 'ID': segment, 'time_to_pull': time_to_pull, 'frame_number': number_of_frames, 'size': body_size, 'raw_body': raw_body } #build dictionary object for buffer last_buffered = segment_pack return segment_pack
def main(): global running global total_segments global delayLabel global vlc_instance global vlc_player global sink global pause_duration arg_parser = ArgumentParser(description='DASH client', add_help=False) arg_parser.add_argument( '-u', '--url', dest='url', action='store', default='http://picard.cs.colgate.edu/dash/manifest.mpd', help='URL for MPD file') arg_parser.add_argument('-o', '--output', dest='output', action='store', default='test.mp4', help='Name of file in which to store video data') settings = arg_parser.parse_args() uri = myhttp.URI(settings.url) if settings.output is None: sink = sys.stdout else: sink = open(settings.output, 'wb') master = Tk() #creates tkinter instance referenced throughout master.geometry("950x720") master.title("Adaptive Real-Time Streaming") fpath = os.path.join(os.getcwd(), "test.mp4") pause_duration = 0 def start( ): #Assigns chosen values to global variables and initiates streaming global running global max_current_buffer global curr_playback_frame global playing global join_segments global delay global run_start_time global delaytype global delayMax global vlc_instance global vlc_player global sink global pause_duration global pause_start_time running = True if curr_playback_frame > 0: #if paused and not restarted begin playback immediatley without resetting variables playing = True vlc_player.set_pause(False) pause_duration += time.time() - pause_start_time else: vlc_instance = vlc.Instance() vlc_player = vlc_instance.media_new(fpath).player_new_from_media() if platform.system() == 'Windows': vlc_player.set_hwnd(videopanel.winfo_id()) else: vlc_player.set_xwindow(videopanel.winfo_id()) pause_duration = 0 #retrieve the slider values and assign them to the global variables raw_MCB = e.get() max_current_buffer = int(e.get() * 1000000) join_segments = int(j.get()) delayMax = float(k.get()) / 1000.0 print("Running simulation with MCB:" + str(raw_MCB) + "Mb and join_segments:" + str(join_segments) + "Delay Type:" + str(delaytype) + "Max delay" + str(delayMax)) run_start_time = time.time() stream(uri.host, uri.abs_path, sink, master, TimeDynamic, SegDynamic, vlc_player, ResDynamic, CustomEquation, delayDynamic, bandwidthDynamic) master.update( ) #update the tkinter user interface allowing perameter adjustment and playback control def stop(): #Pauses the stream by stoping playback global running global playing global vlc_player running = False #total program running playing = False #playback occuring in VlC global pause_start_time print("PAUSED") pause_start_time = time.time() #sets text color to yellow to indicate paused state TimeDynamic.config(fg="yellow") SegDynamic.config(fg="yellow") ResDynamic.config(fg="yellow") delayDynamic.config(fg="yellow") bandwidthDynamic.config(fg="yellow") #Puases the VlC playback if vlc_player.is_playing(): vlc_player.set_pause(True) def restart( ): #processes the user restart request and sets variables to default global running global last_buffered global segments_in_buffer global bandwidth global total_segments global curr_segment_num global join_segments global played_segment_bytes global bytes_in_buffer global running global curr_playback_frame global to_play_buffer global vlc_player global vlc_instance global sink stop() #resets global variables to their standard defaults bytes_in_buffer = 0 bandwidth = 1000 played_segment_bytes = 0 running = False to_play_buffer = [] curr_representation = None curr_segment_num = 0 last_buffered = None total_segments = 0 curr_playback_frame = 0 pause_duration = 0 #pauses vlc playback vlc_player.stop() #sets real time variable text color to indicate stopping TimeDynamic.config(fg="red", text="00:00:00") SegDynamic.config(fg="red", text="0") delayDynamic.config(fg="red", text="0") bandwidthDynamic.config(fg="red", text="0") ResDynamic.config(fg="red", text="0x0") print("RESET") #Deletes the old stream file and creates a new VLC instance for playback os.remove("test.mp4") if settings.output is None: sink = open("test.mp4", 'wb') else: sink = open("test.mp4", 'wb') def setdelay( type ): #assignes the delay type from the buttons to the global variable global delaytype delaytype = type #Add the video player window to the interface videopanel = Frame() canvas = Canvas(videopanel).pack(side=RIGHT, fill=BOTH, expand=1) videopanel.pack(side=RIGHT, fill=BOTH, expand=1) #scale slider for max_current_buffer label = Label(master, text="Maximum active buffer (Mb)", fg="black") label.pack() e = Scale(master, from_=0, to=20, orient=HORIZONTAL) e.pack() e.set(5) #scale slider for join segments label3 = Label(master, text="Join segments", fg="black") label3.pack() j = Scale(master, from_=0, to=30, orient=HORIZONTAL) j.pack() j.set(1) #scale slider for delay ResDynamic = Label(master, text="Max Request Delay (ms)", fg="black") ResDynamic.pack() k = Scale(master, from_=0, to=2500, orient=HORIZONTAL) k.pack() k.set(0.0) #delay time buttons linear = Button(master, text="Linear Max", command=lambda: setdelay("linear")) random = Button(master, text="random", command=lambda: setdelay("random")) lineargrowth = Button(master, text="Linear Growth", command=lambda: setdelay("lineargrowth")) sawtooth = Button(master, text="Sawtooth", command=lambda: setdelay("sawtooth")) custom = Button(master, text="Custom", command=lambda: setdelay("custom")) CustomLabel = Label(master, text="Custom Delay Equation (function of t)") CustomEquation = Entry(master) linear.pack() random.pack() lineargrowth.pack() sawtooth.pack() custom.pack() CustomLabel.pack() CustomEquation.pack() CustomEquation.insert(0, "ex. 3*t, 5*sin(t)") #start and stop buttons b = Button(master, text="Run", command=lambda: start()) s = Button(master, text="Pause", command=lambda: stop()) r = Button(master, text="Restart", command=lambda: restart()) b.pack() s.pack() r.pack() #Real Time Readouts TimeLabel = Label(master, text="Playback Time", fg="black") TimeLabel.pack() TimeDynamic = Label(master, text="00:00:00", fg="red") TimeDynamic.pack() delayLabel = Label(master, text="Current Delay (s)", fg="black") delayLabel.pack() delayDynamic = Label(master, text="0", fg="red") delayDynamic.pack() bandwidthLabel = Label(master, text="Bandwidth (Mb/s)", fg="black") bandwidthLabel.pack() bandwidthDynamic = Label(master, text="0", fg="red") bandwidthDynamic.pack() SegLabel = Label(master, text="Video in Buffer (Mb , s)", fg="black") SegLabel.pack() SegDynamic = Label(master, text="0", fg="red") SegDynamic.pack() ResLabel = Label(master, text="Newly Buffered Resolution", fg="black") ResLabel.pack() ResDynamic = Label(master, text="0x0", fg="red") ResDynamic.pack() mainloop() if settings.output is not None: sink.close()