Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for v4l2loopback #2233

Closed
wants to merge 1 commit into from
Closed

Conversation

martinellimarco
Copy link
Contributor

I've closed the old pull request #2232, I did a mess on that one. I'm referencing it only for the conversation.

This is the updated code rebased on the correct dev branch.

It defaults --lock-video-orientation to 0 when --v4l2sink is used and this solve the problem with rotation.

I've enabled ASAN and solved the use-after-free problem.

@rom1v
Copy link
Collaborator

rom1v commented Apr 11, 2021

In response to #2232 (comment)

Thank you for having rebased it on dev 👍

With ffplay -i /dev/videoN or OBS I have no lag whatsoever.

Yes, it works fine 👍

About your comments, I agree that the frame is decoded twice and I don't really like it either. In fact my first try was to share the video buffer to get the decoded frame. That was working very well when the video was displayed in a window but otherwise there was some logic to change around in screen.c and decoder.c regarding EVENT_NEW_FRAME and I didn't want to change too much outside my file, even considering the fact that this is only limited to linux.

Yes, you did well.

I wanted to add some abstractions for a long time (everything is too hardcoded/intricated currently), so now is a good time to refactor.

Therefore, I worked on a branch to prepare several changes to implement v4l2 properly: traits (compare). It is not merged into dev yet, it needs more tests and reviews (I need more time to re-read all the commits).

Here is a summary of the changes:

  • Remove --render-expired-frames option (see 3ffea72 for details)
  • Remove compat with old FFmpeg decodeing and codec params API (deprecated since 2016)
  • Make video_buffer not consume the input frame (to make possible to send it to several sinks)
  • Add two abstractions (traits):
    • sc_packet_sink: a component which receives packets. It is implemented by the decoder and the recorder, and the stream now push its packets to the registered packet sinks (without depending on the concrete sink types)
    • sc_frame_sink: a component which receives frames. It is implemented by the screen (and in the future by v4l2), and the decoder now pushes its frames to the registered frame sinks (without depending on the concrete sink types)

So now, to avoid decoding a packet twice, the v4l2 component should implement sc_frame_sink and be registered to the decoder (decoder_add_sink()).

                      screen/display
                    /
            decoder
          /         \
         /            [ v4l2 ]
  stream
         \
           recorder

          \--------/  \-------------/
         packet sinks   frame sinks

Would you want to implement v4l2 on that branch, please?

If so, please don't hesitate if you have any question. 😉
If you don't want to (lack of time or other), please say it :)

Regards

@martinellimarco
Copy link
Contributor Author

I'd love to work on this but I will have time only during weekends so don't expect anything too soon.
I've looked at the code and I like how you organized this, it's very neat.

@rom1v
Copy link
Collaborator

rom1v commented Apr 16, 2021

Thank you 😉

so don't expect anything too soon

Could I work on it, then? I would like to rebase your commit on my refactored trait branch.

Of course, your authorship will be preserved (I'll just probably add Co-authored-by: (me)).

@martinellimarco
Copy link
Contributor Author

martinellimarco commented Apr 16, 2021 via email

@TruthAI
Copy link

TruthAI commented Apr 17, 2021

so with this we can have scrcpy work as a webcam the correct way ? that's what I was waiting for, awesome guys !

@rom1v
Copy link
Collaborator

rom1v commented Apr 17, 2021

so with this we can have scrcpy work as a webcam the correct way ?

On Linux, yes.

@TruthAI
Copy link

TruthAI commented Apr 17, 2021

so with this we can have scrcpy work as a webcam the correct way ?

On Linux, yes.

oh man damn :( this won't work on windows ?

@rom1v
Copy link
Collaborator

rom1v commented Apr 17, 2021

No. "v4l" literally means "Video For Linux".

@TruthAI
Copy link

TruthAI commented Apr 17, 2021

No. "v4l" literally means "Video For Linux".

damn, I guess I have to wait till someone tackle this thing on windows then :( since you started it on Linux I'm sure someone will fiddle with a windows alternative ^^

rom1v added a commit that referenced this pull request Apr 19, 2021
It allows to send the video stream to /dev/videoN, so that it can be
captured (like a webcam) by any V4L2-compatible tool.

Refs #2232 <#2232>
Refs #2233 <#2233>

Co-authored-by: Romain Vimont <rom@rom1v.com>
@rom1v rom1v mentioned this pull request Apr 19, 2021
rom1v added a commit that referenced this pull request Apr 20, 2021
It allows to send the video stream to /dev/videoN, so that it can be
captured (like a webcam) by any V4L2-compatible tool.

Refs #2232 <#2232>
Refs #2233 <#2233>

Co-authored-by: Romain Vimont <rom@rom1v.com>
rom1v added a commit that referenced this pull request Apr 25, 2021
It allows to send the video stream to /dev/videoN, so that it can be
captured (like a webcam) by any v4l2-capable tool.

PR #2232 <#2232>
PR #2233 <#2233>
PR #2268 <#2268>

Co-authored-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented Apr 25, 2021

Merged into dev (#2268).

@rom1v rom1v closed this Apr 25, 2021
@sugoides
Copy link

sugoides commented Jul 6, 2021

@martinellimarco Hello will u also be able to implement this for OBS-Virtual-Cam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants