Do not pointlessly call ff_alloc_packet2 multiple times, and fix an infinite loop by clamping the maximum number of bits to target in the algorithm that does not use lambda.
Unified · Split
| @@ -721,6 +721,9 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, · 720 unmodified lines | |||
| 721 | int allz = 0; | 721 | int allz = 0; |
| 722 | float minthr = INFINITY; | 722 | float minthr = INFINITY; |
| 723 | 723 | ||
| 724 | // for values above this the decoder might end up in an endless loop | ||
| 725 | // due to always having more bits than what can be encoded. | ||
| 726 | destbits = FFMIN(destbits, 5800); | ||
| 724 | //XXX: some heuristic to determine initial quantizers will reduce search time | 727 | //XXX: some heuristic to determine initial quantizers will reduce search time |
| 725 | //determine zero bands and upper limits | 728 | //determine zero bands and upper limits |
| 726 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { | 729 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
| @@ -571,11 +571,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 570 unmodified lines | |||
| 571 | } | 571 | } |
| 572 | start_ch += chans; | 572 | start_ch += chans; |
| 573 | } | 573 | } |
| 574 | if ((ret = ff_alloc_packet2(avctx, avpkt, 768 * s->channels))) | ||
| 575 | return ret; | ||
| 574 | do { | 576 | do { |
| 575 | int frame_bits; | 577 | int frame_bits; |
| 576 | 578 | ||
| 577 | if ((ret = ff_alloc_packet2(avctx, avpkt, 768 * s->channels))) | ||
| 578 | return ret; | ||
| 579 | init_put_bits(&s->pb, avpkt->data, avpkt->size); | 579 | init_put_bits(&s->pb, avpkt->data, avpkt->size); |
| 580 | 580 | ||
| 581 | if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) | 581 | if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) |