Loading src/com/android/fmradio/FmService.java +43 −24 Original line number Diff line number Diff line Loading @@ -409,16 +409,8 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan // need to create new audio record and audio play back track, // because input/output device may be changed. if (mAudioRecord != null) { mAudioRecord.stop(); mAudioRecord.release(); mAudioRecord = null; } if (mAudioTrack != null) { mAudioTrack.stop(); mAudioTrack.release(); mAudioTrack = null; } releaseAudioRecorder(); releaseAudioTrack(); initAudioRecordSink(); mIsRender = true; Loading Loading @@ -721,10 +713,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan if (isRdsSupported()) { stopRdsThread(); } if (mWakeLock.isHeld()) { mWakeLock.release(); } releaseWakeLock(); // Remove the notification in the title bar. removeNotification(); return false; Loading @@ -735,11 +724,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan if (isRdsSupported()) { stopRdsThread(); } if (mWakeLock.isHeld()) { mWakeLock.release(); } releaseWakeLock(); // Remove the notification in the title bar. removeNotification(); return true; Loading Loading @@ -1327,10 +1312,15 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan // Thread 1: onCreate() or startRender() // Thread 2: onAudioPatchListUpdate() or startRender() private synchronized void initAudioRecordSink() { if (mAudioRecord == null) { mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.RADIO_TUNER, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE); } if (mAudioTrack == null) { mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE, AudioTrack.MODE_STREAM); SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE, AudioTrack.MODE_STREAM); } } private synchronized int createAudioPatch() { Loading Loading @@ -1440,6 +1430,12 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan } } private synchronized void releaseWakeLock() { if (mWakeLock.isHeld()) { mWakeLock.release(); } } private synchronized void releaseAudioPatch() { if (mAudioPatch != null) { Log.d(TAG, "releaseAudioPatch"); Loading @@ -1450,6 +1446,26 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan mAudioSink = null; } private synchronized void releaseAudioTrack() { if (mAudioTrack != null) { if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) { mAudioTrack.stop(); } mAudioTrack.release(); mAudioTrack = null; } } private synchronized void releaseAudioRecorder() { if (mAudioRecord != null) { if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) { mAudioRecord.stop(); } mAudioRecord.release(); mAudioRecord = null; } } private void registerFmBroadcastReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(SOUND_POWER_DOWN_MSG); Loading @@ -1470,7 +1486,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan @Override public void onDestroy() { mAudioManager.setParameters("AudioFmPreStop=1"); mAudioManager.setParameters("AudioFmPreStop=0"); setMute(true); // stop rds first, avoid blocking other native method if (isRdsSupported()) { Loading @@ -1485,7 +1501,10 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan } stopRender(); exitRenderThread(); releaseWakeLock(); releaseAudioPatch(); releaseAudioRecorder(); releaseAudioTrack(); unregisterAudioPortUpdateListener(); super.onDestroy(); } Loading Loading
src/com/android/fmradio/FmService.java +43 −24 Original line number Diff line number Diff line Loading @@ -409,16 +409,8 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan // need to create new audio record and audio play back track, // because input/output device may be changed. if (mAudioRecord != null) { mAudioRecord.stop(); mAudioRecord.release(); mAudioRecord = null; } if (mAudioTrack != null) { mAudioTrack.stop(); mAudioTrack.release(); mAudioTrack = null; } releaseAudioRecorder(); releaseAudioTrack(); initAudioRecordSink(); mIsRender = true; Loading Loading @@ -721,10 +713,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan if (isRdsSupported()) { stopRdsThread(); } if (mWakeLock.isHeld()) { mWakeLock.release(); } releaseWakeLock(); // Remove the notification in the title bar. removeNotification(); return false; Loading @@ -735,11 +724,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan if (isRdsSupported()) { stopRdsThread(); } if (mWakeLock.isHeld()) { mWakeLock.release(); } releaseWakeLock(); // Remove the notification in the title bar. removeNotification(); return true; Loading Loading @@ -1327,10 +1312,15 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan // Thread 1: onCreate() or startRender() // Thread 2: onAudioPatchListUpdate() or startRender() private synchronized void initAudioRecordSink() { if (mAudioRecord == null) { mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.RADIO_TUNER, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE); } if (mAudioTrack == null) { mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE, AudioTrack.MODE_STREAM); SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, RECORD_BUF_SIZE, AudioTrack.MODE_STREAM); } } private synchronized int createAudioPatch() { Loading Loading @@ -1440,6 +1430,12 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan } } private synchronized void releaseWakeLock() { if (mWakeLock.isHeld()) { mWakeLock.release(); } } private synchronized void releaseAudioPatch() { if (mAudioPatch != null) { Log.d(TAG, "releaseAudioPatch"); Loading @@ -1450,6 +1446,26 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan mAudioSink = null; } private synchronized void releaseAudioTrack() { if (mAudioTrack != null) { if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) { mAudioTrack.stop(); } mAudioTrack.release(); mAudioTrack = null; } } private synchronized void releaseAudioRecorder() { if (mAudioRecord != null) { if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) { mAudioRecord.stop(); } mAudioRecord.release(); mAudioRecord = null; } } private void registerFmBroadcastReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(SOUND_POWER_DOWN_MSG); Loading @@ -1470,7 +1486,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan @Override public void onDestroy() { mAudioManager.setParameters("AudioFmPreStop=1"); mAudioManager.setParameters("AudioFmPreStop=0"); setMute(true); // stop rds first, avoid blocking other native method if (isRdsSupported()) { Loading @@ -1485,7 +1501,10 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan } stopRender(); exitRenderThread(); releaseWakeLock(); releaseAudioPatch(); releaseAudioRecorder(); releaseAudioTrack(); unregisterAudioPortUpdateListener(); super.onDestroy(); } Loading