/**
 * This package provides classes to handle video in Processing. The API is compatible with the built-in video library of Processing. 
 * GSVideo uses the multimedia toolkit GStreamer (http://www.gstreamer.net/)  through the gstreamer-java bindings by Wayne Meissener:
 * http://code.google.com/p/gstreamer-java/ 
 * @author Andres Colubri
 * @version 0.4.5
 *
 * Copyright (c) 2008 Andres Colubri
 *
 * This source is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This code is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * A copy of the GNU General Public License is available on the World
 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also
 * obtain it by writing to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package codeanticode.gsvideo;

import org.gstreamer.*;
import java.util.*;
import java.io.*;

/**
 * This class contains some basic functions used by the rest of the classes in this library.
 */
public class GSVideo
{	
    public void init()
    {
        if (INSTANCES_COUNT == 0) 
        {
		    if (OS() == MACOS)
			{
			    // For MAC it is assumed that gstreamer is installed in /opt/local/lib or /usr/local/lib.
				setOSXPath();
			}
		    if (OS() == WINDOWS)
			{
			    // For MAC it is assumed that gstreamer is installed in /opt/local/lib or /usr/local/lib.
				setWinPath();
			}			

            String[] args = { "" };
            Gst.init("GSVideo", args);
        }
        INSTANCES_COUNT++;	    
    }
	
    public static int OS() 
    {
        String os = System.getProperty("os.name").toUpperCase();
        if (os.indexOf("LINUX") != -1) 
        {
            return LINUX;
        }
        else if (os.indexOf("MAC") != -1) 
        {
            return MACOS;
        }
        else if (os.indexOf("WINDOWS") != -1) 
        {
            return WINDOWS;
        }	  
        else 
        {
            return UNKNOWN;
        }
    }

	public static void setOSXPath()
	{
	    System.setProperty("jna.library.path", jnaLibPathOSX);
    }	

	public static void setWinPath()
	{
	    //System.setProperty("jna.library.path", jnaLibPathWin);
/*
        System.out.println("JNA: " + System.getProperty("jna.library.path"));

        try
        {  
  		  Runtime r = Runtime.getRuntime();
	  	  r.exec("cmd /c set GST_PLUGIN_PATH=C:\\Users\\Andres\\Documents\\Processing\\libraries\\gsvideo\\library");
          System.out.println("just exec");
        } catch (Throwable t)
          {
            t.printStackTrace();
          }
*/
    }	

    public static final int LINUX = 0;
    public static final int MACOS = 1;
    public static final int WINDOWS = 2;
    public static final int UNKNOWN = -1;
    static long INSTANCES_COUNT = 0;
	
	static String jnaLibPathOSX = "/opt/local/lib:/usr/local/lib";
	static String jnaLibPathWin = "C:\\Users\\Andres\\Documents\\Processing\\libraries\\gsvideo\\library";
}
