Beispiel #1
0
    //-------------------------------------------------------------------------

    public bool StartVideo(string filename, bool loop, bool allowNativeFormat, bool useBT709)
    {
        Filename = filename;
        if (!string.IsNullOrEmpty(Filename))
        {
            if (_movieHandle < 0)
            {
                _movieHandle = AVProWindowsMediaPlugin.GetInstanceHandle();
            }

            // Note: we're marshaling the string to IntPtr as the pointer of type wchar_t
            System.IntPtr filenamePtr = Marshal.StringToHGlobalUni(Filename);
            if (AVProWindowsMediaPlugin.LoadMovie(_movieHandle, filenamePtr, loop, false, allowNativeFormat))
            {
                CompleteVideoLoad(useBT709);
            }
            else
            {
                Debug.LogWarning("[AVProWindowsMedia] Movie failed to load");
                Close();
            }
            Marshal.FreeHGlobal(filenamePtr);
        }
        else
        {
            Debug.LogWarning("[AVProWindowsMedia] No movie file specified");
            Close();
        }

        return(_movieHandle >= 0);
    }
Beispiel #2
0
    public bool StartVideoFromMemory(string name, System.IntPtr moviePointer, uint movieLength, bool loop, bool allowNativeFormat, bool useBT709)
    {
        Filename = name;
        if (moviePointer != System.IntPtr.Zero && movieLength > 0)
        {
            if (_movieHandle < 0)
            {
                _movieHandle = AVProWindowsMediaPlugin.GetInstanceHandle();
            }

            if (AVProWindowsMediaPlugin.LoadMovieFromMemory(_movieHandle, moviePointer, movieLength, loop, allowNativeFormat))
            {
                CompleteVideoLoad(useBT709);
            }
            else
            {
                Debug.LogWarning("[AVProWindowsMedia] Movie failed to load");
                Close();
            }
        }
        else
        {
            Debug.LogWarning("[AVProWindowsMedia] No movie file specified");
            Close();
        }

        return(_movieHandle >= 0);
    }
Beispiel #3
0
    public bool StartVideoFromMemory(string name, System.IntPtr moviePointer, long movieLength, bool allowNativeFormat, bool useBT709, bool allowAudio, bool useAudioDelay, bool useAudioMixer, bool useDisplaySync, bool ignoreFlips, FilterMode textureFilterMode, TextureWrapMode textureWrapMode)
    {
        Filename = name;
        if (moviePointer != System.IntPtr.Zero && movieLength > 0)
        {
            if (_movieHandle < 0)
            {
                _movieHandle = AVProWindowsMediaPlugin.GetInstanceHandle();
            }

            if (AVProWindowsMediaPlugin.LoadMovieFromMemory(_movieHandle, moviePointer, movieLength, allowNativeFormat, allowAudio, useAudioDelay, useAudioMixer, useDisplaySync))
            {
                CompleteVideoLoad(useBT709, ignoreFlips, textureFilterMode, textureWrapMode);
            }
            else
            {
                Debug.LogWarning("[AVProWindowsMedia] Movie failed to load");
                Close();
            }
        }
        else
        {
            Debug.LogWarning("[AVProWindowsMedia] No movie file specified");
            Close();
        }

        return(_movieHandle >= 0);
    }
    protected bool Init()
    {
        try
        {
#if UNITY_3_5
            if (AVProWindowsMediaPlugin.Init(true))
#else
            if (AVProWindowsMediaPlugin.Init(false))
#endif
            {
                Debug.Log("[AVProWindowsMedia] version " + AVProWindowsMediaPlugin.GetPluginVersion().ToString("F2") + " initialised");
            }
            else
            {
                Debug.LogError("[AVProWindowsMedia] failed to initialise.");
                this.enabled = false;
                Deinit();
                return(false);
            }
        }
        catch (System.DllNotFoundException e)
        {
            Debug.Log("Unity couldn't find the DLL, did you move the 'Plugins' folder to the root of your project?");
            throw e;
        }

        GetConversionMethod();

        _isInitialised = true;

        return(_isInitialised);
    }
    private void SetUnityFeatures()
    {
#if !AVPROWINDOWSMEDIA_UNITYFEATURE_EXTERNALTEXTURES
        _useExternalTextures = false;
#endif
        AVProWindowsMediaPlugin.SetUnityFeatures(_useExternalTextures);
    }
Beispiel #6
0
 public void Pause()
 {
     if (_movieHandle >= 0)
     {
         AVProWindowsMediaPlugin.Pause(_movieHandle);
         IsPlaying = false;
     }
 }
Beispiel #7
0
 public void Play()
 {
     if (_movieHandle >= 0)
     {
         AVProWindowsMediaPlugin.Play(_movieHandle);
         IsPlaying = true;
     }
 }
