<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AudioToolbox",
  "identifier" : "/documentation/AudioToolbox/AudioCodecProduceOutputPackets(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Audio Toolbox"
    ],
    "preciseIdentifier" : "c:@F@AudioCodecProduceOutputPackets"
  },
  "title" : "AudioCodecProduceOutputPackets(_:_:_:_:_:_:)"
}
-->

# AudioCodecProduceOutputPackets(_:_:_:_:_:_:)

Retrieves output data from a codec.

```
func AudioCodecProduceOutputPackets(_ inCodec: AudioCodec, _ outOutputData: UnsafeMutableRawPointer, _ ioOutputDataByteSize: UnsafeMutablePointer<UInt32>, _ ioNumberPackets: UnsafeMutablePointer<UInt32>, _ outPacketDescription: UnsafeMutablePointer<AudioStreamPacketDescription>?, _ outStatus: UnsafeMutablePointer<UInt32>) -> OSStatus
```

## Parameters

`inCodec`

An audio codec object. Because an audio codec object is a Component Manger component instance, you can use the Component Manager (for example, the functions <doc://com.apple.documentation/documentation/coreservices/1516552-findnextcomponent> and OpenAComponent) to obtain an audio codec object.

`outOutputData`

The output data buffer.

`ioOutputDataByteSize`

Indicates the size of the output data buffer.

`ioNumberPackets`

On input, the number of packets desired. On output, the number of packets actually placed in the output buffer.

`outPacketDescription`

An array of `AudioStreamPacketDescription` structures that describes the packet layout of the data returned by the `outOutputData` parameter. Pass `NULL` if you do not want this information returned. Note that this information is provided only when the output format is not linear PCM.

`outStatus`

On output, information about the codec’s status to allow for proper data management. See [Output Status Constants](/documentation/AudioToolbox/1494122-output-status-constants) for the possible values that can be returned.

## Return Value

Returns `NoErr` if successful. Returns `kAudioCodecStateError` if the codec has not been initialized. Returns `kAudioCodecNotEnoughBufferSpaceError` if the output buffer is not large enough for the requested number of packets. See `Result Codes` for other possible values.

## Discussion

This function causes the codec to produce as many output packets as requested, provided there is sufficient input data. If there is not enough input data to produce the requested number of output packets, the `outStatus` parameter returns the value `kAudioCodecProduceOutputPacketNeedsMoreInputData` and the `ioNumberPackets` parameter indicates the actual number of packets produced. On the other hand, if there is enough input data to produce at least one additional full packet, the `outStatus` parameter returns the value `kAudioCodecProduceOutputPacketSuccessHasMore`.

Note that decoders produce linear PCM data only in multiples of the number of frames in a packet of the encoded format. (See the [`AudioCodecAppendInputData(_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecAppendInputData(_:_:_:_:_:)) function for definitions of *packet* and *frame* as used by this API.) You can use the [`AudioCodecGetProperty(_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecGetProperty(_:_:_:_:)) function to obtain this value from the [`kAudioCodecPropertyPacketFrameSize`](/documentation/AudioToolbox/kAudioCodecPropertyPacketFrameSize) property. Similarly, this property indicates how many frames of linear PCM data an encoder needs in order to produce a packet of the specified output format.

Output data can be produced only in multiples of whole packets.

The combination of the [`AudioCodecAppendInputData(_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecAppendInputData(_:_:_:_:_:)) and [`AudioCodecProduceOutputPackets(_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecProduceOutputPackets(_:_:_:_:_:_:)) functions implement a “push-pull” model of data handling. First, the input data is pushed into the codec, then the resulting output data is pulled out of that same codec.

## See Also

[`AudioCodecInitialize(_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecInitialize(_:_:_:_:_:))

Sets up the specified codec to perform a data format translation.

[`AudioCodecGetProperty(_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecGetProperty(_:_:_:_:))

Retrieves the value of a codec property.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)