summaryrefslogtreecommitdiff
path: root/libavcodec/huffyuvdec.c
diff options
context:
space:
mode:
authorChristophe Gisquet <christophe.gisquet@gmail.com>2014-06-15 12:04:36 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-06-16 00:52:09 +0200
commitf6577bd9cf3e49d522242771184834d6b0c157fd (patch)
treeadb52be554906c1df501b4076256a5af03ace1f9 /libavcodec/huffyuvdec.c
parent02bffc560f5ee91afa62b6c1a1a7012efc161734 (diff)
huffyuvdec: use unsafe bitstream reader
The reader reads in chunks of 11 bits at most, and at most 3 times. The unsafe reader therefore may read 6 chunks instead of 1 in worst case, ie 8 bytes, which is within the padding tolerance. The reader ends up being ~10% faster. Cumulative effect of unsafe reading and code block swapping on 3 sequences is for 1 thread, decoding time goes from 23.3s to 19.0s. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/huffyuvdec.c')
-rw-r--r--libavcodec/huffyuvdec.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index 6691149089..7bb9b2dea0 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -30,6 +30,8 @@
* huffyuv decoder
*/
+#define UNCHECKED_BITSTREAM_READER 1
+
#include "avcodec.h"
#include "get_bits.h"
#include "huffyuv.h"
@@ -613,15 +615,21 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
static void decode_422_bitstream(HYuvContext *s, int count)
{
- int i;
+ int i, icount;
OPEN_READER(re, &s->gb);
count /= 2;
- if (count >= (get_bits_left(&s->gb)) / (32 * 4)) {
- for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
+ icount = get_bits_left(&s->gb) / (32 * 4);
+ if (count >= icount) {
+ for (i = 0; i < icount; i++) {
READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1);
READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
}
+ for (; i < count && get_bits_left(&s->gb) > 0; i++) {
+ READ_2PIX(s->temp[0][2 * i ], s->temp[1][i], 1);
+ if (get_bits_left(&s->gb) <= 0) break;
+ READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
+ }
for (; i < count; i++)
s->temp[0][2 * i ] = s->temp[1][i] =
s->temp[0][2 * i + 1] = s->temp[2][i] = 128;
@@ -716,7 +724,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count,
int i;
OPEN_READER(re, &s->gb);
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
unsigned int index;
int code, n;