aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2010-07-31 16:46:32 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2010-07-31 16:46:32 +0000
commit0f5cc12c4f7282fa35a2bfd34519ac7b04eed7a3 (patch)
treec00ecd93282a30491d1354bfc1fd83c6568cf8c4
parent05236ed7359b8310eb614adcdda025e5ea1a2ed5 (diff)
downloadffmpeg-0f5cc12c4f7282fa35a2bfd34519ac7b04eed7a3.tar.gz
Remove duplicate code by adding a flag for encoding in verbatim mode.
Originally committed as revision 24621 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/flacenc.c40
1 files changed, 6 insertions, 34 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 7eabd9c994..487d0234fb 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -77,6 +77,7 @@ typedef struct FlacFrame {
int bs_code[2];
uint8_t crc8;
int ch_mode;
+ int verbatim_only;
} FlacFrame;
typedef struct FlacEncodeContext {
@@ -472,6 +473,8 @@ static void init_frame(FlacEncodeContext *s)
for (ch = 0; ch < s->channels; ch++)
frame->subframes[ch].obits = 16;
+
+ frame->verbatim_only = 0;
}
@@ -819,7 +822,7 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch)
}
/* VERBATIM */
- if (n < 5) {
+ if (frame->verbatim_only || n < 5) {
sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
encode_residual_verbatim(res, smp, n);
return sub->obits * n;
@@ -985,36 +988,6 @@ static int encode_frame(FlacEncodeContext *s)
}
-static int encode_residual_v(FlacEncodeContext *s, int ch)
-{
- int i, n;
- FlacFrame *frame;
- FlacSubframe *sub;
- int32_t *res, *smp;
-
- frame = &s->frame;
- sub = &frame->subframes[ch];
- res = sub->residual;
- smp = sub->samples;
- n = frame->blocksize;
-
- /* CONSTANT */
- for (i = 1; i < n; i++)
- if (smp[i] != smp[0])
- break;
- if (i == n) {
- sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT;
- res[0] = smp[0];
- return sub->obits;
- }
-
- /* VERBATIM */
- sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
- encode_residual_verbatim(res, smp, n);
- return sub->obits * n;
-}
-
-
static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
{
int i, best;
@@ -1236,7 +1209,6 @@ static void update_md5_sum(FlacEncodeContext *s, const int16_t *samples)
static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
int buf_size, void *data)
{
- int ch;
FlacEncodeContext *s;
const int16_t *samples = data;
int out_bytes;
@@ -1280,8 +1252,8 @@ write_frame:
}
/* frame too large. use verbatim mode */
- for (ch = 0; ch < s->channels; ch++)
- encode_residual_v(s, ch);
+ s->frame.verbatim_only = 1;
+ encode_frame(s);
reencoded = 1;
goto write_frame;
}