J'essaie d'ouvrir un objet IContainer qui lit à partir d'un tampon d'entrée personnalisé plutôt que de lire à partir d'un fichier multimédia. L'implémentation de ce tampon d'entrée personnalisé est la suivante.IContainer.open() échoue lors de l'utilisation avec ByteChannel personnalisé à lire
Le code pour créer et ouvrir le conteneur est le suivant.
// Open up the container for READING
mInputCStore = new CStore();
IContainerFormat format = IContainerFormat.make();
if (format.setInputFormat("flv") < 0) {
throw new IllegalArgumentException("Failed to initialize the input format");
}
// Open up the container
mInputContainer = IContainer.make();
int retval = mInputContainer.open(mPlaybackContainerStore, IContainer.Type.READ, format);
if (retval < 0) {
// This little trick converts the non friendly integer return value into
// a slightly more friendly object to get a human-readable error name
IError error = IError.make(retval);
throw new IllegalArgumentException("could not open input container: " + mPlaybackContainerStore + "; Error: " + error.getDescription());
}
Le code ci-dessus lancer une exception en disant que -
Exception in thread "main" java.lang.IllegalArgumentException: could not open input container: [email protected]; Error: Operation not permitted
Le même tampon personnalisé lors utilisé lors de l'écriture au conteneur travaille avec succès. Quelqu'un peut-il m'aider à comprendre ce qui manque dans l'implémentation du tampon personnalisé, aussi loin que l'utiliser en mode READ et pourquoi la raison de l'échec?
package test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.util.concurrent.ConcurrentLinkedQueue;
public class CStore implements ByteChannel {
private ConcurrentLinkedQueue<DataChunk> mChunkQueue = null;
private int mQueueSize = 0;
// constructor
public CStore(String type) {
mQueueSize = 0;
mChunkQueue = new ConcurrentLinkedQueue<DataChunk>();
mChunkQueue.clear();
}
@Override
public void close() throws IOException {
return;
}
@Override
public boolean isOpen() {
return false;
}
@Override
public int write(ByteBuffer buffer) throws IOException {
DataChunk chunk = new DataChunk(buffer);
mChunkQueue.add(chunk);
mQueueSize += chunk.getLength();
return 0;
}
public int read(ByteBuffer buffer) throws IOException {
int result = 0;
DataChunk chunk = mChunkQueue.poll();
if (chunk != null) {
buffer = chunk.getBuffer();
if (buffer != null) {
result = 0;
} else {
result = 1;
}
}
return result;
}
}
Est-ce que quelqu'un peut m'aider à résoudre ce problème? Cette approche est-elle correcte? – AnilJ