示例#1
0
    public bool Build(int movieHandle, int width, int height, AVProWindowsMediaPlugin.VideoFrameFormat format, bool useBT709, bool flipX, bool flipY)
    {
        Reset();

        _movieHandle = movieHandle;

        _width             = width;
        _height            = height;
        _sourceVideoFormat = format;
        _flipX             = flipX;
        _flipY             = flipY;
        _useBT709          = useBT709;

        if (CreateMaterial())
        {
            CreateTexture();
            CreateUVs(_flipX, _flipY);

            switch (AVProWindowsMediaManager.Instance.TextureConversionMethod)
            {
            case AVProWindowsMediaManager.ConversionMethod.Unity4:
//#if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0
#if !UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0
                AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, _rawTexture.GetNativeTexturePtr());
#endif
                break;

            case AVProWindowsMediaManager.ConversionMethod.Unity34_OpenGL:
                // We set the texture per-frame
                break;

            case AVProWindowsMediaManager.ConversionMethod.Unity35_OpenGL:
#if UNITY_3_5
                AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, new System.IntPtr(_rawTexture.GetNativeTextureID()));
#endif
                break;

            case AVProWindowsMediaManager.ConversionMethod.UnityScript:
//#if !UNITY_4_3 && !UNITY_4_2 && !UNITY_4_1 && !UNITY_4_0_1 && !UNITY_4_0
#if UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_2 || UNITY_3_1 || UNITY_3_0
                CreateBuffer();
#endif
                break;
            }

            CreateRenderTexture();

            _conversionMaterial.mainTexture = _rawTexture;
            bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32);
            if (formatIs422)
            {
                _conversionMaterial.SetFloat("_TextureWidth", _finalTexture.width);
            }
        }

        return(_conversionMaterial != null);
    }
    public Shader GetPixelConversionShader(AVProWindowsMediaPlugin.VideoFrameFormat format, bool useBT709)
    {
        Shader result = null;

        switch (format)
        {
        case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_YUY2:
            result = _shaderYUY2;
            if (useBT709)
            {
                result = _shaderYUY2_709;
            }
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_UYVY:
            result = _shaderUYVY;
            if (useBT709)
            {
                result = _shaderHDYC;
            }
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_YVYU:
            result = _shaderYVYU;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_HDYC:
            result = _shaderHDYC;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_420_NV12:
            result = _shaderNV12;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB:
            result = _shaderCopy;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA:
            result = _shaderCopy;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB_HQ:
            result = _shaderHap_YCoCg;
            break;

        case AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32:
            result = _shaderBGRA32;
            break;

        default:
            Debug.LogError("[AVProWindowsMedia] Unknown pixel format '" + format);
            break;
        }
        return(result);
    }
    public bool Build(int movieHandle, int width, int height, AVProWindowsMediaPlugin.VideoFrameFormat format, bool useBT709, bool flipX, bool flipY)
    {
        Reset();

        _movieHandle = movieHandle;

        _width = width;
        _height = height;
        _sourceVideoFormat = format;
        _flipX = flipX;
        _flipY = flipY;
        _useBT709 = useBT709;

        if (CreateMaterial())
        {
            CreateTexture();
            CreateUVs(_flipX, _flipY);

            switch (AVProWindowsMediaManager.Instance.TextureConversionMethod)
            {
                case AVProWindowsMediaManager.ConversionMethod.Unity4:
        //#if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0
        #if !UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0
                    AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, _rawTexture.GetNativeTexturePtr());
        #endif
                    break;
                case AVProWindowsMediaManager.ConversionMethod.Unity34_OpenGL:
                    // We set the texture per-frame
                    break;
                case AVProWindowsMediaManager.ConversionMethod.Unity35_OpenGL:
        #if UNITY_3_5
                    AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, new System.IntPtr(_rawTexture.GetNativeTextureID()));
        #endif
                    break;
                case AVProWindowsMediaManager.ConversionMethod.UnityScript:
        //#if !UNITY_4_3 && !UNITY_4_2 && !UNITY_4_1 && !UNITY_4_0_1 && !UNITY_4_0
        #if UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_2 || UNITY_3_1 || UNITY_3_0
                    CreateBuffer();
        #endif
                    break;
            }

            CreateRenderTexture();

            _conversionMaterial.mainTexture = _rawTexture;
            bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32);
            if (formatIs422)
            {
                _conversionMaterial.SetFloat("_TextureWidth", _finalTexture.width);
            }
        }

        return (_conversionMaterial != null);
    }
