Mercurial > libavcodec.hg
comparison flacenc.c @ 12325:6da1651834cb libavcodec
Simplify fallback to verbatim mode encoding.
author | jbr |
---|---|
date | Sat, 31 Jul 2010 17:23:29 +0000 |
parents | 549a40628c70 |
children | e9efc7168faf |
comparison
equal
deleted
inserted
replaced
12324:549a40628c70 | 12325:6da1651834cb |
---|---|
1175 put_bits(&s->pb, 16, crc); | 1175 put_bits(&s->pb, 16, crc); |
1176 flush_put_bits(&s->pb); | 1176 flush_put_bits(&s->pb); |
1177 } | 1177 } |
1178 | 1178 |
1179 | 1179 |
1180 static int write_frame(FlacEncodeContext *s, uint8_t *frame, int buf_size) | |
1181 { | |
1182 init_put_bits(&s->pb, frame, buf_size); | |
1183 output_frame_header(s); | |
1184 output_subframes(s); | |
1185 output_frame_footer(s); | |
1186 return put_bits_count(&s->pb) >> 3; | |
1187 } | |
1188 | |
1189 | |
1180 static void update_md5_sum(FlacEncodeContext *s, const int16_t *samples) | 1190 static void update_md5_sum(FlacEncodeContext *s, const int16_t *samples) |
1181 { | 1191 { |
1182 #if HAVE_BIGENDIAN | 1192 #if HAVE_BIGENDIAN |
1183 int i; | 1193 int i; |
1184 for (i = 0; i < s->frame.blocksize * s->channels; i++) { | 1194 for (i = 0; i < s->frame.blocksize * s->channels; i++) { |
1195 int buf_size, void *data) | 1205 int buf_size, void *data) |
1196 { | 1206 { |
1197 FlacEncodeContext *s; | 1207 FlacEncodeContext *s; |
1198 const int16_t *samples = data; | 1208 const int16_t *samples = data; |
1199 int out_bytes; | 1209 int out_bytes; |
1200 int reencoded=0; | |
1201 | 1210 |
1202 s = avctx->priv_data; | 1211 s = avctx->priv_data; |
1203 | 1212 |
1204 if (buf_size < s->max_framesize * 2) { | 1213 if (buf_size < s->max_framesize * 2) { |
1205 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); | 1214 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); |
1220 | 1229 |
1221 channel_decorrelation(s); | 1230 channel_decorrelation(s); |
1222 | 1231 |
1223 encode_frame(s); | 1232 encode_frame(s); |
1224 | 1233 |
1225 write_frame: | 1234 out_bytes = write_frame(s, frame, buf_size); |
1226 init_put_bits(&s->pb, frame, buf_size); | 1235 |
1227 output_frame_header(s); | 1236 /* fallback to verbatim mode if the compressed frame is larger than it |
1228 output_subframes(s); | 1237 would be if encoded uncompressed. */ |
1229 output_frame_footer(s); | |
1230 out_bytes = put_bits_count(&s->pb) >> 3; | |
1231 | |
1232 if (out_bytes > s->max_framesize) { | 1238 if (out_bytes > s->max_framesize) { |
1233 if (reencoded) { | |
1234 /* still too large. must be an error. */ | |
1235 av_log(avctx, AV_LOG_ERROR, "error encoding frame\n"); | |
1236 return -1; | |
1237 } | |
1238 | |
1239 /* frame too large. use verbatim mode */ | |
1240 s->frame.verbatim_only = 1; | 1239 s->frame.verbatim_only = 1; |
1241 encode_frame(s); | 1240 encode_frame(s); |
1242 reencoded = 1; | 1241 out_bytes = write_frame(s, frame, buf_size); |
1243 goto write_frame; | |
1244 } | 1242 } |
1245 | 1243 |
1246 s->frame_count++; | 1244 s->frame_count++; |
1247 avctx->coded_frame->pts = s->sample_count; | 1245 avctx->coded_frame->pts = s->sample_count; |
1248 s->sample_count += avctx->frame_size; | 1246 s->sample_count += avctx->frame_size; |