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
ca079b09
Commit
ca079b09
authored
Jul 07, 2017
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/get_bits: add cached bitstream reader
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
a3c6b7ff
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
367 additions
and
2 deletions
+367
-2
get_bits.h
libavcodec/get_bits.h
+216
-2
golomb.h
libavcodec/golomb.h
+151
-0
No files found.
libavcodec/get_bits.h
View file @
ca079b09
This diff is collapsed.
Click to expand it.
libavcodec/golomb.h
View file @
ca079b09
...
...
@@ -54,6 +54,23 @@ static inline int get_ue_golomb(GetBitContext *gb)
{
unsigned
int
buf
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
if
(
buf
>=
(
1
<<
27
))
{
buf
>>=
32
-
9
;
skip_bits_long
(
gb
,
ff_golomb_vlc_len
[
buf
]);
return
ff_ue_golomb_vlc_code
[
buf
];
}
else
{
int
log
=
2
*
av_log2
(
buf
)
-
31
;
buf
>>=
log
;
buf
--
;
skip_bits_long
(
gb
,
32
-
log
);
return
buf
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -77,6 +94,7 @@ static inline int get_ue_golomb(GetBitContext *gb)
return
buf
;
}
#endif
}
/**
...
...
@@ -101,6 +119,13 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
{
unsigned
int
buf
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
buf
>>=
32
-
9
;
skip_bits_long
(
gb
,
ff_golomb_vlc_len
[
buf
]);
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -108,6 +133,7 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
buf
>>=
32
-
9
;
LAST_SKIP_BITS
(
re
,
gb
,
ff_golomb_vlc_len
[
buf
]);
CLOSE_READER
(
re
,
gb
);
#endif
return
ff_ue_golomb_vlc_code
[
buf
];
}
...
...
@@ -116,6 +142,33 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
{
uint32_t
buf
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
if
(
buf
&
0xAA800000
)
{
buf
>>=
32
-
8
;
skip_bits_long
(
gb
,
ff_interleaved_golomb_vlc_len
[
buf
]);
return
ff_interleaved_ue_golomb_vlc_code
[
buf
];
}
else
{
unsigned
ret
=
1
;
do
{
buf
>>=
32
-
8
;
skip_bits_long
(
gb
,
FFMIN
(
ff_interleaved_golomb_vlc_len
[
buf
],
8
));
if
(
ff_interleaved_golomb_vlc_len
[
buf
]
!=
9
)
{
ret
<<=
(
ff_interleaved_golomb_vlc_len
[
buf
]
-
1
)
>>
1
;
ret
|=
ff_interleaved_dirac_golomb_vlc_code
[
buf
];
break
;
}
ret
=
(
ret
<<
4
)
|
ff_interleaved_dirac_golomb_vlc_code
[
buf
];
buf
=
show_bits_long
(
gb
,
32
);
}
while
(
get_bits_left
(
gb
)
>
0
);
return
ret
-
1
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -147,6 +200,7 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
CLOSE_READER
(
re
,
gb
);
return
ret
-
1
;
}
#endif
}
/**
...
...
@@ -184,6 +238,28 @@ static inline int get_se_golomb(GetBitContext *gb)
{
unsigned
int
buf
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
if
(
buf
>=
(
1
<<
27
))
{
buf
>>=
32
-
9
;
skip_bits_long
(
gb
,
ff_golomb_vlc_len
[
buf
]);
return
ff_se_golomb_vlc_code
[
buf
];
}
else
{
int
log
=
2
*
av_log2
(
buf
)
-
31
;
buf
>>=
log
;
skip_bits_long
(
gb
,
32
-
log
);
if
(
buf
&
1
)
buf
=
-
(
buf
>>
1
);
else
buf
=
(
buf
>>
1
);
return
buf
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -210,6 +286,7 @@ static inline int get_se_golomb(GetBitContext *gb)
return
buf
;
}
#endif
}
static
inline
int
get_se_golomb_long
(
GetBitContext
*
gb
)
...
...
@@ -223,6 +300,30 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
{
unsigned
int
buf
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
if
(
buf
&
0xAA800000
)
{
buf
>>=
32
-
8
;
skip_bits_long
(
gb
,
ff_interleaved_golomb_vlc_len
[
buf
]);
return
ff_interleaved_se_golomb_vlc_code
[
buf
];
}
else
{
int
log
;
skip_bits
(
gb
,
8
);
buf
|=
1
|
show_bits_long
(
gb
,
24
);
if
((
buf
&
0xAAAAAAAA
)
==
0
)
return
INVALID_VLC
;
for
(
log
=
31
;
(
buf
&
0x80000000
)
==
0
;
log
--
)
buf
=
(
buf
<<
2
)
-
((
buf
<<
log
)
>>
(
log
-
1
))
+
(
buf
>>
30
);
skip_bits_long
(
gb
,
63
-
2
*
log
-
8
);
return
(
signed
)
(((((
buf
<<
log
)
>>
log
)
-
1
)
^
-
(
buf
&
0x1
))
+
1
)
>>
1
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -250,6 +351,7 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
return
(
signed
)
(((((
buf
<<
log
)
>>
log
)
-
1
)
^
-
(
buf
&
0x1
))
+
1
)
>>
1
;
}
#endif
}
static
inline
int
dirac_get_se_golomb
(
GetBitContext
*
gb
)
...
...
@@ -273,6 +375,24 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
unsigned
int
buf
;
int
log
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
log
=
av_log2
(
buf
);
if
(
log
>
31
-
limit
)
{
buf
>>=
log
-
k
;
buf
+=
(
30
-
log
)
<<
k
;
skip_bits_long
(
gb
,
32
+
k
-
log
);
return
buf
;
}
else
{
skip_bits_long
(
gb
,
limit
);
buf
=
get_bits_long
(
gb
,
esc_len
);
return
buf
+
limit
-
1
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -297,6 +417,7 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
return
buf
+
limit
-
1
;
}
#endif
}
/**
...
...
@@ -308,6 +429,35 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
unsigned
int
buf
;
int
log
;
#ifdef CACHED_BITSTREAM_READER
buf
=
show_bits_long
(
gb
,
32
);
log
=
av_log2
(
buf
);
if
(
log
-
k
>=
1
&&
32
-
log
<
limit
)
{
buf
>>=
log
-
k
;
buf
+=
(
30
-
log
)
<<
k
;
skip_bits_long
(
gb
,
32
+
k
-
log
);
return
buf
;
}
else
{
int
i
;
for
(
i
=
0
;
i
<
limit
&&
get_bits1
(
gb
)
==
0
&&
get_bits_left
(
gb
)
>
0
;
i
++
);
if
(
i
<
limit
-
1
)
{
buf
=
get_bits_long
(
gb
,
k
);
return
buf
+
(
i
<<
k
);
}
else
if
(
i
==
limit
-
1
)
{
buf
=
get_bits_long
(
gb
,
esc_len
);
return
buf
+
1
;
}
else
return
-
1
;
}
#else
OPEN_READER
(
re
,
gb
);
UPDATE_CACHE
(
re
,
gb
);
buf
=
GET_CACHE
(
re
,
gb
);
...
...
@@ -364,6 +514,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
CLOSE_READER
(
re
,
gb
);
return
buf
;
}
#endif
}
/**
...
...
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