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
2188d539
Commit
2188d539
authored
Apr 18, 2016
by
Alexandra Hájková
Committed by
Anton Khirnov
Nov 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
g72x: Convert to the new bitstream reader
Signed-off-by:
Anton Khirnov
<
anton@khirnov.net
>
parent
799703c3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
47 deletions
+49
-47
g722dec.c
libavcodec/g722dec.c
+7
-6
g723_1dec.c
libavcodec/g723_1dec.c
+36
-36
g726.c
libavcodec/g726.c
+6
-5
No files found.
libavcodec/g722dec.c
View file @
2188d539
...
@@ -36,8 +36,9 @@
...
@@ -36,8 +36,9 @@
#include "libavutil/channel_layout.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "avcodec.h"
#include "
get_bits
.h"
#include "
bitstream
.h"
#include "g722.h"
#include "g722.h"
#include "internal.h"
#include "internal.h"
...
@@ -92,7 +93,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -92,7 +93,7 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
int
j
,
ret
;
int
j
,
ret
;
const
int
skip
=
8
-
c
->
bits_per_codeword
;
const
int
skip
=
8
-
c
->
bits_per_codeword
;
const
int16_t
*
quantizer_table
=
low_inv_quants
[
skip
];
const
int16_t
*
quantizer_table
=
low_inv_quants
[
skip
];
GetBitContext
gb
;
BitstreamContext
bc
;
/* get output buffer */
/* get output buffer */
frame
->
nb_samples
=
avpkt
->
size
*
2
;
frame
->
nb_samples
=
avpkt
->
size
*
2
;
...
@@ -102,15 +103,15 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -102,15 +103,15 @@ static int g722_decode_frame(AVCodecContext *avctx, void *data,
}
}
out_buf
=
(
int16_t
*
)
frame
->
data
[
0
];
out_buf
=
(
int16_t
*
)
frame
->
data
[
0
];
init_get_bits
(
&
gb
,
avpkt
->
data
,
avpkt
->
size
*
8
);
bitstream_init
(
&
bc
,
avpkt
->
data
,
avpkt
->
size
*
8
);
for
(
j
=
0
;
j
<
avpkt
->
size
;
j
++
)
{
for
(
j
=
0
;
j
<
avpkt
->
size
;
j
++
)
{
int
ilow
,
ihigh
,
rlow
,
rhigh
,
dhigh
;
int
ilow
,
ihigh
,
rlow
,
rhigh
,
dhigh
;
int
xout
[
2
];
int
xout
[
2
];
ihigh
=
get_bits
(
&
gb
,
2
);
ihigh
=
bitstream_read
(
&
bc
,
2
);
ilow
=
get_bits
(
&
gb
,
6
-
skip
);
ilow
=
bitstream_read
(
&
bc
,
6
-
skip
);
skip_bits
(
&
gb
,
skip
);
bitstream_skip
(
&
bc
,
skip
);
rlow
=
av_clip_intp2
((
c
->
band
[
0
].
scale_factor
*
quantizer_table
[
ilow
]
>>
10
)
rlow
=
av_clip_intp2
((
c
->
band
[
0
].
scale_factor
*
quantizer_table
[
ilow
]
>>
10
)
+
c
->
band
[
0
].
s_predictor
,
14
);
+
c
->
band
[
0
].
s_predictor
,
14
);
...
...
libavcodec/g723_1dec.c
View file @
2188d539
...
@@ -32,8 +32,8 @@
...
@@ -32,8 +32,8 @@
#define BITSTREAM_READER_LE
#define BITSTREAM_READER_LE
#include "acelp_vectors.h"
#include "acelp_vectors.h"
#include "avcodec.h"
#include "avcodec.h"
#include "bitstream.h"
#include "celp_filters.h"
#include "celp_filters.h"
#include "get_bits.h"
#include "internal.h"
#include "internal.h"
#include "g723_1.h"
#include "g723_1.h"
...
@@ -68,14 +68,14 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
...
@@ -68,14 +68,14 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
static
int
unpack_bitstream
(
G723_1_Context
*
p
,
const
uint8_t
*
buf
,
static
int
unpack_bitstream
(
G723_1_Context
*
p
,
const
uint8_t
*
buf
,
int
buf_size
)
int
buf_size
)
{
{
GetBitContext
gb
;
BitstreamContext
bc
;
int
ad_cb_len
;
int
ad_cb_len
;
int
temp
,
info_bits
,
i
;
int
temp
,
info_bits
,
i
;
init_get_bits
(
&
gb
,
buf
,
buf_size
*
8
);
bitstream_init
(
&
bc
,
buf
,
buf_size
*
8
);
/* Extract frame type and rate info */
/* Extract frame type and rate info */
info_bits
=
get_bits
(
&
gb
,
2
);
info_bits
=
bitstream_read
(
&
bc
,
2
);
if
(
info_bits
==
3
)
{
if
(
info_bits
==
3
)
{
p
->
cur_frame_type
=
UNTRANSMITTED_FRAME
;
p
->
cur_frame_type
=
UNTRANSMITTED_FRAME
;
...
@@ -83,13 +83,13 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
...
@@ -83,13 +83,13 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
}
}
/* Extract 24 bit lsp indices, 8 bit for each band */
/* Extract 24 bit lsp indices, 8 bit for each band */
p
->
lsp_index
[
2
]
=
get_bits
(
&
gb
,
8
);
p
->
lsp_index
[
2
]
=
bitstream_read
(
&
bc
,
8
);
p
->
lsp_index
[
1
]
=
get_bits
(
&
gb
,
8
);
p
->
lsp_index
[
1
]
=
bitstream_read
(
&
bc
,
8
);
p
->
lsp_index
[
0
]
=
get_bits
(
&
gb
,
8
);
p
->
lsp_index
[
0
]
=
bitstream_read
(
&
bc
,
8
);
if
(
info_bits
==
2
)
{
if
(
info_bits
==
2
)
{
p
->
cur_frame_type
=
SID_FRAME
;
p
->
cur_frame_type
=
SID_FRAME
;
p
->
subframe
[
0
].
amp_index
=
get_bits
(
&
gb
,
6
);
p
->
subframe
[
0
].
amp_index
=
bitstream_read
(
&
bc
,
6
);
return
0
;
return
0
;
}
}
...
@@ -97,23 +97,23 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
...
@@ -97,23 +97,23 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
p
->
cur_rate
=
info_bits
?
RATE_5300
:
RATE_6300
;
p
->
cur_rate
=
info_bits
?
RATE_5300
:
RATE_6300
;
p
->
cur_frame_type
=
ACTIVE_FRAME
;
p
->
cur_frame_type
=
ACTIVE_FRAME
;
p
->
pitch_lag
[
0
]
=
get_bits
(
&
gb
,
7
);
p
->
pitch_lag
[
0
]
=
bitstream_read
(
&
bc
,
7
);
if
(
p
->
pitch_lag
[
0
]
>
123
)
/* test if forbidden code */
if
(
p
->
pitch_lag
[
0
]
>
123
)
/* test if forbidden code */
return
-
1
;
return
-
1
;
p
->
pitch_lag
[
0
]
+=
PITCH_MIN
;
p
->
pitch_lag
[
0
]
+=
PITCH_MIN
;
p
->
subframe
[
1
].
ad_cb_lag
=
get_bits
(
&
gb
,
2
);
p
->
subframe
[
1
].
ad_cb_lag
=
bitstream_read
(
&
bc
,
2
);
p
->
pitch_lag
[
1
]
=
get_bits
(
&
gb
,
7
);
p
->
pitch_lag
[
1
]
=
bitstream_read
(
&
bc
,
7
);
if
(
p
->
pitch_lag
[
1
]
>
123
)
if
(
p
->
pitch_lag
[
1
]
>
123
)
return
-
1
;
return
-
1
;
p
->
pitch_lag
[
1
]
+=
PITCH_MIN
;
p
->
pitch_lag
[
1
]
+=
PITCH_MIN
;
p
->
subframe
[
3
].
ad_cb_lag
=
get_bits
(
&
gb
,
2
);
p
->
subframe
[
3
].
ad_cb_lag
=
bitstream_read
(
&
bc
,
2
);
p
->
subframe
[
0
].
ad_cb_lag
=
1
;
p
->
subframe
[
0
].
ad_cb_lag
=
1
;
p
->
subframe
[
2
].
ad_cb_lag
=
1
;
p
->
subframe
[
2
].
ad_cb_lag
=
1
;
for
(
i
=
0
;
i
<
SUBFRAMES
;
i
++
)
{
for
(
i
=
0
;
i
<
SUBFRAMES
;
i
++
)
{
/* Extract combined gain */
/* Extract combined gain */
temp
=
get_bits
(
&
gb
,
12
);
temp
=
bitstream_read
(
&
bc
,
12
);
ad_cb_len
=
170
;
ad_cb_len
=
170
;
p
->
subframe
[
i
].
dirac_train
=
0
;
p
->
subframe
[
i
].
dirac_train
=
0
;
if
(
p
->
cur_rate
==
RATE_6300
&&
p
->
pitch_lag
[
i
>>
1
]
<
SUBFRAME_LEN
-
2
)
{
if
(
p
->
cur_rate
==
RATE_6300
&&
p
->
pitch_lag
[
i
>>
1
]
<
SUBFRAME_LEN
-
2
)
{
...
@@ -130,16 +130,16 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
...
@@ -130,16 +130,16 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
}
}
}
}
p
->
subframe
[
0
].
grid_index
=
get_bits
(
&
gb
,
1
);
p
->
subframe
[
0
].
grid_index
=
bitstream_read
(
&
bc
,
1
);
p
->
subframe
[
1
].
grid_index
=
get_bits
(
&
gb
,
1
);
p
->
subframe
[
1
].
grid_index
=
bitstream_read
(
&
bc
,
1
);
p
->
subframe
[
2
].
grid_index
=
get_bits
(
&
gb
,
1
);
p
->
subframe
[
2
].
grid_index
=
bitstream_read
(
&
bc
,
1
);
p
->
subframe
[
3
].
grid_index
=
get_bits
(
&
gb
,
1
);
p
->
subframe
[
3
].
grid_index
=
bitstream_read
(
&
bc
,
1
);
if
(
p
->
cur_rate
==
RATE_6300
)
{
if
(
p
->
cur_rate
==
RATE_6300
)
{
skip_bits
(
&
gb
,
1
);
/* skip reserved bit */
bitstream_skip
(
&
bc
,
1
);
/* skip reserved bit */
/* Compute pulse_pos index using the 13-bit combined position index */
/* Compute pulse_pos index using the 13-bit combined position index */
temp
=
get_bits
(
&
gb
,
13
);
temp
=
bitstream_read
(
&
bc
,
13
);
p
->
subframe
[
0
].
pulse_pos
=
temp
/
810
;
p
->
subframe
[
0
].
pulse_pos
=
temp
/
810
;
temp
-=
p
->
subframe
[
0
].
pulse_pos
*
810
;
temp
-=
p
->
subframe
[
0
].
pulse_pos
*
810
;
...
@@ -150,28 +150,28 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
...
@@ -150,28 +150,28 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
p
->
subframe
[
3
].
pulse_pos
=
temp
-
p
->
subframe
[
2
].
pulse_pos
*
9
;
p
->
subframe
[
3
].
pulse_pos
=
temp
-
p
->
subframe
[
2
].
pulse_pos
*
9
;
p
->
subframe
[
0
].
pulse_pos
=
(
p
->
subframe
[
0
].
pulse_pos
<<
16
)
+
p
->
subframe
[
0
].
pulse_pos
=
(
p
->
subframe
[
0
].
pulse_pos
<<
16
)
+
get_bits
(
&
gb
,
16
);
bitstream_read
(
&
bc
,
16
);
p
->
subframe
[
1
].
pulse_pos
=
(
p
->
subframe
[
1
].
pulse_pos
<<
14
)
+
p
->
subframe
[
1
].
pulse_pos
=
(
p
->
subframe
[
1
].
pulse_pos
<<
14
)
+
get_bits
(
&
gb
,
14
);
bitstream_read
(
&
bc
,
14
);
p
->
subframe
[
2
].
pulse_pos
=
(
p
->
subframe
[
2
].
pulse_pos
<<
16
)
+
p
->
subframe
[
2
].
pulse_pos
=
(
p
->
subframe
[
2
].
pulse_pos
<<
16
)
+
get_bits
(
&
gb
,
16
);
bitstream_read
(
&
bc
,
16
);
p
->
subframe
[
3
].
pulse_pos
=
(
p
->
subframe
[
3
].
pulse_pos
<<
14
)
+
p
->
subframe
[
3
].
pulse_pos
=
(
p
->
subframe
[
3
].
pulse_pos
<<
14
)
+
get_bits
(
&
gb
,
14
);
bitstream_read
(
&
bc
,
14
);
p
->
subframe
[
0
].
pulse_sign
=
get_bits
(
&
gb
,
6
);
p
->
subframe
[
0
].
pulse_sign
=
bitstream_read
(
&
bc
,
6
);
p
->
subframe
[
1
].
pulse_sign
=
get_bits
(
&
gb
,
5
);
p
->
subframe
[
1
].
pulse_sign
=
bitstream_read
(
&
bc
,
5
);
p
->
subframe
[
2
].
pulse_sign
=
get_bits
(
&
gb
,
6
);
p
->
subframe
[
2
].
pulse_sign
=
bitstream_read
(
&
bc
,
6
);
p
->
subframe
[
3
].
pulse_sign
=
get_bits
(
&
gb
,
5
);
p
->
subframe
[
3
].
pulse_sign
=
bitstream_read
(
&
bc
,
5
);
}
else
{
/* 5300 bps */
}
else
{
/* 5300 bps */
p
->
subframe
[
0
].
pulse_pos
=
get_bits
(
&
gb
,
12
);
p
->
subframe
[
0
].
pulse_pos
=
bitstream_read
(
&
bc
,
12
);
p
->
subframe
[
1
].
pulse_pos
=
get_bits
(
&
gb
,
12
);
p
->
subframe
[
1
].
pulse_pos
=
bitstream_read
(
&
bc
,
12
);
p
->
subframe
[
2
].
pulse_pos
=
get_bits
(
&
gb
,
12
);
p
->
subframe
[
2
].
pulse_pos
=
bitstream_read
(
&
bc
,
12
);
p
->
subframe
[
3
].
pulse_pos
=
get_bits
(
&
gb
,
12
);
p
->
subframe
[
3
].
pulse_pos
=
bitstream_read
(
&
bc
,
12
);
p
->
subframe
[
0
].
pulse_sign
=
get_bits
(
&
gb
,
4
);
p
->
subframe
[
0
].
pulse_sign
=
bitstream_read
(
&
bc
,
4
);
p
->
subframe
[
1
].
pulse_sign
=
get_bits
(
&
gb
,
4
);
p
->
subframe
[
1
].
pulse_sign
=
bitstream_read
(
&
bc
,
4
);
p
->
subframe
[
2
].
pulse_sign
=
get_bits
(
&
gb
,
4
);
p
->
subframe
[
2
].
pulse_sign
=
bitstream_read
(
&
bc
,
4
);
p
->
subframe
[
3
].
pulse_sign
=
get_bits
(
&
gb
,
4
);
p
->
subframe
[
3
].
pulse_sign
=
bitstream_read
(
&
bc
,
4
);
}
}
return
0
;
return
0
;
...
...
libavcodec/g726.c
View file @
2188d539
...
@@ -25,9 +25,10 @@
...
@@ -25,9 +25,10 @@
#include "libavutil/channel_layout.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
#include "put_bits.h"
/**
/**
...
@@ -429,7 +430,7 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -429,7 +430,7 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data,
int
buf_size
=
avpkt
->
size
;
int
buf_size
=
avpkt
->
size
;
G726Context
*
c
=
avctx
->
priv_data
;
G726Context
*
c
=
avctx
->
priv_data
;
int16_t
*
samples
;
int16_t
*
samples
;
GetBitContext
gb
;
BitstreamContext
bc
;
int
out_samples
,
ret
;
int
out_samples
,
ret
;
out_samples
=
buf_size
*
8
/
c
->
code_size
;
out_samples
=
buf_size
*
8
/
c
->
code_size
;
...
@@ -442,12 +443,12 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -442,12 +443,12 @@ static int g726_decode_frame(AVCodecContext *avctx, void *data,
}
}
samples
=
(
int16_t
*
)
frame
->
data
[
0
];
samples
=
(
int16_t
*
)
frame
->
data
[
0
];
init_get_bits
(
&
gb
,
buf
,
buf_size
*
8
);
bitstream_init
(
&
bc
,
buf
,
buf_size
*
8
);
while
(
out_samples
--
)
while
(
out_samples
--
)
*
samples
++
=
g726_decode
(
c
,
get_bits
(
&
gb
,
c
->
code_size
));
*
samples
++
=
g726_decode
(
c
,
bitstream_read
(
&
bc
,
c
->
code_size
));
if
(
get_bits_left
(
&
gb
)
>
0
)
if
(
bitstream_bits_left
(
&
bc
)
>
0
)
av_log
(
avctx
,
AV_LOG_ERROR
,
"Frame invalidly split, missing parser?
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Frame invalidly split, missing parser?
\n
"
);
*
got_frame_ptr
=
1
;
*
got_frame_ptr
=
1
;
...
...
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