Changeset 4617
- Timestamp:
- Oct 9, 2013 3:34:26 AM (11 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/coreaudio_dev.m
r4609 r4617 36 36 #include <CoreAudio/CoreAudio.h> 37 37 #else 38 #include <A udioToolbox/AudioServices.h>38 #include <AVFoundation/AVAudioSession.h> 39 39 40 40 #define AudioDeviceID unsigned … … 52 52 53 53 /* Starting iOS SDK 7, Audio Session API is deprecated. */ 54 #ifdef __IPHONE_7_0 55 #define USE_AUDIO_SESSION_API 0 56 #else 57 #define USE_AUDIO_SESSION_API 1 58 #endif 54 #define USE_AUDIO_SESSION_API 0 59 55 #endif 60 56 … … 144 140 unsigned resample_buf_count; 145 141 unsigned resample_buf_size; 142 143 #if !COREAUDIO_MAC 144 AVAudioSession *sess; 145 #endif 146 146 }; 147 147 … … 289 289 290 290 /* Set the device capabilities here */ 291 #if USE_AUDIO_SESSION_API != 0292 291 cdi->info.caps = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 293 292 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY | 294 293 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING | 294 #if USE_AUDIO_SESSION_API != 0 295 295 PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE | 296 296 PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE | 297 #endif 297 298 PJMEDIA_AUD_DEV_CAP_EC; 298 299 cdi->info.routes = PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER | 299 300 PJMEDIA_AUD_DEV_ROUTE_EARPIECE | 300 301 PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH; 301 #else302 cdi->info.caps = PJMEDIA_AUD_DEV_CAP_EC;303 #endif304 302 305 303 PJ_LOG(4, (THIS_FILE, " dev_id %d: %s (in=%d, out=%d) %dHz", … … 1240 1238 { 1241 1239 OSStatus ostatus; 1242 #if !COREAUDIO_MAC && USE_AUDIO_SESSION_API != 0 1243 UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord; 1240 #if !COREAUDIO_MAC 1244 1241 /* We want to be able to open playback and recording streams */ 1245 ostatus = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,1246 sizeof(audioCategory), 1247 &audioCategory); 1248 if (ostatus != kAudioSessionNoError){1242 strm->sess = [AVAudioSession sharedInstance]; 1243 if ([strm->sess setCategory:AVAudioSessionCategoryPlayAndRecord 1244 error:nil] != YES) 1245 { 1249 1246 PJ_LOG(4, (THIS_FILE, 1250 "Warning: cannot set the audio session category (%i)", 1251 ostatus)); 1247 "Warning: cannot set the audio session category")); 1252 1248 } 1253 1249 #endif … … 1716 1712 } 1717 1713 } 1718 #elif USE_AUDIO_SESSION_API != 0 1719 Float32 latency, latency2; 1720 UInt32 size = sizeof(Float32); 1721 1722 if ((AudioSessionGetProperty( 1723 kAudioSessionProperty_CurrentHardwareInputLatency, 1724 &size, &latency) == kAudioSessionNoError) && 1725 (AudioSessionGetProperty( 1726 kAudioSessionProperty_CurrentHardwareIOBufferDuration, 1727 &size, &latency2) == kAudioSessionNoError)) 1728 { 1729 strm->param.input_latency_ms = (unsigned) 1730 ((latency + latency2) * 1000); 1714 #else 1715 if ([strm->sess respondsToSelector:@selector(inputLatency)]) { 1716 strm->param.input_latency_ms = 1717 (unsigned)(([strm->sess inputLatency] + 1718 [strm->sess IOBufferDuration]) * 1000); 1731 1719 strm->param.input_latency_ms++; 1732 } 1720 } else 1721 return PJMEDIA_EAUD_INVCAP; 1733 1722 #endif 1734 1723 … … 1764 1753 } 1765 1754 } 1766 #elif USE_AUDIO_SESSION_API != 0 1767 Float32 latency, latency2; 1768 UInt32 size = sizeof(Float32); 1769 1770 if ((AudioSessionGetProperty( 1771 kAudioSessionProperty_CurrentHardwareOutputLatency, 1772 &size, &latency) == kAudioSessionNoError) && 1773 (AudioSessionGetProperty( 1774 kAudioSessionProperty_CurrentHardwareIOBufferDuration, 1775 &size, &latency2) == kAudioSessionNoError)) 1776 { 1777 strm->param.output_latency_ms = (unsigned) 1778 ((latency + latency2) * 1000); 1755 #else 1756 if ([strm->sess respondsToSelector:@selector(outputLatency)]) { 1757 strm->param.output_latency_ms = 1758 (unsigned)(([strm->sess outputLatency] + 1759 [strm->sess IOBufferDuration]) * 1000); 1779 1760 strm->param.output_latency_ms++; 1780 } 1761 } else 1762 return PJMEDIA_EAUD_INVCAP; 1781 1763 #endif 1782 1764 *(unsigned*)pval = (++strm->param.output_latency_ms * 2); 1783 1765 return PJ_SUCCESS; 1784 #if COREAUDIO_MAC || USE_AUDIO_SESSION_API != 01785 1766 } else if (cap==PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING && 1786 1767 (strm->param.dir & PJMEDIA_DIR_PLAYBACK)) 1787 1768 { 1769 #if COREAUDIO_MAC 1788 1770 OSStatus ostatus; 1789 1771 Float32 volume; … … 1791 1773 1792 1774 /* Output volume setting */ 1793 #if COREAUDIO_MAC1794 1775 ostatus = AudioUnitGetProperty (strm->io_units[1] ? strm->io_units[1] : 1795 1776 strm->io_units[0], … … 1801 1782 if (ostatus != noErr) 1802 1783 return PJMEDIA_AUDIODEV_ERRNO_FROM_COREAUDIO(ostatus); 1803 #elif USE_AUDIO_SESSION_API != 01804 ostatus = AudioSessionGetProperty(1805 kAudioSessionProperty_CurrentHardwareOutputVolume,1806 &size, &volume);1807 if (ostatus != kAudioSessionNoError) {1808 return PJMEDIA_AUDIODEV_ERRNO_FROM_COREAUDIO(ostatus);1809 }1810 #endif1811 1784 1812 1785 *(unsigned*)pval = (unsigned)(volume * 100); 1813 1786 return PJ_SUCCESS; 1787 #else 1788 if ([strm->sess respondsToSelector:@selector(outputVolume)]) { 1789 *(unsigned*)pval = (unsigned)([strm->sess outputVolume] * 100); 1790 return PJ_SUCCESS; 1791 } else 1792 return PJMEDIA_EAUD_INVCAP; 1814 1793 #endif 1815 1794 … … 1933 1912 1934 1913 return PJ_SUCCESS; 1935 } 1936 1937 #if USE_AUDIO_SESSION_API != 0 1938 1939 else if ((cap==PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY && 1914 } else if ((cap==PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY && 1940 1915 (strm->param.dir & PJMEDIA_DIR_CAPTURE)) || 1941 1916 (cap==PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY && 1942 1917 (strm->param.dir & PJMEDIA_DIR_PLAYBACK))) 1943 1918 { 1944 Float32 bufferDuration = *(unsigned *)pval; 1945 OSStatus ostatus; 1919 NSTimeInterval duration = *(unsigned *)pval; 1946 1920 unsigned latency; 1947 1921 1948 1922 /* For low-latency audio streaming, you can set this value to 1949 1923 * as low as 5 ms (the default is 23ms). However, lowering the 1950 1924 * latency may cause a decrease in audio quality. 1951 1925 */ 1952 bufferDuration /= 1000; 1953 ostatus = AudioSessionSetProperty( 1954 kAudioSessionProperty_PreferredHardwareIOBufferDuration, 1955 sizeof(bufferDuration), &bufferDuration); 1956 if (ostatus != kAudioSessionNoError) { 1926 duration /= 1000; 1927 if ([strm->sess setPreferredIOBufferDuration:duration error:nil] 1928 != YES) 1929 { 1957 1930 PJ_LOG(4, (THIS_FILE, 1958 "Error: cannot set the preferred buffer duration (%i)", 1959 ostatus)); 1960 return PJMEDIA_AUDIODEV_ERRNO_FROM_COREAUDIO(ostatus); 1931 "Error: cannot set the preferred buffer duration")); 1932 return PJMEDIA_EAUD_INVOP; 1961 1933 } 1962 1934 … … 1965 1937 1966 1938 return PJ_SUCCESS; 1967 } else if (cap==PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE && 1939 } 1940 1941 #if USE_AUDIO_SESSION_API != 0 1942 1943 else if (cap==PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE && 1968 1944 (strm->param.dir & PJMEDIA_DIR_CAPTURE)) 1969 1945 { … … 2026 2002 } 2027 2003 2028 #if !COREAUDIO_MAC && USE_AUDIO_SESSION_API != 0 2029 AudioSessionSetActive(true); 2004 #if !COREAUDIO_MAC 2005 if ([stream->sess setActive:true error:nil] != YES) { 2006 PJ_LOG(4, (THIS_FILE, "Warning: cannot activate audio session")); 2007 } 2030 2008 #endif 2031 2009 … … 2084 2062 pj_mutex_unlock(stream->cf->mutex); 2085 2063 2086 #if !COREAUDIO_MAC && USE_AUDIO_SESSION_API != 0 2087 if (should_deactivate) 2088 AudioSessionSetActive(false); 2064 #if !COREAUDIO_MAC 2065 if (should_deactivate) { 2066 if ([stream->sess setActive:false error:nil] != YES) { 2067 PJ_LOG(4, (THIS_FILE, "Warning: cannot deactivate audio session")); 2068 } 2069 } 2089 2070 #endif 2090 2071 -
pjproject/trunk/pjsip-apps/src/pjsua/ios/ipjsua.xcodeproj/project.pbxproj
r4590 r4617 16 16 3ADCCD30172E40120007BE8E /* pjsua_app_legacy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD2B172E40120007BE8E /* pjsua_app_legacy.c */; }; 17 17 3ADCCD31172E40120007BE8E /* pjsua_app.c in Sources */ = {isa = PBXBuildFile; fileRef = 3ADCCD2C172E40120007BE8E /* pjsua_app.c */; }; 18 3ADFCCFD1803B00600B0A097 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3ADFCCFC1803B00600B0A097 /* AVFoundation.framework */; }; 18 19 3AF0580916F050770046B835 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF0580816F050770046B835 /* UIKit.framework */; }; 19 20 3AF0580B16F050770046B835 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF0580A16F050770046B835 /* Foundation.framework */; }; … … 58 59 3ADCCD2B172E40120007BE8E /* pjsua_app_legacy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_app_legacy.c; path = ../../pjsua_app_legacy.c; sourceTree = "<group>"; }; 59 60 3ADCCD2C172E40120007BE8E /* pjsua_app.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_app.c; path = ../../pjsua_app.c; sourceTree = "<group>"; }; 61 3ADFCCFC1803B00600B0A097 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 60 62 3AF0580416F050770046B835 /* ipjsua.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ipjsua.app; sourceTree = BUILT_PRODUCTS_DIR; }; 61 63 3AF0580816F050770046B835 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; … … 101 103 buildActionMask = 2147483647; 102 104 files = ( 105 3ADFCCFD1803B00600B0A097 /* AVFoundation.framework in Frameworks */, 103 106 3A92069316F1DEA500D49F96 /* CFNetwork.framework in Frameworks */, 104 107 3A92068F16F1DE7100D49F96 /* AudioToolbox.framework in Frameworks */, … … 164 167 isa = PBXGroup; 165 168 children = ( 169 3ADFCCFC1803B00600B0A097 /* AVFoundation.framework */, 166 170 3A92069216F1DEA500D49F96 /* CFNetwork.framework */, 167 171 3A92068E16F1DE7100D49F96 /* AudioToolbox.framework */,
Note: See TracChangeset
for help on using the changeset viewer.