aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-01-05 23:34:09 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-01-07 13:38:23 -0500
commit34093ba0819c8f00f024a49cc2cebe0400f020d4 (patch)
tree4e4d433074da41e6757580ad7119de9ac3a61908
parent96219141e2b2a71fde4dca5505325d21f7cc10b7 (diff)
downloadffmpeg-34093ba0819c8f00f024a49cc2cebe0400f020d4.tar.gz
g722enc: split encoding into separate functions for trellis vs. no trellis
-rw-r--r--libavcodec/g722enc.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 1eed784a72..470770c413 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -117,13 +117,12 @@ static inline int encode_low(const struct G722Band* state, int xlow)
return (diff < 0 ? (i < 2 ? 63 : 33) : 61) - i;
}
-static int g722_encode_trellis(AVCodecContext *avctx,
- uint8_t *dst, int buf_size, void *data)
+static void g722_encode_trellis(G722Context *c, int trellis,
+ uint8_t *dst, int nb_samples,
+ const int16_t *samples)
{
- G722Context *c = avctx->priv_data;
- const int16_t *samples = data;
int i, j, k;
- int frontier = 1 << avctx->trellis;
+ int frontier = 1 << trellis;
struct TrellisNode **nodes[2];
struct TrellisNode **nodes_next[2];
int pathn[2] = {0, 0}, froze = -1;
@@ -139,7 +138,7 @@ static int g722_encode_trellis(AVCodecContext *avctx,
nodes[i][0]->state = c->band[i];
}
- for (i = 0; i < buf_size; i++) {
+ for (i = 0; i < nb_samples >> 1; i++) {
int xlow, xhigh;
struct TrellisNode *next[2];
int heap_pos[2] = {0, 0};
@@ -271,8 +270,28 @@ static int g722_encode_trellis(AVCodecContext *avctx,
}
c->band[0] = nodes[0][0]->state;
c->band[1] = nodes[1][0]->state;
+}
+
+static av_always_inline void encode_byte(G722Context *c, uint8_t *dst,
+ const int16_t *samples)
+{
+ int xlow, xhigh, ilow, ihigh;
+ filter_samples(c, samples, &xlow, &xhigh);
+ ihigh = encode_high(&c->band[1], xhigh);
+ ilow = encode_low (&c->band[0], xlow);
+ ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor *
+ ff_g722_high_inv_quant[ihigh] >> 10, ihigh);
+ ff_g722_update_low_predictor(&c->band[0], ilow >> 2);
+ *dst = ihigh << 6 | ilow;
+}
- return i;
+static void g722_encode_no_trellis(G722Context *c,
+ uint8_t *dst, int nb_samples,
+ const int16_t *samples)
+{
+ int i;
+ for (i = 0; i < nb_samples; i += 2)
+ encode_byte(c, dst++, &samples[i]);
}
static int g722_encode_frame(AVCodecContext *avctx,
@@ -280,22 +299,16 @@ static int g722_encode_frame(AVCodecContext *avctx,
{
G722Context *c = avctx->priv_data;
const int16_t *samples = data;
- int i;
+ int nb_samples;
+
+ nb_samples = buf_size * 2;
if (avctx->trellis)
- return g722_encode_trellis(avctx, dst, buf_size, data);
+ g722_encode_trellis(c, avctx->trellis, dst, nb_samples, samples);
+ else
+ g722_encode_no_trellis(c, dst, nb_samples, samples);
- for (i = 0; i < buf_size; i++) {
- int xlow, xhigh, ihigh, ilow;
- filter_samples(c, &samples[2*i], &xlow, &xhigh);
- ihigh = encode_high(&c->band[1], xhigh);
- ilow = encode_low(&c->band[0], xlow);
- ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor *
- ff_g722_high_inv_quant[ihigh] >> 10, ihigh);
- ff_g722_update_low_predictor(&c->band[0], ilow >> 2);
- *dst++ = ihigh << 6 | ilow;
- }
- return i;
+ return buf_size;
}
AVCodec ff_adpcm_g722_encoder = {