Frames | No Frames |
1: /* GstInputStream.java -- Trampoline class for an InputStream, mean to be used 2: by native code. 3: Copyright (C) 2007 Free Software Foundation, Inc. 4: 5: This file is part of GNU Classpath. 6: 7: GNU Classpath is free software; you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation; either version 2, or (at your option) 10: any later version. 11: 12: GNU Classpath is distributed in the hope that it will be useful, but 13: WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15: General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with GNU Classpath; see the file COPYING. If not, write to the 19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20: 02110-1301 USA. 21: 22: Linking this library statically or dynamically with other modules is 23: making a combined work based on this library. Thus, the terms and 24: conditions of the GNU General Public License cover the whole 25: combination. 26: 27: As a special exception, the copyright holders of this library give you 28: permission to link this library with independent modules to produce an 29: executable, regardless of the license terms of these independent 30: modules, and to copy and distribute the resulting executable under 31: terms of your choice, provided that you also meet, for each linked 32: independent module, the terms and conditions of the license of that 33: module. An independent module is a module which is not derived from 34: or based on this library. If you modify this library, you may extend 35: this exception to your version of the library, but you are not 36: obligated to do so. If you do not wish to do so, delete this 37: exception statement from your version. */ 38: 39: package gnu.javax.sound.sampled.gstreamer.io; 40: 41: import gnu.classpath.Pointer; 42: 43: import java.io.IOException; 44: import java.io.InputStream; 45: 46: /** 47: * Encapsulates the functionality of an InputStream Object. 48: * 49: * This class is only meant to be used by the native code, to allow reading 50: * of the given InputStream as part of a the GStreamer InputStream Source 51: * Plugin. 52: * 53: * <strong>Note:</strong> this class will be not garbage collected as the 54: * native code contains strong references to internal fields. 55: * The native layer provides a method that can be called by the C code to 56: * free the resources and to let the garbage collected to handle this class 57: * when not needed anymore. 58: * 59: * @author Mario Torre <neugens@limasoftware.net> 60: */ 61: public class GstInputStream 62: { 63: /** The real InputStream on which to perform reading operations. */ 64: private InputStream istream; 65: 66: /** 67: * Initialized in the native code, don't change without changes 68: * in the native layer. 69: */ 70: private Pointer gstInputStream = null; 71: 72: public GstInputStream(InputStream istream) 73: { 74: this.istream = istream; 75: init_instance(); 76: } 77: 78: public int read(byte[] buf, int off, int len) throws IOException 79: { 80: return this.istream.read(buf, off, len); 81: } 82: 83: public int available() throws IOException 84: { 85: return this.istream.available(); 86: } 87: 88: /** 89: * Return a reference to the GstInputStream native class as a Pointer object. 90: * This method is intended as an helper accessor and the returned pointer 91: * needs to be casted and used in the native code only. 92: * 93: * @return Pointer to the native GstInputStream class. 94: */ 95: public Pointer getNativeClass() 96: { 97: return this.gstInputStream; 98: } 99: 100: /* native methods */ 101: 102: /** 103: * Initialize the native peer and enables the object cache. 104: * It is meant to be used by the class constructor. 105: */ 106: native private final void init_instance(); 107: 108: /** 109: * Initialize the native peer and enables the object cache. 110: * It is meant to be used by the static initializer. 111: */ 112: native private static final void init_id_cache(); 113: 114: static 115: { 116: System.loadLibrary("gstreamerpeer"); //$NON-NLS-1$ 117: init_id_cache(); 118: } 119: }