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
fd065d3e
Commit
fd065d3e
authored
Jul 07, 2011
by
Diego Biurrun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cabac: Move code only used in the cabac test program to cabac.c.
parent
0a858048
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
172 deletions
+134
-172
cabac.c
libavcodec/cabac.c
+134
-0
cabac.h
libavcodec/cabac.h
+0
-172
No files found.
libavcodec/cabac.c
View file @
fd065d3e
...
...
@@ -166,6 +166,140 @@ void ff_init_cabac_states(CABACContext *c){
#include "avcodec.h"
#include "cabac.h"
static
void
put_cabac
(
CABACContext
*
c
,
uint8_t
*
const
state
,
int
bit
){
int
RangeLPS
=
ff_h264_lps_range
[
2
*
(
c
->
range
&
0xC0
)
+
*
state
];
if
(
bit
==
((
*
state
)
&
1
)){
c
->
range
-=
RangeLPS
;
*
state
=
ff_h264_mps_state
[
*
state
];
}
else
{
c
->
low
+=
c
->
range
-
RangeLPS
;
c
->
range
=
RangeLPS
;
*
state
=
ff_h264_lps_state
[
*
state
];
}
renorm_cabac_encoder
(
c
);
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
}
/**
* @param bit 0 -> write zero bit, !=0 write one bit
*/
static
void
put_cabac_bypass
(
CABACContext
*
c
,
int
bit
){
c
->
low
+=
c
->
low
;
if
(
bit
){
c
->
low
+=
c
->
range
;
}
//FIXME optimize
if
(
c
->
low
<
0x200
){
put_cabac_bit
(
c
,
0
);
}
else
if
(
c
->
low
<
0x400
){
c
->
outstanding_count
++
;
c
->
low
-=
0x200
;
}
else
{
put_cabac_bit
(
c
,
1
);
c
->
low
-=
0x400
;
}
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
}
/**
*
* @return the number of bytes written
*/
static
int
put_cabac_terminate
(
CABACContext
*
c
,
int
bit
){
c
->
range
-=
2
;
if
(
!
bit
){
renorm_cabac_encoder
(
c
);
}
else
{
c
->
low
+=
c
->
range
;
c
->
range
=
2
;
renorm_cabac_encoder
(
c
);
assert
(
c
->
low
<=
0x1FF
);
put_cabac_bit
(
c
,
c
->
low
>>
9
);
put_bits
(
&
c
->
pb
,
2
,
((
c
->
low
>>
7
)
&
3
)
|
1
);
flush_put_bits
(
&
c
->
pb
);
//FIXME FIXME FIXME XXX wrong
}
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
return
(
put_bits_count
(
&
c
->
pb
)
+
7
)
>>
3
;
}
/**
* put (truncated) unary binarization.
*/
static
void
put_cabac_u
(
CABACContext
*
c
,
uint8_t
*
state
,
int
v
,
int
max
,
int
max_index
,
int
truncated
){
int
i
;
assert
(
v
<=
max
);
for
(
i
=
0
;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
if
(
truncated
==
0
||
v
<
max
)
put_cabac
(
c
,
state
,
0
);
}
/**
* put unary exp golomb k-th order binarization.
*/
static
void
put_cabac_ueg
(
CABACContext
*
c
,
uint8_t
*
state
,
int
v
,
int
max
,
int
is_signed
,
int
k
,
int
max_index
){
int
i
;
if
(
v
==
0
)
put_cabac
(
c
,
state
,
0
);
else
{
const
int
sign
=
v
<
0
;
if
(
is_signed
)
v
=
FFABS
(
v
);
if
(
v
<
max
){
for
(
i
=
0
;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
put_cabac
(
c
,
state
,
0
);
}
else
{
int
m
=
1
<<
k
;
for
(
i
=
0
;
i
<
max
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
v
-=
max
;
while
(
v
>=
m
){
//FIXME optimize
put_cabac_bypass
(
c
,
1
);
v
-=
m
;
m
+=
m
;
}
put_cabac_bypass
(
c
,
0
);
while
(
m
>>=
1
){
put_cabac_bypass
(
c
,
v
&
m
);
}
}
if
(
is_signed
)
put_cabac_bypass
(
c
,
sign
);
}
}
int
main
(
void
){
CABACContext
c
;
uint8_t
b
[
9
*
SIZE
];
...
...
libavcodec/cabac.h
View file @
fd065d3e
...
...
@@ -90,178 +90,6 @@ static inline void renorm_cabac_encoder(CABACContext *c){
}
}
#ifdef TEST
static
void
put_cabac
(
CABACContext
*
c
,
uint8_t
*
const
state
,
int
bit
){
int
RangeLPS
=
ff_h264_lps_range
[
2
*
(
c
->
range
&
0xC0
)
+
*
state
];
if
(
bit
==
((
*
state
)
&
1
)){
c
->
range
-=
RangeLPS
;
*
state
=
ff_h264_mps_state
[
*
state
];
}
else
{
c
->
low
+=
c
->
range
-
RangeLPS
;
c
->
range
=
RangeLPS
;
*
state
=
ff_h264_lps_state
[
*
state
];
}
renorm_cabac_encoder
(
c
);
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
}
static
void
put_cabac_static
(
CABACContext
*
c
,
int
RangeLPS
,
int
bit
){
assert
(
c
->
range
>
RangeLPS
);
if
(
!
bit
){
c
->
range
-=
RangeLPS
;
}
else
{
c
->
low
+=
c
->
range
-
RangeLPS
;
c
->
range
=
RangeLPS
;
}
renorm_cabac_encoder
(
c
);
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
}
/**
* @param bit 0 -> write zero bit, !=0 write one bit
*/
static
void
put_cabac_bypass
(
CABACContext
*
c
,
int
bit
){
c
->
low
+=
c
->
low
;
if
(
bit
){
c
->
low
+=
c
->
range
;
}
//FIXME optimize
if
(
c
->
low
<
0x200
){
put_cabac_bit
(
c
,
0
);
}
else
if
(
c
->
low
<
0x400
){
c
->
outstanding_count
++
;
c
->
low
-=
0x200
;
}
else
{
put_cabac_bit
(
c
,
1
);
c
->
low
-=
0x400
;
}
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
}
/**
*
* @return the number of bytes written
*/
static
int
put_cabac_terminate
(
CABACContext
*
c
,
int
bit
){
c
->
range
-=
2
;
if
(
!
bit
){
renorm_cabac_encoder
(
c
);
}
else
{
c
->
low
+=
c
->
range
;
c
->
range
=
2
;
renorm_cabac_encoder
(
c
);
assert
(
c
->
low
<=
0x1FF
);
put_cabac_bit
(
c
,
c
->
low
>>
9
);
put_bits
(
&
c
->
pb
,
2
,
((
c
->
low
>>
7
)
&
3
)
|
1
);
flush_put_bits
(
&
c
->
pb
);
//FIXME FIXME FIXME XXX wrong
}
#ifdef STRICT_LIMITS
c
->
symCount
++
;
#endif
return
(
put_bits_count
(
&
c
->
pb
)
+
7
)
>>
3
;
}
/**
* put (truncated) unary binarization.
*/
static
void
put_cabac_u
(
CABACContext
*
c
,
uint8_t
*
state
,
int
v
,
int
max
,
int
max_index
,
int
truncated
){
int
i
;
assert
(
v
<=
max
);
#if 1
for
(
i
=
0
;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
if
(
truncated
==
0
||
v
<
max
)
put_cabac
(
c
,
state
,
0
);
#else
if
(
v
<=
max_index
){
for
(
i
=
0
;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
+
i
,
1
);
}
if
(
truncated
==
0
||
v
<
max
)
put_cabac
(
c
,
state
+
i
,
0
);
}
else
{
for
(
i
=
0
;
i
<=
max_index
;
i
++
){
put_cabac
(
c
,
state
+
i
,
1
);
}
for
(;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
+
max_index
,
1
);
}
if
(
truncated
==
0
||
v
<
max
)
put_cabac
(
c
,
state
+
max_index
,
0
);
}
#endif
}
/**
* put unary exp golomb k-th order binarization.
*/
static
void
put_cabac_ueg
(
CABACContext
*
c
,
uint8_t
*
state
,
int
v
,
int
max
,
int
is_signed
,
int
k
,
int
max_index
){
int
i
;
if
(
v
==
0
)
put_cabac
(
c
,
state
,
0
);
else
{
const
int
sign
=
v
<
0
;
if
(
is_signed
)
v
=
FFABS
(
v
);
if
(
v
<
max
){
for
(
i
=
0
;
i
<
v
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
put_cabac
(
c
,
state
,
0
);
}
else
{
int
m
=
1
<<
k
;
for
(
i
=
0
;
i
<
max
;
i
++
){
put_cabac
(
c
,
state
,
1
);
if
(
i
<
max_index
)
state
++
;
}
v
-=
max
;
while
(
v
>=
m
){
//FIXME optimize
put_cabac_bypass
(
c
,
1
);
v
-=
m
;
m
+=
m
;
}
put_cabac_bypass
(
c
,
0
);
while
(
m
>>=
1
){
put_cabac_bypass
(
c
,
v
&
m
);
}
}
if
(
is_signed
)
put_cabac_bypass
(
c
,
sign
);
}
}
#endif
/* TEST */
static
void
refill
(
CABACContext
*
c
){
#if CABAC_BITS == 16
c
->
low
+=
(
c
->
bytestream
[
0
]
<<
9
)
+
(
c
->
bytestream
[
1
]
<<
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