Search This Blog

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Sunday, November 15, 2015

Dynamic Adaptive Streaming over HTTP (DASH) on WildFly

I've been away for a while.  October 10th, 2015 I started a new project at work, and that has kept me busy.

As demand has increased on internet media, the core web infrastructure has evolved to support new use cases for some pretty old standards.

HTTP has been used since the inception of the web around 1989.  The core concept being, a client's request receives a peer's response.  Originally a content length header element was used to box the request and response body in to some static size.  This was used for a variety of reasons, and was also manipulated to perform denial-of-service (DoS) attacks.  This is now used to stream partial offsets of a video file, allowing the player to start fetching segments with a lower bit-rate.  Hence, dynamic adaptive streaming over http.

You can check out the wildfly and castlab's code at my github public repository: https://github.com/charlescva/mobile-dashjs

Notice the Content-Length is determined by the offset as provided by the MPD and Initial MP4 containing the Metadata about each stream.


You can review the source, but the steps are as follows:

  1. Obtain a standard MP4 example video.
  2. Configure Apache to host the files in the directory dashencrypt is using. This is currently hard-coded in the VideoRegistration.java.
  3. Add Video using the Add a Video tab.  The JAX-RS enabled VideoService.java will handle the request, and dash the file for you.
  4. Upon success, you will see the entry for the video appear on the "Video Player" tab.
Observing the Console.  You can see the logger is outputting the steps as it processes the request.
I am still getting my feet wet as well, and came across a great article on the following website, https://arashafiei.wordpress.com/2012/11/13/quick-dash/.  

I'll be working on integrating a "live" stream in which a imaging device like /dev/video0 (webcam) will be used to generate the video segment data, while the MPD (Manifest) and initial MP4 file containing the Movie Box (moov) and/or Fragment Box (moof) are updated on the fly.  Essentially, the goal is to enable "DASHing" of a live video feed.



Saturday, January 4, 2014

"Cloud Manager" for Netbeans

Working on a side project to help automate server maintenance tasks for various open source distributed services.

Zookeeper, Storm, Accumulo, Hadoop, CentOS are the current software packages I want to manage with this tool.  The reason for providing it as a netbeans platform application is for a few reasons:

  • Java can run on any platform.
  • You don't need to know java to run a netbeans platform application.
  • If you already know java, you can contribute to this application through netbeans.

If you want to contribute code or ideas for the project, you can do so through github.

https://github.com/charlescva/cloud-manager

Currently the tool allows you to add some server nodes, create actions for those nodes, and even assign a UI to the action for easier use.  JAXB is used for marshalling xml.  XSDs were generated against the XML on the Accumulo monitor.

SSH code is integrated.  One can easily deploy Storm topologies with the nimbus node action.

Thursday, August 29, 2013

Java SSH Library

http://www.ganymed.ethz.ch/ssh2/ is the perfect library for making common SSH/SCP calls.  It even support SFTP.  I am using it in my management platform application.  I included the source package with mine, as well as the software license.  I hope that is adequate for anyone seeking to ensure I am not violating any laws in regard to sharing source.  I have also made a good effort to publicize my use of this code, as to not insinuate that it is in any way mine.

Wednesday, June 5, 2013

Java and Google Finance

Here are a couple code snippets using JDK6 to fetch data from the Google Finance website.  
Here are some default variables.  The base URL is the google site that will return a json string with requested symbols.  The symbols file is sitting on my Desktop and is just a CSV with 1 column.  Each record is a stock symbol. e.g. JNJ
The Boolean friendlyPrint variable determines the output format.
 private static String defaultBaseUrl = "http://www.google.com/finance/info?infotype=infoquoteall&q=";  
  private static String defaultSymbolsFile = System.getProperty("user.home")  
   + "/Desktop/NasdaqSymbols.csv";  
  private static boolean friendlyPrint = true;  
This main method first creates an ArrayList of the first 100 stock symbols from the CSV, and then appends them with a comma to the base url.  The URL is submitted and the response is parsed into a Simple-JSON Array. Last, the data is displayed on the console.
  public static void main(String[] args) throws Exception {  
  ArrayList symbols = FileUtils.getTextListValues(defaultSymbolsFile);  
  StringBuilder syms = new StringBuilder();   
  String sb = Util.fetchURL(defaultBaseUrl + syms);  
  JSONArray json = (JSONArray) new JSONParser().parse(sb.substring(3));  
  console.utils.GoogleFinancePrinter.printJsonArray(json, friendlyPrint);  
  }  
This is the method called above to fetch the data using the URLConnection object. It reads each line of the response and passes it into a stringbuilder. Then returns the final string.
 static String fetchURL(String url) throws Exception {   
  URL gf = new URL(url);   
  URLConnection yc = gf.openConnection();   
  BufferedReader in = new BufferedReader(new InputStreamReader(   
   yc.getInputStream()));   
  StringBuilder sb = new StringBuilder();   
  String inputLine;   
  while ((inputLine = in.readLine()) != null)   
   sb.append(inputLine);   
  in.close();   
  return sb.toString();   
  }   
Here is the method that prints the data on the console. There is more data in the json object than what is displayed in the friendly condition. These are just a few.
  public static void printJsonArray(JSONArray json, boolean friendly) {  
  if (friendly) {  
   for (int i = 0; i < json.size(); i++) {  
   System.out.println("ID: "  
    + ((JSONObject) json.get(i)).get("id"));  
   System.out.println("Symbol: "  
    + ((JSONObject) json.get(i)).get("t"));  
   System.out.println("Name: "  
    + ((JSONObject) json.get(i)).get("name"));  
   System.out.println("Type: "  
    + ((JSONObject) json.get(i)).get("type"));  
   System.out.println("Exchange: "  
    + ((JSONObject) json.get(i)).get("e"));  
   System.out.println("LastTrade: $"  
    + ((JSONObject) json.get(i)).get("l"));  
   System.out.println("Last Trade: "  
    + ((JSONObject) json.get(i)).get("lt"));  
   System.out.println("Change: "  
    + ((JSONObject) json.get(i)).get("c") + "("  
    + ((JSONObject) json.get(i)).get("cp") + "%)");  
   System.out.println("------------------------------");  
   }  
  } else {  
   System.out.print(json.toJSONString());  
  }  
  }