Bug 5034 - AudioUnit callback works on simulator, but fails on iPhone device
Summary: AudioUnit callback works on simulator, but fails on iPhone device
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Other
: Normal normal
Target Milestone: (C7)
Assignee: Alex Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-05-11 13:58 UTC by Mika Aalto
Modified: 2016-01-28 19:09 UTC (History)
4 users (show)

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


Attachments
Small app for reproducing this issue (13.56 KB, application/x-gzip)
2012-05-11 13:58 UTC, Mika Aalto
Details
Upgraded test case using new API from C7 (16.70 KB, application/zip)
2016-01-28 19:07 UTC, Alex Soto [MSFT]
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 Mika Aalto 2012-05-11 13:58:40 UTC
Created attachment 1861 [details]
Small app for reproducing this issue

I have an application which uses AudioUnit to playback audio samples from RTP media stream. Audio sample playback works on simulator but application crashes when it's run on iPhone device.

I have attached small sample application which reproduces my issue. Sample app works on simulator but crashes when run on iPhone.


Information about my development environment:
Mono 2.10.9
MonoTouch 5.2.11
Mac OSX 10.7.4
iPhone 4S with IOS 5.1.1
Comment 1 Mika Aalto 2012-05-11 13:59:28 UTC
Crash log from iPhone device when using debug deployment:


Please ensure your device is connected...
Connected to: Mikan iPhone 4S
Loaded assembly: /private/var/mobile/Applications/EA836D6B-E071-4C31-9468-2975B1C43337/AudioTest.app/monotouch.dll
Loaded assembly: /private/var/mobile/Applications/EA836D6B-E071-4C31-9468-2975B1C43337/AudioTest.app/AudioUnitTest.exe
Thread started: Finalizer
Loaded assembly: /private/var/mobile/Applications/EA836D6B-E071-4C31-9468-2975B1C43337/AudioTest.app/System.dll
Thread started: 
Stacktrace:

  at System.Runtime.InteropServices.Marshal.Copy (byte[],int,intptr,int) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:107
  at AudioUnitTest.AppDelegate.AudioUnit_Callback (object,MonoTouch.AudioUnit.AudioUnitEventArgs) [0x0005b] in /Users/mikaa/Projects/AudioTest/AppDelegate.cs:116
  at MonoTouch.AudioUnit.AudioUnit.renderCallback (intptr,MonoTouch.AudioUnit.AudioUnitRenderActionFlags&,MonoTouch.AudioToolbox.AudioTimeStamp&,int,int,MonoTouch.AudioToolbox.AudioBufferList) [0x00032] in /Developer/MonoTouch/Source/monotouch/src/shared/AudioUnit/AudioUnit.cs:187
  at (wrapper native-to-managed) MonoTouch.AudioUnit.AudioUnit.renderCallback (intptr,MonoTouch.AudioUnit.AudioUnitRenderActionFlags&,MonoTouch.AudioToolbox.AudioTimeStamp&,int,int,MonoTouch.AudioToolbox.AudioBufferList) <0xffffffff>

