Gives the Opus code direct access to (non-opaque) OpusRepacketizer

This avoids potential alignment issues with allocating a char
array on the stack.
This commit is contained in:
Jean-Marc Valin 2011-10-27 22:25:33 -04:00
parent f340bba0f2
commit c8649d0e0b
4 changed files with 17 additions and 22 deletions

View file

@ -724,10 +724,9 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
if (frame_size > st->Fs/50 && (st->mode == MODE_CELT_ONLY || st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)) if (frame_size > st->Fs/50 && (st->mode == MODE_CELT_ONLY || st->bandwidth > OPUS_BANDWIDTH_WIDEBAND))
{ {
VARDECL(unsigned char, tmp_data); VARDECL(unsigned char, tmp_data);
VARDECL(unsigned char, rp_);
int nb_frames; int nb_frames;
int bak_mode, bak_bandwidth, bak_channels, bak_to_mono; int bak_mode, bak_bandwidth, bak_channels, bak_to_mono;
OpusRepacketizer *rp; OpusRepacketizer rp;
int bytes_per_frame; int bytes_per_frame;
@ -735,9 +734,8 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
bytes_per_frame = max_data_bytes/nb_frames-3; bytes_per_frame = max_data_bytes/nb_frames-3;
ALLOC(tmp_data, nb_frames*bytes_per_frame, unsigned char); 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_mode = st->user_forced_mode;
bak_bandwidth = st->user_bandwidth; bak_bandwidth = st->user_bandwidth;
@ -762,11 +760,11 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
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); 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) if (tmp_len<0)
return OPUS_INTERNAL_ERROR; 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) if (ret<0)
return OPUS_INTERNAL_ERROR; 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) if (ret<0)
return OPUS_INTERNAL_ERROR; return OPUS_INTERNAL_ERROR;

View file

@ -237,13 +237,10 @@ int opus_multistream_encode_float(
VARDECL(opus_val16, buf); VARDECL(opus_val16, buf);
/* Max size in case the encoder decides to return three frames */ /* Max size in case the encoder decides to return three frames */
unsigned char tmp_data[3*1275+7]; unsigned char tmp_data[3*1275+7];
VARDECL(unsigned char, rp_); OpusRepacketizer rp;
OpusRepacketizer *rp;
ALLOC_STACK; ALLOC_STACK;
ALLOC(buf, 2*frame_size, opus_val16); ALLOC(buf, 2*frame_size, opus_val16);
ALLOC(rp_, opus_repacketizer_get_size(), unsigned char);
rp = (OpusRepacketizer*)rp_;
ptr = (char*)st + align(sizeof(OpusMSEncoder)); ptr = (char*)st + align(sizeof(OpusMSEncoder));
coupled_size = opus_encoder_get_size(2); coupled_size = opus_encoder_get_size(2);
mono_size = opus_encoder_get_size(1); mono_size = opus_encoder_get_size(1);
@ -261,7 +258,7 @@ int opus_multistream_encode_float(
int len; int len;
int curr_max; int curr_max;
opus_repacketizer_init(rp); opus_repacketizer_init(&rp);
enc = (OpusEncoder*)ptr; enc = (OpusEncoder*)ptr;
if (s < st->layout.nb_coupled_streams) if (s < st->layout.nb_coupled_streams)
{ {
@ -293,8 +290,8 @@ int opus_multistream_encode_float(
/* We need to use the repacketizer to add the self-delimiting lengths /* We need to use the repacketizer to add the self-delimiting lengths
while taking into account the fact that the encoder can now return 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) */ more than one frame at a time (e.g. 60 ms CELT-only) */
opus_repacketizer_cat(rp, tmp_data, len); 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); 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; data += len;
tot_size += len; tot_size += len;
} }

View file

@ -32,6 +32,15 @@
#include "arch.h" #include "arch.h"
#include "opus.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_SILK_ONLY 1000
#define MODE_HYBRID 1001 #define MODE_HYBRID 1001
#define MODE_CELT_ONLY 1002 #define MODE_CELT_ONLY 1002

View file

@ -33,15 +33,6 @@
#include "opus_private.h" #include "opus_private.h"
#include "os_support.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) int opus_repacketizer_get_size(void)
{ {