Example #1
0
        public unsafe static int vp8_yv12_de_alloc_frame_buffer(ref YV12_BUFFER_CONFIG ybf)
        {
            //if (ybf)
            //{
            // If libvpx is using frame buffer callbacks then buffer_alloc_sz must
            // not be set.
            if (ybf.buffer_alloc != null && ybf.buffer_alloc_sz > 0)
            {
                vpx_mem.vpx_free(ybf.buffer_alloc);
                ybf.buffer_alloc    = null;
                ybf.buffer_alloc_sz = 0;
            }

            /* buffer_alloc isn't accessed by most functions.  Rather y_buffer,
             * u_buffer and v_buffer point to buffer_alloc and are used.  Clear out
             * all of this so that a freed pointer isn't inadvertently used */
            // memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG));
            //}
            //else
            //{
            //    return -1;
            //}

            return(0);
        }
Example #2
0
        static vpx_image_t vp8_get_frame(vpx_codec_alg_priv_t ctx, vpx_codec_iter_t iter)
        {
            vpx_image_t img = null;

            /* iter acts as a flip flop, so an image is only returned on the first
             * call to get_frame.
             */
            if (iter == IntPtr.Zero && ctx.yv12_frame_buffers.pbi[0] != null)
            {
                YV12_BUFFER_CONFIG sd = new YV12_BUFFER_CONFIG();
                long          time_stamp = 0, time_end_stamp = 0;
                vp8_ppflags_t flags = new vp8_ppflags_t();
                // Port AC: ppflags struct will be initialised to zero by default.
                //vp8_zero(flags);

                //if ([email protected]_flags & VPX_CODEC_USE_POSTPROC) {
                //    flags.post_proc_flag = ctx->postproc_cfg.post_proc_flag;
                //    flags.deblocking_level = ctx->postproc_cfg.deblocking_level;
                //    flags.noise_level = ctx->postproc_cfg.noise_level;
                //}

                if (0 == onyxd.vp8dx_get_raw_frame(ctx.yv12_frame_buffers.pbi[0], ref sd,
                                                   out time_stamp, out time_end_stamp, ref flags))
                {
                    yuvconfig2image(ctx.img, sd, ctx.user_priv);

                    img = ctx.img;
                    //*iter = img;
                }
            }

            return(img);
        }
Example #3
0
 public bool Equals(YV12_BUFFER_CONFIG y)
 {
     return
         (y_width == y.y_width &&
          y_height == y.y_height &&
          y_crop_width == y.y_crop_width &&
          y_crop_height == y.y_crop_height &&
          y_stride == y.y_stride &&
          uv_width == y.uv_width &&
          uv_height == y.uv_height &&
          uv_crop_width == y.uv_crop_width &&
          uv_crop_height == y.uv_crop_height &&
          uv_stride == y.uv_stride &&
          alpha_width == y.alpha_width &&
          alpha_height == y.alpha_height &&
          alpha_stride == y.alpha_stride &&
          y_buffer == y.y_buffer &&
          u_buffer == y.u_buffer &&
          v_buffer == y.v_buffer &&
          alpha_buffer == y.alpha_buffer &&
          buffer_alloc == y.buffer_alloc &&
          buffer_alloc_sz == y.buffer_alloc_sz &&
          border == y.border &&
          frame_size == y.frame_size &&
          subsampling_x == y.subsampling_x &&
          subsampling_y == y.subsampling_y &&
          bit_depth == y.bit_depth &&
          color_space == y.color_space &&
          color_range == y.color_range &&
          render_width == y.render_width &&
          render_height == y.render_height &&
          corrupted == y.corrupted &&
          flags == y.flags);
 }
