title: CMSampleBufferSetDataBufferFromAudioBufferList returning error 12731
body: <p>I am trying to capture app sound and pass it to AVAssetWriter as input. <br>
  I am setting callback for audio unit to get AudioBufferList. <br>
  The problem starts with converting AudioBufferList to CMSampleBufferRef. <br>
  It always return error -12731 which indicates that required parameter is missing <br>
  <br>
  Thanks <br> Karol</p>
  
  <pre><code>-(OSStatus) recordingCallbackWithRef:(void*)inRefCon
                              flags:(AudioUnitRenderActionFlags*)flags
                          timeStamp:(const AudioTimeStamp*)timeStamp
                          busNumber:(UInt32)busNumber
                       framesNumber:(UInt32)numberOfFrames
                               data:(AudioBufferList*)data
  {
  
  AudioBufferList bufferList;
  bufferList.mNumberBuffers = 1;
  bufferList.mBuffers[0].mData = NULL;
  
  OSStatus status;
  
  status = AudioUnitRender(audioUnit,
                           flags,
                           timeStamp,
                           busNumber,
                           numberOfFrames,
                           &amp;bufferList);
  [self checkOSStatus:status];
  
  AudioStreamBasicDescription audioFormat;
  // Describe format
  audioFormat.mSampleRate         = 44100.00;
  audioFormat.mFormatID           = kAudioFormatLinearPCM;
  audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
  audioFormat.mFramesPerPacket    = 1;
  audioFormat.mChannelsPerFrame   = 1;
  audioFormat.mBitsPerChannel     = 16;
  audioFormat.mBytesPerPacket     = 2;
  audioFormat.mBytesPerFrame      = 2;
  
  CMSampleBufferRef buff = NULL;
  CMFormatDescriptionRef format = NULL;
  CMSampleTimingInfo timing = { CMTimeMake(1, 44100), kCMTimeZero, kCMTimeInvalid };
  
  status = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &amp;audioFormat, 0, NULL, 0, NULL, NULL, &amp;format);
  [self checkOSStatus:status];
  
  status = CMSampleBufferCreate(kCFAllocatorDefault,NULL,false,NULL,NULL,format,1, 1, &amp;timing, 0, NULL, &amp;buff);
  [self checkOSStatus:status];
  
  status = CMSampleBufferSetDataBufferFromAudioBufferList(buff, 
                                                          kCFAllocatorDefault, 
                                                          kCFAllocatorDefault, 
                                                          0, 
                                                          &amp;bufferList);
  
  [self checkOSStatus:status]; //Status here is 12731
  
  //Do something with the buffer
  
  return noErr;
  }
  </code></pre>
  
  <p><br>
  Edit: <br>
  I checked bufferList.mBuffers[0].mData and it is not null so probably that's not a problem.<br></p>