shithub: opus

Download patch

ref: d970a85c395d0c8c360fab0cdc15ac9373a8ced8
parent: e4336a5c2188564a82a111c89e5ad047a0de07e3
author: Jean-Marc Valin <[email protected]>
date: Thu Sep 8 17:41:29 EDT 2011

Using opus_repacketizer_init() instead of opus_repacketizer_create() in the encoder

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -569,11 +569,21 @@
     /* Can't support higher than wideband for >20 ms frames */
     if (frame_size > st->Fs/50 && (st->mode == MODE_CELT_ONLY || st->bandwidth > OPUS_BANDWIDTH_WIDEBAND))
     {
-       unsigned char tmp_data[3][1276];
+       VARDECL(unsigned char, tmp_data);
+       VARDECL(unsigned char, rp_);
        int nb_frames;
        int bak_mode, bak_bandwidth, bak_channels;
-       OpusRepacketizer *rp = opus_repacketizer_create();
+       OpusRepacketizer *rp;
+       int bytes_per_frame;
 
+       nb_frames = frame_size > st->Fs/25 ? 3 : 2;
+       bytes_per_frame = max_data_bytes/nb_frames-3;
+
+       ALLOC(tmp_data, nb_frames*bytes_per_frame, unsigned char);
+       ALLOC(rp_, opus_repacketizer_get_size(), unsigned char);
+
+       rp = opus_repacketizer_init((OpusRepacketizer*)rp_);
+
        bak_mode = st->user_forced_mode;
        bak_bandwidth = st->user_bandwidth;
        bak_channels = st->force_channels;
@@ -582,16 +592,13 @@
        st->user_bandwidth = st->bandwidth;
        st->force_channels = st->stream_channels;
 
-       nb_frames = frame_size > st->Fs/25 ? 3 : 2;
        for (i=0;i<nb_frames;i++)
        {
           int tmp_len;
-          tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data[i], max_data_bytes/nb_frames-3);
-          ret = opus_repacketizer_cat(rp, tmp_data[i], tmp_len);
+          tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, tmp_data+i*bytes_per_frame, bytes_per_frame);
+          ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len);
        }
        ret = opus_repacketizer_out(rp, data, max_data_bytes);
-
-       opus_repacketizer_destroy(rp);
 
        st->user_forced_mode = bak_mode;
        st->user_bandwidth = bak_bandwidth;