openframeworks / openframeworks/openFrameworks

bug: Gstreamer pipeline is not closed when starting it was unsuccessful

Open
#5,189 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Hi,

i am working on an open frameworks app (0.9.3) in Ubuntu which is supposed to display a presentation of different pictures and videos. After running my open frameworks app for a few hours it crashed with a "to many open files error" I started investigating and found out there are tons of unix sockets opened and never closed again.

How to reproduce:
Create a of app which tries to playback video using gstreamer. Then tell it to load a video that does not exist (or where the app has no reading rights). Everey time the app tries to load the video, a new unix socket will be created but never closed. Check using lsof -r 1 -p xxxx | grep socket where xxxx is your apps PID.

I looked into the code of ofGstVideoPlayer.cpp and think the error is in the load function:
(starting at line 205)

if(isInitialized()){
        gst_element_set_state (videoUtils.getPipeline(), GST_STATE_READY);
        if(!bIsStream){
            gst_element_get_state (videoUtils.getPipeline(), NULL, NULL, -1);
        }
        internalPixelFormat = OF_PIXELS_NATIVE;
        bIsAllocated = false;
        videoUtils.reallocateOnNextFrame();
        g_object_set(G_OBJECT(videoUtils.getPipeline()), "uri", name.c_str(), (void*)NULL);
        gst_element_set_state (videoUtils.getPipeline(), GST_STATE_PAUSED);
        if(!bIsStream){
            gst_element_get_state (videoUtils.getPipeline(), NULL, NULL, -1);
            return allocate();
        }else{
            return true;
        }
    }else{
        ofGstUtils::startGstMainLoop();
        return createPipeline(name) &&
                videoUtils.startPipeline() &&
                (bIsStream || allocate());
    }

in the "else"-part, a new piepeline is created, but if startPipeline() fails, bLoaded will remain false, so the created pipeline is never released.

I'm working on a fix, but it is kinda difficult because the pipeline itself belongs to the ofGstVideoUtils class and calling close wont do the trick (since loaded is false). Also, what else needs to be done at this point to properly clean up everything thats already loaded?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ofGstVideoPlayer.cpp at load(), then trace createPipeline(), ofGstVideoUtils::startPipeline(), and the existing close path. Reproduce repeated attempts to load an inaccessible video and verify that failed starts release the created pipeline and do not leave Unix sockets open.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux, ubuntu
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.