Native stacktrace:

	0   AudioUnitTest                       0x001d0178 mono_handle_native_sigsegv + 280
	1   AudioUnitTest                       0x001ba798 mono_sigsegv_signal_handler + 268
	2   libsystem_c.dylib                   0x32c5d7ed _sigtramp + 48
	3   AudioUnitTest                       0x00239bf8 ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged + 276
	4   AudioUnitTest                       0x00239bf8 ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged + 276
	5   AudioUnitTest                       0x000c19e4 wrapper_managed_to_native_System_Runtime_InteropServices_Marshal_copy_to_unmanaged_System_Array_int_intptr_int + 84
	6   AudioUnitTest                       0x000037c8 AudioUnitTest_AppDelegate_AudioUnit_Callback_object_MonoTouch_AudioUnit_AudioUnitEventArgs + 588
	7   AudioUnitTest                       0x00007524 MonoTouch_AudioUnit_AudioUnit_renderCallback_intptr_MonoTouch_AudioUnit_AudioUnitRenderActionFlags__MonoTouch_AudioToolbox_AudioTimeStamp__int_int_MonoTouch_AudioToolbox_AudioBufferList + 388
	8   AudioUnitTest                       0x0002557c wrapper_native_to_managed_MonoTouch_AudioUnit_AudioUnit_renderCallback_intptr_MonoTouch_AudioUnit_AudioUnitRenderActionFlags__MonoTouch_AudioToolbox_AudioTimeStamp__int_int_MonoTouch_AudioToolbox_AudioBufferList + 240
	9   AudioToolbox                        0x31ec932d _ZN14AUInputElement9PullInputERmRK14AudioTimeStampmm + 136
	10  AudioToolbox                        0x31ece6fd _ZN23AUInputFormatConverter29InputProcEP20OpaqueAudioConverterPmP15AudioBufferListPP28AudioStreamPacketDescriptionPv + 160
	11  AudioToolbox                        0x31eb3325 _ZN19AudioConverterChain13CallInputProcEm + 360
	12  AudioToolbox                        0x31eb307b _ZN19AudioConverterChain23FillBufferFromInputProcEPmP12CABufferList + 78
	13  AudioToolbox                        0x31eb3025 _ZN22BufferedAudioConverter13GetInputBytesEmRmRPK12CABufferList + 128
	14  AudioToolbox                        0x31ece5c9 _ZN12CBRConverter12RenderOutputEP12CABufferListmRmP28AudioStreamPacketDescription + 80
	15  AudioToolbox                        0x31eb2d53 _ZN22BufferedAudioConverter10FillBufferERmR15AudioBufferListP28AudioStreamPacketDescription + 186
	16  AudioToolbox                        0x31eb300d _ZN22BufferedAudioConverter13GetInputBytesEmRmRPK12CABufferList + 104
	17  AudioToolbox                        0x31ece5c9 _ZN12CBRConverter12RenderOutputEP12CABufferListmRmP28AudioStreamPacketDescription + 80
	18  AudioToolbox                        0x31eb2d53 _ZN22BufferedAudioConverter10FillBufferERmR15AudioBufferListP28AudioStreamPacketDescription + 186
	19  AudioToolbox                        0x31eb300d _ZN22BufferedAudioConverter13GetInputBytesEmRmRPK12CABufferList + 104
	20  AudioToolbox                        0x31efa92f _ZN17Resampler2Wrapper12RenderOutputEP12CABufferListmRm + 146
	21  AudioToolbox                        0x31eb2d53 _ZN22BufferedAudioConverter10FillBufferERmR15AudioBufferListP28AudioStreamPacketDescription + 186
	22  AudioToolbox                        0x31eb2e99 _ZN19AudioConverterChain12RenderOutputEP12CABufferListmRmP28AudioStreamPacketDescription + 92
	23  AudioToolbox                        0x31eb2d53 _ZN22BufferedAudioConverter10FillBufferERmR15AudioBufferListP28AudioStreamPacketDescription + 186
	24  AudioToolbox                        0x31eb2b29 AudioConverterFillComplexBuffer + 356
	25  AudioToolbox                        0x31f789b7 _ZN23AUInputFormatConverter219PullAndConvertInputERK14AudioTimeStampRmR15AudioBufferListP28AudioStreamPacketDescriptionRb + 110
	26  AudioToolbox                        0x31ece51f _ZN15AUConverterBase9RenderBusERmRK14AudioTimeStampmm + 902
	27  AudioToolbox                        0x31f6937d _ZN10AURemoteIO9RenderBusERmRK14AudioTimeStampmm + 48
	28  AudioToolbox                        0x31f7bd8b _ZN6AUBase11DoRenderBusERmRK14AudioTimeStampmP15AUOutputElementmR15AudioBufferList + 190
	29  AudioToolbox                        0x31eb4035 _ZN6AUBase8DoRenderERmRK14AudioTimeStampmmR15AudioBufferList + 444
	30  AudioToolbox                        0x31f69931 _ZN10AURemoteIO9PerformIOEjjRK15XAudioTimeStampS2_Ri + 876
	31  AudioToolbox                        0x31f69a97 AURIOCallbackReceiver_PerformIO + 198
	32  AudioToolbox                        0x31f60a25 _XPerformIO + 184
	33  AudioToolbox                        0x31ec9ce3 mshMIGPerform + 374
	34  AudioToolbox                        0x31f34b9d MSHMIGDispatchMessage + 28
	35  AudioToolbox                        0x31f692f1 _ZN10AURemoteIO8IOThread3RunEv + 64
	36  AudioToolbox                        0x31f6cf49 _ZN10AURemoteIO8IOThread5EntryEPv + 8
	37  AudioToolbox                        0x31ea9ca3 _ZN9CAPThread5EntryEPS_ + 214
	38  libsystem_c.dylib                   0x32c14735 _pthread_start + 320
	39  libsystem_c.dylib                   0x32c145f0 thread_start + 8

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 2 Sebastien Pouliot 2012-05-11 16:05:14 UTC
Thanks for the sample. It seems the memory is shifted by a few bytes so we pointer, on device, is invalid.
Comment 3 Sebastien Pouliot 2012-05-11 16:47:10 UTC
Some fields are not protected with [Preserve] attribute so the linker removes them. Since they are shared with the native side it breaks the 1-to-1 mapping.

Quick workaround: disable the linker on your app (--nolink) or or on monotouch.dll (--linkskip=monotouch.dll)
Comment 4 Mika Aalto 2012-05-11 19:44:33 UTC
Thank you Sebastien for quick response. I got playback working on device by using linker behavior "Don't link" option. I really appreciate your help, thanks!
Comment 5 Sebastien Pouliot 2012-05-11 21:14:43 UTC
Fixed. 5.2.12 will have this fix (and future 5.3+ versions too) so you won't have to disable the linker.

master: b5f707ae9e3e4df9691dd5632adc45306afd934b
5.2-series: fae2e4b42a0fa4bcb3f31011f704978d804f9520

QA: unit test added on both branches
Comment 6 E K 2014-05-16 11:56:43 UTC
Hi. 

Exactly the same issue. Just downloaded the sample attached to this bug and it still crashes on device no matter linking disabled or enabled. Works fine on simulator.

Xamarin Studio 4.2.5
Mono 3.2.6 
Xcode 5.1.1
iOS 7.1

Thanks!
Comment 7 Sebastien Pouliot 2016-01-15 14:38:29 UTC
@Alex please double check this sample as a lot of things changed in C7.
Comment 8 Alex Soto [MSFT] 2016-01-28 19:07:34 UTC
Created attachment 14770 [details]
Upgraded test case using new API from C7
Comment 9 Alex Soto [MSFT] 2016-01-28 19:09:31 UTC
Attached upgraded test case using API from C7, I can confirm it works.