Example #4
0
        public unsafe static void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG ybf)
        {
            int uv_border = ybf.border / 2;

            //assert(ybf->border % 2 == 0);
            //assert(ybf->y_height - ybf->y_crop_height < 16);
            //assert(ybf->y_width - ybf->y_crop_width < 16);
            //assert(ybf->y_height - ybf->y_crop_height >= 0);
            //assert(ybf->y_width - ybf->y_crop_width >= 0);

            extend_plane(ybf.y_buffer, ybf.y_stride, ybf.y_crop_width,
                         ybf.y_crop_height, ybf.border, ybf.border,
                         ybf.border + ybf.y_height - ybf.y_crop_height,
                         ybf.border + ybf.y_width - ybf.y_crop_width);

            extend_plane(ybf.u_buffer, ybf.uv_stride, ybf.uv_crop_width,
                         ybf.uv_crop_height, uv_border, uv_border,
                         uv_border + ybf.uv_height - ybf.uv_crop_height,
                         uv_border + ybf.uv_width - ybf.uv_crop_width);

            extend_plane(ybf.v_buffer, ybf.uv_stride, ybf.uv_crop_width,
                         ybf.uv_crop_height, uv_border, uv_border,
                         uv_border + ybf.uv_height - ybf.uv_crop_height,
                         uv_border + ybf.uv_width - ybf.uv_crop_width);
        }
Example #5
0
 public static void vp8_setup_intra_recon_top_line(YV12_BUFFER_CONFIG ybf)
 {
     //memset(ybf->y_buffer - 1 - ybf->y_stride, 127, ybf->y_width + 5);
     Mem.memset <byte>(ybf.y_buffer - 1 - ybf.y_stride, 127, ybf.y_width + 5);
     //memset(ybf->u_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
     Mem.memset <byte>(ybf.u_buffer - 1 - ybf.uv_stride, 127, ybf.uv_width + 5);
     //memset(ybf->v_buffer - 1 - ybf->uv_stride, 127, ybf->uv_width + 5);
     Mem.memset <byte>(ybf.v_buffer - 1 - ybf.uv_stride, 127, ybf.uv_width + 5);
 }
Example #6
0
        public static int vp8dx_get_raw_frame(VP8D_COMP pbi, ref YV12_BUFFER_CONFIG sd,
                                              out long time_stamp, out long time_end_stamp,
                                              ref vp8_ppflags_t flags)
        {
            int ret = -1;

            time_stamp     = 0;
            time_end_stamp = 0;

            if (pbi.ready_for_new_data == 1)
            {
                return(ret);
            }

            /* ie no raw frame to show!!! */
            if (pbi.common.show_frame == 0)
            {
                return(ret);
            }

            pbi.ready_for_new_data = 1;
            time_stamp             = pbi.last_time_stamp;
            time_end_stamp         = 0;

            //(void)flags;

            if (pbi.common.frame_to_show != null)
            {
                sd           = pbi.common.frame_to_show;
                sd.y_width   = pbi.common.Width;
                sd.y_height  = pbi.common.Height;
                sd.uv_height = pbi.common.Height / 2;
                ret          = 0;
            }
            else
            {
                ret = -1;
            }

            // Port AC: Noop in libvpx.
            //vpx_clear_system_state();
            return(ret);
        }
Example #7
0
        // void vp8_yv12_copy_frame_c(const struct yv12_buffer_config *src_ybc, struct yv12_buffer_config *dst_ybc);
        // #define vp8_yv12_copy_frame vp8_yv12_copy_frame_c

        // Copies the source image into the destination image and updates the
        // destination's UMV borders.
        // Note: The frames are assumed to be identical in size.

        public unsafe static void vp8_yv12_copy_frame(YV12_BUFFER_CONFIG src_ybc,
                                                      YV12_BUFFER_CONFIG dst_ybc)
        {
            int   row;
            byte *src = src_ybc.y_buffer;
            byte *dst = dst_ybc.y_buffer;

            for (row = 0; row < src_ybc.y_height; ++row)
            {
                //memcpy(dst, src, src_ybc.y_width);
                Buffer.MemoryCopy(src, dst, dst_ybc.y_width, src_ybc.y_width);
                src += src_ybc.y_stride;
                dst += dst_ybc.y_stride;
            }

            src = src_ybc.u_buffer;
            dst = dst_ybc.u_buffer;

            for (row = 0; row < src_ybc.uv_height; ++row)
            {
                //memcpy(dst, src, src_ybc.uv_width);
                Buffer.MemoryCopy(src, dst, dst_ybc.uv_width, src_ybc.uv_width);
                src += src_ybc.uv_stride;
                dst += dst_ybc.uv_stride;
            }

            src = src_ybc.v_buffer;
            dst = dst_ybc.v_buffer;

            for (row = 0; row < src_ybc.uv_height; ++row)
            {
                //memcpy(dst, src, src_ybc.uv_width);
                Buffer.MemoryCopy(src, dst, dst_ybc.uv_width, src_ybc.uv_width);
                src += src_ybc.uv_stride;
                dst += dst_ybc.uv_stride;
            }

            vp8_yv12_extend_frame_borders_c(dst_ybc);
        }
