我想使用 G-Streamer 将音频从我的 Raspberry 流式传输到我的 Android 手机。在 Gstreamer 中,我使用以下管道: gst-launch-1.0 audiotestsrc !法克!“音频/mpeg,mpegversion=4”!多路复用器。mpegtsmux 名称=mux !udpsink 主机=224.0.0.1 端口=8001
faac 将音频编码为 AAC LC ( https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-bad-plugins/html/gst-plugins-bad-plugins-faac.html )
和 mpegtsmux 创建一个 MPEG-TS 流(https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-bad-plugins/html/gst-plugins-bad-plugins-mpegtsmux.html)
我尝试自己用 Android Studio 制作 Android 应用程序。我正在使用 Multicastsocket 接收数据。然后我尝试使用媒体编解码器和媒体提取器实现 AAC 解码器。extractor.setDataSource 方法不能直接使用套接字,所以我将数据写入文件,让提取器从文件中获取数据并将其传递给 MediaCodec 以创建解码器。
提取器似乎意识到它的 AAC 但我认为解码器有问题。这是代码的重要部分:
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
正如我所说,我将一些音频数据写入了提取器从中获取信息的文件中。这个文件可以播放!即使使用普通的 Android 音乐应用程序。所以我认为接收数据的部分运作良好。提取器或解码器一定有问题,可能是解码器,因为提取器意识到格式是 AAC。我还下载了 AAC 测试文件,但同样的问题和失败消息。
我希望有一个人可以帮助我!谢谢你的帮助!