English 中文(简体)
AAC header and other info in iPhone
原标题:

I m building an iPhone Application that records sound. I make use of Audio Queue Services, and everything works great for the recording.

The thing is, I m using AudioFileWritePackets for file writing, and I m trying to put the same "AAC + ADTS" packets to a network socket.

The resulting file is different since some "headers" or "adts header" might be missing. I am searching for ideas on how to write the ADTS header and/or AAC header? Could the community assist me with this or refer me to a guide that demonstrated how to do this?

I currently have my Buffer Handler method:

void Recorder::MyInputBufferHandler(void inUserData,
    AudioQueueRefinAQ, AudioQueueBufferRefinBuffer,
    const AudioTimeStamp*inStartTime,
    UInt32 inNumPackets, 
    const AudioStreamPacketDescription*inPacketDesc) {
        AQRecorder *aqr = (AQRecorder *)inUserData;

        try {
            if (inNumPackets > 0) {
                // write packets to file
            XThrowIfError(AudioFileWritePackets(aqr->mRecordFile,
                    FALSE,
                    inBuffer->mAudioDataByteSize,
                    inPacketDesc,
                    aqr->mRecordPacket,
                    &inNumPackets,
                    inBuffer->mAudioData),
                    "AudioFileWritePackets failed");

                    fprintf(stderr, "Writing.");    

                // We write the Net Buffer.
                [aqr->socket_if writeData :(void *)(inBuffer->mAudioData)
                    :inBuffer->mAudioDataByteSize];

                aqr->mRecordPacket += inNumPackets;
            }

            // if we re not stopping, re-enqueue the buffe so that it gets filled again
            if (aqr->IsRunning()) {
            XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL),
                    "AudioQueueEnqueueBuffer failed");
            }

        } 

        catch (CAXException e) {
            char buf[256];
            fprintf(stderr, "Error: %s (%s)
", e.mOperation, e.FormatError(buf));
        }
    }
问题回答

I ve found the solution for this:

I implemented the callback

  XThrowIfError(
                  AudioFileInitializeWithCallbacks(
                                                   this,
                                                   nil,
                                                   BufferFilled_callback,
                                                   nil,
                                                   nil,
                                                   //kAudioFileCAFType,
                                                   kAudioFileAAC_ADTSType,
                                                   &mRecordFormat,
                                                   kAudioFileFlags_EraseFile,
                                                   &mRecordFile),
                  "InitializeWithCallbacks failed");

... And voilá! The real callback you have to implement is BufferFilled_callback. Here is my implementation:

OSStatus AQRecorder::BufferFilled_callback(
                                           void *                               inUserData,
                                           SInt64                               inPosition,
                                           UInt32                               requestCount,
                                           const void *                         buffer,
                                           UInt32 *                             actualCount) {

    AQRecorder *aqr = (AQRecorder *)inUserData;

    // You can write these bytes to anywhere. 
    // You can build a streaming server 

    return 0;
}

If you want to see more about audio queue services, you can get some ideas from Flipzu for iPhone (ex-app for live broadcasting audio // we have to shut it down because we could not raise money).

https://github.com/lucaslain/Flipzu_iPhone

Best,

Lucas.

I ve recently encountered this issue with the iLBC codec, and arrived at the solution as follows:

Record the audio data you want and just write it to a file. Then, take that file and do an octal dump on it. You can use the -c flag to see ascii characters.

Then, create a separate file that you know doesn t contain the header. This is just your data from the buffers on the audio queue. Octal dump that, and compare.

From this, you should have the header and enough info on how to proceed. Hope this helps.





相关问题
Audio format for stream recording: FLV or mp4?

I m capturing microphone (speech) input and publishing it on a flash server. I want this content to eventually be able to be streamed on iPhones as well as in the browser, so I m wondering if I should ...

AAC header and other info in iPhone

I m building an iPhone Application that records sound. I make use of Audio Queue Services, and everything works great for the recording. The thing is, I m using AudioFileWritePackets for file ...

Can t correctly stream x264 video to mobile via RTSP

I m creating mobile version of YouTube-like website. And i m going to use Darwin Streaming Server for streaming low-res clips compressed with x264 and NeroAAC and hinted with MP4Box. When i m playing ...

How to develop an AAC converter for Linux?

I am a beginner developer want to develop a MP3 to AAC converter for Linux. But I don t know how to start as I havn t done any development in Linux before. I am using Ubuntu 10.04. Can anyone tell me ...

Flash/Flex: play embedded AAC audio?

Is it possible to play an embedded AAC file in Flash/Flex somehow? I know you can playback embedded MP3 files, but I hear that you can t do that with AAC. Anyone know any sneaky ways to get around ...

Encode audio to aac with libavcodec

I m using libavcodec (latest git as of 3/3/10) to encode raw pcm to aac (libfaac support enabled). I do this by calling avcodec_encode_audio repeatedly with codec_context->frame_size samples each ...

read or write ratings from AAC file

I m trying to figure out how to read the "ratings" from an AAC file on Windows 7. This data is somehow persisted in the file as the Windows 7 shell and WMP can read / write the ratings. In MP3 the ...

热门标签