Several encoders were multiplying the buffer size by 8, in order to get
a bit size. However, the buffer_size argument is for the byte size of
the buffer. We had experienced crashes encoding prores (Anatoliy) at
size 4096x4096.
(cherry picked from commit 50833c9f7b)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
tags/n2.4.8
| @@ -165,7 +165,7 @@ static void put_audio_specific_config(AVCodecContext *avctx) | |||||
| PutBitContext pb; | PutBitContext pb; | ||||
| AACEncContext *s = avctx->priv_data; | AACEncContext *s = avctx->priv_data; | ||||
| init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8); | |||||
| init_put_bits(&pb, avctx->extradata, avctx->extradata_size); | |||||
| put_bits(&pb, 5, 2); //object type - AAC-LC | put_bits(&pb, 5, 2); //object type - AAC-LC | ||||
| put_bits(&pb, 4, s->samplerate_index); //sample rate index | put_bits(&pb, 4, s->samplerate_index); //sample rate index | ||||
| put_bits(&pb, 4, s->channels); | put_bits(&pb, 4, s->channels); | ||||
| @@ -541,7 +541,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, | |||||
| case AV_CODEC_ID_ADPCM_IMA_QT: | case AV_CODEC_ID_ADPCM_IMA_QT: | ||||
| { | { | ||||
| PutBitContext pb; | PutBitContext pb; | ||||
| init_put_bits(&pb, dst, pkt_size * 8); | |||||
| init_put_bits(&pb, dst, pkt_size); | |||||
| for (ch = 0; ch < avctx->channels; ch++) { | for (ch = 0; ch < avctx->channels; ch++) { | ||||
| ADPCMChannelStatus *status = &c->status[ch]; | ADPCMChannelStatus *status = &c->status[ch]; | ||||
| @@ -571,7 +571,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, | |||||
| case AV_CODEC_ID_ADPCM_SWF: | case AV_CODEC_ID_ADPCM_SWF: | ||||
| { | { | ||||
| PutBitContext pb; | PutBitContext pb; | ||||
| init_put_bits(&pb, dst, pkt_size * 8); | |||||
| init_put_bits(&pb, dst, pkt_size); | |||||
| n = frame->nb_samples - 1; | n = frame->nb_samples - 1; | ||||
| @@ -251,7 +251,7 @@ static void put_line(uint8_t *dst, int size, int width, const int *runs) | |||||
| PutBitContext pb; | PutBitContext pb; | ||||
| int run, mode = ~0, pix_left = width, run_idx = 0; | int run, mode = ~0, pix_left = width, run_idx = 0; | ||||
| init_put_bits(&pb, dst, size * 8); | |||||
| init_put_bits(&pb, dst, size); | |||||
| while (pix_left > 0) { | while (pix_left > 0) { | ||||
| run = runs[run_idx++]; | run = runs[run_idx++]; | ||||
| mode = ~mode; | mode = ~mode; | ||||
| @@ -287,7 +287,7 @@ static int write_header(FlashSV2Context * s, uint8_t * buf, int buf_size) | |||||
| if (buf_size < 5) | if (buf_size < 5) | ||||
| return -1; | return -1; | ||||
| init_put_bits(&pb, buf, buf_size * 8); | |||||
| init_put_bits(&pb, buf, buf_size); | |||||
| put_bits(&pb, 4, (s->block_width >> 4) - 1); | put_bits(&pb, 4, (s->block_width >> 4) - 1); | ||||
| put_bits(&pb, 12, s->image_width); | put_bits(&pb, 12, s->image_width); | ||||
| @@ -151,7 +151,7 @@ static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf, | |||||
| int buf_pos, res; | int buf_pos, res; | ||||
| int pred_blocks = 0; | int pred_blocks = 0; | ||||
| init_put_bits(&pb, buf, buf_size * 8); | |||||
| init_put_bits(&pb, buf, buf_size); | |||||
| put_bits(&pb, 4, block_width / 16 - 1); | put_bits(&pb, 4, block_width / 16 - 1); | ||||
| put_bits(&pb, 12, s->image_width); | put_bits(&pb, 12, s->image_width); | ||||
| @@ -303,7 +303,7 @@ static void encode_block(NellyMoserEncodeContext *s, unsigned char *output, int | |||||
| apply_mdct(s); | apply_mdct(s); | ||||
| init_put_bits(&pb, output, output_size * 8); | |||||
| init_put_bits(&pb, output, output_size); | |||||
| i = 0; | i = 0; | ||||
| for (band = 0; band < NELLY_BANDS; band++) { | for (band = 0; band < NELLY_BANDS; band++) { | ||||
| @@ -304,7 +304,7 @@ static int encode_slice_plane(AVCodecContext *avctx, int mb_count, | |||||
| } | } | ||||
| blocks_per_slice = mb_count << (2 - chroma); | blocks_per_slice = mb_count << (2 - chroma); | ||||
| init_put_bits(&pb, buf, buf_size << 3); | |||||
| init_put_bits(&pb, buf, buf_size); | |||||
| encode_dc_coeffs(&pb, blocks, blocks_per_slice, qmat); | encode_dc_coeffs(&pb, blocks, blocks_per_slice, qmat); | ||||
| encode_ac_coeffs(avctx, &pb, blocks, blocks_per_slice, qmat); | encode_ac_coeffs(avctx, &pb, blocks, blocks_per_slice, qmat); | ||||
| @@ -1057,7 +1057,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, | |||||
| slice_hdr = pkt->data + (slice_hdr - start); | slice_hdr = pkt->data + (slice_hdr - start); | ||||
| tmp = pkt->data + (tmp - start); | tmp = pkt->data + (tmp - start); | ||||
| } | } | ||||
| init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf)) * 8); | |||||
| init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf))); | |||||
| ret = encode_slice(avctx, pic, &pb, sizes, x, y, q, | ret = encode_slice(avctx, pic, &pb, sizes, x, y, q, | ||||
| mbs_per_slice); | mbs_per_slice); | ||||
| if (ret < 0) | if (ret < 0) | ||||
| @@ -82,7 +82,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, | |||||
| return ret; | return ret; | ||||
| o = avpkt->data; | o = avpkt->data; | ||||
| init_put_bits(&pb, o, buf_size * 8); | |||||
| init_put_bits(&pb, o, buf_size); | |||||
| put_bits(&pb, 16, buf_size - AES3_HEADER_LEN); | put_bits(&pb, 16, buf_size - AES3_HEADER_LEN); | ||||
| put_bits(&pb, 2, (avctx->channels - 2) >> 1); // number of channels | put_bits(&pb, 2, (avctx->channels - 2) >> 1); // number of channels | ||||
| put_bits(&pb, 8, 0); // channel ID | put_bits(&pb, 8, 0); // channel ID | ||||