Fixing video recording issues in Linphone v4.1.1 for Windows

0.00 avg. rating (0% score) - 0 votes

In one of my projects, I noticed an interesting issue with Linphone v4.1.1 for Windows, a popular open-source cross-platform VoIP application. If I attempted to record a video call, when the call ended, the program would apparently inform me that the recording had completed and show me a link to the recorded file at the bottom right corner of the screen. However, after clicking on the link, it redirected me to the Documents\Linphone folder, which was empty! Changing the recording folder also did not help and the problem still persisted. So what was the issue?

Without having the time to look into the source code, I performed some forensics analysis with Sysinternals Process Monitor. Filtering out the filesystem activity from process linphone.exe and I saw Linphone’s attempt to create the MKV recording file:

linphone_name_invalid

The attempt however failed with a NAME_INVALID error (displayed towards the right of the dialog and unfortunately not shown in the above screenshot). Why? Although this puzzled me at first, the reason became apparent when I looked closely at the recording filename generated by Linphone:

2017-10-13_16:42:03.mkv

The program had attempted to generate the recording filename in the format ‘yyyy-mm-dd_hh:mm:ss.mkv’, which included a colon ‘:’ that is not allowed by most Windows-friendly file-systems (FAT, FAT32, NTFS). The reason for the prohibition is simply because colon is part of the drive letter naming convention (A: or C:) in Windows (and its predecessor MS-DOS). The developers of Linphone, who perhaps wrote the code on Linux that does not have such a restriction, probably overlooked this part and did not test it on Windows, thus causing the bug.

By searching the code using grep, I quickly identified the lines responsible for this issue:

Method setRecordFile() in CallModel.cpp:

void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &callParams) {
 callParams->setRecordFile(
 ::Utils::appStringToCoreString(
 QStringLiteral("%1%2.mkv")
 .arg(CoreManager::getInstance()->getSettingsModel()->getSavedVideosFolder())
 .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_loc:ss"))
 )
 );
}

Method startRecording() in ConferenceModel.cpp:

void ConferenceModel::startRecording () {
  if (mRecording)
    return;

  qInfo() << QStringLiteral("Start recording conference:") << this;

  CoreManager *coreManager = CoreManager::getInstance();
  coreManager->getCore()->startConferenceRecording(
    ::Utils::appStringToCoreString(
      QStringLiteral("%1%2.mkv")
      .arg(coreManager->getSettingsModel()->getSavedVideosFolder())
      .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh:mm:ss"))
    )
  );
  mRecording = true;

  emit recordingChanged(true);
}

So how should I solve the issue? I obviously did not want to fix the format strings and recompiling the code (and the setup package) which would involve installing Qt (that consumes lots of disk space) and wasting hours getting the correct build configuration. I therefore decided to use a hex editor such as HxD to open linphone.exe to patch the format strings.

This turned out to be an easy task as the format string could be located around position 0x6F210:

linphone mkv patch

I simply changed it to yyyy-mm-dd_hh_mm_ss:

linphone mkv patch 2

I saved the file, relaunched Linphone and that was it, video recording now worked properly, generating an MKV file! There was no need to go through the hassle of recompiling the code, just patching a few bytes. I was lucky that the linphone.exe file was not packed or compressed; otherwise I would have to unpack it before attempting any patches. Also interestingly, the filename format strings appear in at least two different locations (CallModel.cpp and ConferenceModel.cpp) in the code but only in a single location in the linphone.exe file. This may be due to code optimizations or something else which I have missed. Nevertheless, I am happy as long as video recording works fine.

The patched version of the linphone.exe file for Linphone v4.1.1 can be downloaded here.

0.00 avg. rating (0% score) - 0 votes
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>