Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16a17cd0 authored by Kryten2k35's avatar Kryten2k35 Committed by emancebo
Browse files

Call recording encoder/format choice 1/3

PS1: Adds a user option between WB AMR (the default) or HE-AAC for the encoding
 of call recording audio. Also changes the output format of the file
 appropriately (WB AMR now uses the WB_AMR output format and HE_AAC chooses
 the MPEG_4 output. File extensions are adjust accordingly as well).

This was in reponse to people complaining the quality of call recording audio
 is poor. It's noticibly better using HE-AAC, but filesizes are larger.

PS2: Removed unnecessary code in DialtactsActivity (see Teleservice patch).
 Removed whitespace and changed coding style to meet the standard

PS3: Fixed whitespace, finally!

Change-Id: I95620bf944e18491652c716890396c3da4be70c4
parent 84f8765d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
<resources>
    <bool name="call_recording_enabled">false</bool>
    <integer name="call_recording_audio_source">1</integer>
    <integer name="call_recording_audio_encoder">0</integer>
    <bool name="call_durationtype_enabled">false</bool>

    <!-- Flag whether to enable IP Prefix setting-->
+32 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.media.MediaRecorder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;

import com.android.services.callrecorder.common.CallRecording;
@@ -52,6 +53,8 @@ public class CallRecorderService extends Service {

    private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    private int mDefaultEncoder;

    private final ICallRecorderService.Stub mBinder = new ICallRecorderService.Stub() {
        @Override
        public CallRecording stopRecording() {
@@ -86,6 +89,7 @@ public class CallRecorderService extends Service {
    @Override
    public void onCreate() {
        if (DBG) Log.d(TAG, "Creating CallRecorderService");
        mDefaultEncoder = getResources().getInteger(R.integer.call_recording_audio_encoder);
    }

    @Override
@@ -98,6 +102,26 @@ public class CallRecorderService extends Service {
        return SystemProperties.getInt(AUDIO_SOURCE_PROPERTY, defaultValue);
    }

    private int getAudioFormat() {
        int formatValue =  Settings.System.getInt(
                getContentResolver(), Settings.System.CALL_RECORDING_FORMAT, mDefaultEncoder);
        if (formatValue == 0){
            return MediaRecorder.OutputFormat.AMR_WB;
        } else {
            return MediaRecorder.OutputFormat.MPEG_4;
        }
    }

    private int getAudioEncoder() {
        int formatValue =  Settings.System.getInt(
                getContentResolver(), Settings.System.CALL_RECORDING_FORMAT, mDefaultEncoder);
        if (formatValue == 0){
            return MediaRecorder.AudioEncoder.AMR_WB;
        } else {
            return MediaRecorder.AudioEncoder.HE_AAC;
        }
    }

    private synchronized boolean startRecordingInternal(File file) {
        if (mMediaRecorder != null) {
            if (DBG) {
@@ -113,8 +137,8 @@ public class CallRecorderService extends Service {
            int audioSource = getAudioSource();
            if (DBG) Log.d(TAG, "Creating media recorder with audio source " + audioSource);
            mMediaRecorder.setAudioSource(audioSource);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            mMediaRecorder.setOutputFormat(getAudioFormat());
            mMediaRecorder.setAudioEncoder(getAudioEncoder());
        } catch (IllegalStateException e) {
            Log.w(TAG, "Error initializing media recorder", e);
            return false;
@@ -179,7 +203,12 @@ public class CallRecorderService extends Service {

    private String generateFilename() {
        String timestamp = DATE_FORMAT.format(new Date());
        int audioFormat = getAudioFormat();
        if (audioFormat == MediaRecorder.OutputFormat.AMR_WB){
            return "callrecorder_" + timestamp + ".amr";
        } else {
            return "callrecorder_" + timestamp + ".m4a ";
        }
    }

    public static boolean isEnabled(Context context) {