ref: c8649d0e0bbc726313a5e483ecdaba34ed33e19b
parent: f340bba0f23dd04649c9cf308a388cd6c357397c
author: Jean-Marc Valin <[email protected]>
date: Thu Oct 27 18:25:33 EDT 2011
Gives the Opus code direct access to (non-opaque) OpusRepacketizer This avoids potential alignment issues with allocating a char array on the stack.
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -724,10 +724,9 @@
if (frame_size > st->Fs/50 && (st->mode == MODE_CELT_ONLY || st->bandwidth > OPUS_BANDWIDTH_WIDEBAND))
{
VARDECL(unsigned char, tmp_data);
- VARDECL(unsigned char, rp_);
int nb_frames;
int bak_mode, bak_bandwidth, bak_channels, bak_to_mono;
- OpusRepacketizer *rp;
+ OpusRepacketizer rp;
int bytes_per_frame;
@@ -735,9 +734,8 @@
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_);
+ opus_repacketizer_init(&rp);
bak_mode = st->user_forced_mode;
bak_bandwidth = st->user_bandwidth;
@@ -762,11 +760,11 @@
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);
if (tmp_len<0)
return OPUS_INTERNAL_ERROR;
- ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len);
+ ret = opus_repacketizer_cat(&rp, tmp_data+i*bytes_per_frame, tmp_len);
if (ret<0)
return OPUS_INTERNAL_ERROR;
}
- ret = opus_repacketizer_out(rp, data, max_data_bytes);
+ ret = opus_repacketizer_out(&rp, data, max_data_bytes);
if (ret<0)
return OPUS_INTERNAL_ERROR;
--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -237,13 +237,10 @@
VARDECL(opus_val16, buf);
/* Max size in case the encoder decides to return three frames */
unsigned char tmp_data[3*1275+7];
- VARDECL(unsigned char, rp_);
- OpusRepacketizer *rp;
+ OpusRepacketizer rp;
ALLOC_STACK;
ALLOC(buf, 2*frame_size, opus_val16);
- ALLOC(rp_, opus_repacketizer_get_size(), unsigned char);
- rp = (OpusRepacketizer*)rp_;
ptr = (char*)st + align(sizeof(OpusMSEncoder));
coupled_size = opus_encoder_get_size(2);
mono_size = opus_encoder_get_size(1);
@@ -261,7 +258,7 @@
int len;
int curr_max;
- opus_repacketizer_init(rp);
+ opus_repacketizer_init(&rp);
enc = (OpusEncoder*)ptr;
if (s < st->layout.nb_coupled_streams)
{
@@ -293,8 +290,8 @@
/* We need to use the repacketizer to add the self-delimiting lengths
while taking into account the fact that the encoder can now return
more than one frame at a time (e.g. 60 ms CELT-only) */
- opus_repacketizer_cat(rp, tmp_data, len);
- len = opus_repacketizer_out_range_impl(rp, 0, opus_repacketizer_get_nb_frames(rp), data, max_data_bytes-tot_size, s != st->layout.nb_streams-1);
+ opus_repacketizer_cat(&rp, tmp_data, len);
+ len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_frames(&rp), data, max_data_bytes-tot_size, s != st->layout.nb_streams-1);
data += len;
tot_size += len;
}
--- a/src/opus_private.h
+++ b/src/opus_private.h
@@ -32,6 +32,15 @@
#include "arch.h"
#include "opus.h"
+struct OpusRepacketizer {
+ unsigned char toc;
+ int nb_frames;
+ const unsigned char *frames[48];
+ short len[48];
+ int framesize;
+};
+
+
#define MODE_SILK_ONLY 1000
#define MODE_HYBRID 1001
#define MODE_CELT_ONLY 1002
--- a/src/repacketizer.c
+++ b/src/repacketizer.c
@@ -33,15 +33,6 @@
#include "opus_private.h"
#include "os_support.h"
-struct OpusRepacketizer {
- unsigned char toc;
- int nb_frames;
- const unsigned char *frames[48];
- short len[48];
- int framesize;
-};
-
-
int opus_repacketizer_get_size(void)
{