Beispiel #8
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 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);
    }
    private IEnumerator FinalRenderCapture()
    {
        while (Application.isPlaying)
        {
            int flags = AVProWindowsMediaPlugin.PluginID | (int)AVProWindowsMediaPlugin.PluginEvent.UpdateAllTextures;
#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1
            GL.IssuePluginEvent(AVProWindowsMediaPlugin.GetRenderEventFunc(), flags);
#else
            GL.IssuePluginEvent(flags);
#endif

            yield return(new WaitForEndOfFrame());
        }
    }
Beispiel #11
0
    void Update()
    {
        if (_movie.MovieInstance != null)
        {
            // Generate audio matrix values
            _parent.UpdateAudioMatrix(Position, ref _audioMatrixValues);

            // Apply matrix values to movie instance

            /*for (int i = 0; i < _audioMatrixValues.Length; i++)
             *      Debug.Log("v " + i + " " + _audioMatrixValues[i]);
             * Debug.Log("apply to " + _movie.MovieInstance.Handle);*/
            AVProWindowsMediaPlugin.SetAudioChannelMatrix(_movie.MovieInstance.Handle, _audioMatrixValues, _audioMatrixValues.Length);
        }
    }
Beispiel #12
0
    private void PreRoll()
    {
        if (_movieHandle < 0)
        {
            return;
        }

        float vol = Volume;

        Volume = 0.0f;
        Play();
        Pause();
        AVProWindowsMediaPlugin.SeekFrames(_movieHandle, 0);
        Volume = vol;
    }
    public void Update()
    {
#if UNITY_EDITOR
        if (_instance == null)
        {
            return;
        }
#endif
        int flags = AVProWindowsMediaPlugin.PluginID | (int)AVProWindowsMediaPlugin.PluginEvent.UpdateAllTextures;
#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1
        GL.IssuePluginEvent(AVProWindowsMediaPlugin.GetRenderEventFunc(), flags);
#else
        GL.IssuePluginEvent(flags);
#endif
    }
Beispiel #14
0
    private bool UpdateTexture()
    {
        bool result = false;

        AVProWindowsMediaManager.ConversionMethod method = AVProWindowsMediaManager.Instance.TextureConversionMethod;

//#if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0 || UNITY_3_5
#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0
        if (method == AVProWindowsMediaManager.ConversionMethod.Unity4 ||
            method == AVProWindowsMediaManager.ConversionMethod.Unity35_OpenGL)
        {
            // We update all the textures from AVProQuickTimeManager.Update()
            // so just check if the update was done
            int lastFrameUploaded = AVProWindowsMediaPlugin.GetLastFrameUploaded(_movieHandle);
            if (_lastFrameUploaded != lastFrameUploaded)
            {
                _lastFrameUploaded = lastFrameUploaded;
                result             = true;
            }
            return(result);
        }
#endif

#if UNITY_3_4
        // Update the OpenGL texture directly
        if (method == AVProWindowsMediaManager.ConversionMethod.Unity34_OpenGL)
        {
            result = AVProWindowsMediaPlugin.UpdateTextureGL(_movieHandle, _rawTexture.GetNativeTextureID(), ref _lastFrameUploaded);
            GL.InvalidateState();
        }
#endif

//#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
        // Update the texture using Unity scripting, this is the slowest method
        if (method == AVProWindowsMediaManager.ConversionMethod.UnityScript)
        {
            result = AVProWindowsMediaPlugin.GetFramePixels(_movieHandle, _frameHandle.AddrOfPinnedObject(), _rawTexture.width, _rawTexture.height, ref _lastFrameUploaded);
            if (result)
            {
                _rawTexture.SetPixels32(_frameData);
                _rawTexture.Apply(false, false);
            }
        }
#endif

        return(result);
    }
    private bool UpdateTexture()
    {
        bool result = false;

        // We update all the textures from AVProQuickTimeManager.Update()
        // so just check if the update was done
        int lastFrameUploaded = AVProWindowsMediaPlugin.GetLastFrameUploaded(_movieHandle);

        if (_lastFrameUploaded != lastFrameUploaded)
        {
            _lastFrameUploaded = lastFrameUploaded;
            result             = true;
        }

        return(result);
    }
Beispiel #16
0
    private void Close()
    {
#if AVPROWINDOWSMEDIA_FPS
        ResetFPS();
#endif

        Width = Height = 0;

        if (_movieHandle >= 0)
        {
            Pause();
            AVProWindowsMediaPlugin.Stop(_movieHandle);
            AVProWindowsMediaPlugin.FreeInstanceHandle(_movieHandle);
            _movieHandle = -1;
        }
    }
Beispiel #17
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();
    }
Beispiel #18
0
    private void Close()
    {
        Pause();
        AVProWindowsMediaPlugin.Stop(_movieHandle);

#if UNITY_EDITOR
        ResetFPS();
#endif

        Width = Height = 0;

        if (_movieHandle >= 0)
        {
            AVProWindowsMediaPlugin.FreeInstanceHandle(_movieHandle);
            _movieHandle = -1;
        }
    }
    public void Deinit()
    {
        // Clean up any open movies
        AVProWindowsMediaMovie[] movies = (AVProWindowsMediaMovie[])FindObjectsOfType(typeof(AVProWindowsMediaMovie));
        if (movies != null && movies.Length > 0)
        {
            for (int i = 0; i < movies.Length; i++)
            {
                movies[i].UnloadMovie();
            }
        }

        _instance      = null;
        _isInitialised = false;

        AVProWindowsMediaPlugin.Deinit();
    }
Beispiel #20
0
    //-------------------------------------------------------------------------

    public bool StartVideo(string filename, bool allowNativeFormat, bool useBT709, bool allowAudio, bool useAudioDelay, bool useAudioMixer, bool useDisplaySync, bool ignoreFlips, FilterMode textureFilterMode, TextureWrapMode textureWrapMode)
    {
        Filename = filename;
        if (!string.IsNullOrEmpty(Filename))
        {
            if (System.IO.File.Exists(filename))
            {
                if (_movieHandle < 0)
                {
                    _movieHandle = AVProWindowsMediaPlugin.GetInstanceHandle();
                }

                // Note: we're marshaling the string to IntPtr as the pointer of type wchar_t
                System.IntPtr filenamePtr = Marshal.StringToHGlobalUni(Filename);
                if (AVProWindowsMediaPlugin.LoadMovie(_movieHandle, filenamePtr, false, allowNativeFormat, allowAudio, useAudioDelay, useAudioMixer, useDisplaySync))
                {
                    CompleteVideoLoad(useBT709, ignoreFlips, textureFilterMode, textureWrapMode);
                }
                else
                {
                    Debug.LogError("[AVProWindowsMedia] Movie failed to load - do you have the required codecs installed?  See documentation for details.");
                    if (filename.ToLower().EndsWith(".mp4"))
                    {
                        Debug.LogError("[AVProWindowsMedia] For MP4 files you need an MP4 splitter such as Haali Media Splitter or GDCL.");
                        Debug.LogError("[AVProWindowsMedia] For HIGH profile H.264 videos you need to install an external H.264 decoder.  See documentation for details.");
                    }
                    Close();
                }
                Marshal.FreeHGlobal(filenamePtr);
            }
            else
            {
                Debug.LogError("[AVProWindowsMedia] File not found " + filename);
                Close();
            }
        }
        else
        {
            Debug.LogError("[AVProWindowsMedia] No movie file specified");
            Close();
        }

        return(_movieHandle >= 0);
    }
Beispiel #21
0
    public bool Update(bool force)
    {
        bool updated = false;

        if (_movieHandle >= 0)
        {
            AVProWindowsMediaPlugin.Update(_movieHandle);
            if (_formatConverter != null)
            {
                bool ready = true;

//#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
                ready = true;
#else
                if (AVProWindowsMediaManager.ConversionMethod.Unity35_OpenGL == AVProWindowsMediaManager.Instance.TextureConversionMethod)
                {
                    ready = true;
                }
                else if (!force)
                {
                    ready = AVProWindowsMediaPlugin.IsNextFrameReadyForGrab(_movieHandle);
                }
#endif

                if (ready)
                {
                    updated = _formatConverter.Update();
#if UNITY_EDITOR
                    if (updated)
                    {
                        UpdateFPS();
                    }
#endif
                }
            }
            else
            {
                updated = false;
            }
        }
        return(updated);
    }
Beispiel #22
0
    public bool Update(bool force)
    {
        bool updated = false;

        if (_movieHandle >= 0)
        {
            AVProWindowsMediaPlugin.Update(_movieHandle);
            if (_formatConverter != null)
            {
                updated = _formatConverter.Update();
#if AVPROWINDOWSMEDIA_FPS
                if (updated)
                {
                    UpdateFPS();
                }
#endif
            }
        }
        return(updated);
    }
Beispiel #23
0
    public bool StartAudio(string filename, bool loop)
    {
        Filename = filename;
        Width    = Height = 0;
        if (!string.IsNullOrEmpty(Filename))
        {
            if (_movieHandle < 0)
            {
                _movieHandle = AVProWindowsMediaPlugin.GetInstanceHandle();
            }

            if (_formatConverter != null)
            {
                _formatConverter.Dispose();
                _formatConverter = null;
            }

            // Note: we're marshaling the string to IntPtr as the pointer of type wchar_t
            System.IntPtr filenamePtr = Marshal.StringToHGlobalUni(Filename);
            if (AVProWindowsMediaPlugin.LoadAudio(_movieHandle, filenamePtr, loop))
            {
                Volume          = _volume;
                DurationSeconds = AVProWindowsMediaPlugin.GetDurationSeconds(_movieHandle);

                Debug.Log("[AVProWindowsMedia] Loaded audio " + Filename + " " + DurationSeconds.ToString("F2") + " sec");
            }
            else
            {
                Debug.LogWarning("[AVProWindowsMedia] Movie failed to load");
                Close();
            }
            Marshal.FreeHGlobal(filenamePtr);
        }
        else
        {
            Debug.LogWarning("[AVProWindowsMedia] No movie file specified");
            Close();
        }

        return(_movieHandle >= 0);
    }
    private bool StartExtractFrames(string filePath, uint numSamples)
    {
        DestroyTextures();

        if (_movie.StartVideo(filePath, true, true, false, false, false, false, false, FilterMode.Bilinear, TextureWrapMode.Clamp))
        {
            _textures = new Texture2D[numSamples];
            _contents = new GUIContent[numSamples];
            for (int i = 0; i < numSamples; i++)
            {
                _contents[i] = new GUIContent(" ");
            }

            uint numFrames = _movie.DurationFrames;
            _frameStep    = numFrames / numSamples;
            _targetFrame  = 0;
            _textureIndex = 0;

            if (!_async)
            {
                _isExtracting = true;
                while (_isExtracting)
                {
#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1
                    GL.IssuePluginEvent(AVProWindowsMediaPlugin.GetRenderEventFunc(), (int)AVProWindowsMediaPlugin.PluginEvent.UpdateAllTextures);
#else
                    GL.IssuePluginEvent(AVProWindowsMediaPlugin.PluginID | (int)AVProWindowsMediaPlugin.PluginEvent.UpdateAllTextures);
#endif

                    UpdateExtracting();
                }

                return(false);
            }

            return(true);
        }

        return(false);
    }
    protected bool Init()
    {
        if (_isInitialised)
        {
            return(true);
        }

        try
        {
            if (AVProWindowsMediaPlugin.Init())
            {
                if (UnityEngine.Application.isPlaying)
                {
                    Debug.Log("[AVProWindowsMedia] version " + AVProWindowsMediaPlugin.GetPluginVersion().ToString("F2") + " initialised");
                }
            }
            else
            {
                Debug.LogError("[AVProWindowsMedia] failed to initialise.");
                this.enabled = false;
                Deinit();
                return(false);
            }
        }
        catch (System.DllNotFoundException e)
        {
            Debug.LogError("[AVProWindowsMedia] Unity couldn't find the DLL, did you move the 'Plugins' folder to the root of your project?");
            throw e;
        }

        LoadShaders();
        GetConversionMethod();
        SetUnityFeatures();

//		StartCoroutine("FinalRenderCapture");
        _isInitialised = true;

        return(_isInitialised);
    }
    private void CreateExternalTexture()
    {
        System.IntPtr texPtr = AVProWindowsMediaPlugin.GetTexturePointer(_movieHandle);
        if (texPtr != System.IntPtr.Zero)
        {
            int           texWidth      = _width;
            TextureFormat textureFormat = TextureFormat.ARGB32;
            switch (_sourceVideoFormat)
            {
            case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGBA:
            case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB_HQ:
                textureFormat = TextureFormat.DXT5;
                break;

            case AVProWindowsMediaPlugin.VideoFrameFormat.Hap_RGB:
                textureFormat = TextureFormat.DXT1;
                break;

            case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_YUY2:
            case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_UYVY:
            case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_YVYU:
            case AVProWindowsMediaPlugin.VideoFrameFormat.YUV_422_HDYC:
                texWidth = _width / 2;
                break;
            }

            _usedTextureWidth  = texWidth;
            _usedTextureHeight = _height;
            _rawTexture        = Texture2D.CreateExternalTexture(texWidth, _height, textureFormat, false, false, texPtr);

            _rawTexture.wrapMode   = TextureWrapMode.Clamp;
            _rawTexture.filterMode = FilterMode.Point;
            _rawTexture.name       = "AVProWindowsMedia-RawExternal";

            _isExternalTexture = true;
        }
    }
	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);
	}
	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;
	}
Beispiel #29
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();
    }
Beispiel #30
0
 public void SetFrameRange(int min, int max)
 {
     AVProWindowsMediaPlugin.SetDisplayFrameRange(_movieHandle, min, max);
 }
    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);
    }