Bug 5218 - AVAssetImageGenerator.CopyCGImageAtTime should have correct signature
Summary: AVAssetImageGenerator.CopyCGImageAtTime should have correct signature
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-05-21 15:44 UTC by tome
Modified: 2012-05-25 21:39 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
monotouch.dll hotfix (3.05 MB, application/octet-stream)
2012-05-25 15:51 UTC, Sebastien Pouliot
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description tome 2012-05-21 15:44:31 UTC
AVAssetImageGenerator.CopyCGImageAtTime method should have 2 of 'out' parameter,
actualTime and outError.

That signature of my expectation is;

CGImage CopyCGImageAtTime (CMTime requestedTime, out CMTime actualTime, out NSError outError)

And now I patched to use it with following code;

public static class MonoTouchFixes
{	
	// to fix the signature of AVAssetImageGenerator.CopyCGImageAtTime
	// on MonoTouch 5.2.11
	public static CGImage CopyCGImageAtTime (
							AVAssetImageGenerator imgGenerator
							, CMTime requestTime
							, out CMTime actualTime
							, out NSError outError)
	{
		int sizeOfCMTime = Marshal.SizeOf (typeof (CMTime));
		IntPtr intPtrForActualTime = Marshal.AllocHGlobal (sizeOfCMTime);
		FillZero (intPtrForActualTime, sizeOfCMTime);		
			
		IntPtr intPtrForError = Marshal.AllocHGlobal (4);
		Marshal.WriteInt32 (intPtrForError, 0);
			
		CGImage cgImage = new CGImage (Messaging.IntPtr_objc_msgSend_CMTime_IntPtr_IntPtr (
						imgGenerator.Handle
                                                , selCopyCGImageAtTimeActualTimeError_
                                                , requestTime
                                                , intPtrForActualTime
                                                , intPtrForError));
			
		actualTime = (CMTime)Marshal.PtrToStructure (intPtrForActualTime, typeof (CMTime));
				
		IntPtr intPtr2 = Marshal.ReadIntPtr (intPtrForError);
		outError = ((!(intPtr2 != IntPtr.Zero)) ? null : ((NSError)Runtime.GetNSObject (intPtr2)));
		Marshal.FreeHGlobal (intPtrForActualTime);
		Marshal.FreeHGlobal (intPtrForError);

		return cgImage;
	}

	static void FillZero (IntPtr ptr, int size)
	{
		for (int i=0; i < size; ++ i)
			Marshal.WriteByte (ptr, i, 0x0);
	}
		
	static IntPtr selCopyCGImageAtTimeActualTimeError_ = sel_registerName (
				Selector.GetHandle ("copyCGImageAtTime:actualTime:error:"));

  	[DllImport ("/usr/lib/libobjc.dylib")]
	static extern IntPtr sel_registerName (IntPtr name);
}

Thanks, I dig Mono and MonoTouch
Comment 1 Sebastien Pouliot 2012-05-22 10:56:48 UTC
Right again, CMTime being a struct we should use `out`.
Comment 2 Sebastien Pouliot 2012-05-22 11:22:32 UTC
Fixed.
5.2-series: f8e7d0eb90b9bc1dd3d23ec6d2f9e8b61465567f
master: c7389678ca5752df37c3c718a71829b6e147f12c

QA: unit tests added to both branches
Comment 3 baramuse 2012-05-24 23:10:41 UTC
Hi,

trying to use it on 5.2.12, could you provide me with a hotfix please ?

Thanks.
Comment 4 Sebastien Pouliot 2012-05-25 15:51:24 UTC
Created attachment 1959 [details]
monotouch.dll hotfix

Here's an hotfix that can be used until 5.2.13 is released. It should be discarded afterward (the update will overwrite it, just don't apply it again).

To use the attached assembly (on top of MonoTouch 5.2.12) do:

1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll and /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb files

2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll

3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb symbols (they won't match anymore)

4) clean, rebuild and test your application

Note that this includes other fixes (beside this bug). If you have an issue please state that you're using this .dll in your bug reports.
Comment 5 baramuse 2012-05-25 21:39:23 UTC
Works perfectly.

Thanks!