title: Objective c: Send audio data in rtp packet via socket
body: <p>In my app, I have to capture microphone and send audio data in rtp packet. But I only see receive rtp data like <a href="https://stackoverflow.com/questions/33517511/ios-rtp-live-audio-receiving">iOS RTP live audio receiving</a> or unanswered <a href="https://stackoverflow.com/questions/5856841/ios4-send-data-using-udp-socket">one</a>.</p>
  
  <p>I used following code with <a href="https://github.com/robbiehanson/CocoaAsyncSocket" rel="nofollow noreferrer">AsuncUdpSocket</a> to sent audio data but it wasn't wrap in rtp packet. Is there any library to wrap my audio data into rtp packet?</p>
  
  <p>initial AsyncUdpSocket:</p>
  
  <pre><code> udpSender = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
  
  NSError *error;
  [udpSender connectToHost:@"192.168.1.29" onPort:1024 error:&amp;error];   
  </code></pre>
  
  <p>I send audio data in my playback callback function:</p>
  
  <pre><code>static OSStatus playbackCallback(void *inRefCon, 
                               AudioUnitRenderActionFlags *ioActionFlags, 
                               const AudioTimeStamp *inTimeStamp, 
                               UInt32 inBusNumber, 
                               UInt32 inNumberFrames, 
                               AudioBufferList *ioData) {    
  
  /**
   This is the reference to the object who owns the callback.
   */
  AudioProcessor *audioProcessor = (AudioProcessor*) inRefCon;
  
  // iterate over incoming stream an copy to output stream
  for (int i=0; i &lt; ioData-&gt;mNumberBuffers; i++) { 
      AudioBuffer buffer = ioData-&gt;mBuffers[i];
  
      // find minimum size
      UInt32 size = min(buffer.mDataByteSize, [audioProcessor audioBuffer].mDataByteSize);
  
      // copy buffer to audio buffer which gets played after function return
      memcpy(buffer.mData, [audioProcessor audioBuffer].mData, size);
  
      // set data size
      buffer.mDataByteSize = size;
  
      //Send data to remote server      
  
      NSMutableData *data=[[NSMutableData alloc] init];
      Float32 *frame = (Float32*)buffer.mData;
      [data appendBytes:frame length:size];
      if ([udpSender isConnected])
      {
          [udpSender sendData:data withTimeout:-1 tag:1];
      }
  
  
  }
  
  
  
  return noErr;
  } 
  </code></pre>
  
  <p>How do I accomplish this?</p>
  
  <p>Thanks.</p>