summaryrefslogtreecommitdiff
path: root/libavcodec/flacenc.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-07-31 17:23:29 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-07-31 17:23:29 +0000
commitb22f9d6535c10ccb453c3a3fad118bc34675dfb1 (patch)
tree1cf0c771dca20d7f7e5763281255373ca3469c69 /libavcodec/flacenc.c
parent45e29087573916ab327265d9c23caca461315082 (diff)
downloadffmpeg-b22f9d6535c10ccb453c3a3fad118bc34675dfb1.tar.gz
Simplify fallback to verbatim mode encoding.
Originally committed as revision 24626 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/flacenc.c')
-rw-r--r--libavcodec/flacenc.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index d5a9a16c94..d9f9251c9e 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -1177,6 +1177,16 @@ static void output_frame_footer(FlacEncodeContext *s)
}
+static int write_frame(FlacEncodeContext *s, uint8_t *frame, int buf_size)
+{
+ init_put_bits(&s->pb, frame, buf_size);
+ output_frame_header(s);
+ output_subframes(s);
+ output_frame_footer(s);
+ return put_bits_count(&s->pb) >> 3;
+}
+
+
static void update_md5_sum(FlacEncodeContext *s, const int16_t *samples)
{
#if HAVE_BIGENDIAN
@@ -1197,7 +1207,6 @@ static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
FlacEncodeContext *s;
const int16_t *samples = data;
int out_bytes;
- int reencoded=0;
s = avctx->priv_data;
@@ -1222,25 +1231,14 @@ static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
encode_frame(s);
-write_frame:
- init_put_bits(&s->pb, frame, buf_size);
- output_frame_header(s);
- output_subframes(s);
- output_frame_footer(s);
- out_bytes = put_bits_count(&s->pb) >> 3;
+ out_bytes = write_frame(s, frame, buf_size);
+ /* fallback to verbatim mode if the compressed frame is larger than it
+ would be if encoded uncompressed. */
if (out_bytes > s->max_framesize) {
- if (reencoded) {
- /* still too large. must be an error. */
- av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
- return -1;
- }
-
- /* frame too large. use verbatim mode */
s->frame.verbatim_only = 1;
encode_frame(s);
- reencoded = 1;
- goto write_frame;
+ out_bytes = write_frame(s, frame, buf_size);
}
s->frame_count++;