BelledonneCommunications / linphone-sdk

Mirror for linphone-sdk (https://gitlab.linphone.org/BC/public/linphone-sdk.git)
GNU Affero General Public License v3.0
104 stars 80 forks source link

Crash when using MJPEG in DirectShow UVC WebCams #92

Closed evgeny-test closed 1 month ago

evgeny-test commented 3 years ago

Modern webcams are able to get FullHD video. They usually encode it into a YUY2 or MJPEG, but the frame rate is very different. For example for Creative Live! Cam Sync 1080p and Logitech HD Pro Webcam C920 and many other: YUY2 1920x1080 5 fps MJPEG 1920x1080 30 fps Of course I would like to use MJPEG, but Linphone chooses YUY2 even if I set the priority setting for a high frame rate or 30 fps. OK, I took Linphone Desktop branch 4.2.4 and edited the file \linphone-desktop\linphone-sdk\mediastreamer2\src\videofilters\msdscap.cc to increase the priority of MJPEG.

int DSCapture::selectBestFormat(SharedComPtr<IAMStreamConfig> streamConfig, int count){
    int index;

    _pixfmt=MS_MJPEG;   //Just moved MJPEG to the beginning
    index=find_best_format(streamConfig, count, &_vsize, _pixfmt);
    if (index!=-1) goto success;
    _pixfmt=MS_YUV420P;
    index=find_best_format(streamConfig, count, &_vsize, _pixfmt);
    if (index!=-1) goto success;
    _pixfmt=MS_YUY2;
    index=find_best_format(streamConfig, count, &_vsize,_pixfmt);
    if (index!=-1) goto success;
    _pixfmt=MS_YUYV;
    index=find_best_format(streamConfig, count, &_vsize, _pixfmt);
    if (index!=-1) goto success;
    _pixfmt=MS_RGB24;
    index=find_best_format(streamConfig, count, &_vsize, _pixfmt);
    if (index!=-1) {
        _pixfmt=MS_RGB24_REV;
        goto success;
    }
    ms_error("This camera does not support any of our pixel formats.");
    return -1;
...

I open the video settings window and click the view button. Linphone selects MJPEG format, displays a black screen for 5 seconds and closes without reporting an error. I have attached an extended log file for the described startup case: linphone1.log

I tried to debug the code myself but was not successful.

I can open a MJPEG video stream from my camera in some other programs and see a good FullHD video. For example, the Camera application from Windows 10.

Additionally, I want to say that I am using Windows 10 Pro 64 bit with last updates. I compile Linphone according to the official instructions and get binaries that are very similar to the original assembly. If I don't change the code, then the video plays, but 5 frames per second in YUY2. I've tried other video resolutions, but MJPEG doesn't work anyway.

Do you have the opportunity to look at MJPEG implementation again or help me fix this bug?

Thank you for any help and feedback!

Ledjlale commented 1 month ago

DirectShow is deprecated. MSFoundation should be used instead.