예제 #1
0
        //public unsafe static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t ctx,
        //                          ref vpx_codec_stream_info_t si)
        //{
        //    uint sz;

        //    if (si.sz >= sizeof(vp8_stream_info_t))
        //    {
        //        sz = sizeof(vp8_stream_info_t);
        //    }
        //    else
        //    {
        //        sz = sizeof(vpx_codec_stream_info_t);
        //    }

        //    memcpy(si, &ctx->si, sz);
        //    si->sz = sz;

        //    return VPX_CODEC_OK;
        //}

        public unsafe static vpx_codec_err_t vp8_peek_si_internal(byte *data,
                                                                  uint data_sz,
                                                                  ref vpx_codec_stream_info_t si,
                                                                  vpx_decrypt_cb decrypt_cb,
                                                                  IntPtr decrypt_state)
        {
            vpx_codec_err_t res = vpx_codec_err_t.VPX_CODEC_OK;

            //assert(data != NULL);
            if (data == null)
            {
                return(vpx_codec_err_t.VPX_CODEC_INVALID_PARAM);
            }

            if (data + data_sz <= data)
            {
                res = vpx_codec_err_t.VPX_CODEC_INVALID_PARAM;
            }
            else
            {
                /* Parse uncompresssed part of key frame header.
                 * 3 bytes:- including version, frame type and an offset
                 * 3 bytes:- sync code (0x9d, 0x01, 0x2a)
                 * 4 bytes:- including image width and height in the lowest 14 bits
                 *           of each 2-byte value.
                 */
                byte[] clear_buffer = new byte[10];
                byte * clear        = data;
                //if (decrypt_cb)
                //{
                //    int n = VPXMIN(sizeof(clear_buffer), data_sz);
                //    decrypt_cb(decrypt_state, data, clear_buffer, n);
                //    clear = clear_buffer;
                //}
                si.is_kf = 0;

                if (data_sz >= 10 && (clear[0] & 0x01) == 0)
                { /* I-Frame */
                    si.is_kf = 1;

                    /* vet via sync code */
                    if (clear[3] != 0x9d || clear[4] != 0x01 || clear[5] != 0x2a)
                    {
                        return(vpx_codec_err_t.VPX_CODEC_UNSUP_BITSTREAM);
                    }

                    si.w = (uint)(clear[6] | (clear[7] << 8)) & 0x3fff;
                    si.h = (uint)(clear[8] | (clear[9] << 8)) & 0x3fff;

                    /*printf("w=%d, h=%d\n", si->w, si->h);*/
                    if (si.h == 0 || si.w == 0)
                    {
                        res = vpx_codec_err_t.VPX_CODEC_CORRUPT_FRAME;
                    }
                }
                else
                {
                    res = vpx_codec_err_t.VPX_CODEC_UNSUP_BITSTREAM;
                }
            }

            return(res);
        }
예제 #2
0
 public unsafe static vpx_codec_err_t vp8_peek_si(byte *data, uint data_sz,
                                                  ref vpx_codec_stream_info_t si)
 {
     return(vp8_peek_si_internal(data, data_sz, ref si, null, IntPtr.Zero));
 }