Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
f7ec7f54
Commit
f7ec7f54
authored
Apr 15, 2016
by
Alexandra Hájková
Committed by
Diego Biurrun
Feb 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wma: Convert to the new bitstream reader
parent
58d87e0f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
387 additions
and
383 deletions
+387
-383
wma.c
libavcodec/wma.c
+21
-20
wma.h
libavcodec/wma.h
+4
-4
wmadec.c
libavcodec/wmadec.c
+33
-31
wmalosslessdec.c
libavcodec/wmalosslessdec.c
+94
-94
wmaprodec.c
libavcodec/wmaprodec.c
+104
-103
wmavoice.c
libavcodec/wmavoice.c
+131
-131
No files found.
libavcodec/wma.c
View file @
f7ec7f54
...
...
@@ -22,6 +22,7 @@
#include "libavutil/attributes.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "sinewin.h"
#include "wma.h"
...
...
@@ -382,30 +383,30 @@ int ff_wma_end(AVCodecContext *avctx)
/**
* Decode an uncompressed coefficient.
* @param
gb GetBit
Context
* @param
bc Bitstream
Context
* @return the decoded coefficient
*/
unsigned
int
ff_wma_get_large_val
(
GetBitContext
*
gb
)
unsigned
int
ff_wma_get_large_val
(
BitstreamContext
*
bc
)
{
/** consumes up to 34 bits */
int
n_bits
=
8
;
/** decode length */
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
n_bits
+=
8
;
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
n_bits
+=
8
;
if
(
get_bits1
(
gb
))
if
(
bitstream_read_bit
(
bc
))
n_bits
+=
7
;
}
}
return
get_bits_long
(
gb
,
n_bits
);
return
bitstream_read
(
bc
,
n_bits
);
}
/**
* Decode run level compressed coefficients.
* @param avctx codec context
* @param
gb
bitstream reader context
* @param vlc
vlc table for get_vlc2
* @param
bc
bitstream reader context
* @param vlc
VLC table for bitstream_read_vlc
* @param level_table level codes
* @param run_table run codes
* @param version 0 for wma1,2 1 for wmapro
...
...
@@ -417,7 +418,7 @@ unsigned int ff_wma_get_large_val(GetBitContext *gb)
* @param coef_nb_bits number of bits for escaped level codes
* @return 0 on success, -1 otherwise
*/
int
ff_wma_run_level_decode
(
AVCodecContext
*
avctx
,
GetBitContext
*
gb
,
int
ff_wma_run_level_decode
(
AVCodecContext
*
avctx
,
BitstreamContext
*
bc
,
VLC
*
vlc
,
const
float
*
level_table
,
const
uint16_t
*
run_table
,
int
version
,
WMACoef
*
ptr
,
int
offset
,
int
num_coefs
,
...
...
@@ -429,11 +430,11 @@ int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
uint32_t
*
iptr
=
(
uint32_t
*
)
ptr
;
const
unsigned
int
coef_mask
=
block_len
-
1
;
for
(;
offset
<
num_coefs
;
offset
++
)
{
code
=
get_vlc2
(
gb
,
vlc
->
table
,
VLCBITS
,
VLCMAX
);
code
=
bitstream_read_vlc
(
bc
,
vlc
->
table
,
VLCBITS
,
VLCMAX
);
if
(
code
>
1
)
{
/** normal code */
offset
+=
run_table
[
code
];
sign
=
get_bits1
(
gb
)
-
1
;
sign
=
bitstream_read_bit
(
bc
)
-
1
;
iptr
[
offset
&
coef_mask
]
=
ilvl
[
code
]
^
sign
<<
31
;
}
else
if
(
code
==
1
)
{
/** EOB */
...
...
@@ -441,26 +442,26 @@ int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
}
else
{
/** escape */
if
(
!
version
)
{
level
=
get_bits
(
gb
,
coef_nb_bits
);
level
=
bitstream_read
(
bc
,
coef_nb_bits
);
/** NOTE: this is rather suboptimal. reading
* block_len_bits would be better */
offset
+=
get_bits
(
gb
,
frame_len_bits
);
offset
+=
bitstream_read
(
bc
,
frame_len_bits
);
}
else
{
level
=
ff_wma_get_large_val
(
gb
);
level
=
ff_wma_get_large_val
(
bc
);
/** escape decode */
if
(
get_bits1
(
gb
))
{
if
(
get_bits1
(
gb
))
{
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
if
(
bitstream_read_bit
(
bc
))
{
if
(
bitstream_read_bit
(
bc
))
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"broken escape sequence
\n
"
);
return
-
1
;
}
else
offset
+=
get_bits
(
gb
,
frame_len_bits
)
+
4
;
offset
+=
bitstream_read
(
bc
,
frame_len_bits
)
+
4
;
}
else
offset
+=
get_bits
(
gb
,
2
)
+
1
;
offset
+=
bitstream_read
(
bc
,
2
)
+
1
;
}
}
sign
=
get_bits1
(
gb
)
-
1
;
sign
=
bitstream_read_bit
(
bc
)
-
1
;
ptr
[
offset
&
coef_mask
]
=
(
level
^
sign
)
-
sign
;
}
}
...
...
libavcodec/wma.h
View file @
f7ec7f54
...
...
@@ -25,8 +25,8 @@
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "bitstream.h"
#include "fft.h"
#include "get_bits.h"
#include "put_bits.h"
/* size of blocks */
...
...
@@ -66,7 +66,7 @@ typedef struct CoefVLCTable {
typedef
struct
WMACodecContext
{
AVCodecContext
*
avctx
;
GetBitContext
gb
;
BitstreamContext
bc
;
PutBitContext
pb
;
int
version
;
///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
int
use_bit_reservoir
;
...
...
@@ -147,8 +147,8 @@ extern const uint8_t ff_aac_scalefactor_bits[121];
int
ff_wma_init
(
AVCodecContext
*
avctx
,
int
flags2
);
int
ff_wma_total_gain_to_bits
(
int
total_gain
);
int
ff_wma_end
(
AVCodecContext
*
avctx
);
unsigned
int
ff_wma_get_large_val
(
GetBitContext
*
gb
);
int
ff_wma_run_level_decode
(
AVCodecContext
*
avctx
,
GetBitContext
*
gb
,
unsigned
int
ff_wma_get_large_val
(
BitstreamContext
*
bc
);
int
ff_wma_run_level_decode
(
AVCodecContext
*
avctx
,
BitstreamContext
*
bc
,
VLC
*
vlc
,
const
float
*
level_table
,
const
uint16_t
*
run_table
,
int
version
,
WMACoef
*
ptr
,
int
offset
,
int
num_coefs
,
...
...
libavcodec/wmadec.c
View file @
f7ec7f54
...
...
@@ -36,6 +36,7 @@
#include "libavutil/attributes.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "wma.h"
...
...
@@ -209,9 +210,9 @@ static void decode_exp_lsp(WMACodecContext *s, int ch)
for
(
i
=
0
;
i
<
NB_LSP_COEFS
;
i
++
)
{
if
(
i
==
0
||
i
>=
8
)
val
=
get_bits
(
&
s
->
gb
,
3
);
val
=
bitstream_read
(
&
s
->
bc
,
3
);
else
val
=
get_bits
(
&
s
->
gb
,
4
);
val
=
bitstream_read
(
&
s
->
bc
,
4
);
lsp_coefs
[
i
]
=
ff_wma_lsp_codebook
[
i
][
val
];
}
...
...
@@ -318,7 +319,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
q_end
=
q
+
s
->
block_len
;
max_scale
=
0
;
if
(
s
->
version
==
1
)
{
last_exp
=
get_bits
(
&
s
->
gb
,
5
)
+
10
;
last_exp
=
bitstream_read
(
&
s
->
bc
,
5
)
+
10
;
v
=
ptab
[
last_exp
];
iv
=
iptab
[
last_exp
];
max_scale
=
v
;
...
...
@@ -333,7 +334,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
last_exp
=
36
;
while
(
q
<
q_end
)
{
code
=
get_vlc2
(
&
s
->
gb
,
s
->
exp_vlc
.
table
,
EXPVLCBITS
,
EXPMAX
);
code
=
bitstream_read_vlc
(
&
s
->
bc
,
s
->
exp_vlc
.
table
,
EXPVLCBITS
,
EXPMAX
);
if
(
code
<
0
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"Exponent vlc invalid
\n
"
);
return
-
1
;
...
...
@@ -436,7 +437,7 @@ static int wma_decode_block(WMACodecContext *s)
if
(
s
->
reset_block_lengths
)
{
s
->
reset_block_lengths
=
0
;
v
=
get_bits
(
&
s
->
gb
,
n
);
v
=
bitstream_read
(
&
s
->
bc
,
n
);
if
(
v
>=
s
->
nb_block_sizes
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"prev_block_len_bits %d out of range
\n
"
,
...
...
@@ -444,7 +445,7 @@ static int wma_decode_block(WMACodecContext *s)
return
-
1
;
}
s
->
prev_block_len_bits
=
s
->
frame_len_bits
-
v
;
v
=
get_bits
(
&
s
->
gb
,
n
);
v
=
bitstream_read
(
&
s
->
bc
,
n
);
if
(
v
>=
s
->
nb_block_sizes
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"block_len_bits %d out of range
\n
"
,
...
...
@@ -457,7 +458,7 @@ static int wma_decode_block(WMACodecContext *s)
s
->
prev_block_len_bits
=
s
->
block_len_bits
;
s
->
block_len_bits
=
s
->
next_block_len_bits
;
}
v
=
get_bits
(
&
s
->
gb
,
n
);
v
=
bitstream_read
(
&
s
->
bc
,
n
);
if
(
v
>=
s
->
nb_block_sizes
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"next_block_len_bits %d out of range
\n
"
,
...
...
@@ -480,10 +481,10 @@ static int wma_decode_block(WMACodecContext *s)
}
if
(
s
->
avctx
->
channels
==
2
)
s
->
ms_stereo
=
get_bits1
(
&
s
->
gb
);
s
->
ms_stereo
=
bitstream_read_bit
(
&
s
->
bc
);
v
=
0
;
for
(
ch
=
0
;
ch
<
s
->
avctx
->
channels
;
ch
++
)
{
a
=
get_bits1
(
&
s
->
gb
);
a
=
bitstream_read_bit
(
&
s
->
bc
);
s
->
channel_coded
[
ch
]
=
a
;
v
|=
a
;
}
...
...
@@ -499,7 +500,7 @@ static int wma_decode_block(WMACodecContext *s)
* coef escape coding */
total_gain
=
1
;
for
(;;)
{
a
=
get_bits
(
&
s
->
gb
,
7
);
a
=
bitstream_read
(
&
s
->
bc
,
7
);
total_gain
+=
a
;
if
(
a
!=
127
)
break
;
...
...
@@ -519,7 +520,7 @@ static int wma_decode_block(WMACodecContext *s)
int
i
,
n
,
a
;
n
=
s
->
exponent_high_sizes
[
bsize
];
for
(
i
=
0
;
i
<
n
;
i
++
)
{
a
=
get_bits1
(
&
s
->
gb
);
a
=
bitstream_read_bit
(
&
s
->
bc
);
s
->
high_band_coded
[
ch
][
i
]
=
a
;
/* if noise coding, the coefficients are not transmitted */
if
(
a
)
...
...
@@ -536,9 +537,10 @@ static int wma_decode_block(WMACodecContext *s)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
(
s
->
high_band_coded
[
ch
][
i
])
{
if
(
val
==
(
int
)
0x80000000
)
{
val
=
get_bits
(
&
s
->
gb
,
7
)
-
19
;
val
=
bitstream_read
(
&
s
->
bc
,
7
)
-
19
;
}
else
{
code
=
get_vlc2
(
&
s
->
gb
,
s
->
hgain_vlc
.
table
,
code
=
bitstream_read_vlc
(
&
s
->
bc
,
s
->
hgain_vlc
.
table
,
HGAINVLCBITS
,
HGAINMAX
);
if
(
code
<
0
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
...
...
@@ -555,7 +557,7 @@ static int wma_decode_block(WMACodecContext *s)
}
/* exponents can be reused in short blocks. */
if
((
s
->
block_len_bits
==
s
->
frame_len_bits
)
||
get_bits1
(
&
s
->
gb
))
{
if
((
s
->
block_len_bits
==
s
->
frame_len_bits
)
||
bitstream_read_bit
(
&
s
->
bc
))
{
for
(
ch
=
0
;
ch
<
s
->
avctx
->
channels
;
ch
++
)
{
if
(
s
->
channel_coded
[
ch
])
{
if
(
s
->
use_exp_vlc
)
{
...
...
@@ -579,13 +581,13 @@ static int wma_decode_block(WMACodecContext *s)
* there is potentially less energy there */
tindex
=
(
ch
==
1
&&
s
->
ms_stereo
);
memset
(
ptr
,
0
,
s
->
block_len
*
sizeof
(
WMACoef
));
ff_wma_run_level_decode
(
s
->
avctx
,
&
s
->
gb
,
&
s
->
coef_vlc
[
tindex
],
ff_wma_run_level_decode
(
s
->
avctx
,
&
s
->
bc
,
&
s
->
coef_vlc
[
tindex
],
s
->
level_table
[
tindex
],
s
->
run_table
[
tindex
],
0
,
ptr
,
0
,
nb_coefs
[
ch
],
s
->
block_len
,
s
->
frame_len_bits
,
coef_nb_bits
);
}
if
(
s
->
version
==
1
&&
s
->
avctx
->
channels
>=
2
)
align_get_bits
(
&
s
->
gb
);
bitstream_align
(
&
s
->
bc
);
}
/* normalize */
...
...
@@ -810,12 +812,12 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
}
buf_size
=
avctx
->
block_align
;
init_get_bits
(
&
s
->
gb
,
buf
,
buf_size
*
8
);
bitstream_init8
(
&
s
->
bc
,
buf
,
buf_size
);
if
(
s
->
use_bit_reservoir
)
{
/* read super frame header */
skip_bits
(
&
s
->
gb
,
4
);
/* super frame index */
nb_frames
=
get_bits
(
&
s
->
gb
,
4
)
-
(
s
->
last_superframe_len
<=
0
);
bitstream_skip
(
&
s
->
bc
,
4
);
/* super frame index */
nb_frames
=
bitstream_read
(
&
s
->
bc
,
4
)
-
(
s
->
last_superframe_len
<=
0
);
}
else
nb_frames
=
1
;
...
...
@@ -829,11 +831,11 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
samples_offset
=
0
;
if
(
s
->
use_bit_reservoir
)
{
bit_offset
=
get_bits
(
&
s
->
gb
,
s
->
byte_offset_bits
+
3
);
if
(
bit_offset
>
get_bits_left
(
&
s
->
gb
))
{
bit_offset
=
bitstream_read
(
&
s
->
bc
,
s
->
byte_offset_bits
+
3
);
if
(
bit_offset
>
bitstream_bits_left
(
&
s
->
bc
))
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Invalid last frame bit offset %d > buf size %d (%d)
\n
"
,
bit_offset
,
get_bits_left
(
&
s
->
gb
),
buf_size
);
bit_offset
,
bitstream_bits_left
(
&
s
->
bc
),
buf_size
);
goto
fail
;
}
...
...
@@ -845,19 +847,19 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
q
=
s
->
last_superframe
+
s
->
last_superframe_len
;
len
=
bit_offset
;
while
(
len
>
7
)
{
*
q
++
=
(
get_bits
)
(
&
s
->
gb
,
8
);
*
q
++
=
bitstream_read
(
&
s
->
bc
,
8
);
len
-=
8
;
}
if
(
len
>
0
)
*
q
++
=
(
get_bits
)
(
&
s
->
gb
,
len
)
<<
(
8
-
len
);
*
q
++
=
bitstream_read
(
&
s
->
bc
,
len
)
<<
(
8
-
len
);
memset
(
q
,
0
,
AV_INPUT_BUFFER_PADDING_SIZE
);
/* XXX: bit_offset bits into last frame */
init_get_bits
(
&
s
->
gb
,
s
->
last_superframe
,
bitstream_init
(
&
s
->
bc
,
s
->
last_superframe
,
s
->
last_superframe_len
*
8
+
bit_offset
);
/* skip unused bits */
if
(
s
->
last_bitoffset
>
0
)
skip_bits
(
&
s
->
gb
,
s
->
last_bitoffset
);
bitstream_skip
(
&
s
->
bc
,
s
->
last_bitoffset
);
/* this frame is stored in the last superframe and in the
* current one */
if
(
wma_decode_frame
(
s
,
samples
,
samples_offset
)
<
0
)
...
...
@@ -870,10 +872,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
pos
=
bit_offset
+
4
+
4
+
s
->
byte_offset_bits
+
3
;
if
(
pos
>=
MAX_CODED_SUPERFRAME_SIZE
*
8
||
pos
>
buf_size
*
8
)
return
AVERROR_INVALIDDATA
;
init_get_bits
(
&
s
->
gb
,
buf
+
(
pos
>>
3
),
(
buf_size
-
(
pos
>>
3
))
*
8
);
bitstream_init8
(
&
s
->
bc
,
buf
+
(
pos
>>
3
),
buf_size
-
(
pos
>>
3
)
);
len
=
pos
&
7
;
if
(
len
>
0
)
skip_bits
(
&
s
->
gb
,
len
);
bitstream_skip
(
&
s
->
bc
,
len
);
s
->
reset_block_lengths
=
1
;
for
(
i
=
0
;
i
<
nb_frames
;
i
++
)
{
...
...
@@ -883,7 +885,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
}
/* we copy the end of the frame in the last frame buffer */
pos
=
get_bits_count
(
&
s
->
gb
)
+
pos
=
bitstream_tell
(
&
s
->
bc
)
+
((
bit_offset
+
4
+
4
+
s
->
byte_offset_bits
+
3
)
&
~
7
);
s
->
last_bitoffset
=
pos
&
7
;
pos
>>=
3
;
...
...
libavcodec/wmalosslessdec.c
View file @
f7ec7f54
...
...
@@ -28,8 +28,8 @@
#include "libavutil/avassert.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
#include "wma.h"
#include "wma_common.h"
...
...
@@ -87,7 +87,7 @@ typedef struct WmallDecodeCtx {
uint16_t
min_samples_per_subframe
;
/* packet decode state */
GetBitContext
pgb
;
///< bitstream reader context for the packet
BitstreamContext
pbc
;
///< bitstream reader context for the packet
int
next_packet_start
;
///< start offset of the next WMA packet in the demuxer packet
uint8_t
packet_offset
;
///< offset to the frame in the packet
uint8_t
packet_sequence_number
;
///< current packet number
...
...
@@ -99,7 +99,7 @@ typedef struct WmallDecodeCtx {
/* frame decode state */
uint32_t
frame_num
;
///< current frame number (not used for decoding)
GetBitContext
gb
;
///< bitstream reader context
BitstreamContext
bc
;
///< bitstream reader context
int
buf_bit_size
;
///< buffer size in bits
int16_t
*
samples_16
[
WMALL_MAX_CHANNELS
];
///< current sample buffer pointer (16-bit)
int32_t
*
samples_32
[
WMALL_MAX_CHANNELS
];
///< current sample buffer pointer (24-bit)
...
...
@@ -286,7 +286,7 @@ static int decode_subframe_length(WmallDecodeCtx *s, int offset)
return
s
->
min_samples_per_subframe
;
len
=
av_log2
(
s
->
max_num_subframes
-
1
)
+
1
;
frame_len_ratio
=
get_bits
(
&
s
->
gb
,
len
);
frame_len_ratio
=
bitstream_read
(
&
s
->
bc
,
len
);
subframe_len
=
s
->
min_samples_per_subframe
*
(
frame_len_ratio
+
1
);
/* sanity check the length */
...
...
@@ -332,7 +332,7 @@ static int decode_tilehdr(WmallDecodeCtx *s)
for
(
c
=
0
;
c
<
s
->
num_channels
;
c
++
)
s
->
channel
[
c
].
num_subframes
=
0
;
tile_aligned
=
get_bits1
(
&
s
->
gb
);
tile_aligned
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
max_num_subframes
==
1
||
tile_aligned
)
fixed_channel_layout
=
1
;
...
...
@@ -347,7 +347,7 @@ static int decode_tilehdr(WmallDecodeCtx *s)
(
min_channel_len
==
s
->
samples_per_frame
-
s
->
min_samples_per_subframe
))
{
contains_subframe
[
c
]
=
in_use
=
1
;
}
else
{
if
(
get_bits1
(
&
s
->
gb
))
if
(
bitstream_read_bit
(
&
s
->
bc
))
contains_subframe
[
c
]
=
in_use
=
1
;
}
}
else
...
...
@@ -407,32 +407,32 @@ static int decode_tilehdr(WmallDecodeCtx *s)
static
void
decode_ac_filter
(
WmallDecodeCtx
*
s
)
{
int
i
;
s
->
acfilter_order
=
get_bits
(
&
s
->
gb
,
4
)
+
1
;
s
->
acfilter_scaling
=
get_bits
(
&
s
->
gb
,
4
);
s
->
acfilter_order
=
bitstream_read
(
&
s
->
bc
,
4
)
+
1
;
s
->
acfilter_scaling
=
bitstream_read
(
&
s
->
bc
,
4
);
for
(
i
=
0
;
i
<
s
->
acfilter_order
;
i
++
)
s
->
acfilter_coeffs
[
i
]
=
get_bitsz
(
&
s
->
gb
,
s
->
acfilter_scaling
)
+
1
;
s
->
acfilter_coeffs
[
i
]
=
bitstream_read
(
&
s
->
bc
,
s
->
acfilter_scaling
)
+
1
;
}
static
void
decode_mclms
(
WmallDecodeCtx
*
s
)
{
s
->
mclms_order
=
(
get_bits
(
&
s
->
gb
,
4
)
+
1
)
*
2
;
s
->
mclms_scaling
=
get_bits
(
&
s
->
gb
,
4
);
if
(
get_bits1
(
&
s
->
gb
))
{
s
->
mclms_order
=
(
bitstream_read
(
&
s
->
bc
,
4
)
+
1
)
*
2
;
s
->
mclms_scaling
=
bitstream_read
(
&
s
->
bc
,
4
);
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
int
i
,
send_coef_bits
;
int
cbits
=
av_log2
(
s
->
mclms_scaling
+
1
);
if
(
1
<<
cbits
<
s
->
mclms_scaling
+
1
)
cbits
++
;
send_coef_bits
=
get_bitsz
(
&
s
->
gb
,
cbits
)
+
2
;
send_coef_bits
=
bitstream_read
(
&
s
->
bc
,
cbits
)
+
2
;
for
(
i
=
0
;
i
<
s
->
mclms_order
*
s
->
num_channels
*
s
->
num_channels
;
i
++
)
s
->
mclms_coeffs
[
i
]
=
get_bits
(
&
s
->
gb
,
send_coef_bits
);
s
->
mclms_coeffs
[
i
]
=
bitstream_read
(
&
s
->
bc
,
send_coef_bits
);
for
(
i
=
0
;
i
<
s
->
num_channels
;
i
++
)
{
int
c
;
for
(
c
=
0
;
c
<
i
;
c
++
)
s
->
mclms_coeffs_cur
[
i
*
s
->
num_channels
+
c
]
=
get_bits
(
&
s
->
gb
,
send_coef_bits
);
s
->
mclms_coeffs_cur
[
i
*
s
->
num_channels
+
c
]
=
bitstream_read
(
&
s
->
bc
,
send_coef_bits
);
}
}
}
...
...
@@ -440,12 +440,12 @@ static void decode_mclms(WmallDecodeCtx *s)
static
int
decode_cdlms
(
WmallDecodeCtx
*
s
)
{
int
c
,
i
;
int
cdlms_send_coef
=
get_bits1
(
&
s
->
gb
);
int
cdlms_send_coef
=
bitstream_read_bit
(
&
s
->
bc
);
for
(
c
=
0
;
c
<
s
->
num_channels
;
c
++
)
{
s
->
cdlms_ttl
[
c
]
=
get_bits
(
&
s
->
gb
,
3
)
+
1
;
s
->
cdlms_ttl
[
c
]
=
bitstream_read
(
&
s
->
bc
,
3
)
+
1
;
for
(
i
=
0
;
i
<
s
->
cdlms_ttl
[
c
];
i
++
)
{
s
->
cdlms
[
c
][
i
].
order
=
(
get_bits
(
&
s
->
gb
,
7
)
+
1
)
*
8
;
s
->
cdlms
[
c
][
i
].
order
=
(
bitstream_read
(
&
s
->
bc
,
7
)
+
1
)
*
8
;
if
(
s
->
cdlms
[
c
][
i
].
order
>
MAX_ORDER
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"Order[%d][%d] %d > max (%d), not supported
\n
"
,
...
...
@@ -456,7 +456,7 @@ static int decode_cdlms(WmallDecodeCtx *s)
}
for
(
i
=
0
;
i
<
s
->
cdlms_ttl
[
c
];
i
++
)
s
->
cdlms
[
c
][
i
].
scaling
=
get_bits
(
&
s
->
gb
,
4
);
s
->
cdlms
[
c
][
i
].
scaling
=
bitstream_read
(
&
s
->
bc
,
4
);
if
(
cdlms_send_coef
)
{
for
(
i
=
0
;
i
<
s
->
cdlms_ttl
[
c
];
i
++
)
{
...
...
@@ -464,18 +464,18 @@ static int decode_cdlms(WmallDecodeCtx *s)
cbits
=
av_log2
(
s
->
cdlms
[
c
][
i
].
order
);
if
((
1
<<
cbits
)
<
s
->
cdlms
[
c
][
i
].
order
)
cbits
++
;
s
->
cdlms
[
c
][
i
].
coefsend
=
get_bits
(
&
s
->
gb
,
cbits
)
+
1
;
s
->
cdlms
[
c
][
i
].
coefsend
=
bitstream_read
(
&
s
->
bc
,
cbits
)
+
1
;
cbits
=
av_log2
(
s
->
cdlms
[
c
][
i
].
scaling
+
1
);
if
((
1
<<
cbits
)
<
s
->
cdlms
[
c
][
i
].
scaling
+
1
)
cbits
++
;
s
->
cdlms
[
c
][
i
].
bitsend
=
get_bitsz
(
&
s
->
gb
,
cbits
)
+
2
;
s
->
cdlms
[
c
][
i
].
bitsend
=
bitstream_read
(
&
s
->
bc
,
cbits
)
+
2
;
shift_l
=
32
-
s
->
cdlms
[
c
][
i
].
bitsend
;
shift_r
=
32
-
s
->
cdlms
[
c
][
i
].
scaling
-
2
;
for
(
j
=
0
;
j
<
s
->
cdlms
[
c
][
i
].
coefsend
;
j
++
)
s
->
cdlms
[
c
][
i
].
coefs
[
j
]
=
(
get_bits
(
&
s
->
gb
,
s
->
cdlms
[
c
][
i
].
bitsend
)
<<
shift_l
)
>>
shift_r
;
(
bitstream_read
(
&
s
->
bc
,
s
->
cdlms
[
c
][
i
].
bitsend
)
<<
shift_l
)
>>
shift_r
;
}
}
}
...
...
@@ -487,9 +487,9 @@ static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
{
int
i
=
0
;
unsigned
int
ave_mean
;
s
->
transient
[
ch
]
=
get_bits1
(
&
s
->
gb
);
s
->
transient
[
ch
]
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
transient
[
ch
])
{
s
->
transient_pos
[
ch
]
=
get_bits
(
&
s
->
gb
,
av_log2
(
tile_size
));
s
->
transient_pos
[
ch
]
=
bitstream_read
(
&
s
->
bc
,
av_log2
(
tile_size
));
if
(
s
->
transient_pos
[
ch
])
s
->
transient
[
ch
]
=
0
;
s
->
channel
[
ch
].
transient_counter
=
...
...
@@ -498,33 +498,33 @@ static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
s
->
transient
[
ch
]
=
1
;
if
(
s
->
seekable_tile
)
{
ave_mean
=
get_bits
(
&
s
->
gb
,
s
->
bits_per_sample
);
ave_mean
=
bitstream_read
(
&
s
->
bc
,
s
->
bits_per_sample
);
s
->
ave_sum
[
ch
]
=
ave_mean
<<
(
s
->
movave_scaling
+
1
);
}
if
(
s
->
seekable_tile
)
{
if
(
s
->
do_inter_ch_decorr
)
s
->
channel_residues
[
ch
][
0
]
=
get_sbits
(
&
s
->
gb
,
s
->
bits_per_sample
+
1
);
s
->
channel_residues
[
ch
][
0
]
=
bitstream_read_signed
(
&
s
->
bc
,
s
->
bits_per_sample
+
1
);
else
s
->
channel_residues
[
ch
][
0
]
=
get_sbits
(
&
s
->
gb
,
s
->
bits_per_sample
);
s
->
channel_residues
[
ch
][
0
]
=
bitstream_read_signed
(
&
s
->
bc
,
s
->
bits_per_sample
);
i
++
;
}
for
(;
i
<
tile_size
;
i
++
)
{
int
quo
=
0
,
rem
,
rem_bits
,
residue
;
while
(
get_bits1
(
&
s
->
gb
))
{
while
(
bitstream_read_bit
(
&
s
->
bc
))
{
quo
++
;
if
(
get_bits_left
(
&
s
->
gb
)
<=
0
)
if
(
bitstream_bits_left
(
&
s
->
bc
)
<=
0
)
return
-
1
;
}
if
(
quo
>=
32
)
quo
+=
get_bits_long
(
&
s
->
gb
,
get_bits
(
&
s
->
gb
,
5
)
+
1
);
quo
+=
bitstream_read
(
&
s
->
bc
,
bitstream_read
(
&
s
->
bc
,
5
)
+
1
);
ave_mean
=
(
s
->
ave_sum
[
ch
]
+
(
1
<<
s
->
movave_scaling
))
>>
(
s
->
movave_scaling
+
1
);
if
(
ave_mean
<=
1
)
residue
=
quo
;
else
{
rem_bits
=
av_ceil_log2
(
ave_mean
);
rem
=
rem_bits
?
get_bits_long
(
&
s
->
gb
,
rem_bits
)
:
0
;
rem
=
rem_bits
?
bitstream_read
(
&
s
->
bc
,
rem_bits
)
:
0
;
residue
=
(
quo
<<
rem_bits
)
+
rem
;
}
...
...
@@ -545,13 +545,13 @@ static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
static
void
decode_lpc
(
WmallDecodeCtx
*
s
)
{
int
ch
,
i
,
cbits
;
s
->
lpc_order
=
get_bits
(
&
s
->
gb
,
5
)
+
1
;
s
->
lpc_scaling
=
get_bits
(
&
s
->
gb
,
4
);
s
->
lpc_intbits
=
get_bits
(
&
s
->
gb
,
3
)
+
1
;
s
->
lpc_order
=
bitstream_read
(
&
s
->
bc
,
5
)
+
1
;
s
->
lpc_scaling
=
bitstream_read
(
&
s
->
bc
,
4
);
s
->
lpc_intbits
=
bitstream_read
(
&
s
->
bc
,
3
)
+
1
;
cbits
=
s
->
lpc_scaling
+
s
->
lpc_intbits
;
for
(
ch
=
0
;
ch
<
s
->
num_channels
;
ch
++
)
for
(
i
=
0
;
i
<
s
->
lpc_order
;
i
++
)
s
->
lpc_coefs
[
ch
][
i
]
=
get_sbits
(
&
s
->
gb
,
cbits
);
s
->
lpc_coefs
[
ch
][
i
]
=
bitstream_read_signed
(
&
s
->
bc
,
cbits
);
}
static
void
clear_codec_buffers
(
WmallDecodeCtx
*
s
)
...
...
@@ -846,7 +846,7 @@ static int decode_subframe(WmallDecodeCtx *s)
int
total_samples
=
s
->
samples_per_frame
*
s
->
num_channels
;
int
i
,
j
,
rawpcm_tile
,
padding_zeroes
,
res
;
s
->
subframe_offset
=
get_bits_count
(
&
s
->
gb
);
s
->
subframe_offset
=
bitstream_tell
(
&
s
->
bc
);
/* reset channel context and find the next block offset and size
== the next block of the channel with the smallest number of
...
...
@@ -883,18 +883,18 @@ static int decode_subframe(WmallDecodeCtx *s)
s
->
parsed_all_subframes
=
1
;
s
->
seekable_tile
=
get_bits1
(
&
s
->
gb
);
s
->
seekable_tile
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
seekable_tile
)
{
clear_codec_buffers
(
s
);
s
->
do_arith_coding
=
get_bits1
(
&
s
->
gb
);
s
->
do_arith_coding
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
do_arith_coding
)
{
avpriv_request_sample
(
s
->
avctx
,
"Arithmetic coding"
);
return
AVERROR_PATCHWELCOME
;
}
s
->
do_ac_filter
=
get_bits1
(
&
s
->
gb
);
s
->
do_inter_ch_decorr
=
get_bits1
(
&
s
->
gb
);
s
->
do_mclms
=
get_bits1
(
&
s
->
gb
);
s
->
do_ac_filter
=
bitstream_read_bit
(
&
s
->
bc
);
s
->
do_inter_ch_decorr
=
bitstream_read_bit
(
&
s
->
bc
);
s
->
do_mclms
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
do_ac_filter
)
decode_ac_filter
(
s
);
...
...
@@ -904,8 +904,8 @@ static int decode_subframe(WmallDecodeCtx *s)
if
((
res
=
decode_cdlms
(
s
))
<
0
)
return
res
;
s
->
movave_scaling
=
get_bits
(
&
s
->
gb
,
3
);
s
->
quant_stepsize
=
get_bits
(
&
s
->
gb
,
8
)
+
1
;
s
->
movave_scaling
=
bitstream_read
(
&
s
->
bc
,
3
);
s
->
quant_stepsize
=
bitstream_read
(
&
s
->
bc
,
8
)
+
1
;
reset_codec
(
s
);
}
else
if
(
!
s
->
cdlms
[
0
][
0
].
order
)
{
...
...
@@ -915,18 +915,18 @@ static int decode_subframe(WmallDecodeCtx *s)
return
-
1
;
}
rawpcm_tile
=
get_bits1
(
&
s
->
gb
);
rawpcm_tile
=
bitstream_read_bit
(
&
s
->
bc
);
for
(
i
=
0
;
i
<
s
->
num_channels
;
i
++
)
s
->
is_channel_coded
[
i
]
=
1
;
if
(
!
rawpcm_tile
)
{
for
(
i
=
0
;
i
<
s
->
num_channels
;
i
++
)
s
->
is_channel_coded
[
i
]
=
get_bits1
(
&
s
->
gb
);
s
->
is_channel_coded
[
i
]
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
bV3RTM
)
{
// LPC
s
->
do_lpc
=
get_bits1
(
&
s
->
gb
);
s
->
do_lpc
=
bitstream_read_bit
(
&
s
->
bc
);
if
(
s
->
do_lpc
)
{
decode_lpc
(
s
);
avpriv_request_sample
(
s
->
avctx
,
"Expect wrong output since "
...
...
@@ -937,8 +937,8 @@ static int decode_subframe(WmallDecodeCtx *s)
}
if
(
get_bits1
(
&
s
->
gb
))
padding_zeroes
=
get_bits
(
&
s
->
gb
,
5
);
if
(
bitstream_read_bit
(
&
s
->
bc
))
padding_zeroes
=
bitstream_read
(
&
s
->
bc
,
5
);
else
padding_zeroes
=
0
;
...
...
@@ -951,10 +951,10 @@ static int decode_subframe(WmallDecodeCtx *s)
}
ff_dlog
(
s
->
avctx
,
"RAWPCM %d bits per sample. "
"total %d bits, remain=%d
\n
"
,
bits
,
bits
*
s
->
num_channels
*
subframe_len
,
get_bits_count
(
&
s
->
gb
));
bits
*
s
->
num_channels
*
subframe_len
,
bitstream_tell
(
&
s
->
bc
));
for
(
i
=
0
;
i
<
s
->
num_channels
;
i
++
)
for
(
j
=
0
;
j
<
subframe_len
;
j
++
)
s
->
channel_coeffs
[
i
][
j
]
=
get_sbits
(
&
s
->
gb
,
bits
);
s
->
channel_coeffs
[
i
][
j
]
=
bitstream_read_signed
(
&
s
->
bc
,
bits
);
}
else
{
for
(
i
=
0
;
i
<
s
->
num_channels
;
i
++
)
if
(
s
->
is_channel_coded
[
i
])
{
...
...
@@ -1015,7 +1015,7 @@ static int decode_subframe(WmallDecodeCtx *s)
*/
static
int
decode_frame
(
WmallDecodeCtx
*
s
)
{
GetBitContext
*
gb
=
&
s
->
gb
;
BitstreamContext
*
bc
=
&
s
->
bc
;
int
more_frames
=
0
,
len
=
0
,
i
,
ret
;
s
->
frame
->
nb_samples
=
s
->
samples_per_frame
;
...
...
@@ -1033,7 +1033,7 @@ static int decode_frame(WmallDecodeCtx *s)
/* get frame length */
if
(
s
->
len_prefix
)
len
=
get_bits
(
gb
,
s
->
log2_frame_size
);
len
=
bitstream_read
(
bc
,
s
->
log2_frame_size
);
/* decode tile information */
if
(
decode_tilehdr
(
s
))
{
...
...
@@ -1043,22 +1043,22 @@ static int decode_frame(WmallDecodeCtx *s)
/* read drc info */
if
(
s
->
dynamic_range_compression
)
s
->
drc_gain
=
get_bits
(
gb
,
8
);
s
->
drc_gain
=
bitstream_read
(
bc
,
8
);
/* no idea what these are for, might be the number of samples
that need to be skipped at the beginning or end of a stream */
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
int
av_unused
skip
;
/* usually true for the first frame */
if
(
get_bits1
(
gb
))
{
skip
=
get_bits
(
gb
,
av_log2
(
s
->
samples_per_frame
*
2
));
if
(
bitstream_read_bit
(
bc
))
{
skip
=
bitstream_read
(
bc
,
av_log2
(
s
->
samples_per_frame
*
2
));
ff_dlog
(
s
->
avctx
,
"start skip: %i
\n
"
,
skip
);
}
/* sometimes true for the last frame */
if
(
get_bits1
(
gb
))
{
skip
=
get_bits
(
gb
,
av_log2
(
s
->
samples_per_frame
*
2
));
if
(
bitstream_read_bit
(
bc
))
{
skip
=
bitstream_read
(
bc
,
av_log2
(
s
->
samples_per_frame
*
2
));
ff_dlog
(
s
->
avctx
,
"end skip: %i
\n
"
,
skip
);
}
...
...
@@ -1085,22 +1085,22 @@ static int decode_frame(WmallDecodeCtx *s)
s
->
skip_frame
=
0
;
if
(
s
->
len_prefix
)
{
if
(
len
!=
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
+
2
)
{
if
(
len
!=
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
+
2
)
{
/* FIXME: not sure if this is always an error */
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"frame[%"
PRIu32
"] would have to skip %i bits
\n
"
,
s
->
frame_num
,
len
-
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
-
1
);
len
-
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
-
1
);
s
->
packet_loss
=
1
;
return
0
;
}
/* skip the rest of the frame data */
skip_bits_long
(
gb
,
len
-
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
-
1
);
bitstream_skip
(
bc
,
len
-
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
-
1
);
}
/* decode trailer bit */
more_frames
=
get_bits1
(
gb
);
more_frames
=
bitstream_read_bit
(
bc
);
++
s
->
frame_num
;
return
more_frames
;
}
...
...
@@ -1108,22 +1108,22 @@ static int decode_frame(WmallDecodeCtx *s)
/**
* @brief Calculate remaining input buffer length.
* @param s codec context
* @param
gb
bitstream reader context
* @param
bc
bitstream reader context
* @return remaining size in bits
*/
static
int
remaining_bits
(
WmallDecodeCtx
*
s
,
GetBitContext
*
gb
)
static
int
remaining_bits
(
WmallDecodeCtx
*
s
,
BitstreamContext
*
bc
)
{
return
s
->
buf_bit_size
-
get_bits_count
(
gb
);
return
s
->
buf_bit_size
-
bitstream_tell
(
bc
);
}
/**
* @brief Fill the bit reservoir with a (partial) frame.
* @param s codec context
* @param
gb
bitstream reader context
* @param
bc
bitstream reader context
* @param len length of the partial frame
* @param append decides whether to reset the buffer or not
*/
static
void
save_bits
(
WmallDecodeCtx
*
s
,
GetBitContext
*
gb
,
int
len
,
static
void
save_bits
(
WmallDecodeCtx
*
s
,
BitstreamContext
*
bc
,
int
len
,
int
append
)
{
int
buflen
;
...
...
@@ -1134,7 +1134,7 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
and skipped later so that a fast byte copy is possible */
if
(
!
append
)
{
s
->
frame_offset
=
get_bits_count
(
gb
)
&
7
;
s
->
frame_offset
=
bitstream_tell
(
bc
)
&
7
;
s
->
num_saved_bits
=
s
->
frame_offset
;
init_put_bits
(
&
s
->
pb
,
s
->
frame_data
,
MAX_FRAMESIZE
);
}
...
...
@@ -1149,29 +1149,29 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
s
->
num_saved_bits
+=
len
;
if
(
!
append
)
{
avpriv_copy_bits
(
&
s
->
pb
,
gb
->
buffer
+
(
get_bits_count
(
gb
)
>>
3
),
avpriv_copy_bits
(
&
s
->
pb
,
bc
->
buffer
+
(
bitstream_tell
(
bc
)
>>
3
),
s
->
num_saved_bits
);
}
else
{
int
align
=
8
-
(
get_bits_count
(
gb
)
&
7
);
int
align
=
8
-
(
bitstream_tell
(
bc
)
&
7
);
align
=
FFMIN
(
align
,
len
);
put_bits
(
&
s
->
pb
,
align
,
get_bits
(
gb
,
align
));
put_bits
(
&
s
->
pb
,
align
,
bitstream_read
(
bc
,
align
));
len
-=
align
;
avpriv_copy_bits
(
&
s
->
pb
,
gb
->
buffer
+
(
get_bits_count
(
gb
)
>>
3
),
len
);
avpriv_copy_bits
(
&
s
->
pb
,
bc
->
buffer
+
(
bitstream_tell
(
bc
)
>>
3
),
len
);
}
skip_bits_long
(
gb
,
len
);
bitstream_skip
(
bc
,
len
);
tmp
=
s
->
pb
;
flush_put_bits
(
&
tmp
);
init_get_bits
(
&
s
->
gb
,
s
->
frame_data
,
s
->
num_saved_bits
);
skip_bits
(
&
s
->
gb
,
s
->
frame_offset
);
bitstream_init
(
&
s
->
bc
,
s
->
frame_data
,
s
->
num_saved_bits
);
bitstream_skip
(
&
s
->
bc
,
s
->
frame_offset
);
}
static
int
decode_packet
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
got_frame_ptr
,
AVPacket
*
avpkt
)
{
WmallDecodeCtx
*
s
=
avctx
->
priv_data
;
GetBitContext
*
gb
=
&
s
->
pgb
;
BitstreamContext
*
bc
=
&
s
->
pbc
;
const
uint8_t
*
buf
=
avpkt
->
data
;
int
buf_size
=
avpkt
->
size
;
int
num_bits_prev_frame
,
packet_sequence_number
,
spliced_packet
;
...
...
@@ -1190,15 +1190,15 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
s
->
buf_bit_size
=
buf_size
<<
3
;
/* parse packet header */
init_get_bits
(
gb
,
buf
,
s
->
buf_bit_size
);
packet_sequence_number
=
get_bits
(
gb
,
4
);
skip_bits
(
gb
,
1
);
// Skip seekable_frame_in_packet, currently
unused
spliced_packet
=
get_bits1
(
gb
);
bitstream_init
(
bc
,
buf
,
s
->
buf_bit_size
);
packet_sequence_number
=
bitstream_read
(
bc
,
4
);
bitstream_skip
(
bc
,
1
);
// Skip seekable_frame_in_packet, currently un
unused
spliced_packet
=
bitstream_read_bit
(
bc
);
if
(
spliced_packet
)
avpriv_request_sample
(
avctx
,
"Bitstream splicing"
);
/* get number of bits that need to be added to the previous frame */
num_bits_prev_frame
=
get_bits
(
gb
,
s
->
log2_frame_size
);
num_bits_prev_frame
=
bitstream_read
(
bc
,
s
->
log2_frame_size
);
/* check for packet loss */
if
(
!
s
->
packet_loss
&&
...
...
@@ -1211,7 +1211,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
s
->
packet_sequence_number
=
packet_sequence_number
;
if
(
num_bits_prev_frame
>
0
)
{
int
remaining_packet_bits
=
s
->
buf_bit_size
-
get_bits_count
(
gb
);
int
remaining_packet_bits
=
s
->
buf_bit_size
-
bitstream_tell
(
bc
);
if
(
num_bits_prev_frame
>=
remaining_packet_bits
)
{
num_bits_prev_frame
=
remaining_packet_bits
;
s
->
packet_done
=
1
;
...
...
@@ -1219,7 +1219,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
/* Append the previous frame data to the remaining data from the
* previous packet to create a full frame. */
save_bits
(
s
,
gb
,
num_bits_prev_frame
,
1
);
save_bits
(
s
,
bc
,
num_bits_prev_frame
,
1
);
/* decode the cross packet frame if it is valid */
if
(
num_bits_prev_frame
<
remaining_packet_bits
&&
!
s
->
packet_loss
)
...
...
@@ -1241,16 +1241,16 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
int
frame_size
;
s
->
buf_bit_size
=
(
avpkt
->
size
-
s
->
next_packet_start
)
<<
3
;
init_get_bits
(
gb
,
avpkt
->
data
,
s
->
buf_bit_size
);
skip_bits
(
gb
,
s
->
packet_offset
);
bitstream_init
(
bc
,
avpkt
->
data
,
s
->
buf_bit_size
);
bitstream_skip
(
bc
,
s
->
packet_offset
);
if
(
s
->
len_prefix
&&
remaining_bits
(
s
,
gb
)
>
s
->
log2_frame_size
&&
(
frame_size
=
show_bits
(
gb
,
s
->
log2_frame_size
))
&&
frame_size
<=
remaining_bits
(
s
,
gb
))
{
save_bits
(
s
,
gb
,
frame_size
,
0
);
if
(
s
->
len_prefix
&&
remaining_bits
(
s
,
bc
)
>
s
->
log2_frame_size
&&
(
frame_size
=
bitstream_peek
(
bc
,
s
->
log2_frame_size
))
&&
frame_size
<=
remaining_bits
(
s
,
bc
))
{
save_bits
(
s
,
bc
,
frame_size
,
0
);
s
->
packet_done
=
!
decode_frame
(
s
);
}
else
if
(
!
s
->
len_prefix
&&
s
->
num_saved_bits
>
get_bits_count
(
&
s
->
gb
))
{
&&
s
->
num_saved_bits
>
bitstream_tell
(
&
s
->
bc
))
{
/* when the frames do not have a length prefix, we don't know the
* compressed length of the individual frames however, we know what
* part of a new packet belongs to the previous frame therefore we
...
...
@@ -1264,18 +1264,18 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
}
if
(
s
->
packet_done
&&
!
s
->
packet_loss
&&
remaining_bits
(
s
,
gb
)
>
0
)
{
remaining_bits
(
s
,
bc
)
>
0
)
{
/* save the rest of the data so that it can be decoded
* with the next packet */
save_bits
(
s
,
gb
,
remaining_bits
(
s
,
gb
),
0
);
save_bits
(
s
,
bc
,
remaining_bits
(
s
,
bc
),
0
);
}
*
got_frame_ptr
=
s
->
frame
->
nb_samples
>
0
;
av_frame_move_ref
(
data
,
s
->
frame
);
s
->
packet_offset
=
get_bits_count
(
gb
)
&
7
;
s
->
packet_offset
=
bitstream_tell
(
bc
)
&
7
;
return
(
s
->
packet_loss
)
?
AVERROR_INVALIDDATA
:
get_bits_count
(
gb
)
>>
3
;
return
(
s
->
packet_loss
)
?
AVERROR_INVALIDDATA
:
bitstream_tell
(
bc
)
>>
3
;
}
static
void
flush
(
AVCodecContext
*
avctx
)
...
...
libavcodec/wmaprodec.c
View file @
f7ec7f54
...
...
@@ -91,9 +91,10 @@
#include "libavutil/float_dsp.h"
#include "libavutil/intfloat.h"
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
#include "wmaprodata.h"
#include "sinewin.h"
...
...
@@ -197,7 +198,7 @@ typedef struct WMAProDecodeCtx {
int16_t
subwoofer_cutoffs
[
WMAPRO_BLOCK_SIZES
];
///< subwoofer cutoff values
/* packet decode state */
GetBitContext
pgb
;
///< bitstream reader context for the packet
BitstreamContext
pbc
;
///< bitstream reader context for the packet
int
next_packet_start
;
///< start offset of the next wma packet in the demuxer packet
uint8_t
packet_offset
;
///< frame offset in the packet
uint8_t
packet_sequence_number
;
///< current packet number
...
...
@@ -209,7 +210,7 @@ typedef struct WMAProDecodeCtx {
/* frame decode state */
uint32_t
frame_num
;
///< current frame number (not used for decoding)
GetBitContext
gb
;
///< bitstream reader context
BitstreamContext
bc
;
///< bitstream reader context
int
buf_bit_size
;
///< buffer size in bits
uint8_t
drc_gain
;
///< gain for the DRC tool
int8_t
skip_frame
;
///< skip output step
...
...
@@ -495,10 +496,11 @@ static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
/** 1 bit indicates if the subframe is of maximum length */
if
(
s
->
max_subframe_len_bit
)
{
if
(
get_bits1
(
&
s
->
gb
))
frame_len_shift
=
1
+
get_bits
(
&
s
->
gb
,
s
->
subframe_len_bits
-
1
);
if
(
bitstream_read_bit
(
&
s
->
bc
))
frame_len_shift
=
1
+
bitstream_read
(
&
s
->
bc
,
s
->
subframe_len_bits
-
1
);
}
else
frame_len_shift
=
get_bits
(
&
s
->
gb
,
s
->
subframe_len_bits
);
frame_len_shift
=
bitstream_read
(
&
s
->
bc
,
s
->
subframe_len_bits
);
subframe_len
=
s
->
samples_per_frame
>>
frame_len_shift
;
...
...
@@ -551,7 +553,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
for
(
c
=
0
;
c
<
s
->
avctx
->
channels
;
c
++
)
s
->
channel
[
c
].
num_subframes
=
0
;
if
(
s
->
max_num_subframes
==
1
||
get_bits1
(
&
s
->
gb
))
if
(
s
->
max_num_subframes
==
1
||
bitstream_read_bit
(
&
s
->
bc
))
fixed_channel_layout
=
1
;
/** loop until the frame data is split between the subframes */
...
...
@@ -565,7 +567,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
(
min_channel_len
==
s
->
samples_per_frame
-
s
->
min_samples_per_subframe
))
contains_subframe
[
c
]
=
1
;
else
contains_subframe
[
c
]
=
get_bits1
(
&
s
->
gb
);
contains_subframe
[
c
]
=
bitstream_read_bit
(
&
s
->
bc
);
}
else
contains_subframe
[
c
]
=
0
;
}
...
...
@@ -633,11 +635,11 @@ static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
s
->
avctx
->
channels
*
sizeof
(
*
chgroup
->
decorrelation_matrix
));
for
(
i
=
0
;
i
<
chgroup
->
num_channels
*
(
chgroup
->
num_channels
-
1
)
>>
1
;
i
++
)
rotation_offset
[
i
]
=
get_bits
(
&
s
->
gb
,
6
);
rotation_offset
[
i
]
=
bitstream_read
(
&
s
->
bc
,
6
);
for
(
i
=
0
;
i
<
chgroup
->
num_channels
;
i
++
)
chgroup
->
decorrelation_matrix
[
chgroup
->
num_channels
*
i
+
i
]
=
get_bits1
(
&
s
->
gb
)
?
1
.
0
:
-
1
.
0
;
bitstream_read_bit
(
&
s
->
bc
)
?
1
.
0
:
-
1
.
0
;
for
(
i
=
1
;
i
<
chgroup
->
num_channels
;
i
++
)
{
int
x
;
...
...
@@ -686,7 +688,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
if
(
s
->
avctx
->
channels
>
1
)
{
int
remaining_channels
=
s
->
channels_for_cur_subframe
;
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
avpriv_request_sample
(
s
->
avctx
,
"Channel transform bit"
);
return
AVERROR_PATCHWELCOME
;
...
...
@@ -704,7 +706,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
for
(
i
=
0
;
i
<
s
->
channels_for_cur_subframe
;
i
++
)
{
int
channel_idx
=
s
->
channel_indexes_for_cur_subframe
[
i
];
if
(
!
s
->
channel
[
channel_idx
].
grouped
&&
get_bits1
(
&
s
->
gb
))
{
&&
bitstream_read_bit
(
&
s
->
bc
))
{
++
chgroup
->
num_channels
;
s
->
channel
[
channel_idx
].
grouped
=
1
;
*
channel_data
++
=
s
->
channel
[
channel_idx
].
coeffs
;
...
...
@@ -722,8 +724,8 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
/** decode transform type */
if
(
chgroup
->
num_channels
==
2
)
{
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
avpriv_request_sample
(
s
->
avctx
,
"Unknown channel transform type"
);
return
AVERROR_PATCHWELCOME
;
...
...
@@ -744,9 +746,9 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
}
}
}
else
if
(
chgroup
->
num_channels
>
2
)
{
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
chgroup
->
transform
=
1
;
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
decode_decorrelation_matrix
(
s
,
chgroup
);
}
else
{
/** FIXME: more than 6 coupled channels not supported */
...
...
@@ -765,11 +767,11 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
/** decode transform on / off */
if
(
chgroup
->
transform
)
{
if
(
!
get_bits1
(
&
s
->
gb
))
{
if
(
!
bitstream_read_bit
(
&
s
->
bc
))
{
int
i
;
/** transform can be enabled for individual bands */
for
(
i
=
0
;
i
<
s
->
num_bands
;
i
++
)
{
chgroup
->
transform_band
[
i
]
=
get_bits1
(
&
s
->
gb
);
chgroup
->
transform_band
[
i
]
=
bitstream_read_bit
(
&
s
->
bc
);
}
}
else
{
memset
(
chgroup
->
transform_band
,
1
,
s
->
num_bands
);
...
...
@@ -809,7 +811,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
ff_dlog
(
s
->
avctx
,
"decode coefficients for channel %i
\n
"
,
c
);
vlctable
=
get_bits1
(
&
s
->
gb
);
vlctable
=
bitstream_read_bit
(
&
s
->
bc
);
vlc
=
&
coef_vlc
[
vlctable
];
if
(
vlctable
)
{
...
...
@@ -828,19 +830,19 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
int
i
;
unsigned
int
idx
;
idx
=
get_vlc2
(
&
s
->
gb
,
vec4_vlc
.
table
,
VLCBITS
,
VEC4MAXDEPTH
);
idx
=
bitstream_read_vlc
(
&
s
->
bc
,
vec4_vlc
.
table
,
VLCBITS
,
VEC4MAXDEPTH
);
if
(
idx
==
HUFF_VEC4_SIZE
-
1
)
{
for
(
i
=
0
;
i
<
4
;
i
+=
2
)
{
idx
=
get_vlc2
(
&
s
->
gb
,
vec2_vlc
.
table
,
VLCBITS
,
VEC2MAXDEPTH
);
idx
=
bitstream_read_vlc
(
&
s
->
bc
,
vec2_vlc
.
table
,
VLCBITS
,
VEC2MAXDEPTH
);
if
(
idx
==
HUFF_VEC2_SIZE
-
1
)
{
uint32_t
v0
,
v1
;
v0
=
get_vlc2
(
&
s
->
gb
,
vec1_vlc
.
table
,
VLCBITS
,
VEC1MAXDEPTH
);
v0
=
bitstream_read_vlc
(
&
s
->
bc
,
vec1_vlc
.
table
,
VLCBITS
,
VEC1MAXDEPTH
);
if
(
v0
==
HUFF_VEC1_SIZE
-
1
)
v0
+=
ff_wma_get_large_val
(
&
s
->
gb
);
v1
=
get_vlc2
(
&
s
->
gb
,
vec1_vlc
.
table
,
VLCBITS
,
VEC1MAXDEPTH
);
v0
+=
ff_wma_get_large_val
(
&
s
->
bc
);
v1
=
bitstream_read_vlc
(
&
s
->
bc
,
vec1_vlc
.
table
,
VLCBITS
,
VEC1MAXDEPTH
);
if
(
v1
==
HUFF_VEC1_SIZE
-
1
)
v1
+=
ff_wma_get_large_val
(
&
s
->
gb
);
v1
+=
ff_wma_get_large_val
(
&
s
->
bc
);
vals
[
i
]
=
av_float2int
(
v0
);
vals
[
i
+
1
]
=
av_float2int
(
v1
);
}
else
{
...
...
@@ -858,7 +860,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
/** decode sign */
for
(
i
=
0
;
i
<
4
;
i
++
)
{
if
(
vals
[
i
])
{
uint32_t
sign
=
get_bits1
(
&
s
->
gb
)
-
1
;
uint32_t
sign
=
bitstream_read_bit
(
&
s
->
bc
)
-
1
;
AV_WN32A
(
&
ci
->
coeffs
[
cur_coeff
],
vals
[
i
]
^
sign
<<
31
);
num_zeros
=
0
;
}
else
{
...
...
@@ -875,7 +877,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
if
(
cur_coeff
<
s
->
subframe_len
)
{
memset
(
&
ci
->
coeffs
[
cur_coeff
],
0
,
sizeof
(
*
ci
->
coeffs
)
*
(
s
->
subframe_len
-
cur_coeff
));
if
(
ff_wma_run_level_decode
(
s
->
avctx
,
&
s
->
gb
,
vlc
,
if
(
ff_wma_run_level_decode
(
s
->
avctx
,
&
s
->
bc
,
vlc
,
level
,
run
,
1
,
ci
->
coeffs
,
cur_coeff
,
s
->
subframe_len
,
s
->
subframe_len
,
s
->
esc_len
,
0
))
...
...
@@ -918,15 +920,14 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
s
->
channel
[
c
].
saved_scale_factors
[
s
->
channel
[
c
].
scale_factor_idx
][
*
sf_offsets
++
];
}
if
(
!
s
->
channel
[
c
].
cur_subframe
||
get_bits1
(
&
s
->
gb
))
{
if
(
!
s
->
channel
[
c
].
cur_subframe
||
bitstream_read_bit
(
&
s
->
bc
))
{
if
(
!
s
->
channel
[
c
].
reuse_sf
)
{
int
val
;
/** decode DPCM coded scale factors */
s
->
channel
[
c
].
scale_factor_step
=
get_bits
(
&
s
->
gb
,
2
)
+
1
;
s
->
channel
[
c
].
scale_factor_step
=
bitstream_read
(
&
s
->
bc
,
2
)
+
1
;
val
=
45
/
s
->
channel
[
c
].
scale_factor_step
;
for
(
sf
=
s
->
channel
[
c
].
scale_factors
;
sf
<
sf_end
;
sf
++
)
{
val
+=
get_vlc2
(
&
s
->
gb
,
sf_vlc
.
table
,
SCALEVLCBITS
,
SCALEMAXDEPTH
)
-
60
;
val
+=
bitstream_read_vlc
(
&
s
->
bc
,
sf_vlc
.
table
,
SCALEVLCBITS
,
SCALEMAXDEPTH
)
-
60
;
*
sf
=
val
;
}
}
else
{
...
...
@@ -938,10 +939,10 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
int
val
;
int
sign
;
idx
=
get_vlc2
(
&
s
->
gb
,
sf_rl_vlc
.
table
,
VLCBITS
,
SCALERLMAXDEPTH
);
idx
=
bitstream_read_vlc
(
&
s
->
bc
,
sf_rl_vlc
.
table
,
VLCBITS
,
SCALERLMAXDEPTH
);
if
(
!
idx
)
{
uint32_t
code
=
get_bits
(
&
s
->
gb
,
14
);
uint32_t
code
=
bitstream_read
(
&
s
->
bc
,
14
);
val
=
code
>>
6
;
sign
=
(
code
&
1
)
-
1
;
skip
=
(
code
&
0x3f
)
>>
1
;
...
...
@@ -950,7 +951,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
}
else
{
skip
=
scale_rl_run
[
idx
];
val
=
scale_rl_level
[
idx
];
sign
=
get_bits1
(
&
s
->
gb
)
-
1
;
sign
=
bitstream_read_bit
(
&
s
->
bc
)
-
1
;
}
i
+=
skip
;
...
...
@@ -1077,7 +1078,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
int
transmit_coeffs
=
0
;
int
cur_subwoofer_cutoff
;
s
->
subframe_offset
=
get_bits_count
(
&
s
->
gb
);
s
->
subframe_offset
=
bitstream_tell
(
&
s
->
bc
);
/** reset channel context and find the next block offset and size
== the next block of the channel with the smallest number of
...
...
@@ -1141,25 +1142,25 @@ static int decode_subframe(WMAProDecodeCtx *s)
s
->
esc_len
=
av_log2
(
s
->
subframe_len
-
1
)
+
1
;
/** skip extended header if any */
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
int
num_fill_bits
;
if
(
!
(
num_fill_bits
=
get_bits
(
&
s
->
gb
,
2
)))
{
int
len
=
get_bits
(
&
s
->
gb
,
4
);
num_fill_bits
=
get_bitsz
(
&
s
->
gb
,
len
)
+
1
;
if
(
!
(
num_fill_bits
=
bitstream_read
(
&
s
->
bc
,
2
)))
{
int
len
=
bitstream_read
(
&
s
->
bc
,
4
);
num_fill_bits
=
bitstream_read
(
&
s
->
bc
,
len
)
+
1
;
}
if
(
num_fill_bits
>=
0
)
{
if
(
get_bits_count
(
&
s
->
gb
)
+
num_fill_bits
>
s
->
num_saved_bits
)
{
if
(
bitstream_tell
(
&
s
->
bc
)
+
num_fill_bits
>
s
->
num_saved_bits
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"invalid number of fill bits
\n
"
);
return
AVERROR_INVALIDDATA
;
}
skip_bits_long
(
&
s
->
gb
,
num_fill_bits
);
bitstream_skip
(
&
s
->
bc
,
num_fill_bits
);
}
}
/** no idea for what the following bit is used */
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
avpriv_request_sample
(
s
->
avctx
,
"Reserved bit"
);
return
AVERROR_PATCHWELCOME
;
}
...
...
@@ -1171,7 +1172,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
for
(
i
=
0
;
i
<
s
->
channels_for_cur_subframe
;
i
++
)
{
int
c
=
s
->
channel_indexes_for_cur_subframe
[
i
];
if
((
s
->
channel
[
c
].
transmit_coefs
=
get_bits1
(
&
s
->
gb
)))
if
((
s
->
channel
[
c
].
transmit_coefs
=
bitstream_read_bit
(
&
s
->
bc
)))
transmit_coeffs
=
1
;
}
...
...
@@ -1180,11 +1181,11 @@ static int decode_subframe(WMAProDecodeCtx *s)
int
quant_step
=
90
*
s
->
bits_per_sample
>>
4
;
/** decode number of vector coded coefficients */
if
((
s
->
transmit_num_vec_coeffs
=
get_bits1
(
&
s
->
gb
)))
{
if
((
s
->
transmit_num_vec_coeffs
=
bitstream_read_bit
(
&
s
->
bc
)))
{
int
num_bits
=
av_log2
((
s
->
subframe_len
+
3
)
/
4
)
+
1
;
for
(
i
=
0
;
i
<
s
->
channels_for_cur_subframe
;
i
++
)
{
int
c
=
s
->
channel_indexes_for_cur_subframe
[
i
];
int
num_vec_coeffs
=
get_bits
(
&
s
->
gb
,
num_bits
)
<<
2
;
int
num_vec_coeffs
=
bitstream_read
(
&
s
->
bc
,
num_bits
)
<<
2
;
if
(
num_vec_coeffs
+
offset
>
FF_ARRAY_ELEMS
(
s
->
channel
[
c
].
out
))
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"num_vec_coeffs %d is too large
\n
"
,
num_vec_coeffs
);
return
AVERROR_INVALIDDATA
;
...
...
@@ -1198,13 +1199,13 @@ static int decode_subframe(WMAProDecodeCtx *s)
}
}
/** decode quantization step */
step
=
get_sbits
(
&
s
->
gb
,
6
);
step
=
bitstream_read_signed
(
&
s
->
bc
,
6
);
quant_step
+=
step
;
if
(
step
==
-
32
||
step
==
31
)
{
const
int
sign
=
(
step
==
31
)
-
1
;
int
quant
=
0
;
while
(
get_bits_count
(
&
s
->
gb
)
+
5
<
s
->
num_saved_bits
&&
(
step
=
get_bits
(
&
s
->
gb
,
5
))
==
31
)
{
while
(
bitstream_tell
(
&
s
->
bc
)
+
5
<
s
->
num_saved_bits
&&
(
step
=
bitstream_read
(
&
s
->
bc
,
5
))
==
31
)
{
quant
+=
31
;
}
quant_step
+=
((
quant
+
step
)
^
sign
)
-
sign
;
...
...
@@ -1218,13 +1219,13 @@ static int decode_subframe(WMAProDecodeCtx *s)
if
(
s
->
channels_for_cur_subframe
==
1
)
{
s
->
channel
[
s
->
channel_indexes_for_cur_subframe
[
0
]].
quant_step
=
quant_step
;
}
else
{
int
modifier_len
=
get_bits
(
&
s
->
gb
,
3
);
int
modifier_len
=
bitstream_read
(
&
s
->
bc
,
3
);
for
(
i
=
0
;
i
<
s
->
channels_for_cur_subframe
;
i
++
)
{
int
c
=
s
->
channel_indexes_for_cur_subframe
[
i
];
s
->
channel
[
c
].
quant_step
=
quant_step
;
if
(
get_bits1
(
&
s
->
gb
))
{
if
(
bitstream_read_bit
(
&
s
->
bc
))
{
if
(
modifier_len
)
{
s
->
channel
[
c
].
quant_step
+=
get_bits
(
&
s
->
gb
,
modifier_len
)
+
1
;
s
->
channel
[
c
].
quant_step
+=
bitstream_read
(
&
s
->
bc
,
modifier_len
)
+
1
;
}
else
++
s
->
channel
[
c
].
quant_step
;
}
...
...
@@ -1237,13 +1238,13 @@ static int decode_subframe(WMAProDecodeCtx *s)
}
ff_dlog
(
s
->
avctx
,
"BITSTREAM: subframe header length was %i
\n
"
,
get_bits_count
(
&
s
->
gb
)
-
s
->
subframe_offset
);
bitstream_tell
(
&
s
->
bc
)
-
s
->
subframe_offset
);
/** parse coefficients */
for
(
i
=
0
;
i
<
s
->
channels_for_cur_subframe
;
i
++
)
{
int
c
=
s
->
channel_indexes_for_cur_subframe
[
i
];
if
(
s
->
channel
[
c
].
transmit_coefs
&&
get_bits_count
(
&
s
->
gb
)
<
s
->
num_saved_bits
)
{
bitstream_tell
(
&
s
->
bc
)
<
s
->
num_saved_bits
)
{
decode_coeffs
(
s
,
c
);
}
else
memset
(
s
->
channel
[
c
].
coeffs
,
0
,
...
...
@@ -1251,7 +1252,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
}
ff_dlog
(
s
->
avctx
,
"BITSTREAM: subframe length was %i
\n
"
,
get_bits_count
(
&
s
->
gb
)
-
s
->
subframe_offset
);
bitstream_tell
(
&
s
->
bc
)
-
s
->
subframe_offset
);
if
(
transmit_coeffs
)
{
FFTContext
*
mdct
=
&
s
->
mdct_ctx
[
av_log2
(
subframe_len
)
-
WMAPRO_BLOCK_MIN_BITS
];
...
...
@@ -1309,14 +1310,14 @@ static int decode_subframe(WMAProDecodeCtx *s)
static
int
decode_frame
(
WMAProDecodeCtx
*
s
,
AVFrame
*
frame
,
int
*
got_frame_ptr
)
{
AVCodecContext
*
avctx
=
s
->
avctx
;
GetBitContext
*
gb
=
&
s
->
gb
;
BitstreamContext
*
bc
=
&
s
->
bc
;
int
more_frames
=
0
;
int
len
=
0
;
int
i
,
ret
;
/** get frame length */
if
(
s
->
len_prefix
)
len
=
get_bits
(
gb
,
s
->
log2_frame_size
);
len
=
bitstream_read
(
bc
,
s
->
log2_frame_size
);
ff_dlog
(
s
->
avctx
,
"decoding frame with length %x
\n
"
,
len
);
...
...
@@ -1327,40 +1328,40 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
}
/** read postproc transform */
if
(
s
->
avctx
->
channels
>
1
&&
get_bits1
(
gb
))
{
if
(
get_bits1
(
gb
))
{
if
(
s
->
avctx
->
channels
>
1
&&
bitstream_read_bit
(
bc
))
{
if
(
bitstream_read_bit
(
bc
))
{
for
(
i
=
0
;
i
<
avctx
->
channels
*
avctx
->
channels
;
i
++
)
skip_bits
(
gb
,
4
);
bitstream_skip
(
bc
,
4
);
}
}
/** read drc info */
if
(
s
->
dynamic_range_compression
)
{
s
->
drc_gain
=
get_bits
(
gb
,
8
);
s
->
drc_gain
=
bitstream_read
(
bc
,
8
);
ff_dlog
(
s
->
avctx
,
"drc_gain %i
\n
"
,
s
->
drc_gain
);
}
/** no idea what these are for, might be the number of samples
that need to be skipped at the beginning or end of a stream */
if
(
get_bits1
(
gb
))
{
if
(
bitstream_read_bit
(
bc
))
{
int
av_unused
skip
;
/** usually true for the first frame */
if
(
get_bits1
(
gb
))
{
skip
=
get_bits
(
gb
,
av_log2
(
s
->
samples_per_frame
*
2
));
if
(
bitstream_read_bit
(
bc
))
{
skip
=
bitstream_read
(
bc
,
av_log2
(
s
->
samples_per_frame
*
2
));
ff_dlog
(
s
->
avctx
,
"start skip: %i
\n
"
,
skip
);
}
/** sometimes true for the last frame */
if
(
get_bits1
(
gb
))
{
skip
=
get_bits
(
gb
,
av_log2
(
s
->
samples_per_frame
*
2
));
if
(
bitstream_read_bit
(
bc
))
{
skip
=
bitstream_read
(
bc
,
av_log2
(
s
->
samples_per_frame
*
2
));
ff_dlog
(
s
->
avctx
,
"end skip: %i
\n
"
,
skip
);
}
}
ff_dlog
(
s
->
avctx
,
"BITSTREAM: frame header length was %i
\n
"
,
get_bits_count
(
gb
)
-
s
->
frame_offset
);
bitstream_tell
(
bc
)
-
s
->
frame_offset
);
/** reset subframe states */
s
->
parsed_all_subframes
=
0
;
...
...
@@ -1407,25 +1408,25 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
}
if
(
s
->
len_prefix
)
{
if
(
len
!=
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
+
2
)
{
if
(
len
!=
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
+
2
)
{
/** FIXME: not sure if this is always an error */
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"frame[%"
PRIu32
"] would have to skip %i bits
\n
"
,
s
->
frame_num
,
len
-
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
-
1
);
len
-
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
-
1
);
s
->
packet_loss
=
1
;
return
0
;
}
/** skip the rest of the frame data */
skip_bits_long
(
gb
,
len
-
(
get_bits_count
(
gb
)
-
s
->
frame_offset
)
-
1
);
bitstream_skip
(
bc
,
len
-
(
bitstream_tell
(
bc
)
-
s
->
frame_offset
)
-
1
);
}
else
{
while
(
get_bits_count
(
gb
)
<
s
->
num_saved_bits
&&
get_bits1
(
gb
)
==
0
)
{
while
(
bitstream_tell
(
bc
)
<
s
->
num_saved_bits
&&
bitstream_read_bit
(
bc
)
==
0
)
{
}
}
/** decode trailer bit */
more_frames
=
get_bits1
(
gb
);
more_frames
=
bitstream_read_bit
(
bc
);
++
s
->
frame_num
;
return
more_frames
;
...
...
@@ -1434,22 +1435,22 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
/**
*@brief Calculate remaining input buffer length.
*@param s codec context
*@param
gb
bitstream reader context
*@param
bc
bitstream reader context
*@return remaining size in bits
*/
static
int
remaining_bits
(
WMAProDecodeCtx
*
s
,
GetBitContext
*
gb
)
static
int
remaining_bits
(
WMAProDecodeCtx
*
s
,
BitstreamContext
*
bc
)
{
return
s
->
buf_bit_size
-
get_bits_count
(
gb
);
return
s
->
buf_bit_size
-
bitstream_tell
(
bc
);
}
/**
*@brief Fill the bit reservoir with a (partial) frame.
*@param s codec context
*@param
gb
bitstream reader context
*@param
bc
bitstream reader context
*@param len length of the partial frame
*@param append decides whether to reset the buffer or not
*/
static
void
save_bits
(
WMAProDecodeCtx
*
s
,
GetBitContext
*
gb
,
int
len
,
static
void
save_bits
(
WMAProDecodeCtx
*
s
,
BitstreamContext
*
bc
,
int
len
,
int
append
)
{
int
buflen
;
...
...
@@ -1459,7 +1460,7 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
and skipped later so that a fast byte copy is possible */
if
(
!
append
)
{
s
->
frame_offset
=
get_bits_count
(
gb
)
&
7
;
s
->
frame_offset
=
bitstream_tell
(
bc
)
&
7
;
s
->
num_saved_bits
=
s
->
frame_offset
;
init_put_bits
(
&
s
->
pb
,
s
->
frame_data
,
MAX_FRAMESIZE
);
}
...
...
@@ -1482,24 +1483,24 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
s
->
num_saved_bits
+=
len
;
if
(
!
append
)
{
avpriv_copy_bits
(
&
s
->
pb
,
gb
->
buffer
+
(
get_bits_count
(
gb
)
>>
3
),
avpriv_copy_bits
(
&
s
->
pb
,
bc
->
buffer
+
(
bitstream_tell
(
bc
)
>>
3
),
s
->
num_saved_bits
);
}
else
{
int
align
=
8
-
(
get_bits_count
(
gb
)
&
7
);
int
align
=
8
-
(
bitstream_tell
(
bc
)
&
7
);
align
=
FFMIN
(
align
,
len
);
put_bits
(
&
s
->
pb
,
align
,
get_bits
(
gb
,
align
));
put_bits
(
&
s
->
pb
,
align
,
bitstream_read
(
bc
,
align
));
len
-=
align
;
avpriv_copy_bits
(
&
s
->
pb
,
gb
->
buffer
+
(
get_bits_count
(
gb
)
>>
3
),
len
);
avpriv_copy_bits
(
&
s
->
pb
,
bc
->
buffer
+
(
bitstream_tell
(
bc
)
>>
3
),
len
);
}
skip_bits_long
(
gb
,
len
);
bitstream_skip
(
bc
,
len
);
{
PutBitContext
tmp
=
s
->
pb
;
flush_put_bits
(
&
tmp
);
}
init_get_bits
(
&
s
->
gb
,
s
->
frame_data
,
s
->
num_saved_bits
);
skip_bits
(
&
s
->
gb
,
s
->
frame_offset
);
bitstream_init
(
&
s
->
bc
,
s
->
frame_data
,
s
->
num_saved_bits
);
bitstream_skip
(
&
s
->
bc
,
s
->
frame_offset
);
}
/**
...
...
@@ -1513,7 +1514,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
int
*
got_frame_ptr
,
AVPacket
*
avpkt
)
{
WMAProDecodeCtx
*
s
=
avctx
->
priv_data
;
GetBitContext
*
gb
=
&
s
->
pgb
;
BitstreamContext
*
bc
=
&
s
->
pbc
;
const
uint8_t
*
buf
=
avpkt
->
data
;
int
buf_size
=
avpkt
->
size
;
int
num_bits_prev_frame
;
...
...
@@ -1536,12 +1537,12 @@ static int decode_packet(AVCodecContext *avctx, void *data,
s
->
buf_bit_size
=
buf_size
<<
3
;
/** parse packet header */
init_get_bits
(
gb
,
buf
,
s
->
buf_bit_size
);
packet_sequence_number
=
get_bits
(
gb
,
4
);
skip_bits
(
gb
,
2
);
bitstream_init
(
bc
,
buf
,
s
->
buf_bit_size
);
packet_sequence_number
=
bitstream_read
(
bc
,
4
);
bitstream_skip
(
bc
,
2
);
/** get number of bits that need to be added to the previous frame */
num_bits_prev_frame
=
get_bits
(
gb
,
s
->
log2_frame_size
);
num_bits_prev_frame
=
bitstream_read
(
bc
,
s
->
log2_frame_size
);
ff_dlog
(
avctx
,
"packet[%d]: nbpf %x
\n
"
,
avctx
->
frame_number
,
num_bits_prev_frame
);
...
...
@@ -1556,7 +1557,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
s
->
packet_sequence_number
=
packet_sequence_number
;
if
(
num_bits_prev_frame
>
0
)
{
int
remaining_packet_bits
=
s
->
buf_bit_size
-
get_bits_count
(
gb
);
int
remaining_packet_bits
=
s
->
buf_bit_size
-
bitstream_tell
(
bc
);
if
(
num_bits_prev_frame
>=
remaining_packet_bits
)
{
num_bits_prev_frame
=
remaining_packet_bits
;
s
->
packet_done
=
1
;
...
...
@@ -1564,7 +1565,7 @@ static int decode_packet(AVCodecContext *avctx, void *data,
/** append the previous frame data to the remaining data from the
previous packet to create a full frame */
save_bits
(
s
,
gb
,
num_bits_prev_frame
,
1
);
save_bits
(
s
,
bc
,
num_bits_prev_frame
,
1
);
ff_dlog
(
avctx
,
"accumulated %x bits of frame data
\n
"
,
s
->
num_saved_bits
-
s
->
frame_offset
);
...
...
@@ -1587,15 +1588,15 @@ static int decode_packet(AVCodecContext *avctx, void *data,
}
else
{
int
frame_size
;
s
->
buf_bit_size
=
(
avpkt
->
size
-
s
->
next_packet_start
)
<<
3
;
init_get_bits
(
gb
,
avpkt
->
data
,
s
->
buf_bit_size
);
skip_bits
(
gb
,
s
->
packet_offset
);
if
(
s
->
len_prefix
&&
remaining_bits
(
s
,
gb
)
>
s
->
log2_frame_size
&&
(
frame_size
=
show_bits
(
gb
,
s
->
log2_frame_size
))
&&
frame_size
<=
remaining_bits
(
s
,
gb
))
{
save_bits
(
s
,
gb
,
frame_size
,
0
);
bitstream_init
(
bc
,
avpkt
->
data
,
s
->
buf_bit_size
);
bitstream_skip
(
bc
,
s
->
packet_offset
);
if
(
s
->
len_prefix
&&
remaining_bits
(
s
,
bc
)
>
s
->
log2_frame_size
&&
(
frame_size
=
bitstream_peek
(
bc
,
s
->
log2_frame_size
))
&&
frame_size
<=
remaining_bits
(
s
,
bc
))
{
save_bits
(
s
,
bc
,
frame_size
,
0
);
s
->
packet_done
=
!
decode_frame
(
s
,
data
,
got_frame_ptr
);
}
else
if
(
!
s
->
len_prefix
&&
s
->
num_saved_bits
>
get_bits_count
(
&
s
->
gb
))
{
&&
s
->
num_saved_bits
>
bitstream_tell
(
&
s
->
bc
))
{
/** when the frames do not have a length prefix, we don't know
the compressed length of the individual frames
however, we know what part of a new packet belongs to the
...
...
@@ -1609,17 +1610,17 @@ static int decode_packet(AVCodecContext *avctx, void *data,
}
if
(
s
->
packet_done
&&
!
s
->
packet_loss
&&
remaining_bits
(
s
,
gb
)
>
0
)
{
remaining_bits
(
s
,
bc
)
>
0
)
{
/** save the rest of the data so that it can be decoded
with the next packet */
save_bits
(
s
,
gb
,
remaining_bits
(
s
,
gb
),
0
);
save_bits
(
s
,
bc
,
remaining_bits
(
s
,
bc
),
0
);
}
s
->
packet_offset
=
get_bits_count
(
gb
)
&
7
;
s
->
packet_offset
=
bitstream_tell
(
bc
)
&
7
;
if
(
s
->
packet_loss
)
return
AVERROR_INVALIDDATA
;
return
get_bits_count
(
gb
)
>>
3
;
return
bitstream_tell
(
bc
)
>>
3
;
}
/**
...
...
libavcodec/wmavoice.c
View file @
f7ec7f54
...
...
@@ -25,16 +25,15 @@
* @author Ronald S. Bultje <rsbultje@gmail.com>
*/
#define UNCHECKED_BITSTREAM_READER 1
#include <math.h>
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
#include "wmavoice_data.h"
#include "celp_filters.h"
...
...
@@ -136,7 +135,7 @@ typedef struct WMAVoiceContext {
* @name Global values specified in the stream header / extradata or used all over.
* @{
*/
GetBitContext
gb
;
///< packet bitreader. During decoder init,
BitstreamContext
bc
;
///< packet bitreader. During decoder init,
///< it contains the extradata from the
///< demuxer. During decoding, it contains
///< packet data.
...
...
@@ -296,20 +295,20 @@ typedef struct WMAVoiceContext {
/**
* Set up the variable bit mode (VBM) tree from container extradata.
* @param
gb
bit I/O context.
* The bit context (s->
gb
) should be loaded with byte 23-46 of the
* @param
bc
bit I/O context.
* The bit context (s->
bc
) should be loaded with byte 23-46 of the
* container extradata (i.e. the ones containing the VBM tree).
* @param vbm_tree pointer to array to which the decoded VBM tree will be
* written.
* @return 0 on success, <0 on error.
*/
static
av_cold
int
decode_vbmtree
(
GetBitContext
*
gb
,
int8_t
vbm_tree
[
25
])
static
av_cold
int
decode_vbmtree
(
BitstreamContext
*
bc
,
int8_t
vbm_tree
[
25
])
{
int
cntr
[
8
]
=
{
0
},
n
,
res
;
memset
(
vbm_tree
,
0xff
,
sizeof
(
vbm_tree
[
0
])
*
25
);
for
(
n
=
0
;
n
<
17
;
n
++
)
{
res
=
get_bits
(
gb
,
3
);
res
=
bitstream_read
(
bc
,
3
);
if
(
cntr
[
res
]
>
3
)
// should be >= 3 + (res == 7))
return
-
1
;
vbm_tree
[
res
*
3
+
cntr
[
res
]
++
]
=
n
;
...
...
@@ -401,8 +400,8 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
for
(
n
=
0
;
n
<
s
->
lsps
;
n
++
)
s
->
prev_lsps
[
n
]
=
M_PI
*
(
n
+
1
.
0
)
/
(
s
->
lsps
+
1
.
0
);
init_get_bits
(
&
s
->
gb
,
ctx
->
extradata
+
22
,
(
ctx
->
extradata_size
-
22
)
<<
3
);
if
(
decode_vbmtree
(
&
s
->
gb
,
s
->
vbm_tree
)
<
0
)
{
bitstream_init8
(
&
s
->
bc
,
ctx
->
extradata
+
22
,
ctx
->
extradata_size
-
22
);
if
(
decode_vbmtree
(
&
s
->
bc
,
s
->
vbm_tree
)
<
0
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid VBM tree; broken extradata?
\n
"
);
return
AVERROR_INVALIDDATA
;
}
...
...
@@ -857,7 +856,7 @@ static void dequant_lsps(double *lsps, int num,
/**
* Parse 10 independently-coded LSPs.
*/
static
void
dequant_lsp10i
(
GetBitContext
*
gb
,
double
*
lsps
)
static
void
dequant_lsp10i
(
BitstreamContext
*
bc
,
double
*
lsps
)
{
static
const
uint16_t
vec_sizes
[
4
]
=
{
256
,
64
,
32
,
32
};
static
const
double
mul_lsf
[
4
]
=
{
...
...
@@ -870,10 +869,10 @@ static void dequant_lsp10i(GetBitContext *gb, double *lsps)
};
uint16_t
v
[
4
];
v
[
0
]
=
get_bits
(
gb
,
8
);
v
[
1
]
=
get_bits
(
gb
,
6
);
v
[
2
]
=
get_bits
(
gb
,
5
);
v
[
3
]
=
get_bits
(
gb
,
5
);
v
[
0
]
=
bitstream_read
(
bc
,
8
);
v
[
1
]
=
bitstream_read
(
bc
,
6
);
v
[
2
]
=
bitstream_read
(
bc
,
5
);
v
[
3
]
=
bitstream_read
(
bc
,
5
);
dequant_lsps
(
lsps
,
10
,
v
,
vec_sizes
,
4
,
wmavoice_dq_lsp10i
,
mul_lsf
,
base_lsf
);
...
...
@@ -883,7 +882,7 @@ static void dequant_lsp10i(GetBitContext *gb, double *lsps)
* Parse 10 independently-coded LSPs, and then derive the tables to
* generate LSPs for the other frames from them (residual coding).
*/
static
void
dequant_lsp10r
(
GetBitContext
*
gb
,
static
void
dequant_lsp10r
(
BitstreamContext
*
bc
,
double
*
i_lsps
,
const
double
*
old
,
double
*
a1
,
double
*
a2
,
int
q_mode
)
{
...
...
@@ -899,12 +898,12 @@ static void dequant_lsp10r(GetBitContext *gb,
uint16_t
interpol
,
v
[
3
];
int
n
;
dequant_lsp10i
(
gb
,
i_lsps
);
dequant_lsp10i
(
bc
,
i_lsps
);
interpol
=
get_bits
(
gb
,
5
);
v
[
0
]
=
get_bits
(
gb
,
7
);
v
[
1
]
=
get_bits
(
gb
,
6
);
v
[
2
]
=
get_bits
(
gb
,
6
);
interpol
=
bitstream_read
(
bc
,
5
);
v
[
0
]
=
bitstream_read
(
bc
,
7
);
v
[
1
]
=
bitstream_read
(
bc
,
6
);
v
[
2
]
=
bitstream_read
(
bc
,
6
);
for
(
n
=
0
;
n
<
10
;
n
++
)
{
double
delta
=
old
[
n
]
-
i_lsps
[
n
];
...
...
@@ -919,7 +918,7 @@ static void dequant_lsp10r(GetBitContext *gb,
/**
* Parse 16 independently-coded LSPs.
*/
static
void
dequant_lsp16i
(
GetBitContext
*
gb
,
double
*
lsps
)
static
void
dequant_lsp16i
(
BitstreamContext
*
bc
,
double
*
lsps
)
{
static
const
uint16_t
vec_sizes
[
5
]
=
{
256
,
64
,
128
,
64
,
128
};
static
const
double
mul_lsf
[
5
]
=
{
...
...
@@ -934,11 +933,11 @@ static void dequant_lsp16i(GetBitContext *gb, double *lsps)
};
uint16_t
v
[
5
];
v
[
0
]
=
get_bits
(
gb
,
8
);
v
[
1
]
=
get_bits
(
gb
,
6
);
v
[
2
]
=
get_bits
(
gb
,
7
);
v
[
3
]
=
get_bits
(
gb
,
6
);
v
[
4
]
=
get_bits
(
gb
,
7
);
v
[
0
]
=
bitstream_read
(
bc
,
8
);
v
[
1
]
=
bitstream_read
(
bc
,
6
);
v
[
2
]
=
bitstream_read
(
bc
,
7
);
v
[
3
]
=
bitstream_read
(
bc
,
6
);
v
[
4
]
=
bitstream_read
(
bc
,
7
);
dequant_lsps
(
lsps
,
5
,
v
,
vec_sizes
,
2
,
wmavoice_dq_lsp16i1
,
mul_lsf
,
base_lsf
);
...
...
@@ -952,7 +951,7 @@ static void dequant_lsp16i(GetBitContext *gb, double *lsps)
* Parse 16 independently-coded LSPs, and then derive the tables to
* generate LSPs for the other frames from them (residual coding).
*/
static
void
dequant_lsp16r
(
GetBitContext
*
gb
,
static
void
dequant_lsp16r
(
BitstreamContext
*
bc
,
double
*
i_lsps
,
const
double
*
old
,
double
*
a1
,
double
*
a2
,
int
q_mode
)
{
...
...
@@ -968,12 +967,12 @@ static void dequant_lsp16r(GetBitContext *gb,
uint16_t
interpol
,
v
[
3
];
int
n
;
dequant_lsp16i
(
gb
,
i_lsps
);
dequant_lsp16i
(
bc
,
i_lsps
);
interpol
=
get_bits
(
gb
,
5
);
v
[
0
]
=
get_bits
(
gb
,
7
);
v
[
1
]
=
get_bits
(
gb
,
7
);
v
[
2
]
=
get_bits
(
gb
,
7
);
interpol
=
bitstream_read
(
bc
,
5
);
v
[
0
]
=
bitstream_read
(
bc
,
7
);
v
[
1
]
=
bitstream_read
(
bc
,
7
);
v
[
2
]
=
bitstream_read
(
bc
,
7
);
for
(
n
=
0
;
n
<
16
;
n
++
)
{
double
delta
=
old
[
n
]
-
i_lsps
[
n
];
...
...
@@ -999,10 +998,10 @@ static void dequant_lsp16r(GetBitContext *gb,
* Parse the offset of the first pitch-adaptive window pulses, and
* the distribution of pulses between the two blocks in this frame.
* @param s WMA Voice decoding context private data
* @param
gb
bit I/O context
* @param
bc
bit I/O context
* @param pitch pitch for each block in this frame
*/
static
void
aw_parse_coords
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
void
aw_parse_coords
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
const
int
*
pitch
)
{
static
const
int16_t
start_offset
[
94
]
=
{
...
...
@@ -1019,9 +1018,9 @@ static void aw_parse_coords(WMAVoiceContext *s, GetBitContext *gb,
/* position of pulse */
s
->
aw_idx_is_ext
=
0
;
if
((
bits
=
get_bits
(
gb
,
6
))
>=
54
)
{
if
((
bits
=
bitstream_read
(
bc
,
6
))
>=
54
)
{
s
->
aw_idx_is_ext
=
1
;
bits
+=
(
bits
-
54
)
*
3
+
get_bits
(
gb
,
2
);
bits
+=
(
bits
-
54
)
*
3
+
bitstream_read
(
bc
,
2
);
}
/* for a repeated pulse at pulse_off with a pitch_lag of pitch[], count
...
...
@@ -1049,12 +1048,12 @@ static void aw_parse_coords(WMAVoiceContext *s, GetBitContext *gb,
/**
* Apply second set of pitch-adaptive window pulses.
* @param s WMA Voice decoding context private data
* @param
gb
bit I/O context
* @param
bc
bit I/O context
* @param block_idx block index in frame [0, 1]
* @param fcb structure containing fixed codebook vector info
* @return -1 on error, 0 otherwise
*/
static
int
aw_pulse_set2
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
int
aw_pulse_set2
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
int
block_idx
,
AMRFixed
*
fcb
)
{
uint16_t
use_mask_mem
[
9
];
// only 5 are used, rest is padding
...
...
@@ -1108,7 +1107,7 @@ static int aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
}
/* find the 'aidx'th offset that is not excluded */
aidx
=
get_bits
(
gb
,
s
->
aw_n_pulses
[
0
]
>
0
?
5
-
2
*
block_idx
:
4
);
aidx
=
bitstream_read
(
bc
,
s
->
aw_n_pulses
[
0
]
>
0
?
5
-
2
*
block_idx
:
4
);
for
(
n
=
0
;
n
<=
aidx
;
pulse_start
++
)
{
for
(
idx
=
pulse_start
;
idx
<
0
;
idx
+=
fcb
->
pitch_lag
)
;
if
(
idx
>=
MAX_FRAMESIZE
/
2
)
{
// find from zero
...
...
@@ -1128,7 +1127,7 @@ static int aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
}
fcb
->
x
[
fcb
->
n
]
=
start_off
;
fcb
->
y
[
fcb
->
n
]
=
get_bits1
(
gb
)
?
-
1
.
0
:
1
.
0
;
fcb
->
y
[
fcb
->
n
]
=
bitstream_read_bit
(
bc
)
?
-
1
.
0
:
1
.
0
;
fcb
->
n
++
;
/* set offset for next block, relative to start of that block */
...
...
@@ -1140,14 +1139,14 @@ static int aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
/**
* Apply first set of pitch-adaptive window pulses.
* @param s WMA Voice decoding context private data
* @param
gb
bit I/O context
* @param
bc
bit I/O context
* @param block_idx block index in frame [0, 1]
* @param fcb storage location for fixed codebook pulse info
*/
static
void
aw_pulse_set1
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
void
aw_pulse_set1
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
int
block_idx
,
AMRFixed
*
fcb
)
{
int
val
=
get_bits
(
gb
,
12
-
2
*
(
s
->
aw_idx_is_ext
&&
!
block_idx
));
int
val
=
bitstream_read
(
bc
,
12
-
2
*
(
s
->
aw_idx_is_ext
&&
!
block_idx
));
float
v
;
if
(
s
->
aw_n_pulses
[
block_idx
]
>
0
)
{
...
...
@@ -1241,7 +1240,7 @@ static int pRNG(int frame_cntr, int block_num, int block_size)
* Parse hardcoded signal for a single block.
* @note see #synth_block().
*/
static
void
synth_block_hardcoded
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
void
synth_block_hardcoded
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
int
block_idx
,
int
size
,
const
struct
frame_type_desc
*
frame_desc
,
float
*
excitation
)
...
...
@@ -1256,8 +1255,8 @@ static void synth_block_hardcoded(WMAVoiceContext *s, GetBitContext *gb,
r_idx
=
pRNG
(
s
->
frame_cntr
,
block_idx
,
size
);
gain
=
s
->
silence_gain
;
}
else
/* FCB_TYPE_HARDCODED */
{
r_idx
=
get_bits
(
gb
,
8
);
gain
=
wmavoice_gain_universal
[
get_bits
(
gb
,
6
)];
r_idx
=
bitstream_read
(
bc
,
8
);
gain
=
wmavoice_gain_universal
[
bitstream_read
(
bc
,
6
)];
}
/* Clear gain prediction parameters */
...
...
@@ -1272,7 +1271,7 @@ static void synth_block_hardcoded(WMAVoiceContext *s, GetBitContext *gb,
* Parse FCB/ACB signal for a single block.
* @note see #synth_block().
*/
static
void
synth_block_fcb_acb
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
void
synth_block_fcb_acb
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
int
block_idx
,
int
size
,
int
block_pitch_sh2
,
const
struct
frame_type_desc
*
frame_desc
,
...
...
@@ -1296,8 +1295,8 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
/* For the other frame types, this is where we apply the innovation
* (fixed) codebook pulses of the speech signal. */
if
(
frame_desc
->
fcb_type
==
FCB_TYPE_AW_PULSES
)
{
aw_pulse_set1
(
s
,
gb
,
block_idx
,
&
fcb
);
if
(
aw_pulse_set2
(
s
,
gb
,
block_idx
,
&
fcb
))
{
aw_pulse_set1
(
s
,
bc
,
block_idx
,
&
fcb
);
if
(
aw_pulse_set2
(
s
,
bc
,
block_idx
,
&
fcb
))
{
/* Conceal the block with silence and return.
* Skip the correct amount of bits to read the next
* block from the correct offset. */
...
...
@@ -1306,7 +1305,7 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
for
(
n
=
0
;
n
<
size
;
n
++
)
excitation
[
n
]
=
wmavoice_std_codebook
[
r_idx
+
n
]
*
s
->
silence_gain
;
skip_bits
(
gb
,
7
+
1
);
bitstream_skip
(
bc
,
7
+
1
);
return
;
}
}
else
/* FCB_TYPE_EXC_PULSES */
{
...
...
@@ -1319,12 +1318,12 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
float
sign
;
int
pos1
,
pos2
;
sign
=
get_bits1
(
gb
)
?
1
.
0
:
-
1
.
0
;
pos1
=
get_bits
(
gb
,
offset_nbits
);
sign
=
bitstream_read_bit
(
bc
)
?
1
.
0
:
-
1
.
0
;
pos1
=
bitstream_read
(
bc
,
offset_nbits
);
fcb
.
x
[
fcb
.
n
]
=
n
+
5
*
pos1
;
fcb
.
y
[
fcb
.
n
++
]
=
sign
;
if
(
n
<
frame_desc
->
dbl_pulses
)
{
pos2
=
get_bits
(
gb
,
offset_nbits
);
pos2
=
bitstream_read
(
bc
,
offset_nbits
);
fcb
.
x
[
fcb
.
n
]
=
n
+
5
*
pos2
;
fcb
.
y
[
fcb
.
n
++
]
=
(
pos1
<
pos2
)
?
-
sign
:
sign
;
}
...
...
@@ -1334,7 +1333,7 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
/* Calculate gain for adaptive & fixed codebook signal.
* see ff_amr_set_fixed_gain(). */
idx
=
get_bits
(
gb
,
7
);
idx
=
bitstream_read
(
bc
,
7
);
fcb_gain
=
expf
(
avpriv_scalarproduct_float_c
(
s
->
gain_pred_err
,
gain_coeff
,
6
)
-
5
.
2409161640
+
wmavoice_gain_codebook_fcb
[
idx
]);
...
...
@@ -1396,7 +1395,7 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
* @note we assume enough bits are available, caller should check.
*
* @param s WMA Voice decoding context private data
* @param
gb
bit I/O context
* @param
bc
bit I/O context
* @param block_idx index of the to-be-read block
* @param size amount of samples to be read in this block
* @param block_pitch_sh2 pitch for this block << 2
...
...
@@ -1407,7 +1406,7 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
* @param synth target memory for the speech synthesis filter output
* @return 0 on success, <0 on error.
*/
static
void
synth_block
(
WMAVoiceContext
*
s
,
GetBitContext
*
gb
,
static
void
synth_block
(
WMAVoiceContext
*
s
,
BitstreamContext
*
bc
,
int
block_idx
,
int
size
,
int
block_pitch_sh2
,
const
double
*
lsps
,
const
double
*
prev_lsps
,
...
...
@@ -1420,9 +1419,9 @@ static void synth_block(WMAVoiceContext *s, GetBitContext *gb,
int
n
;
if
(
frame_desc
->
acb_type
==
ACB_TYPE_NONE
)
synth_block_hardcoded
(
s
,
gb
,
block_idx
,
size
,
frame_desc
,
excitation
);
synth_block_hardcoded
(
s
,
bc
,
block_idx
,
size
,
frame_desc
,
excitation
);
else
synth_block_fcb_acb
(
s
,
gb
,
block_idx
,
size
,
block_pitch_sh2
,
synth_block_fcb_acb
(
s
,
bc
,
block_idx
,
size
,
block_pitch_sh2
,
frame_desc
,
excitation
);
/* convert interpolated LSPs to LPCs */
...
...
@@ -1440,7 +1439,7 @@ static void synth_block(WMAVoiceContext *s, GetBitContext *gb,
* @note we assume enough bits are available, caller should check.
*
* @param ctx WMA Voice decoder context
* @param
gb bit I/O context (s->gb
or one for cross-packet superframes)
* @param
bc bit I/O context (s->bc
or one for cross-packet superframes)
* @param frame_idx Frame number within superframe [0-2]
* @param samples pointer to output sample buffer, has space for at least 160
* samples
...
...
@@ -1450,8 +1449,8 @@ static void synth_block(WMAVoiceContext *s, GetBitContext *gb,
* @param synth target buffer for synthesized speech data
* @return 0 on success, <0 on error.
*/
static
int
synth_frame
(
AVCodecContext
*
ctx
,
GetBitContext
*
gb
,
int
frame_idx
,
float
*
samples
,
static
int
synth_frame
(
AVCodecContext
*
ctx
,
BitstreamContext
*
bc
,
int
frame_idx
,
float
*
samples
,
const
double
*
lsps
,
const
double
*
prev_lsps
,
float
*
excitation
,
float
*
synth
)
{
...
...
@@ -1460,7 +1459,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
int
pitch
[
MAX_BLOCKS
],
last_block_pitch
;
/* Parse frame type ("frame header"), see frame_descs */
int
bd_idx
=
s
->
vbm_tree
[
get_vlc2
(
gb
,
frame_type_vlc
.
table
,
6
,
3
)],
block_nsamples
;
int
bd_idx
=
s
->
vbm_tree
[
bitstream_read_vlc
(
bc
,
frame_type_vlc
.
table
,
6
,
3
)],
block_nsamples
;
if
(
bd_idx
<
0
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
...
...
@@ -1478,7 +1477,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
* incrementing/decrementing prev_frame_pitch to cur_pitch_val. */
n_blocks_x2
=
frame_descs
[
bd_idx
].
n_blocks
<<
1
;
log_n_blocks_x2
=
frame_descs
[
bd_idx
].
log_n_blocks
+
1
;
cur_pitch_val
=
s
->
min_pitch_val
+
get_bits
(
gb
,
s
->
pitch_nbits
);
cur_pitch_val
=
s
->
min_pitch_val
+
bitstream_read
(
bc
,
s
->
pitch_nbits
);
cur_pitch_val
=
FFMIN
(
cur_pitch_val
,
s
->
max_pitch_val
-
1
);
if
(
s
->
last_acb_type
==
ACB_TYPE_NONE
||
20
*
abs
(
cur_pitch_val
-
s
->
last_pitch_val
)
>
...
...
@@ -1502,10 +1501,10 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
/* Global gain (if silence) and pitch-adaptive window coordinates */
switch
(
frame_descs
[
bd_idx
].
fcb_type
)
{
case
FCB_TYPE_SILENCE
:
s
->
silence_gain
=
wmavoice_gain_silence
[
get_bits
(
gb
,
8
)];
s
->
silence_gain
=
wmavoice_gain_silence
[
bitstream_read
(
bc
,
8
)];
break
;
case
FCB_TYPE_AW_PULSES
:
aw_parse_coords
(
s
,
gb
,
pitch
);
aw_parse_coords
(
s
,
bc
,
pitch
);
break
;
}
...
...
@@ -1526,10 +1525,10 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
t3
=
s
->
block_conv_table
[
3
]
-
s
->
block_conv_table
[
2
]
+
1
;
if
(
n
==
0
)
{
block_pitch
=
get_bits
(
gb
,
s
->
block_pitch_nbits
);
block_pitch
=
bitstream_read
(
bc
,
s
->
block_pitch_nbits
);
}
else
block_pitch
=
last_block_pitch
-
s
->
block_delta_pitch_hrange
+
get_bits
(
gb
,
s
->
block_delta_pitch_nbits
);
bitstream_read
(
bc
,
s
->
block_delta_pitch_nbits
);
/* Convert last_ so that any next delta is within _range */
last_block_pitch
=
av_clip
(
block_pitch
,
s
->
block_delta_pitch_hrange
,
...
...
@@ -1567,7 +1566,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
break
;
}
synth_block
(
s
,
gb
,
n
,
block_nsamples
,
bl_pitch_sh2
,
synth_block
(
s
,
bc
,
n
,
block_nsamples
,
bl_pitch_sh2
,
lsps
,
prev_lsps
,
&
frame_descs
[
bd_idx
],
&
excitation
[
n
*
block_nsamples
],
&
synth
[
n
*
block_nsamples
]);
...
...
@@ -1658,32 +1657,32 @@ static void stabilize_lsps(double *lsps, int num)
/**
* Test if there's enough bits to read 1 superframe.
*
* @param orig_
gb
bit I/O context used for reading. This function
* @param orig_
bc
bit I/O context used for reading. This function
* does not modify the state of the bitreader; it
* only uses it to copy the current stream position
* @param s WMA Voice decoding context private data
* @return < 0 on error, 1 on not enough bits or 0 if OK.
*/
static
int
check_bits_for_superframe
(
GetBitContext
*
orig_gb
,
static
int
check_bits_for_superframe
(
BitstreamContext
*
orig_bc
,
WMAVoiceContext
*
s
)
{
GetBitContext
s_gb
,
*
gb
=
&
s_gb
;
BitstreamContext
s_bc
,
*
bc
=
&
s_bc
;
int
n
,
need_bits
,
bd_idx
;
const
struct
frame_type_desc
*
frame_desc
;
/* initialize a copy */
*
gb
=
*
orig_gb
;
*
bc
=
*
orig_bc
;
/* superframe header */
if
(
get_bits_left
(
gb
)
<
14
)
if
(
bitstream_bits_left
(
bc
)
<
14
)
return
1
;
if
(
!
get_bits1
(
gb
))
if
(
!
bitstream_read_bit
(
bc
))
return
AVERROR
(
ENOSYS
);
// WMAPro-in-WMAVoice superframe
if
(
get_bits1
(
gb
))
skip_bits
(
gb
,
12
);
// number of samples in superframe
if
(
bitstream_read_bit
(
bc
))
bitstream_skip
(
bc
,
12
);
// number of samples in superframe
if
(
s
->
has_residual_lsps
)
{
// residual LSPs (for all frames)
if
(
get_bits_left
(
gb
)
<
s
->
sframe_lsp_bitsize
)
if
(
bitstream_bits_left
(
bc
)
<
s
->
sframe_lsp_bitsize
)
return
1
;
skip_bits_long
(
gb
,
s
->
sframe_lsp_bitsize
);
bitstream_skip
(
bc
,
s
->
sframe_lsp_bitsize
);
}
/* frames */
...
...
@@ -1691,24 +1690,25 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
int
aw_idx_is_ext
=
0
;
if
(
!
s
->
has_residual_lsps
)
{
// independent LSPs (per-frame)
if
(
get_bits_left
(
gb
)
<
s
->
frame_lsp_bitsize
)
return
1
;
skip_bits_long
(
gb
,
s
->
frame_lsp_bitsize
);
if
(
bitstream_bits_left
(
bc
)
<
s
->
frame_lsp_bitsize
)
return
1
;
bitstream_skip
(
bc
,
s
->
frame_lsp_bitsize
);
}
bd_idx
=
s
->
vbm_tree
[
get_vlc2
(
gb
,
frame_type_vlc
.
table
,
6
,
3
)];
bd_idx
=
s
->
vbm_tree
[
bitstream_read_vlc
(
bc
,
frame_type_vlc
.
table
,
6
,
3
)];
if
(
bd_idx
<
0
)
return
AVERROR_INVALIDDATA
;
// invalid frame type VLC code
frame_desc
=
&
frame_descs
[
bd_idx
];
if
(
frame_desc
->
acb_type
==
ACB_TYPE_ASYMMETRIC
)
{
if
(
get_bits_left
(
gb
)
<
s
->
pitch_nbits
)
if
(
bitstream_bits_left
(
bc
)
<
s
->
pitch_nbits
)
return
1
;
skip_bits_long
(
gb
,
s
->
pitch_nbits
);
bitstream_skip
(
bc
,
s
->
pitch_nbits
);
}
if
(
frame_desc
->
fcb_type
==
FCB_TYPE_SILENCE
)
{
skip_bits
(
gb
,
8
);
bitstream_skip
(
bc
,
8
);
}
else
if
(
frame_desc
->
fcb_type
==
FCB_TYPE_AW_PULSES
)
{
int
tmp
=
get_bits
(
gb
,
6
);
int
tmp
=
bitstream_read
(
bc
,
6
);
if
(
tmp
>=
0x36
)
{
skip_bits
(
gb
,
2
);
bitstream_skip
(
bc
,
2
);
aw_idx_is_ext
=
1
;
}
}
...
...
@@ -1722,9 +1722,9 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
}
else
need_bits
=
0
;
need_bits
+=
frame_desc
->
frame_size
;
if
(
get_bits_left
(
gb
)
<
need_bits
)
if
(
bitstream_bits_left
(
bc
)
<
need_bits
)
return
1
;
skip_bits_long
(
gb
,
need_bits
);
bitstream_skip
(
bc
,
need_bits
);
}
return
0
;
...
...
@@ -1733,7 +1733,7 @@ static int check_bits_for_superframe(GetBitContext *orig_gb,
/**
* Synthesize output samples for a single superframe. If we have any data
* cached in s->sframe_cache, that will be used instead of whatever is loaded
* in s->
gb
.
* in s->
bc
.
*
* WMA Voice superframes contain 3 frames, each containing 160 audio samples,
* to give a total of 480 samples per frame. See #synth_frame() for frame
...
...
@@ -1751,7 +1751,7 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
int
*
got_frame_ptr
)
{
WMAVoiceContext
*
s
=
ctx
->
priv_data
;
GetBitContext
*
gb
=
&
s
->
gb
,
s_gb
;
BitstreamContext
*
bc
=
&
s
->
bc
,
s_bc
;
int
n
,
res
,
n_samples
=
480
;
double
lsps
[
MAX_FRAMES
][
MAX_LSPS
];
const
double
*
mean_lsf
=
s
->
lsps
==
16
?
...
...
@@ -1766,12 +1766,12 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
s
->
history_nsamples
*
sizeof
(
*
excitation
));
if
(
s
->
sframe_cache_size
>
0
)
{
gb
=
&
s_gb
;
init_get_bits
(
gb
,
s
->
sframe_cache
,
s
->
sframe_cache_size
);
bc
=
&
s_bc
;
bitstream_init
(
bc
,
s
->
sframe_cache
,
s
->
sframe_cache_size
);
s
->
sframe_cache_size
=
0
;
}
if
((
res
=
check_bits_for_superframe
(
gb
,
s
))
==
1
)
{
if
((
res
=
check_bits_for_superframe
(
bc
,
s
))
==
1
)
{
*
got_frame_ptr
=
0
;
return
1
;
}
else
if
(
res
<
0
)
...
...
@@ -1781,14 +1781,14 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
* speech samples (the actual codec) and WMAVoice music samples, which
* are really WMAPro-in-WMAVoice-superframes. I've never seen those in
* the wild yet. */
if
(
!
get_bits1
(
gb
))
{
if
(
!
bitstream_read_bit
(
bc
))
{
avpriv_request_sample
(
ctx
,
"WMAPro-in-WMAVoice"
);
return
AVERROR_PATCHWELCOME
;
}
/* (optional) nr. of samples in superframe; always <= 480 and >= 0 */
if
(
get_bits1
(
gb
))
{
if
((
n_samples
=
get_bits
(
gb
,
12
))
>
480
)
{
if
(
bitstream_read_bit
(
bc
))
{
if
((
n_samples
=
bitstream_read
(
bc
,
12
))
>
480
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Superframe encodes >480 samples (%d), not allowed
\n
"
,
n_samples
);
...
...
@@ -1803,9 +1803,9 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
prev_lsps
[
n
]
=
s
->
prev_lsps
[
n
]
-
mean_lsf
[
n
];
if
(
s
->
lsps
==
10
)
{
dequant_lsp10r
(
gb
,
lsps
[
2
],
prev_lsps
,
a1
,
a2
,
s
->
lsp_q_mode
);
dequant_lsp10r
(
bc
,
lsps
[
2
],
prev_lsps
,
a1
,
a2
,
s
->
lsp_q_mode
);
}
else
/* s->lsps == 16 */
dequant_lsp16r
(
gb
,
lsps
[
2
],
prev_lsps
,
a1
,
a2
,
s
->
lsp_q_mode
);
dequant_lsp16r
(
bc
,
lsps
[
2
],
prev_lsps
,
a1
,
a2
,
s
->
lsp_q_mode
);
for
(
n
=
0
;
n
<
s
->
lsps
;
n
++
)
{
lsps
[
0
][
n
]
=
mean_lsf
[
n
]
+
(
a1
[
n
]
-
a2
[
n
*
2
]);
...
...
@@ -1831,16 +1831,16 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
int
m
;
if
(
s
->
lsps
==
10
)
{
dequant_lsp10i
(
gb
,
lsps
[
n
]);
dequant_lsp10i
(
bc
,
lsps
[
n
]);
}
else
/* s->lsps == 16 */
dequant_lsp16i
(
gb
,
lsps
[
n
]);
dequant_lsp16i
(
bc
,
lsps
[
n
]);
for
(
m
=
0
;
m
<
s
->
lsps
;
m
++
)
lsps
[
n
][
m
]
+=
mean_lsf
[
m
];
stabilize_lsps
(
lsps
[
n
],
s
->
lsps
);
}
if
((
res
=
synth_frame
(
ctx
,
gb
,
n
,
if
((
res
=
synth_frame
(
ctx
,
bc
,
n
,
&
samples
[
n
*
MAX_FRAMESIZE
],
lsps
[
n
],
n
==
0
?
s
->
prev_lsps
:
lsps
[
n
-
1
],
&
excitation
[
s
->
history_nsamples
+
n
*
MAX_FRAMESIZE
],
...
...
@@ -1853,9 +1853,9 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
/* Statistics? FIXME - we don't check for length, a slight overrun
* will be caught by internal buffer padding, and anything else
* will be skipped, not read. */
if
(
get_bits1
(
gb
))
{
res
=
get_bits
(
gb
,
4
);
skip_bits
(
gb
,
10
*
(
res
+
1
));
if
(
bitstream_read_bit
(
bc
))
{
res
=
bitstream_read
(
bc
,
4
);
bitstream_skip
(
bc
,
10
*
(
res
+
1
));
}
*
got_frame_ptr
=
1
;
...
...
@@ -1883,31 +1883,31 @@ static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,
*/
static
int
parse_packet_header
(
WMAVoiceContext
*
s
)
{
GetBitContext
*
gb
=
&
s
->
gb
;
BitstreamContext
*
bc
=
&
s
->
bc
;
unsigned
int
res
;
if
(
get_bits_left
(
gb
)
<
11
)
if
(
bitstream_bits_left
(
bc
)
<
11
)
return
1
;
skip_bits
(
gb
,
4
);
// packet sequence number
s
->
has_residual_lsps
=
get_bits1
(
gb
);
bitstream_skip
(
bc
,
4
);
// packet sequence number
s
->
has_residual_lsps
=
bitstream_read_bit
(
bc
);
do
{
res
=
get_bits
(
gb
,
6
);
// number of superframes per packet
res
=
bitstream_read
(
bc
,
6
);
// number of superframes per packet
// (minus first one if there is spillover)
if
(
get_bits_left
(
gb
)
<
6
*
(
res
==
0x3F
)
+
s
->
spillover_bitsize
)
if
(
bitstream_bits_left
(
bc
)
<
6
*
(
res
==
0x3F
)
+
s
->
spillover_bitsize
)
return
1
;
}
while
(
res
==
0x3F
);
s
->
spillover_nbits
=
get_bits
(
gb
,
s
->
spillover_bitsize
);
s
->
spillover_nbits
=
bitstream_read
(
bc
,
s
->
spillover_bitsize
);
return
0
;
}
/**
* Copy (unaligned) bits from
gb
/data/size to pb.
* Copy (unaligned) bits from
bc
/data/size to pb.
*
* @param pb target buffer to copy bits into
* @param data source buffer to copy bits from
* @param size size of the source data, in bytes
* @param
gb
bit I/O context specifying the current position in the source.
* @param
bc
bit I/O context specifying the current position in the source.
* data. This function might use this to align the bit position to
* a whole-byte boundary before calling #avpriv_copy_bits() on aligned
* source data
...
...
@@ -1918,18 +1918,18 @@ static int parse_packet_header(WMAVoiceContext *s)
*/
static
void
copy_bits
(
PutBitContext
*
pb
,
const
uint8_t
*
data
,
int
size
,
GetBitContext
*
gb
,
int
nbits
)
BitstreamContext
*
bc
,
int
nbits
)
{
int
rmn_bytes
,
rmn_bits
;
rmn_bits
=
rmn_bytes
=
get_bits_left
(
gb
);
rmn_bits
=
rmn_bytes
=
bitstream_bits_left
(
bc
);
if
(
rmn_bits
<
nbits
)
return
;
if
(
nbits
>
pb
->
size_in_bits
-
put_bits_count
(
pb
))
return
;
rmn_bits
&=
7
;
rmn_bytes
>>=
3
;
if
((
rmn_bits
=
FFMIN
(
rmn_bits
,
nbits
))
>
0
)
put_bits
(
pb
,
rmn_bits
,
get_bits
(
gb
,
rmn_bits
));
put_bits
(
pb
,
rmn_bits
,
bitstream_read
(
bc
,
rmn_bits
));
avpriv_copy_bits
(
pb
,
data
+
size
-
rmn_bytes
,
FFMIN
(
nbits
-
rmn_bits
,
rmn_bytes
<<
3
));
}
...
...
@@ -1949,7 +1949,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
int
*
got_frame_ptr
,
AVPacket
*
avpkt
)
{
WMAVoiceContext
*
s
=
ctx
->
priv_data
;
GetBitContext
*
gb
=
&
s
->
gb
;
BitstreamContext
*
bc
=
&
s
->
bc
;
int
size
,
res
,
pos
;
/* Packets are sometimes a multiple of ctx->block_align, with a packet
...
...
@@ -1962,7 +1962,7 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
*
got_frame_ptr
=
0
;
return
0
;
}
init_get_bits
(
&
s
->
gb
,
avpkt
->
data
,
size
<<
3
);
bitstream_init8
(
&
s
->
bc
,
avpkt
->
data
,
size
);
/* size == ctx->block_align is used to indicate whether we are dealing with
* a new packet or a packet of which we already read the packet header
...
...
@@ -1976,8 +1976,8 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
* continuing to parse new superframes in the current packet. */
if
(
s
->
spillover_nbits
>
0
)
{
if
(
s
->
sframe_cache_size
>
0
)
{
int
cnt
=
get_bits_count
(
gb
);
copy_bits
(
&
s
->
pb
,
avpkt
->
data
,
size
,
gb
,
s
->
spillover_nbits
);
int
cnt
=
bitstream_tell
(
bc
);
copy_bits
(
&
s
->
pb
,
avpkt
->
data
,
size
,
bc
,
s
->
spillover_nbits
);
flush_put_bits
(
&
s
->
pb
);
s
->
sframe_cache_size
+=
s
->
spillover_nbits
;
if
((
res
=
synth_superframe
(
ctx
,
data
,
got_frame_ptr
))
==
0
&&
...
...
@@ -1986,33 +1986,33 @@ static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
s
->
skip_bits_next
=
cnt
&
7
;
return
cnt
>>
3
;
}
else
skip_bits_long
(
gb
,
s
->
spillover_nbits
-
cnt
+
get_bits_count
(
gb
));
// resync
bitstream_skip
(
bc
,
s
->
spillover_nbits
-
cnt
+
bitstream_tell
(
bc
));
// resync
}
else
skip_bits_long
(
gb
,
s
->
spillover_nbits
);
// resync
bitstream_skip
(
bc
,
s
->
spillover_nbits
);
// resync
}
}
else
if
(
s
->
skip_bits_next
)
skip_bits
(
gb
,
s
->
skip_bits_next
);
bitstream_skip
(
bc
,
s
->
skip_bits_next
);
/* Try parsing superframes in current packet */
s
->
sframe_cache_size
=
0
;
s
->
skip_bits_next
=
0
;
pos
=
get_bits_left
(
gb
);
pos
=
bitstream_bits_left
(
bc
);
if
((
res
=
synth_superframe
(
ctx
,
data
,
got_frame_ptr
))
<
0
)
{
return
res
;
}
else
if
(
*
got_frame_ptr
)
{
int
cnt
=
get_bits_count
(
gb
);
int
cnt
=
bitstream_tell
(
bc
);
s
->
skip_bits_next
=
cnt
&
7
;
return
cnt
>>
3
;
}
else
if
((
s
->
sframe_cache_size
=
pos
)
>
0
)
{
/* rewind bit reader to start of last (incomplete) superframe... */
init_get_bits
(
gb
,
avpkt
->
data
,
size
<<
3
);
skip_bits_long
(
gb
,
(
size
<<
3
)
-
pos
);
assert
(
get_bits_left
(
gb
)
==
pos
);
bitstream_init8
(
bc
,
avpkt
->
data
,
size
);
bitstream_skip
(
bc
,
(
size
<<
3
)
-
pos
);
assert
(
bitstream_bits_left
(
bc
)
==
pos
);
/* ...and cache it for spillover in next packet */
init_put_bits
(
&
s
->
pb
,
s
->
sframe_cache
,
SFRAME_CACHE_MAXSIZE
);
copy_bits
(
&
s
->
pb
,
avpkt
->
data
,
size
,
gb
,
s
->
sframe_cache_size
);
copy_bits
(
&
s
->
pb
,
avpkt
->
data
,
size
,
bc
,
s
->
sframe_cache_size
);
// FIXME bad - just copy bytes as whole and add use the
// skip_bits_next field
}
...
...
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