Example #8
0
        private unsafe static int vp8_yv12_realloc_frame_buffer(ref YV12_BUFFER_CONFIG ybf, int width,
                                                                int height, int border)
        {
            int aligned_width  = (width + 15) & ~15;
            int aligned_height = (height + 15) & ~15;
            int y_stride       = ((aligned_width + 2 * border) + 31) & ~31;
            int yplane_size    = (aligned_height + 2 * border) * y_stride;
            int uv_width       = aligned_width >> 1;
            int uv_height      = aligned_height >> 1;

            /** There is currently a bunch of code which assumes
            *  uv_stride == y_stride/2, so enforce this here. */
            int   uv_stride    = y_stride >> 1;
            int   uvplane_size = (uv_height + border) * uv_stride;
            ulong frame_size   = (ulong)yplane_size + 2 * (ulong)uvplane_size;

            if (ybf.buffer_alloc == null || (IntPtr)ybf.buffer_alloc == IntPtr.Zero)
            {
                ybf.buffer_alloc = (byte *)vpx_mem.vpx_memalign(32, frame_size);
                //ybf.buffer_alloc = (byte*)vpx_malloc((int)frame_size);
                ybf.buffer_alloc_sz = frame_size;
            }

            // Port AC: This check seems intended to catch cases where a YV12 buffer needs to be re-used
            // and the memory buffer was not released first. It would seem safer to simply release the
            // existing memory if it was present and then allocate the new memory required. In order
            // to keep compatibility this logic is currently being left as is and the caveat is the
            // vp8_yv12_de_alloc_frame_buffer will always need to be called before re-using a buffer
            // with a different size.
            if (ybf.buffer_alloc == null ||
                (IntPtr)ybf.buffer_alloc == IntPtr.Zero ||
                ybf.buffer_alloc_sz < frame_size)
            {
                return(-1);
            }

            /* Only support allocating buffers that have a border that's a multiple
             * of 32. The border restriction is required to get 16-byte alignment of
             * the start of the chroma rows without introducing an arbitrary gap
             * between planes, which would break the semantics of things like
             * vpx_img_set_rect(). */
            if ((border & 0x1f) > 0)
            {
                return(-3);
            }

            ybf.y_crop_width  = width;
            ybf.y_crop_height = height;
            ybf.y_width       = aligned_width;
            ybf.y_height      = aligned_height;
            ybf.y_stride      = y_stride;

            ybf.uv_crop_width  = (width + 1) / 2;
            ybf.uv_crop_height = (height + 1) / 2;
            ybf.uv_width       = uv_width;
            ybf.uv_height      = uv_height;
            ybf.uv_stride      = uv_stride;

            ybf.alpha_width  = 0;
            ybf.alpha_height = 0;
            ybf.alpha_stride = 0;

            ybf.border     = border;
            ybf.frame_size = frame_size;

            ybf.y_buffer = ybf.buffer_alloc + (border * y_stride) + border;
            ybf.u_buffer =
                ybf.buffer_alloc + yplane_size + (border / 2 * uv_stride) + border / 2;
            ybf.v_buffer = ybf.buffer_alloc + yplane_size + uvplane_size +
                           (border / 2 * uv_stride) + border / 2;
            ybf.alpha_buffer = null;

            ybf.corrupted = 0; /* assume not currupted by errors */
            return(0);
        }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ybf"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="border">The border must be a multiple of 32.</param>
 /// <returns></returns>
 public static int vp8_yv12_alloc_frame_buffer(ref YV12_BUFFER_CONFIG ybf, int width, int height,
                                               int border)
 {
     vp8_yv12_de_alloc_frame_buffer(ref ybf);
     return(vp8_yv12_realloc_frame_buffer(ref ybf, width, height, border));
 }