Ciao a tutti ragazzi, io avrei un problema con questa libreria
https://github.com/fyhertz/libstreaming
in pratica permette via wireless di mandare lo streaming della visione delle photocamera, come da descrizione permette di utilizzare 3 metodologie 2 che utilizzano i mediacodec e 1 che utilizza il mediarecorder.
Io vorrei modificarla e per forza di cose devo utilizzare i mediacodec, ma con tutti i dispositivi con cui l'ho provata ho sempre lo stesso errore:
mi dice che il dispositivo può utilizzare i mediacodec, imposta l'encoder e si pianta quando testa il decoder, in quanto il buffer è pieno di -1.
Questo è il metodo dove avviene l'eccezione, qualche anima pia riesce ad aiutarmi?
private long decode(boolean withPrefix) {
int n = 0, i = 0, j = 0;
long elapsed = 0, now = timestamp();
int decInputIndex = 0, decOutputIndex = 0;
ByteBuffer[] decInputBuffers = mDecoder.getInputBuffers();
ByteBuffer[] decOutputBuffers = mDecoder.getOutputBuffers();
BufferInfo info = new BufferInfo();
while (elapsed<3000000) {
// Feeds the decoder with a NAL unit
if (i<NB_ENCODED) {
if (VERBOSE) Log.e(TAG,"Feeds the decoder with a NAL unit");
decInputIndex = mDecoder.dequeueInputBuffer(1000000/FRAMERATE);
if (decInputIndex>=0) {
if (VERBOSE) Log.e(TAG,"FEEDS 1 if");
int l1 = decInputBuffers[decInputIndex].capacity();
int l2 = mVideo[i].length;
decInputBuffers[decInputIndex].clear();
if ((withPrefix && hasPrefix(mVideo[i])) || (!withPrefix && !hasPrefix(mVideo[i]))) {
if (VERBOSE) Log.e(TAG,"FEEDS 2 if");
check(l1>=l2, "The decoder input buffer is not big enough (nal="+l2+", capacity="+l1+").");
decInputBuffers[decInputIndex].put(mVideo[i],0,mVideo[i].length);
} else if (withPrefix && !hasPrefix(mVideo[i])) {
if (VERBOSE) Log.e(TAG,"FEEDS 3 if");
check(l1>=l2+4, "The decoder input buffer is not big enough (nal="+(l2+4)+", capacity="+l1+").");
decInputBuffers[decInputIndex].put(new byte[] {0,0,0,1});
decInputBuffers[decInputIndex].put(mVideo[i],0,mVideo[i].length);
} else if (!withPrefix && hasPrefix(mVideo[i])) {
if (VERBOSE) Log.e(TAG,"FEEDS 4 if");
check(l1>=l2-4, "The decoder input buffer is not big enough (nal="+(l2-4)+", capacity="+l1+").");
decInputBuffers[decInputIndex].put(mVideo[i],4,mVideo[i].length-4);
}
mDecoder.queueInputBuffer(decInputIndex, 0, l2, timestamp(), 0);
i++;
} else {
if (VERBOSE) Log.d(TAG,"No buffer available !");
}
}
// Tries to get a decoded image
if (VERBOSE) Log.e(TAG,"Tries to get a decoded image 1000000/FRAMERATE = "+(1000000/FRAMERATE));
decOutputIndex = mDecoder.dequeueOutputBuffer(info, 1000000/FRAMERATE);
if (VERBOSE) Log.e(TAG,"DECODE decOutputIndex = "+decOutputIndex);
if (decOutputIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
if (VERBOSE) Log.e(TAG,"DECODE 1 if");
decOutputBuffers = mDecoder.getOutputBuffers();
} else if (decOutputIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
if (VERBOSE) Log.e(TAG,"DECODE 2 if");
mDecOutputFormat = mDecoder.getOutputFormat();
} else if (decOutputIndex>=0) {
if (VERBOSE) Log.e(TAG,"DECODE 3 if");
if (n>2) {
if (VERBOSE) Log.e(TAG,"DECODE 4 if");
// We have successfully encoded and decoded an image !
int length = info.size;
mDecodedVideo[j] = new byte[length];
decOutputBuffers[decOutputIndex].clear();
decOutputBuffers[decOutputIndex].get(mDecodedVideo[j], 0, length);
// Converts the decoded frame to NV21
convertToNV21(j);
if (j>=NB_DECODED-1) {
if (VERBOSE) Log.e(TAG,"DECODE 5 if");
flushMediaCodec(mDecoder);
if (VERBOSE) Log.v(TAG, "Decoding "+n+" frames took "+elapsed/1000+" ms");
return elapsed;
}
j++;
}
mDecoder.releaseOutputBuffer(decOutputIndex, false);
n++;
}
elapsed = timestamp() - now;
}
throw new RuntimeException("The decoder did not decode anything.");
}