private void testFFMPEGUrlReadTestFile(String filename) { long retval = 0; // Call url_open wrapper FfmpegIOHandle handle = new FfmpegIOHandle(); retval = FfmpegIO.url_open(handle, filename, IURLProtocolHandler.URL_RDONLY_MODE); assertTrue("url_open(" + filename + ") failed: " + retval, retval >= 0); // call url_read wrapper long bytesRead = 0; byte[] buffer = new byte[1024]; while ((retval = FfmpegIO.url_read(handle, buffer, buffer.length)) > 0) { bytesRead += retval; } assertEquals(4546420, bytesRead); // call url_close wrapper retval = FfmpegIO.url_close(handle); assertTrue("url_close failed: " + retval, retval >= 0); }
private void testFFMPEGUrlWriteTestFile(String filename) { int retval = 0; // Call url_open wrapper FfmpegIOHandle handle = new FfmpegIOHandle(); retval = FfmpegIO.url_open(handle, filename, IURLProtocolHandler.URL_WRONLY_MODE); assertTrue("url_open failed for filename: " + filename + "; : " + retval, retval >= 0); // call url_read wrapper byte[] buffer = new byte[4]; buffer[0] = 'F'; buffer[1] = 'L'; buffer[2] = 'V'; buffer[3] = 0; retval = FfmpegIO.url_write(handle, buffer, buffer.length); assertTrue("url_write failed: " + retval, retval == buffer.length); // call url_close wrapper retval = FfmpegIO.url_close(handle); assertTrue("url_close failed: " + retval, retval >= 0); }
@Test public void testAutoUnmapping() throws FileNotFoundException { int flags = IURLProtocolHandler.URL_RDONLY_MODE; FileInputStream stream = new FileInputStream(mSampleFile); // map the URL, telling the factory to unmap it // when closed String url = mProtocolString + ":1"; mFactory.mapIO(url, new InputOutputStreamHandler(stream, null, true), true); int retval = -1; // now, try opening using FFMPEG FfmpegIOHandle handle = new FfmpegIOHandle(); retval = FfmpegIO.url_open(handle, url, flags); assertEquals(0, retval); assertNull("found handler when we expected it to be unmapped", mFactory.unmapIO(url)); retval = FfmpegIO.url_close(handle); assertEquals(0, retval); }
@Test public void testValidFFMPEGURLFileOpenForReading() throws FileNotFoundException { int flags = IURLProtocolHandler.URL_RDONLY_MODE; FileInputStream stream = new FileInputStream(mSampleFile); String url = mProtocolString + ":" + mSampleFile; mFactory.mapIO(url, new InputOutputStreamHandler(stream, null, true), false); int retval = -1; // Test all the different ways to open a valid file. mHandler = mFactory.getHandler(XugglerIO.DEFAULT_PROTOCOL, url, flags); assertTrue("could not find a mHandler using the mFactory", mHandler != null); // the mFactory should pass the URL to the mHandler retval = mHandler.open(null, flags); assertEquals(0, retval); retval = mHandler.close(); assertEquals(0, retval); retval = mHandler.open(url, flags); assertTrue(retval == 0); retval = mHandler.close(); assertEquals(0, retval); // now, try opening using FFMPEG FfmpegIOHandle handle = new FfmpegIOHandle(); retval = FfmpegIO.url_open(handle, url, flags); assertEquals(0, retval); retval = FfmpegIO.url_close(handle); assertTrue(retval == 0); assertNotNull(mFactory.unmapIO(url)); }