示例#1
0
        private Shader GetShader()
        {
            var pixelFormat = NativeDll.GetPixelFormat(_mediaId);

            switch (pixelFormat)
            {
            case PixelFormat.YCoCg:
                return(_shaderHapQ);

            case PixelFormat.YCoCgAndAlphaP:
                return(_shaderHapQAlpha);

            // TODO
            //case PixelFormat.YUV420P:
            //case PixelFormat.YUV422P10LE:
            default:
                // No color conversion needed
                return(null);
            }
        }
示例#2
0
        private void OnOpened()
        {
            Debug.Log("[DemolitionMedia] Opened media with url: " + mediaUrl);

            // Cache the media parameters
            int width, height;

            NativeDll.GetResolution(_mediaId, out width, out height);
            VideoWidth  = width;
            VideoHeight = height;

            DurationSeconds = NativeDll.GetDuration(_mediaId);
            VideoNumFrames  = NativeDll.GetNumFrames(_mediaId);
            VideoFramerate  = NativeDll.GetFramerate(_mediaId);

            bool flipX, flipY;

            NativeDll.GetNeedFlipVideo(_mediaId, out flipX, out flipY);
            VideoNeedFlipX = flipX;
            VideoNeedFlipY = flipY;

            VideoPixelFormat = NativeDll.GetPixelFormat(_mediaId);
            Debug.Log("[DemolitionMedia] video pixel format: " + VideoPixelFormat);

            // Check hardware acceleration ability
            bool hasHardwareAcceleration = NativeDll.IsDecodingHardwareAccelerated(_mediaId);

            Debug.Log("[DemolitionMedia] Hardware acceleration: " + hasHardwareAcceleration);

            // Execute host application-dependent code
            OnOpenedImpl();

            // Start playing if needed
            if (playOnOpen)
            {
                Play();
            }
        }
示例#3
0
        public bool CreateExternalTextures()
        {
            // Get the video frame pixel format: it should be available prior the texture creation
            var pixelFormat = NativeDll.GetPixelFormat(_mediaId);

            if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Direct3D9 &&
                pixelFormat == PixelFormat.YCoCgAndAlphaP)
            {
                // TODO: at some point use the standard way of generating errors in the native plugin for this one
                InvokeEvent(MediaEvent.Type.PlaybackErrorOccured, MediaError.GraphicsDeviceError);
                Close();

                Debug.LogError("[DemolitionMedia] Hap Q Alpha is unsupported on Direct3D9 graphics device, since it uses BC4 compressed texture");
                return(false);
            }

            // Check whether the native texture(s) created already
            bool texturesCreated = NativeDll.AreNativeTexturesCreated(_mediaId);

            if (!texturesCreated)
            {
                return(false);
            }

            // FIXME: clear all the textures?
            if (_nativeTextures.Count != 0)
            {
                // Note: this isn't needed
                //_nativeTexture.UpdateExternalTexture(nativeTexture);

                // Apply() is slow as hell, don't use it
                //mMovieTexture.Apply();
            }

            var texturesCount = NativeDll.GetNativeTexturesCount(_mediaId);

            for (int idx = 0; idx < texturesCount; ++idx)
            {
                int width, height;
                NativeDll.NativeTextureFormat nativeFormat;
                IntPtr nativeTexture, shaderResourceView;

                bool result = NativeDll.GetNativeTexturePtrByIndex(_mediaId, idx,
                                                                   out nativeTexture, out shaderResourceView,
                                                                   out width, out height, out nativeFormat);

                if (!result || nativeTexture == IntPtr.Zero || nativeTexture.ToInt32() == 0 ||
                    width <= 0 || height <= 0 || nativeFormat == NativeDll.NativeTextureFormat.Unknown)
                {
                    // FIXME: clear all the textures?
                    Debug.LogWarning("[DemolitionMedia] native texture is invalid");
                    return(false);
                }

                // DX11 render backend requires SRV, others the texture handle
                var texPtr = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11
                    ? shaderResourceView : nativeTexture;

                var format = TextureFormatNativeToUnity(nativeFormat);
                var tex    = Texture2D.CreateExternalTexture(width, height, format, false, false, texPtr);

                tex.wrapMode   = TextureWrapMode.Clamp;
                tex.filterMode = FilterMode.Bilinear;

                // Append the new texture
                _nativeTextures.Add(tex);
            }

            // Perform the color conversion for the first frame if needed
            PerformColorConversionIfNeeded();

            return(true);
        }