0

Thanks in advance for the help!

I am trying to record calls using the Linphone SDK in Swift on Mac OS, and am having trouble passing a path into the function:

func linphone_call_params_set_record_file(_ cp: OpaquePointer!, _ path: UnsafePointer<Int8>!)

that works correctly (the SDK is written in C, though I am accessing it using Swift and a bridging header). The Linphone SDK works properly, and I can make and receive calls programmatically, with full audio support.

In trying to invoke the call recorder, I pass this function a path (pathtofile), such as:

let pathtofile = "/Users/Alex/Safety/1.wav"

where I would like to store the recording file.

func SafetyNetAVRecorderInitializer(pathtofile: String) -> Bool {
    // Convert pathtofile to UnsafePointer<Int8>.
    let cpathtofile = (pathtofile as NSString).utf8String
    let path = UnsafeMutablePointer<Int8>(mutating: cpathtofile)

    // Actually begin call recording.
    if currentcall != nil {
        let currentcallparameters = linphone_call_get_current_params(currentcall)
        linphone_call_params_set_record_file (currentcallparameters, path)
        linphone_call_start_recording(currentcall)
        return true
    }
    return false
}

No runtime errors are encountered on linphone_call_params_set_record_file(), but when I try to invoke linphone_call_start_recording(), the recording does not begin, and an error is printed in the console that reads:

ortp-error-linphone_call_start_recording(): no output file specified. Use linphone_call_params_set_record_file().

How can I correctly pass a valid path to linphone_call_params_set_record_file()? I have tried directly passing a plain Swift String instead of an UnsafePointer<Int8> to no avail. Am I just misunderstanding how paths are formatted in C?

For reference, the SDK method source is:

void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){
if (cp->record_file){
    ms_free(cp->record_file);
    cp->record_file=NULL;
}
if (path) cp->record_file=ms_strdup(path);
}

Thanks again!

kmypwn
  • 437
  • 1
  • 6
  • 17

1 Answers1

0

Try this:

let cpathtofile = (pathtofile as NSString).utf8String! // Unwraps!
...
inphone_call_params_set_record_file(currentcallparameters, cpathtofile)
Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
  • That did not work, unfortunately-- thank you for your help, though! – kmypwn Apr 11 '17 at 21:15
  • @kmypwn You should be really able to [directly pass](http://stackoverflow.com/a/41308592/819340) `pathtofile: String` as well. Maybe your bug is elsewhere... :-( – Paulo Mattos Apr 11 '17 at 21:18
  • I suspect that it is... hopefully someone with more intimate knowledge of the Linphone SDK can provide some insight. – kmypwn Apr 11 '17 at 21:38
  • For what it's worth, here is the SDK function linphone_call_params_set_record_file(): `void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){ if (cp->record_file){ ms_free(cp->record_file); cp->record_file=NULL; } if (path) cp->record_file=ms_strdup(path); }` – kmypwn Apr 11 '17 at 21:39
  • @PauloMattos, Thanks this worked for me. But I am facing issue in playing records file. currently it is recorded in .mkv file. Can you suggest an alternate way? – Megha Pawar Nov 15 '19 at 10:27