public void clone(AVPacket packet) { // growing must be done here (to get the new buffer size) int growBy = packet.size() - getSize(); if (growBy > 0) grow(growBy); int res = avcodecLibrary.av_packet_copy_props( Pointer.getPointer(internal), Pointer.getPointer(packet)); if (res != 0) throw new LibavRuntimeException(res); Pointer<Byte> pData = packet.data(); if (pData != null) pData.copyTo(getData(), packet.size()); setSize(packet.size()); }
public synchronized void dispose() { if (internal == null) return; Pointer<AVPacket> pointer = Pointer.getPointer(internal); avcodecLibrary.av_free_packet(pointer); internal = null; // pointer.release(); }
protected boolean installSyntheticVTablePtr(Type type, NativeLibrary library, Pointer<?> peer) { synchronized (syntheticVirtualTables) { VTable vtable = syntheticVirtualTables.get(type); if (vtable == null) { if (!typesThatDontNeedASyntheticVirtualTable.contains(type)) { List<VirtMeth> methods = new ArrayList<VirtMeth>(); listVirtualMethods(Utils.getClass(type), methods); boolean needsASyntheticVirtualTable = false; for (VirtMeth method : methods) if (!Modifier.isNative(method.implementation.getModifiers())) { needsASyntheticVirtualTable = true; break; } if (needsASyntheticVirtualTable) { Type parentType = Utils.getParent(type); Pointer<Pointer> parentVTablePtr = null; if (CPPObject.class.isAssignableFrom(Utils.getClass(parentType))) { parentVTablePtr = peer.getPointer(Pointer.class); if (BridJ.debug) { BridJ.info( "Found parent virtual table pointer = " + ptrToString(parentVTablePtr, library)); /*Pointer<Pointer> expectedParentVTablePtr = pointerToAddress(getVirtualTable(parentType, library), Pointer.class); if (expectedParentVTablePtr != null && !Utils.eq(parentVTablePtr, expectedParentVTablePtr)) BridJ.warning("Weird parent virtual table pointer : expected " + ptrToString(expectedParentVTablePtr, library) + ", got " + ptrToString(parentVTablePtr, library)); */ } // parentVTablePtr = pointerToAddress(getVirtualTable(parentType, library), // Pointer.class); } syntheticVirtualTables.put( type, vtable = synthetizeVirtualTable(type, parentVTablePtr, methods, library)); } else { typesThatDontNeedASyntheticVirtualTable.add(type); } } } if (vtable != null) { if (BridJ.debug) BridJ.info( "Installing synthetic vtable pointer " + vtable.ptr + " to instance at " + peer + " (type = " + Utils.toString(type) + ", " + vtable.callbacks.size() + " callbacks)"); peer.setPointer(vtable.ptr); return vtable.ptr != null; } else return false; } }
public PooledPacket alloc() { avcodecLibrary.av_init_packet(Pointer.getPointer(internal)); bufferSize = internal.size(); return this; }
public void grow(int growBy) { int result = avcodecLibrary.av_grow_packet(Pointer.getPointer(internal), growBy); if (result != 0) throw new LibavRuntimeException(result); bufferSize = internal.size(); }
public static void main(String[] args) throws IOException { try { { JFrame f = new JFrame(); f.setVisible(true); long hwndVal = JAWTUtils.getNativePeerHandle(f); // TODO com.sun.jna.Native.getComponentID(this); System.out.println("#\n# hwndVal = " + hwndVal + "\n#"); BridJ.register(); ValuedEnum<ETest> t = testEnum(ETest.eFirst); if (t != ETest.eFirst) throw new RuntimeException(); } testSetGetIntBuffer(10); // if (Platform.isMacOSX()) { // new NSCalendar(); // new NSAutoReleasePool(); // } // NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new // File("/System/Library/Frameworks/OpenCL.framework/OpenCL")); // NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new // File("/usr/lib/libobjc.dylib")); // NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new // File("/Users/ochafik/nativelibs4java/Runtime/BridJ/src/test/cpp/test/build_out/darwin_universal_gcc_debug/libtest.dylib")); // Collection<Symbol> symbols = lib.getSymbols(); BridJ.register(MyCallback.class); BridJ.register(); int ra = testAddDyncall(10, 4); if (ra != 14) throw new RuntimeException("Expected 14, got " + ra); ra = testAddDyncall(10, 4); if (ra != 14) throw new RuntimeException("Expected 14, got " + ra); testNativeTargetCallbacks(); testJavaTargetCallbacks(); if (true) return; long crea = Ctest.createTest(); crea = Pointer.pointerToAddress(crea).getPointer().getPeer(); print("Ctest.createTest()", crea, 10, 0); Ctest test = new Ctest(); // long thisPtr = test.$this.getPeer(); // System.out.println(hex(thisPtr)); print("Ctest.this", Pointer.getPointer(test, Ctest.class).getPointer().getPeer(), 10, 2); int res = test.testAdd(1, 2); System.out.println("res = " + res); res = test.testVirtualAdd(1, 2); System.out.println("res = " + res); res = test.testVirtualAddStdCall(null, 1, 2); System.out.println("res = " + res); res = test.testAddStdCall(null, 1, 2); System.out.println("res = " + res); TaskbarListDemo.main(null); IShellWindows win = COMRuntime.newInstance(IShellWindows.class); IUnknown iu = win.QueryInterface(IUnknown.class); if (iu == null) throw new RuntimeException("Interface does not handle IUnknown !"); win.Release(); try { new FunctionTest().add(); MyStruct s = new MyStruct(); s.a(10); System.out.println("Created MyStruct and set it to 10"); int a = Pointer.getPointer(s).getInt(); a = s.a(); Pointer.getPointer(s).setInt(10); a = Pointer.getPointer(s).getInt(); a = s.a(); if (s.a() != 10) throw new RuntimeException("invalid value = " + a); s.b(100.0); if (s.b() != 100.0) throw new RuntimeException("invalid value = " + a); } catch (Throwable ex) { ex.printStackTrace(); } library = BridJ.getNativeLibrary("test"); // NativeLibrary.load(libraryPath); new VC9Demangler(null, "?sinInt@@YANH@Z").parseSymbol(); new VC9Demangler(null, "?forwardCall@@YAHP6AHHH@ZHH@Z").parseSymbol(); BridJ.register(); // new VC9Demangler(null, "??0Ctest2@@QEAA@XZ").parseSymbol(); for (Demangler.Symbol symbol : library.getSymbols()) { String name = symbol.getName(); long addr = symbol.getAddress(); System.out.println(name + " = \t" + hex(addr)); if (name.startsWith("_ZTV") || name.startsWith("_ZTI") || name.startsWith("??_")) { print("vtable", addr, 10, 1); } else System.out.println("'" + name + "'"); } boolean is64 = Platform.is64Bits(); } catch (Throwable ex) { ex.printStackTrace(); } finally { System.in.read(); } /*double dres = PerfLib.testASinB(1, 2); res = PerfLib.testAddJNI(1, 2); System.out.println("Done");*/ }