示例#4
0
    private void CompleteVideoLoad(bool useBT709)
    {
        // Gather properties
        Volume          = _volume;
        Width           = AVProWindowsMediaPlugin.GetWidth(_movieHandle);
        Height          = AVProWindowsMediaPlugin.GetHeight(_movieHandle);
        FrameRate       = AVProWindowsMediaPlugin.GetFrameRate(_movieHandle);
        DurationSeconds = AVProWindowsMediaPlugin.GetDurationSeconds(_movieHandle);
        DurationFrames  = AVProWindowsMediaPlugin.GetDurationFrames(_movieHandle);

        AVProWindowsMediaPlugin.VideoFrameFormat sourceFormat = (AVProWindowsMediaPlugin.VideoFrameFormat)AVProWindowsMediaPlugin.GetFormat(_movieHandle);
        Debug.Log(string.Format("[AVProWindowsMedia] Loaded video '{0}' ({1}x{2} @ {3} fps) {4} frames, {5} seconds - format: {6}", Filename, Width, Height, FrameRate.ToString("F2"), DurationFrames, DurationSeconds.ToString("F2"), sourceFormat.ToString()));

        // Create format converter
        if (Width < 0 || Width > 4096 || Height < 0 || Height > 4096)
        {
            Debug.LogWarning("[AVProWindowsMedia] invalid width or height");
            Width = Height = 0;
            if (_formatConverter != null)
            {
                _formatConverter.Dispose();
                _formatConverter = null;
            }
        }
        else
        {
            bool isTopDown = AVProWindowsMediaPlugin.IsOrientedTopDown(_movieHandle);

            if (_formatConverter == null)
            {
                _formatConverter = new AVProWindowsMediaFormatConverter();
            }
            if (!_formatConverter.Build(_movieHandle, Width, Height, sourceFormat, useBT709, false, isTopDown))
            {
                Debug.LogWarning("[AVProWindowsMedia] unable to convert video format");
                Width = Height = 0;
                if (_formatConverter != null)
                {
                    _formatConverter.Dispose();
                    _formatConverter = null;
                }
                // TODO: close movie here?
            }
        }

        PreRoll();
    }
    public bool Build(int movieHandle, int width, int height, AVProWindowsMediaPlugin.VideoFrameFormat format, bool useBT709, bool flipX, bool flipY, FilterMode filterMode, TextureWrapMode wrapMode)
    {
        Reset();

        _outputTexture = null;
        _movieHandle   = movieHandle;

        _width             = width;
        _height            = height;
        _sourceVideoFormat = format;
        _flipX             = flipX;
        _flipY             = flipY;
        _useBT709          = useBT709;

#if AVPROWINDOWSMEDIA_UNITYFEATURE_EXTERNALTEXTURES
        if (AVProWindowsMediaManager.Instance._useExternalTextures)
        {
            CreateExternalTexture();
        }
        else
#endif
        CreateTexture();

        if (_rawTexture != null)
        {
            _requiresConversion  = false;
            _requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);
            if (_requiresTextureCrop)
            {
                SetFlip(_flipX, _flipY);
                _requiresConversion = true;
            }

            if (!_isExternalTexture)
            {
                AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, _rawTexture.GetNativeTexturePtr());
            }

            if (!_requiresConversion)
            {
                bool isDX11 = SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 11");

                if (_flipX || _flipY)
                {
                    _requiresConversion = true;
                }
                else if (_sourceVideoFormat == AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32 && isDX11)
                {
#if UNITY_5
                    // DX11 has red and blue channels swapped around
                    if (!SystemInfo.SupportsTextureFormat(TextureFormat.BGRA32))
                    {
                        _requiresConversion = true;
                    }
#else
                    _requiresConversion = true;
#endif
                }
                else if (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB &&
                         _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA &&
                         _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32)
                {
                    _requiresConversion = true;
                }
            }

            if (_requiresConversion)
            {
                if (CreateMaterial())
                {
                    CreateRenderTexture();
                    _outputTexture = _finalTexture;

                    _conversionMaterial.mainTexture = _rawTexture;
                    SetFlip(_flipX, _flipY);
                    bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32);
                    if (formatIs422)
                    {
                        _conversionMaterial.SetFloat("_TextureWidth", _finalTexture.width);
                    }
                }
            }
            else
            {
                bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32 &&
                                    _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB &&
                                    _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA);
                if (formatIs422)
                {
                    CreateMaterial();
                    _conversionMaterial.SetFloat("_TextureWidth", _width);
                    _rawTexture.filterMode = FilterMode.Point;
                }
                else
                {
                    _rawTexture.filterMode = FilterMode.Bilinear;
                }
                //_rawTexture.wrapMode = TextureWrapMode.Repeat;
                _outputTexture = _rawTexture;
            }
        }

        if (_outputTexture != null)
        {
            _outputTexture.filterMode = filterMode;
            _outputTexture.wrapMode   = wrapMode;
        }

        return(_outputTexture != null);
    }
	public bool Build(int movieHandle, int width, int height, AVProWindowsMediaPlugin.VideoFrameFormat format, bool useBT709, bool flipX, bool flipY, FilterMode filterMode, TextureWrapMode wrapMode)
	{
		Reset();

		_outputTexture = null;
		_movieHandle = movieHandle;

		_width = width;
		_height = height;
		_sourceVideoFormat = format;
		_flipX = flipX;
		_flipY = flipY;
		_useBT709 = useBT709;
		
#if AVPROWINDOWSMEDIA_UNITYFEATURE_EXTERNALTEXTURES
		if (AVProWindowsMediaManager.Instance._useExternalTextures)
			CreateExternalTexture();
		else
#endif
			CreateTexture();

		if (_rawTexture != null)
		{
			_requiresConversion = false;
			_requiresTextureCrop = (_usedTextureWidth != _rawTexture.width || _usedTextureHeight != _rawTexture.height);
			if (_requiresTextureCrop)
			{
				CreateUVs(_flipX, _flipY);
				_requiresConversion = true;
			}

			if (!_isExternalTexture)
				AVProWindowsMediaPlugin.SetTexturePointer(_movieHandle, _rawTexture.GetNativeTexturePtr());

			if (!_requiresConversion)
			{
				bool isDX11 = SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 11");

				if (_flipX || _flipY)
				{
					_requiresConversion = true;
				}
				else if (_sourceVideoFormat == AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32 && isDX11)
				{
#if UNITY_5
					// DX11 has red and blue channels swapped around
					if (!SystemInfo.SupportsTextureFormat(TextureFormat.BGRA32))
						_requiresConversion = true;
#else
                    _requiresConversion = true;
#endif
				}
				else if (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB &&
					 	_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA &&
						_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32)
				{
					_requiresConversion = true;
				}
			}

			if (_requiresConversion)
			{
				if (CreateMaterial())
				{
					CreateRenderTexture();
					_outputTexture = _finalTexture;

					_conversionMaterial.mainTexture = _rawTexture;
					if (!_requiresTextureCrop)
					{
						if (_flipX)
						{
							// Flip X and offset back to get back to normalised range
							_conversionMaterial.mainTextureScale = new Vector2(-1.0f, _conversionMaterial.mainTextureScale.y);
							_conversionMaterial.mainTextureOffset = new Vector2(1.0f, _conversionMaterial.mainTextureOffset.y);
						}
						if (_flipY)
						{
							// Flip Y and offset back to get back to normalised range
							_conversionMaterial.mainTextureScale = new Vector2(_conversionMaterial.mainTextureScale.x, -1.0f);
							_conversionMaterial.mainTextureOffset = new Vector2(_conversionMaterial.mainTextureOffset.x, 1.0f);
						}
					}
					bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32);
					if (formatIs422)
					{
						_conversionMaterial.SetFloat("_TextureWidth", _finalTexture.width);
					}
				}
			}
			else
			{

				bool formatIs422 = (_sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.RAW_BGRA32 &&
				                    _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB &&
				                    _sourceVideoFormat != AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA);
				if (formatIs422)
				{
					CreateMaterial();
					_conversionMaterial.SetFloat("_TextureWidth", _width);
					_rawTexture.filterMode = FilterMode.Point;
				}
				else
				{
					_rawTexture.filterMode = FilterMode.Bilinear;
				}
				//_rawTexture.wrapMode = TextureWrapMode.Repeat;
				_outputTexture = _rawTexture;
			}
		}

		if (_outputTexture != null)
		{
			_outputTexture.filterMode = filterMode;
			_outputTexture.wrapMode = wrapMode;
		}
		
		return (_outputTexture != null);
	}
