我想将AAC编码的音频数据从我的Raspberry流式传输到我的Android手机。 接收数据的部分运行良好,但解码时存在一些问题。
我使用Media Extractor和Media Codec解码音频数据。 以下是代码的重要部分:
MediaExtractor extractor = new MediaExtractor();
Uri path = Uri.fromFile(file);
extractor.setDataSource(path.toString());
format = extractor.getTrackFormat(0);
String mime = format.getString(MediaFormat.KEY_MIME);
decoder = MediaCodec.createDecoderByType(mime);
decoder.configure(format, null, null, 0);
while (!stopTrack) {
multicastSocket.receive(packet);
decoder.start();
data = packet.getData();
inputBuffers = decoder.getInputBuffers();
outputBuffers = decoder.getOutputBuffers();
inputBufferIndex = decoder.dequeueInputBuffer(-1);
if (inputBufferIndex >= 0)
{
inputBuffer = inputBuffers[inputBufferIndex];
inputBuffer.clear();
inputBuffer.put(data);
decoder.queueInputBuffer(inputBufferIndex, 0, data.length, 0, 0);
}
bufferInfo = new MediaCodec.BufferInfo();
outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, 0);
while (outputBufferIndex >= 0)
{
outputBuffer = outputBuffers[outputBufferIndex];
outputBuffer.position(bufferInfo.offset);
outputBuffer.limit(bufferInfo.offset + bufferInfo.size);
outData = new byte[bufferInfo.size];
outputBuffer.get(outData);
// Log.d("AudioDecoder", outData.length + " bytes decoded");
track.write(outData, 0, outData.length);
decoder.releaseOutputBuffer(outputBufferIndex, false);
outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, 0);
}
这些是我在logcat中收到的错误消息:
D/ExtendedUtils: Try creating ExtendedExtractor
E/MM_OSAL: FileSource::FileSource
E/MM_OSAL: FileSource::FileSource m_bEveryThingOK 1
E/MM_OSAL: MM_File_Create File Name /data/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: MM_File_Create failed .Efs Error No -1 , File Name /data/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: Open or read fail on /data/mmosal_logmask.cfg. Possible permission denied issue. Looking for /data/misc/media/mmosal_logmask.cfg
E/MM_OSAL: MM_File_Create File Name /data/misc/media/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: MM_File_Create failed .Efs Error No -1 , File Name /data/misc/media/mmosal_logmask.cfg , Mode 0
E/MMParserExtractor: FileSourceWrapper::New returned NULL
D/ExtendedUtils: default extractor is NULL, return extended extractor
E/MM_OSAL: FileSource::FileSource
E/MM_OSAL: FileSource::FileSource m_bEveryThingOK 1
E/MM_OSAL: MM_File_Create File Name /data/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: MM_File_Create failed .Efs Error No -1 , File Name /data/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: Open or read fail on /data/mmosal_logmask.cfg. Possible permission denied issue. Looking for /data/misc/media/mmosal_logmask.cfg
E/MM_OSAL: MM_File_Create File Name /data/misc/media/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: MM_File_Create failed .Efs Error No -1 , File Name /data/misc/media/mmosal_logmask.cfg , Mode 0
E/MM_OSAL: parseTransportStreamPacket isPESPacket failed 18954
E/MM_OSAL: parseTransportStreamPacket isPESPacket failed 18783
E/MM_OSAL: parseTransportStreamPacket isPESPacket failed 18954
E/MM_OSAL: parseTransportStreamPacket isPESPacket failed 18783
I/OMXClient: Using client-side OMX mux.
E/OMXMaster: A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
D/MediaCodec: MediaCodec[kWhatConfigure]: video-output-protection: 00000000, audio-output-protection: 00000000
E/Format:: audio/mp4a-latm
W/SoftAAC2: aacDecoder_DecodeFrame decoderErr = 0x4004
W/SoftAAC2: AAC decoder returned error 0x4004, substituting silence
I/SoftAAC2: Reconfiguring decoder: 0->44100 Hz, 0->0 channels
什么是MM_OSAL?为什么要在" / data"中创建文件?我手机上的文件夹?我搜索了它,发现你需要root权限才能访问这个文件夹。 我用android studio直接用我的手机通过USB调试应用程序,这是一个问题吗?
感谢您的帮助!