use of java.io.FileDescriptor in project robolectric by robolectric.
the class ShadowParcelFileDescriptor method open.
@Implementation
public static ParcelFileDescriptor open(File file, int mode) throws FileNotFoundException {
ParcelFileDescriptor pfd;
try {
Constructor<ParcelFileDescriptor> constructor = ParcelFileDescriptor.class.getDeclaredConstructor(FileDescriptor.class);
pfd = constructor.newInstance(new FileDescriptor());
} catch (Exception e) {
throw new RuntimeException(e);
}
Shadows.shadowOf(pfd).file = new RandomAccessFile(file, mode == ParcelFileDescriptor.MODE_READ_ONLY ? "r" : "rw");
return pfd;
}
use of java.io.FileDescriptor in project robolectric by robolectric.
the class ShadowBitmapFactoryTest method decodeFileDescriptor_shouldGetWidthAndHeightFromHints.
@Test
public void decodeFileDescriptor_shouldGetWidthAndHeightFromHints() throws Exception {
File tmpFile = File.createTempFile("BitmapFactoryTest", null);
try {
tmpFile.deleteOnExit();
FileInputStream is = new FileInputStream(tmpFile);
try {
FileDescriptor fd = is.getFD();
ShadowBitmapFactory.provideWidthAndHeightHints(fd, 123, 456);
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
assertEquals("Bitmap for fd:" + fd, shadowOf(bitmap).getDescription());
assertEquals(123, bitmap.getWidth());
assertEquals(456, bitmap.getHeight());
} finally {
is.close();
}
} finally {
tmpFile.delete();
}
}
use of java.io.FileDescriptor in project libstreaming by fyhertz.
the class AudioStream method encodeWithMediaRecorder.
@Override
protected void encodeWithMediaRecorder() throws IOException {
// We need a local socket to forward data output by the camera to the packetizer
createSockets();
Log.v(TAG, "Requested audio with " + mQuality.bitRate / 1000 + "kbps" + " at " + mQuality.samplingRate / 1000 + "kHz");
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(mAudioSource);
mMediaRecorder.setOutputFormat(mOutputFormat);
mMediaRecorder.setAudioEncoder(mAudioEncoder);
mMediaRecorder.setAudioChannels(1);
mMediaRecorder.setAudioSamplingRate(mQuality.samplingRate);
mMediaRecorder.setAudioEncodingBitRate(mQuality.bitRate);
// We write the output of the camera in a local socket instead of a file !
// This one little trick makes streaming feasible quiet simply: data from the camera
// can then be manipulated at the other end of the socket
FileDescriptor fd = null;
if (sPipeApi == PIPE_API_PFD) {
fd = mParcelWrite.getFileDescriptor();
} else {
fd = mSender.getFileDescriptor();
}
mMediaRecorder.setOutputFile(fd);
mMediaRecorder.setOutputFile(fd);
mMediaRecorder.prepare();
mMediaRecorder.start();
InputStream is = null;
if (sPipeApi == PIPE_API_PFD) {
is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
} else {
try {
// mReceiver.getInputStream contains the data from the camera
is = mReceiver.getInputStream();
} catch (IOException e) {
stop();
throw new IOException("Something happened with the local sockets :/ Start failed !");
}
}
// the mPacketizer encapsulates this stream in an RTP stream and send it over the network
mPacketizer.setInputStream(is);
mPacketizer.start();
mStreaming = true;
}
use of java.io.FileDescriptor in project fresco by facebook.
the class GingerbreadPurgeableDecoder method decodeFileDescriptorAsPurgeable.
protected Bitmap decodeFileDescriptorAsPurgeable(CloseableReference<PooledByteBuffer> bytesRef, int inputLength, byte[] suffix, BitmapFactory.Options options) {
MemoryFile memoryFile = null;
try {
memoryFile = copyToMemoryFile(bytesRef, inputLength, suffix);
FileDescriptor fd = getMemoryFileDescriptor(memoryFile);
Bitmap bitmap = sWebpBitmapFactory.decodeFileDescriptor(fd, null, options);
return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
if (memoryFile != null) {
memoryFile.close();
}
}
}
use of java.io.FileDescriptor in project fresco by facebook.
the class WebpBitmapFactoryTest method testWebpFileDescriptorDecode.
@Test
public void testWebpFileDescriptorDecode() throws Throwable {
FileDescriptor fd = getImageFileDescriptor("redsquare.webp");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(fd, null, null);
testBitmapDefault(bitmap, 20, 20);
}
Aggregations