示例#7
0
    private void CompleteVideoLoad(bool useBT709, bool ignoreFlips, FilterMode textureFilterMode, TextureWrapMode textureWrapMode)
    {
        RequiresFlipY = false;
        Loop          = false;
        Volume        = _volume;

        // Gather properties
        Width           = AVProWindowsMediaPlugin.GetWidth(_movieHandle);
        Height          = AVProWindowsMediaPlugin.GetHeight(_movieHandle);
        FrameRate       = AVProWindowsMediaPlugin.GetFrameRate(_movieHandle);
        DurationSeconds = AVProWindowsMediaPlugin.GetDurationSeconds(_movieHandle);
        DurationFrames  = AVProWindowsMediaPlugin.GetDurationFrames(_movieHandle);

        AVProWindowsMediaPlugin.VideoFrameFormat sourceFormat = (AVProWindowsMediaPlugin.VideoFrameFormat)AVProWindowsMediaPlugin.GetFormat(_movieHandle);

        if (AVProWindowsMediaManager.Instance._logVideoLoads)
        {
            Debug.Log(string.Format("[AVProWindowsMedia] Loaded video '{0}' ({1}x{2} @ {3} fps) {4} frames, {5} seconds - format: {6}", Filename, Width, Height, FrameRate.ToString("F2"), DurationFrames, DurationSeconds.ToString("F2"), sourceFormat.ToString()));
        }

        // Create format converter
        bool hasVideo = (Width > 0 && Width <= 8192 || Height > 0 && Height <= 8192);

        if (!hasVideo)
        {
            Width = Height = 0;
            if (_formatConverter != null)
            {
                _formatConverter.Dispose();
                _formatConverter = null;
            }
        }
        else
        {
            bool isTopDown = AVProWindowsMediaPlugin.IsOrientedTopDown(_movieHandle);

            if (_formatConverter == null)
            {
                _formatConverter = new AVProWindowsMediaFormatConverter();
            }

            bool flipX = false;
            bool flipY = isTopDown;
            if (ignoreFlips)
            {
                if (flipY)
                {
                    RequiresFlipY = true;
                }

                flipX = flipY = false;
            }
            if (!_formatConverter.Build(_movieHandle, Width, Height, sourceFormat, useBT709, flipX, flipY, textureFilterMode, textureWrapMode))
            {
                Debug.LogError("[AVProWindowsMedia] unable to convert video format");
                Width = Height = 0;
                if (_formatConverter != null)
                {
                    _formatConverter.Dispose();
                    _formatConverter = null;
                    Close();
                }
            }
        }

        PreRoll();
    }