media/libvpx/vp9/vp9_iface_common.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10 #ifndef VP9_VP9_IFACE_COMMON_H_
michael@0 11 #define VP9_VP9_IFACE_COMMON_H_
michael@0 12
michael@0 13 static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
michael@0 14 void *user_priv) {
michael@0 15 /** vpx_img_wrap() doesn't allow specifying independent strides for
michael@0 16 * the Y, U, and V planes, nor other alignment adjustments that
michael@0 17 * might be representable by a YV12_BUFFER_CONFIG, so we just
michael@0 18 * initialize all the fields.*/
michael@0 19 int bps = 12;
michael@0 20 if (yv12->uv_height == yv12->y_height) {
michael@0 21 if (yv12->uv_width == yv12->y_width) {
michael@0 22 img->fmt = VPX_IMG_FMT_I444;
michael@0 23 bps = 24;
michael@0 24 } else {
michael@0 25 img->fmt = VPX_IMG_FMT_I422;
michael@0 26 bps = 16;
michael@0 27 }
michael@0 28 } else {
michael@0 29 img->fmt = VPX_IMG_FMT_I420;
michael@0 30 }
michael@0 31 img->w = yv12->y_stride;
michael@0 32 img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9BORDERINPIXELS, 3);
michael@0 33 img->d_w = yv12->y_crop_width;
michael@0 34 img->d_h = yv12->y_crop_height;
michael@0 35 img->x_chroma_shift = yv12->uv_width < yv12->y_width;
michael@0 36 img->y_chroma_shift = yv12->uv_height < yv12->y_height;
michael@0 37 img->planes[VPX_PLANE_Y] = yv12->y_buffer;
michael@0 38 img->planes[VPX_PLANE_U] = yv12->u_buffer;
michael@0 39 img->planes[VPX_PLANE_V] = yv12->v_buffer;
michael@0 40 img->planes[VPX_PLANE_ALPHA] = yv12->alpha_buffer;
michael@0 41 img->stride[VPX_PLANE_Y] = yv12->y_stride;
michael@0 42 img->stride[VPX_PLANE_U] = yv12->uv_stride;
michael@0 43 img->stride[VPX_PLANE_V] = yv12->uv_stride;
michael@0 44 img->stride[VPX_PLANE_ALPHA] = yv12->alpha_stride;
michael@0 45 img->bps = bps;
michael@0 46 img->user_priv = user_priv;
michael@0 47 img->img_data = yv12->buffer_alloc;
michael@0 48 img->img_data_owner = 0;
michael@0 49 img->self_allocd = 0;
michael@0 50 }
michael@0 51
michael@0 52 static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
michael@0 53 YV12_BUFFER_CONFIG *yv12) {
michael@0 54 yv12->y_buffer = img->planes[VPX_PLANE_Y];
michael@0 55 yv12->u_buffer = img->planes[VPX_PLANE_U];
michael@0 56 yv12->v_buffer = img->planes[VPX_PLANE_V];
michael@0 57 yv12->alpha_buffer = img->planes[VPX_PLANE_ALPHA];
michael@0 58
michael@0 59 yv12->y_crop_width = img->d_w;
michael@0 60 yv12->y_crop_height = img->d_h;
michael@0 61 yv12->y_width = img->d_w;
michael@0 62 yv12->y_height = img->d_h;
michael@0 63
michael@0 64 yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
michael@0 65 : yv12->y_width;
michael@0 66 yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
michael@0 67 : yv12->y_height;
michael@0 68
michael@0 69 yv12->alpha_width = yv12->alpha_buffer ? img->d_w : 0;
michael@0 70 yv12->alpha_height = yv12->alpha_buffer ? img->d_h : 0;
michael@0 71
michael@0 72 yv12->y_stride = img->stride[VPX_PLANE_Y];
michael@0 73 yv12->uv_stride = img->stride[VPX_PLANE_U];
michael@0 74 yv12->alpha_stride = yv12->alpha_buffer ? img->stride[VPX_PLANE_ALPHA] : 0;
michael@0 75
michael@0 76 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
michael@0 77 #if CONFIG_ALPHA
michael@0 78 // For development purposes, force alpha to hold the same data a Y for now.
michael@0 79 yv12->alpha_buffer = yv12->y_buffer;
michael@0 80 yv12->alpha_width = yv12->y_width;
michael@0 81 yv12->alpha_height = yv12->y_height;
michael@0 82 yv12->alpha_stride = yv12->y_stride;
michael@0 83 #endif
michael@0 84 return VPX_CODEC_OK;
michael@0 85 }
michael@0 86
michael@0 87 #endif // VP9_VP9_IFACE_COMMON_H_

mercurial