Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mark Harris
Opus
Commits
44ffd5a8
Commit
44ffd5a8
authored
Feb 22, 2008
by
Jean-Marc Valin
Browse files
Making sure freed or corrupted modes can't be used (produce a run-time warning).
parent
14f5e7cd
Changes
4
Hide whitespace changes
Inline
Side-by-side
libcelt/celt.c
View file @
44ffd5a8
...
...
@@ -89,6 +89,10 @@ CELTEncoder *celt_encoder_create(const CELTMode *mode)
{
int
i
,
N
,
B
,
C
,
N4
;
CELTEncoder
*
st
;
if
(
check_mode
(
mode
)
!=
CELT_OK
)
return
NULL
;
N
=
mode
->
mdctSize
;
B
=
mode
->
nbMdctBlocks
;
C
=
mode
->
nbChannels
;
...
...
@@ -135,6 +139,9 @@ void celt_encoder_destroy(CELTEncoder *st)
celt_warning
(
"NULL passed to celt_encoder_destroy"
);
return
;
}
if
(
check_mode
(
st
->
mode
)
!=
CELT_OK
)
return
;
ec_byte_writeclear
(
&
st
->
buf
);
mdct_clear
(
&
st
->
mdct_lookup
);
...
...
@@ -224,6 +231,10 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
VARDECL
(
float
*
mask
);
VARDECL
(
float
*
bandE
);
VARDECL
(
float
*
gains
);
if
(
check_mode
(
st
->
mode
)
!=
CELT_OK
)
return
CELT_INVALID_MODE
;
N
=
st
->
block_size
;
B
=
st
->
nb_blocks
;
C
=
st
->
mode
->
nbChannels
;
...
...
@@ -450,6 +461,10 @@ CELTDecoder *celt_decoder_create(const CELTMode *mode)
{
int
i
,
N
,
B
,
C
,
N4
;
CELTDecoder
*
st
;
if
(
check_mode
(
mode
)
!=
CELT_OK
)
return
NULL
;
N
=
mode
->
mdctSize
;
B
=
mode
->
nbMdctBlocks
;
C
=
mode
->
nbChannels
;
...
...
@@ -493,6 +508,8 @@ void celt_decoder_destroy(CELTDecoder *st)
celt_warning
(
"NULL passed to celt_encoder_destroy"
);
return
;
}
if
(
check_mode
(
st
->
mode
)
!=
CELT_OK
)
return
;
mdct_clear
(
&
st
->
mdct_lookup
);
...
...
@@ -556,6 +573,10 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
VARDECL
(
float
*
P
);
VARDECL
(
float
*
bandE
);
VARDECL
(
float
*
gains
);
if
(
check_mode
(
st
->
mode
)
!=
CELT_OK
)
return
CELT_INVALID_MODE
;
N
=
st
->
block_size
;
B
=
st
->
nb_blocks
;
C
=
st
->
mode
->
nbChannels
;
...
...
@@ -565,6 +586,8 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
ALLOC
(
bandE
,
st
->
mode
->
nbEBands
*
C
,
float
);
ALLOC
(
gains
,
st
->
mode
->
nbPBands
,
float
);
if
(
check_mode
(
st
->
mode
)
!=
CELT_OK
)
return
CELT_INVALID_MODE
;
if
(
data
==
NULL
)
{
celt_decode_lost
(
st
,
pcm
);
...
...
libcelt/modes.c
View file @
44ffd5a8
...
...
@@ -38,6 +38,10 @@
#include "rate.h"
#include "os_support.h"
#define MODEVALID 0xa110ca7e
#define MODEFREED 0xb10cf8ee
int
celt_mode_info
(
const
CELTMode
*
mode
,
int
request
,
celt_int32_t
*
value
)
{
switch
(
request
)
...
...
@@ -255,6 +259,8 @@ CELTMode *celt_mode_create(int Fs, int channels, int frame_size, int lookahead,
compute_allocation_table
(
mode
,
res
);
compute_alloc_cache
(
mode
);
/*printf ("%d bands\n", mode->nbEBands);*/
mode
->
marker_start
=
MODEVALID
;
mode
->
marker_end
=
MODEVALID
;
return
mode
;
}
...
...
@@ -262,6 +268,8 @@ void celt_mode_destroy(CELTMode *mode)
{
int
i
;
const
int
*
prevPtr
=
NULL
;
if
(
check_mode
(
mode
)
!=
CELT_OK
)
return
;
celt_free
((
int
*
)
mode
->
eBands
);
celt_free
((
int
*
)
mode
->
pBands
);
celt_free
((
int
*
)
mode
->
allocVectors
);
...
...
@@ -275,7 +283,19 @@ void celt_mode_destroy(CELTMode *mode)
}
}
celt_free
((
int
**
)
mode
->
bits
);
mode
->
marker_start
=
MODEFREED
;
mode
->
marker_end
=
MODEFREED
;
celt_free
((
CELTMode
*
)
mode
);
}
int
check_mode
(
const
CELTMode
*
mode
)
{
if
(
mode
->
marker_start
==
MODEVALID
&&
mode
->
marker_end
==
MODEVALID
)
return
CELT_OK
;
if
(
mode
->
marker_start
==
MODEFREED
||
mode
->
marker_end
==
MODEFREED
)
celt_warning
(
"Using a mode that has already been freed"
);
else
celt_warning
(
"This is not a valid CELT mode"
);
return
CELT_INVALID_MODE
;
}
libcelt/modes.h
View file @
44ffd5a8
...
...
@@ -39,7 +39,8 @@
@brief Mode definition
*/
struct
CELTMode
{
int
Fs
;
celt_int32_t
marker_start
;
celt_int32_t
Fs
;
int
overlap
;
int
mdctSize
;
int
nbMdctBlocks
;
...
...
@@ -58,7 +59,9 @@ struct CELTMode {
const
int
*
allocVectors
;
/**< Number of bits in each band for several rates */
const
int
*
const
*
bits
;
/**< Cache for pulses->bits mapping in each band */
celt_int32_t
marker_end
;
};
int
check_mode
(
const
CELTMode
*
mode
);
#endif
tools/celtenc.c
View file @
44ffd5a8
...
...
@@ -221,6 +221,7 @@ void usage()
printf
(
" -V Verbose mode (show bit-rate)
\n
"
);
printf
(
"Raw input options:
\n
"
);
printf
(
" --rate n Sampling rate for raw input
\n
"
);
printf
(
" --mono Consider raw input as mono
\n
"
);
printf
(
" --stereo Consider raw input as stereo
\n
"
);
printf
(
" --le Raw input is little-endian
\n
"
);
printf
(
" --be Raw input is big-endian
\n
"
);
...
...
@@ -255,6 +256,7 @@ int main(int argc, char **argv)
{
"be"
,
no_argument
,
NULL
,
0
},
{
"8bit"
,
no_argument
,
NULL
,
0
},
{
"16bit"
,
no_argument
,
NULL
,
0
},
{
"mono"
,
no_argument
,
NULL
,
0
},
{
"stereo"
,
no_argument
,
NULL
,
0
},
{
"rate"
,
required_argument
,
NULL
,
0
},
{
"version"
,
no_argument
,
NULL
,
0
},
...
...
@@ -339,7 +341,9 @@ int main(int argc, char **argv)
}
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"stereo"
)
==
0
)
{
chan
=
2
;
mode
=
celt_stereo
;
}
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"mono"
)
==
0
)
{
chan
=
1
;
}
else
if
(
strcmp
(
long_options
[
option_index
].
name
,
"rate"
)
==
0
)
{
rate
=
atoi
(
optarg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment