public override void Update()
        {
            // Only call this once per frame!
            OSXMediaPlayer.IssuePluginEvent(AVPPluginEventType.PlayerUpdate, AVPPlayerGetHandle(_player));

            int width  = 0;
            int height = 0;

            AVPPlayerGetTextureSize(_player, out width, out height);
            IntPtr native = AVPPlayerGetTextureHandle(_player);

            if (_texture != null && (_width != width || _height != height))
            {
                // Have to update with zero to release Metal textures!
                _texture.UpdateExternalTexture(IntPtr.Zero);
                Texture2D.Destroy(_texture);
                _texture = null;
            }

            if (_texture == null && native != IntPtr.Zero)
            {
                TextureFormat format = TextureFormat.BGRA32;
                bool          mipmap = false;
                bool          linear = false;
                _texture = Texture2D.CreateExternalTexture(width, height, format, mipmap, linear, native);
                _width   = width;
                _height  = height;
                _native  = native;
                ApplyTextureProperties(_texture);
            }
            else if (_texture != null && native != _native)
            {
                _texture.UpdateExternalTexture(native);
                _native = native;
            }

            // Check for meta data to become available
            if (!_isMetaDataReady)
            {
                if (AVPPlayerHasMetaData(_player) || CanPlay())
                {
                    if (HasVideo())
                    {
                        if (width > 0 && height > 0)
                        {
                            if (Mathf.Max(width, height) > SystemInfo.maxTextureSize)
                            {
                                Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize");
                            }
                            _isMetaDataReady = true;
                        }
                    }
                    else if (HasAudio())
                    {
                        _isMetaDataReady = true;
                    }
                }
            }
        }
        public override void Dispose()
        {
            if (_texture != null)
            {
                // Have to update with zero to release Metal textures!
                _texture.UpdateExternalTexture(IntPtr.Zero);
                Texture2D.Destroy(_texture);
                _texture = null;
            }

            if (_player != IntPtr.Zero)
            {
                OSXMediaPlayer.IssuePluginEvent(AVPPluginEventType.FreeTextureResources, AVPPlayerGetHandle(_player));
                AVPPlayerRelease(_player);
                _player = IntPtr.Zero;
            }
        }
Пример #3
0
 // Convenience method for calling OSXMediaPlayer.IssuePluginEvent.
 //
 private void IssuePluginEvent(AVPPluginEventType type)
 {
     OSXMediaPlayer.IssuePluginEvent(type, _handle);
 }
Пример #4
0
 public override void Dispose()
 {
     OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerShutdown, AVPPlayerGetHandle(_player));
     AVPPlayerRelease(_player);
     _player = IntPtr.Zero;
 }
Пример #5
0
        public override void Update()
        {
            // Called before Render.

            // Check for meta data to become available
            if (!_isMetaDataReady)
            {
                if (AVPPlayerHasMetaData(_player) || CanPlay())
                {
                    if (HasVideo())
                    {
                        int width = 0, height = 0;
                        AVPPlayerGetTextureSize(_player, out width, out height);

                        if (width > 0 && height > 0)
                        {
                            if (Mathf.Max(width, height) > SystemInfo.maxTextureSize)
                            {
                                Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize");
                            }
                            else
                            {
                                _width  = width;
                                _height = height;
                            }
                            _isMetaDataReady = true;
                        }
                    }
                    else if (HasAudio())
                    {
                        _isMetaDataReady = true;
                    }
                }
            }

            // Free texture
            if (_texture != null)
            {
                IntPtr native = AVPPlayerGetTextureHandle(_player);
                if (native == IntPtr.Zero)
                {
                    if (_texture != null)
                    {
                        Texture2D.Destroy(_texture);
                        _texture = null;
                    }
                    _width         = _height = 0;
                    _nativeTexture = IntPtr.Zero;
                }
            }

            if (HasVideo() && _width > 0 && _height > 0)
            {
                IntPtr native = AVPPlayerGetTextureHandle(_player);

                int width = 0, height = 0;
                AVPPlayerGetTextureSize(_player, out width, out height);

                if (_texture != null)
                {
                    // Point to a new texture
                    if (native != _nativeTexture)
                    {
                        _texture.UpdateExternalTexture(native);
                        _nativeTexture = native;

                        _width  = width;
                        _height = height;
                    }
                }
                if (_texture == null || width != _width || height != _height)
                {
                    TextureFormat format = TextureFormat.BGRA32;
                    bool          mipmap = false;
                    bool          linear = false;

                    // Free existing texture if any
                    if (_texture != null)
                    {
                        Texture2D.Destroy(_texture);
                        _texture = null;
                    }
                    _width         = _height = 0;
                    _nativeTexture = IntPtr.Zero;

                    _texture       = Texture2D.CreateExternalTexture(width, height, format, mipmap, linear, native);
                    _nativeTexture = native;
                    _width         = width;
                    _height        = height;

                    OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, AVPPlayerGetHandle(_player));
                }
            }
        }
Пример #6
0
 public override void Render()
 {
     OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, AVPPlayerGetHandle(_player));
 }