summaryrefslogtreecommitdiff
path: root/vp8/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/decoder')
-rw-r--r--vp8/decoder/dboolhuff.c45
-rw-r--r--vp8/decoder/dboolhuff.h62
-rw-r--r--vp8/decoder/decodemv.h4
-rw-r--r--vp8/decoder/decoderthreading.h20
-rw-r--r--vp8/decoder/decodframe.c60
-rw-r--r--vp8/decoder/detokenize.h7
-rw-r--r--vp8/decoder/ec_types.h3
-rw-r--r--vp8/decoder/error_concealment.c4
-rw-r--r--vp8/decoder/error_concealment.h6
-rw-r--r--vp8/decoder/onyxd_int.h8
-rw-r--r--vp8/decoder/threading.c2
-rw-r--r--vp8/decoder/treereader.h9
-rw-r--r--vp8/decoder/vp8_asm_dec_offsets.c (renamed from vp8/decoder/asm_dec_offsets.c)0
13 files changed, 133 insertions, 97 deletions
diff --git a/vp8/decoder/dboolhuff.c b/vp8/decoder/dboolhuff.c
index 7e7b05aa6..aa7a56a02 100644
--- a/vp8/decoder/dboolhuff.c
+++ b/vp8/decoder/dboolhuff.c
@@ -10,18 +10,20 @@
#include "dboolhuff.h"
-#include "vpx_ports/mem.h"
-#include "vpx_mem/vpx_mem.h"
int vp8dx_start_decode(BOOL_DECODER *br,
const unsigned char *source,
- unsigned int source_sz)
+ unsigned int source_sz,
+ const unsigned char *origin,
+ const unsigned char *key)
{
br->user_buffer_end = source+source_sz;
br->user_buffer = source;
br->value = 0;
br->count = -8;
br->range = 255;
+ br->origin = origin;
+ br->key = key;
if (source_sz && !source)
return 1;
@@ -32,19 +34,34 @@ int vp8dx_start_decode(BOOL_DECODER *br,
return 0;
}
-
void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
{
- const unsigned char *bufptr;
- const unsigned char *bufend;
- VP8_BD_VALUE value;
- int count;
- bufend = br->user_buffer_end;
- bufptr = br->user_buffer;
- value = br->value;
- count = br->count;
-
- VP8DX_BOOL_DECODER_FILL(count, value, bufptr, bufend);
+ const unsigned char *bufptr = br->user_buffer;
+ const unsigned char *bufend = br->user_buffer_end;
+ VP8_BD_VALUE value = br->value;
+ int count = br->count;
+ int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8);
+ size_t bits_left = (bufend - bufptr)*CHAR_BIT;
+ int x = (int)(shift + CHAR_BIT - bits_left);
+ int loop_end = 0;
+
+ if(x >= 0)
+ {
+ count += VP8_LOTS_OF_BITS;
+ loop_end = x;
+ }
+
+ if (x < 0 || bits_left)
+ {
+ while(shift >= loop_end)
+ {
+ count += CHAR_BIT;
+ value |= ((VP8_BD_VALUE)decrypt_byte(bufptr, br->origin,
+ br->key)) << shift;
+ ++bufptr;
+ shift -= CHAR_BIT;
+ }
+ }
br->user_buffer = bufptr;
br->value = value;
diff --git a/vp8/decoder/dboolhuff.h b/vp8/decoder/dboolhuff.h
index 1a08c057b..46a4dd60e 100644
--- a/vp8/decoder/dboolhuff.h
+++ b/vp8/decoder/dboolhuff.h
@@ -9,21 +9,36 @@
*/
-#ifndef DBOOLHUFF_H
-#define DBOOLHUFF_H
+#ifndef DBOOLHUFF_H_
+#define DBOOLHUFF_H_
+
#include <stddef.h>
#include <limits.h>
+
#include "vpx_config.h"
#include "vpx_ports/mem.h"
#include "vpx/vpx_integer.h"
typedef size_t VP8_BD_VALUE;
-# define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
+#define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
+
/*This is meant to be a large, positive constant that can still be efficiently
loaded as an immediate (on platforms like ARM, for example).
Even relatively modest values like 100 would work fine.*/
-# define VP8_LOTS_OF_BITS (0x40000000)
+#define VP8_LOTS_OF_BITS (0x40000000)
+
+static unsigned char decrypt_byte(const unsigned char *ch,
+ const unsigned char *origin,
+ const unsigned char *key)
+{
+#if CONFIG_DECRYPT
+ const int offset = (int)(ch - origin);
+ return *ch ^ key[offset % 32]; // VP8_DECRYPT_KEY_SIZE
+#else
+ return *ch;
+#endif
+}
typedef struct
{
@@ -32,46 +47,20 @@ typedef struct
VP8_BD_VALUE value;
int count;
unsigned int range;
+ const unsigned char *origin;
+ const unsigned char *key;
} BOOL_DECODER;
DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
int vp8dx_start_decode(BOOL_DECODER *br,
const unsigned char *source,
- unsigned int source_sz);
+ unsigned int source_sz,
+ const unsigned char *origin,
+ const unsigned char *key);
void vp8dx_bool_decoder_fill(BOOL_DECODER *br);
-/*The refill loop is used in several places, so define it in a macro to make
- sure they're all consistent.
- An inline function would be cleaner, but has a significant penalty, because
- multiple BOOL_DECODER fields must be modified, and the compiler is not smart
- enough to eliminate the stores to those fields and the subsequent reloads
- from them when inlining the function.*/
-#define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \
- do \
- { \
- int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \
- int loop_end, x; \
- size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \
- \
- x = (int)(shift + CHAR_BIT - bits_left); \
- loop_end = 0; \
- if(x >= 0) \
- { \
- (_count) += VP8_LOTS_OF_BITS; \
- loop_end = x; \
- if(!bits_left) break; \
- } \
- while(shift >= loop_end) \
- { \
- (_count) += CHAR_BIT; \
- (_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \
- shift -= CHAR_BIT; \
- } \
- } \
- while(0) \
-
static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) {
unsigned int bit = 0;
@@ -151,4 +140,5 @@ static int vp8dx_bool_error(BOOL_DECODER *br)
/* No error. */
return 0;
}
-#endif
+
+#endif // DBOOLHUFF_H_
diff --git a/vp8/decoder/decodemv.h b/vp8/decoder/decodemv.h
index 940342447..05a33d27f 100644
--- a/vp8/decoder/decodemv.h
+++ b/vp8/decoder/decodemv.h
@@ -8,7 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#ifndef DECODEMV_H_
+#define DECODEMV_H_
#include "onyxd_int.h"
void vp8_decode_mode_mvs(VP8D_COMP *);
+
+#endif // DECODEMV_H_
diff --git a/vp8/decoder/decoderthreading.h b/vp8/decoder/decoderthreading.h
index 60c39d1e1..bc716e489 100644
--- a/vp8/decoder/decoderthreading.h
+++ b/vp8/decoder/decoderthreading.h
@@ -8,19 +8,15 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
-
-
-
-#ifndef _DECODER_THREADING_H
-#define _DECODER_THREADING_H
+#ifndef DECODERTHREADING_H_
+#define DECODERTHREADING_H_
#if CONFIG_MULTITHREAD
-extern void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd);
-extern void vp8_decoder_remove_threads(VP8D_COMP *pbi);
-extern void vp8_decoder_create_threads(VP8D_COMP *pbi);
-extern void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows);
-extern void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows);
+void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd);
+void vp8_decoder_remove_threads(VP8D_COMP *pbi);
+void vp8_decoder_create_threads(VP8D_COMP *pbi);
+void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows);
+void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows);
#endif
-#endif
+#endif // DECODERTHREADING_H_
diff --git a/vp8/decoder/decodframe.c b/vp8/decoder/decodframe.c
index 6f8282a64..7060005a9 100644
--- a/vp8/decoder/decodframe.c
+++ b/vp8/decoder/decodframe.c
@@ -893,7 +893,9 @@ static void setup_token_decoder(VP8D_COMP *pbi,
{
if (vp8dx_start_decode(bool_decoder,
pbi->fragments.ptrs[partition_idx],
- pbi->fragments.sizes[partition_idx]))
+ pbi->fragments.sizes[partition_idx],
+ pbi->fragments.ptrs[0],
+ pbi->decrypt_key))
vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d",
partition_idx);
@@ -980,10 +982,11 @@ static void init_frame(VP8D_COMP *pbi)
int vp8_decode_frame(VP8D_COMP *pbi)
{
- vp8_reader *const bc = & pbi->mbc[8];
- VP8_COMMON *const pc = & pbi->common;
- MACROBLOCKD *const xd = & pbi->mb;
+ vp8_reader *const bc = &pbi->mbc[8];
+ VP8_COMMON *const pc = &pbi->common;
+ MACROBLOCKD *const xd = &pbi->mb;
const unsigned char *data = pbi->fragments.ptrs[0];
+ const unsigned char *const origin = data;
const unsigned char *data_end = data + pbi->fragments.sizes[0];
ptrdiff_t first_partition_length_in_bytes;
@@ -1016,13 +1019,21 @@ int vp8_decode_frame(VP8D_COMP *pbi)
}
else
{
- pc->frame_type = (FRAME_TYPE)(data[0] & 1);
- pc->version = (data[0] >> 1) & 7;
- pc->show_frame = (data[0] >> 4) & 1;
+ const unsigned char data0 = decrypt_byte(data + 0, origin,
+ pbi->decrypt_key);
+ const unsigned char data1 = decrypt_byte(data + 1, origin,
+ pbi->decrypt_key);
+ const unsigned char data2 = decrypt_byte(data + 2, origin,
+ pbi->decrypt_key);
+
+ pc->frame_type = (FRAME_TYPE)(data0 & 1);
+ pc->version = (data0 >> 1) & 7;
+ pc->show_frame = (data0 >> 4) & 1;
first_partition_length_in_bytes =
- (data[0] | (data[1] << 8) | (data[2] << 16)) >> 5;
+ (data0 | (data1 << 8) | (data2 << 16)) >> 5;
- if (!pbi->ec_active && (data + first_partition_length_in_bytes > data_end
+ if (!pbi->ec_active &&
+ (data + first_partition_length_in_bytes > data_end
|| data + first_partition_length_in_bytes < data))
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet or corrupt partition 0 length");
@@ -1040,7 +1051,13 @@ int vp8_decode_frame(VP8D_COMP *pbi)
*/
if (!pbi->ec_active || data + 3 < data_end)
{
- if (data[0] != 0x9d || data[1] != 0x01 || data[2] != 0x2a)
+ const unsigned char data0 = decrypt_byte(data + 0, origin,
+ pbi->decrypt_key);
+ const unsigned char data1 = decrypt_byte(data + 1, origin,
+ pbi->decrypt_key);
+ const unsigned char data2 = decrypt_byte(data + 2, origin,
+ pbi->decrypt_key);
+ if (data0 != 0x9d || data1 != 0x01 || data2 != 0x2a)
vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM,
"Invalid frame sync code");
}
@@ -1051,10 +1068,19 @@ int vp8_decode_frame(VP8D_COMP *pbi)
*/
if (!pbi->ec_active || data + 6 < data_end)
{
- pc->Width = (data[3] | (data[4] << 8)) & 0x3fff;
- pc->horiz_scale = data[4] >> 6;
- pc->Height = (data[5] | (data[6] << 8)) & 0x3fff;
- pc->vert_scale = data[6] >> 6;
+ const unsigned char data3 = decrypt_byte(data + 3, origin,
+ pbi->decrypt_key);
+ const unsigned char data4 = decrypt_byte(data + 4, origin,
+ pbi->decrypt_key);
+ const unsigned char data5 = decrypt_byte(data + 5, origin,
+ pbi->decrypt_key);
+ const unsigned char data6 = decrypt_byte(data + 6, origin,
+ pbi->decrypt_key);
+
+ pc->Width = (data3 | (data4 << 8)) & 0x3fff;
+ pc->horiz_scale = data4 >> 6;
+ pc->Height = (data5 | (data6 << 8)) & 0x3fff;
+ pc->vert_scale = data6 >> 6;
}
data += 7;
@@ -1072,7 +1098,11 @@ int vp8_decode_frame(VP8D_COMP *pbi)
init_frame(pbi);
- if (vp8dx_start_decode(bc, data, (unsigned int)(data_end - data)))
+ if (vp8dx_start_decode(bc,
+ data,
+ (unsigned int)(data_end - data),
+ pbi->fragments.ptrs[0],
+ pbi->decrypt_key))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder 0");
if (pc->frame_type == KEY_FRAME) {
diff --git a/vp8/decoder/detokenize.h b/vp8/decoder/detokenize.h
index 8640bda4c..f2130b361 100644
--- a/vp8/decoder/detokenize.h
+++ b/vp8/decoder/detokenize.h
@@ -8,13 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
-#ifndef DETOKENIZE_H
-#define DETOKENIZE_H
+#ifndef DETOKENIZE_H_
+#define DETOKENIZE_H_
#include "onyxd_int.h"
void vp8_reset_mb_tokens_context(MACROBLOCKD *x);
int vp8_decode_mb_tokens(VP8D_COMP *, MACROBLOCKD *);
-#endif /* DETOKENIZE_H */
+#endif // DETOKENIZE_H
diff --git a/vp8/decoder/ec_types.h b/vp8/decoder/ec_types.h
index ccb5ddbb9..b24bfd943 100644
--- a/vp8/decoder/ec_types.h
+++ b/vp8/decoder/ec_types.h
@@ -14,7 +14,6 @@
#define MAX_OVERLAPS 16
-
/* The area (pixel area in Q6) the block pointed to by bmi overlaps
* another block with.
*/
@@ -48,4 +47,4 @@ typedef struct
MV_REFERENCE_FRAME ref_frame;
} EC_BLOCK;
-#endif /* VP8_DEC_EC_TYPES_H */
+#endif // VP8_DEC_EC_TYPES_H
diff --git a/vp8/decoder/error_concealment.c b/vp8/decoder/error_concealment.c
index 8b2e32be6..0b58c98fd 100644
--- a/vp8/decoder/error_concealment.c
+++ b/vp8/decoder/error_concealment.c
@@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <assert.h>
+
#include "error_concealment.h"
#include "onyxd_int.h"
#include "decodemv.h"
#include "vpx_mem/vpx_mem.h"
#include "vp8/common/findnearmv.h"
-#include <assert.h>
-
#define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y))
diff --git a/vp8/decoder/error_concealment.h b/vp8/decoder/error_concealment.h
index 65ae9d9be..fb96b3605 100644
--- a/vp8/decoder/error_concealment.h
+++ b/vp8/decoder/error_concealment.h
@@ -9,8 +9,8 @@
*/
-#ifndef ERROR_CONCEALMENT_H
-#define ERROR_CONCEALMENT_H
+#ifndef ERROR_CONCEALMENT_H_
+#define ERROR_CONCEALMENT_H_
#include "onyxd_int.h"
#include "ec_types.h"
@@ -38,4 +38,4 @@ void vp8_interpolate_motion(MACROBLOCKD *mb,
*/
void vp8_conceal_corrupt_mb(MACROBLOCKD *xd);
-#endif
+#endif // ERROR_CONCEALMENT_H_
diff --git a/vp8/decoder/onyxd_int.h b/vp8/decoder/onyxd_int.h
index fb2dde852..c2325ebef 100644
--- a/vp8/decoder/onyxd_int.h
+++ b/vp8/decoder/onyxd_int.h
@@ -9,8 +9,9 @@
*/
-#ifndef __INC_VP8D_INT_H
-#define __INC_VP8D_INT_H
+#ifndef ONYXD_INT_H_
+#define ONYXD_INT_H_
+
#include "vpx_config.h"
#include "vp8/common/onyxd.h"
#include "treereader.h"
@@ -121,6 +122,7 @@ typedef struct VP8D_COMP
int independent_partitions;
int frame_corrupt_residual;
+ const unsigned char *decrypt_key;
} VP8D_COMP;
int vp8_decode_frame(VP8D_COMP *cpi);
@@ -145,4 +147,4 @@ int vp8_remove_decoder_instances(struct frame_buffers *fb);
} while(0)
#endif
-#endif
+#endif // ONYXD_INT_H_
diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c
index b18cb5065..73f9a8356 100644
--- a/vp8/decoder/threading.c
+++ b/vp8/decoder/threading.c
@@ -36,7 +36,7 @@
} while (0)
-extern void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
+void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
{
diff --git a/vp8/decoder/treereader.h b/vp8/decoder/treereader.h
index 238ff8536..9393bb478 100644
--- a/vp8/decoder/treereader.h
+++ b/vp8/decoder/treereader.h
@@ -9,18 +9,17 @@
*/
-#ifndef tree_reader_h
-#define tree_reader_h 1
+#ifndef TREEREADER_H_
+#define TREEREADER_H_
#include "vp8/common/treecoder.h"
-
#include "dboolhuff.h"
typedef BOOL_DECODER vp8_reader;
#define vp8_read vp8dx_decode_bool
#define vp8_read_literal vp8_decode_value
-#define vp8_read_bit( R) vp8_read( R, vp8_prob_half)
+#define vp8_read_bit(R) vp8_read(R, vp8_prob_half)
/* Intent of tree data structure is to make decoding trivial. */
@@ -38,4 +37,4 @@ static int vp8_treed_read(
return -i;
}
-#endif /* tree_reader_h */
+#endif // TREEREADER_H_
diff --git a/vp8/decoder/asm_dec_offsets.c b/vp8/decoder/vp8_asm_dec_offsets.c
index 842a0d574..842a0d574 100644
--- a/vp8/decoder/asm_dec_offsets.c
+++ b/vp8/decoder/vp8_asm_dec_offsets.c