summaryrefslogtreecommitdiff
path: root/vp8/vp8_dx_iface.c
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2013-03-27 10:41:29 -0700
committerJohn Koleszar <jkoleszar@google.com>2013-03-27 10:46:19 -0700
commit771fc832f3889c067b76899c8209bd0854ba7f7d (patch)
tree617379cd79f034d2ea2f709e90ab59105bbfc7cc /vp8/vp8_dx_iface.c
parent513157e0939b2774db583a31fe29c9d34948e09c (diff)
parent8015a9aedc2358135940180884f0b9bba9509009 (diff)
downloadlibvpx-771fc832f3889c067b76899c8209bd0854ba7f7d.tar
libvpx-771fc832f3889c067b76899c8209bd0854ba7f7d.tar.gz
libvpx-771fc832f3889c067b76899c8209bd0854ba7f7d.tar.bz2
libvpx-771fc832f3889c067b76899c8209bd0854ba7f7d.zip
Merge branch 'master' into experimental
Pick up VP8 encryption, quantization changes, and some fixes to vpxenc Conflicts: test/decode_test_driver.cc test/decode_test_driver.h test/encode_test_driver.cc vp8/vp8cx.mk vpxdec.c vpxenc.c Change-Id: I9fbcc64808ead47e22f1f22501965cc7f0c4791c
Diffstat (limited to 'vp8/vp8_dx_iface.c')
-rw-r--r--vp8/vp8_dx_iface.c87
1 files changed, 64 insertions, 23 deletions
diff --git a/vp8/vp8_dx_iface.c b/vp8/vp8_dx_iface.c
index 1db61f161..f3834b063 100644
--- a/vp8/vp8_dx_iface.c
+++ b/vp8/vp8_dx_iface.c
@@ -29,6 +29,8 @@
#define VP8_CAP_ERROR_CONCEALMENT (CONFIG_ERROR_CONCEALMENT ? \
VPX_CODEC_CAP_ERROR_CONCEALMENT : 0)
+#define VP8_DECRYPT_KEY_SIZE 32
+
typedef vpx_codec_stream_info_t vp8_stream_info_t;
/* Structures for handling memory allocations */
@@ -73,6 +75,7 @@ struct vpx_codec_alg_priv
int dbg_color_b_modes_flag;
int dbg_display_mv_flag;
#endif
+ unsigned char decrypt_key[VP8_DECRYPT_KEY_SIZE];
vpx_image_t img;
int img_setup;
struct frame_buffers yv12_frame_buffers;
@@ -150,6 +153,8 @@ static vpx_codec_err_t vp8_validate_mmaps(const vp8_stream_info_t *si,
return res;
}
+static const unsigned char fake_decrypt_key[VP8_DECRYPT_KEY_SIZE] = { 0 };
+
static void vp8_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap)
{
int i;
@@ -164,6 +169,8 @@ static void vp8_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap)
ctx->priv->alg_priv->mmaps[0] = *mmap;
ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si);
+ memcpy(ctx->priv->alg_priv->decrypt_key, fake_decrypt_key,
+ VP8_DECRYPT_KEY_SIZE);
ctx->priv->init_flags = ctx->init_flags;
if (ctx->config.dec)
@@ -211,21 +218,19 @@ static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx,
mmap.flags = vp8_mem_req_segs[0].flags;
res = vp8_mmap_alloc(&mmap);
+ if (res != VPX_CODEC_OK) return res;
- if (!res)
- {
- vp8_init_ctx(ctx, &mmap);
+ vp8_init_ctx(ctx, &mmap);
- /* initialize number of fragments to zero */
- ctx->priv->alg_priv->fragments.count = 0;
- /* is input fragments enabled? */
- ctx->priv->alg_priv->fragments.enabled =
- (ctx->priv->alg_priv->base.init_flags &
- VPX_CODEC_USE_INPUT_FRAGMENTS);
+ /* initialize number of fragments to zero */
+ ctx->priv->alg_priv->fragments.count = 0;
+ /* is input fragments enabled? */
+ ctx->priv->alg_priv->fragments.enabled =
+ (ctx->priv->alg_priv->base.init_flags &
+ VPX_CODEC_USE_INPUT_FRAGMENTS);
- ctx->priv->alg_priv->defer_alloc = 1;
- /*post processing level initialized to do nothing */
- }
+ ctx->priv->alg_priv->defer_alloc = 1;
+ /*post processing level initialized to do nothing */
}
ctx->priv->alg_priv->yv12_frame_buffers.use_frame_threads =
@@ -264,14 +269,17 @@ static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
return VPX_CODEC_OK;
}
-static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
- unsigned int data_sz,
- vpx_codec_stream_info_t *si)
+static vpx_codec_err_t vp8_peek_si_external(const uint8_t *data,
+ unsigned int data_sz,
+ vpx_codec_stream_info_t *si,
+ const unsigned char *decrypt_key)
{
vpx_codec_err_t res = VPX_CODEC_OK;
if(data + data_sz <= data)
+ {
res = VPX_CODEC_INVALID_PARAM;
+ }
else
{
/* Parse uncompresssed part of key frame header.
@@ -280,30 +288,45 @@ static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
* 4 bytes:- including image width and height in the lowest 14 bits
* of each 2-byte value.
*/
- si->is_kf = 0;
- if (data_sz >= 10 && !(data[0] & 0x01)) /* I-Frame */
+ const uint8_t data0 = decrypt_byte(data, data, decrypt_key);
+ si->is_kf = 0;
+ if (data_sz >= 10 && !(data0 & 0x01)) /* I-Frame */
{
- const uint8_t *c = data + 3;
+ const uint8_t data3 = decrypt_byte(data + 3, data, decrypt_key);
+ const uint8_t data4 = decrypt_byte(data + 4, data, decrypt_key);
+ const uint8_t data5 = decrypt_byte(data + 5, data, decrypt_key);
+ const uint8_t data6 = decrypt_byte(data + 6, data, decrypt_key);
+ const uint8_t data7 = decrypt_byte(data + 7, data, decrypt_key);
+ const uint8_t data8 = decrypt_byte(data + 8, data, decrypt_key);
+ const uint8_t data9 = decrypt_byte(data + 9, data, decrypt_key);
+
si->is_kf = 1;
/* vet via sync code */
- if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
+ if (data3 != 0x9d || data4 != 0x01 || data5 != 0x2a)
res = VPX_CODEC_UNSUP_BITSTREAM;
- si->w = (c[3] | (c[4] << 8)) & 0x3fff;
- si->h = (c[5] | (c[6] << 8)) & 0x3fff;
+ si->w = (data6 | (data7 << 8)) & 0x3fff;
+ si->h = (data8 | (data9 << 8)) & 0x3fff;
/*printf("w=%d, h=%d\n", si->w, si->h);*/
if (!(si->h | si->w))
res = VPX_CODEC_UNSUP_BITSTREAM;
}
else
+ {
res = VPX_CODEC_UNSUP_BITSTREAM;
+ }
}
return res;
+}
+static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
+ unsigned int data_sz,
+ vpx_codec_stream_info_t *si) {
+ return vp8_peek_si_external(data, data_sz, si, fake_decrypt_key);
}
static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t *ctx,
@@ -432,8 +455,10 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
w = ctx->si.w;
h = ctx->si.h;
- res = ctx->base.iface->dec.peek_si(ctx->fragments.ptrs[0],
- ctx->fragments.sizes[0], &ctx->si);
+ res = vp8_peek_si_external(ctx->fragments.ptrs[0],
+ ctx->fragments.sizes[0],
+ &ctx->si,
+ ctx->decrypt_key);
if((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf)
{
@@ -507,6 +532,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
}
res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf);
+ ctx->yv12_frame_buffers.pbi[0]->decrypt_key = ctx->decrypt_key;
}
ctx->decoder_init = 1;
@@ -928,6 +954,20 @@ static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
}
+
+static vpx_codec_err_t vp8_set_decrypt_key(vpx_codec_alg_priv_t *ctx,
+ int ctr_id,
+ va_list args)
+{
+ const unsigned char *data = va_arg(args, const unsigned char *);
+ if (data == NULL) {
+ return VPX_CODEC_INVALID_PARAM;
+ }
+
+ memcpy(ctx->decrypt_key, data, VP8_DECRYPT_KEY_SIZE);
+ return VPX_CODEC_OK;
+}
+
vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
{
{VP8_SET_REFERENCE, vp8_set_reference},
@@ -940,6 +980,7 @@ vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
{VP8D_GET_LAST_REF_UPDATES, vp8_get_last_ref_updates},
{VP8D_GET_FRAME_CORRUPTED, vp8_get_frame_corrupted},
{VP8D_GET_LAST_REF_USED, vp8_get_last_ref_frame},
+ {VP8_SET_DECRYPT_KEY, vp8_set_decrypt_key},
{ -1, NULL},
};