AAC解码器Android媒体编解码器(来自Gstreamer的数据)

时间:2016-05-04 19:36:24

标签: android gstreamer mediacodec aac mediaextractor

我想将带有G-Streamer的Raspberry的音频流传输到我的Android手机。在Gstreamer中,我使用以下管道: gst-launch-1.0 audiotestsrc! faac! “audio / mpeg,mpegversion = 4”! MUX。 mpegtsmux name = mux! udpsink host = 224.0.0.1 port = 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方法不能直接使用套接字,因此我将数据写入文件,让提取器从File获取其数据并将其传递给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测试文件,但是同样的问题和失败的消息。

我希望有人可以帮助我!谢谢你的帮助!

0 个答案:

没有答案