public override bool WaitForNextFrame(Camera camera, int previousFrameCount) { int count = 2; AVPPlayerTextureInfo[] textures = new AVPPlayerTextureInfo[count]; int ret = AVPPlayerExtractFrame(_player, textures, ref count, 0.0); if (ret == 0) { _planeCount = count; for (int i = 0; i < count; ++i) { if (_texture[i] == null || _texture[i].width != textures[i].width || _texture[i].height != textures[i].height || _texture[i].format != (TextureFormat)textures[i].format) { int format = textures[i].format; #if !UNITY_5_6_OR_NEWER // Older Unitys do not support R8 or RG16 texture formats so patch them through to Alpha8 and ARGB4444 respectively. if (format == 63) { format = 1; } else if (format == 62) { format = 2; } #endif _texture[i] = Texture2D.CreateExternalTexture(textures[i].width, textures[i].height, (TextureFormat)format, /*mipmap*/ false, /*linear*/ false, textures[i].native); if (i == 0) { _width = textures[i].width; _height = textures[i].height; _flipped = textures[i].flipped != 0; } } else { _texture[i].UpdateExternalTexture(textures[i].native); } } return(true); } return(false); }
public void UpdateTextures() { AVPPlayerTextureInfo[] textures = new AVPPlayerTextureInfo[2]; int count = textures.Length; if (AVPPlayerGetTextures(_player, textures, ref count)) { _planeCount = count; for (int i = 0; i < count; ++i) { if (_texture[i] == null || _texture[i].width != textures[i].width || _texture[i].height != textures[i].height || _texture[i].format != (TextureFormat)textures[i].format) { if (_texture[i] != null) { _texture[i].UpdateExternalTexture(IntPtr.Zero); _texture[i] = null; } int format = textures[i].format; #if !UNITY_5_6_OR_NEWER // Older Unitys do not support R8 or RG16 texture formats so patch them through to Alpha8 and ARGB4444 respectively. if (format == 63) { format = 1; } else if (format == 62) { format = 2; } #endif _texture[i] = Texture2D.CreateExternalTexture(textures[i].width, textures[i].height, (TextureFormat)format, /*mipmap*/ false, /*linear*/ false, textures[i].native); if (i == 0) { _width = textures[i].width; _height = textures[i].height; _flipped = textures[i].flipped != 0; } if (_texture[i] != null) { ApplyTextureProperties(_texture[i]); } } else { _texture[i].UpdateExternalTexture(textures[i].native); } } // If Y'CbCr grab the transform if (_useYpCbCr && !_YpCbCrTransformIsValid) { float[] transform = new float[16]; _YpCbCrTransformIsValid = AVPPlayerGetYpCbCrTransform(_player, ref transform[0]); for (int i = 0; i < 16; ++i) { _YpCbCrTransform[i] = transform[i]; } } } }