| 514 | } |
| 515 | |
| 516 | static int ffat_encode(AVCodecContext *avctx, AVPacket *avpkt, |
| 517 | const AVFrame *frame, int *got_packet_ptr) |
| 518 | { |
| 519 | ATDecodeContext *at = avctx->priv_data; |
| 520 | OSStatus ret; |
| 521 | |
| 522 | AudioBufferList out_buffers = { |
| 523 | .mNumberBuffers = 1, |
| 524 | .mBuffers = { |
| 525 | { |
| 526 | .mNumberChannels = avctx->ch_layout.nb_channels, |
| 527 | .mDataByteSize = at->pkt_size, |
| 528 | } |
| 529 | } |
| 530 | }; |
| 531 | AudioStreamPacketDescription out_pkt_desc = {0}; |
| 532 | |
| 533 | if (frame) { |
| 534 | AVFrame *in_frame; |
| 535 | |
| 536 | if (ff_bufqueue_is_full(&at->frame_queue)) { |
| 537 | /* |
| 538 | * The frame queue is significantly larger than needed in practice, |
| 539 | * but no clear way to determine the minimum number of samples to |
| 540 | * get output from AudioConverterFillComplexBuffer(). |
| 541 | */ |
| 542 | av_log(avctx, AV_LOG_ERROR, "Bug: frame queue is too small.\n"); |
| 543 | return AVERROR_BUG; |
| 544 | } |
| 545 | |
| 546 | if ((ret = ff_af_queue_add(&at->afq, frame)) < 0) |
| 547 | return ret; |
| 548 | |
| 549 | in_frame = av_frame_clone(frame); |
| 550 | if (!in_frame) |
| 551 | return AVERROR(ENOMEM); |
| 552 | |
| 553 | ff_bufqueue_add(avctx, &at->frame_queue, in_frame); |
| 554 | } else { |
| 555 | at->eof = 1; |
| 556 | } |
| 557 | |
| 558 | if ((ret = ff_alloc_packet(avctx, avpkt, at->pkt_size)) < 0) |
| 559 | return ret; |
| 560 | |
| 561 | |
| 562 | out_buffers.mBuffers[0].mData = avpkt->data; |
| 563 | |
| 564 | *got_packet_ptr = avctx->frame_size / at->frame_size; |
| 565 | |
| 566 | ret = AudioConverterFillComplexBuffer(at->converter, ffat_encode_callback, avctx, |
| 567 | got_packet_ptr, &out_buffers, |
| 568 | (avctx->frame_size > at->frame_size) ? NULL : &out_pkt_desc); |
| 569 | |
| 570 | ff_bufqueue_discard_all(&at->used_frame_queue); |
| 571 | |
| 572 | if ((!ret || ret == 1) && *got_packet_ptr) { |
| 573 | avpkt->size = out_buffers.mBuffers[0].mDataByteSize; |
nothing calls this directly
no test coverage detected