MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / flac_encode_frame

Function flac_encode_frame

libavcodec/flacenc.c:1175–1240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1173}
1174
1175static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
1176 int buf_size, void *data)
1177{
1178 int ch;
1179 FlacEncodeContext *s;
1180 int16_t *samples = data;
1181 int out_bytes;
1182 int reencoded=0;
1183
1184 s = avctx->priv_data;
1185
1186 if(buf_size < s->max_framesize*2) {
1187 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
1188 return 0;
1189 }
1190
1191 /* when the last block is reached, update the header in extradata */
1192 if (!data) {
1193 s->max_framesize = s->max_encoded_framesize;
1194 av_md5_final(s->md5ctx, s->md5sum);
1195 write_streaminfo(s, avctx->extradata);
1196 return 0;
1197 }
1198
1199 init_frame(s);
1200
1201 copy_samples(s, samples);
1202
1203 channel_decorrelation(s);
1204
1205 for(ch=0; ch<s->channels; ch++) {
1206 encode_residual(s, ch);
1207 }
1208
1209write_frame:
1210 init_put_bits(&s->pb, frame, buf_size);
1211 output_frame_header(s);
1212 output_subframes(s);
1213 output_frame_footer(s);
1214 out_bytes = put_bits_count(&s->pb) >> 3;
1215
1216 if(out_bytes > s->max_framesize) {
1217 if(reencoded) {
1218 /* still too large. must be an error. */
1219 av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
1220 return -1;
1221 }
1222
1223 /* frame too large. use verbatim mode */
1224 for(ch=0; ch<s->channels; ch++) {
1225 encode_residual_v(s, ch);
1226 }
1227 reencoded = 1;
1228 goto write_frame;
1229 }
1230
1231 s->frame_count++;
1232 s->sample_count += avctx->frame_size;

Callers

nothing calls this directly

Calls 14

av_logFunction · 0.85
av_md5_finalFunction · 0.85
init_frameFunction · 0.85
copy_samplesFunction · 0.85
channel_decorrelationFunction · 0.85
encode_residualFunction · 0.85
init_put_bitsFunction · 0.85
output_subframesFunction · 0.85
output_frame_footerFunction · 0.85
put_bits_countFunction · 0.85
encode_residual_vFunction · 0.85
update_md5_sumFunction · 0.85

Tested by

no test coverage detected