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

UDP problem with live streaming #133

Closed
coder1995 opened this issue Aug 2, 2016 · 13 comments
Closed

UDP problem with live streaming #133

coder1995 opened this issue Aug 2, 2016 · 13 comments
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request

Comments

@coder1995
Copy link

I have a stream source (created with ffmpeg) which plays fine in VLC. The problem is that if I already have a client connected to that stream shaka-packager cannot connect to it. For example I open the stream with VLC and then run shaka-packager I will receive this error:

[0802/112146:INFO:demuxer.cc(60)] Initialize Demuxer for file 'udp://224.0.0.1:2014'.
[0802/112146:ERROR:udp_file_posix.cc(193)] Could not bind UDP socket
[0802/112146:ERROR:packager_main.cc(301)] Demuxer failed to initialize: 5 (FILE_FAILURE): Cannot open file for reading udp://224.0.0.1:2014

If I close VLC and nothing is connected to the stream then shaka-packager will work. This conflict is related only to shaka-packager as I am able to open multiple VLC instances or other players or even ffmpeg. On the other hand if I manage to open the stream with shaka-packager then I cannot open it with VLC or anything else in parallel.

Is there a way to open the stream with shaka-packager just as a client? Maybe some flags that I missed?

Thanks.

@kqyang
Copy link
Contributor

kqyang commented Aug 3, 2016

Interesting. We'll investigate how to obtain shared access instead of exclusive access to the socket.

@peyoh
Copy link

peyoh commented Aug 7, 2016

setsockopt so_reuseaddr and let ksoftirqd to do it's job

@coder1995
Copy link
Author

Forgive my ignorance but is there a parameter I can add to the udp link (something like udp://224.0.0.1:2014/?so_reuseaddr) to instruct shaka-packager to obtain shared access?

Thanks.

@peyoh
Copy link

peyoh commented Aug 8, 2016

Unfortunately not. It must be set with setsockopt() on the udp socket in the shaka source and recompile. I have never tested it here btw, because this usage isn't good for production use because highter ksoftirqd load.
I think @kqyang can help.

@sammirata
Copy link
Contributor

so_reuseaddr is used by any and all other UDP listening applications in our PRODUCTION environment and we see no performance impact. The point of multicast udp input is to be able to open it from multiple applications at the same time. Without this flag, you cannot. Here is the patch that we use on our version of the packager for anyone that is brave enough to compile their own:

commit 8c9c6ca84ce20426f3fe262babf3fb57cf5ea748
Author: Sergio Ammirata sergio@ammirata.net
Date: Sat Mar 26 11:24:05 2016 -0400

do not require exclusive bind of udp sockets

diff --git a/packager/media/file/udp_file_posix.cc b/packager/media/file/udp_file_posix.cc
index 6df6fbf..625531f 100644
--- a/packager/media/file/udp_file_posix.cc
+++ b/packager/media/file/udp_file_posix.cc
@@ -187,6 +187,9 @@ bool UdpFile::Open() {
local_sock_addr.sin_family = AF_INET;
local_sock_addr.sin_port = htons(dest_port);
local_sock_addr.sin_addr.s_addr = htonl(dest_addr);

  • // We do not need to require exclusive bind of udp sockets
  • int optval = 1;
  • setsockopt(new_socket.get(), SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
    if (bind(new_socket.get(),
    reinterpret_cast<struct sockaddr*>(&local_sock_addr),
    sizeof(local_sock_addr))) {

@sammirata
Copy link
Contributor

Here is the patch as an attachment:
udp.patch.zip

@kqyang
Copy link
Contributor

kqyang commented Aug 18, 2016

@sammirata Cool. Thanks for working on this. Would you like to contribute this patch to shaka packager? You can send a pull request!

It will be good to make it configurable though, e.g. enabled only if having "reuse" in udp url, something like "udp://224.0.0.1:2014?reuse=1" (Feel free to work on it if you want; If not, I can work on it after your change is merged)

Thanks!

@kqyang kqyang added the type: enhancement New feature or request label Aug 18, 2016
@sammirata
Copy link
Contributor

Yes, I would like to contribute a patch. I have never done it before using github pull requests. I did not see the config parser inside the udp module. Where is it defined?

@kqyang
Copy link
Contributor

kqyang commented Aug 25, 2016

Cool. Thanks!

Right now the port address is assumed to contain only ip address and port number, which is parsed in https://cs.corp.google.com/github/google/shaka-packager/packager/media/file/udp_file_posix.cc?rcl=52cbcb321df0cb2c831516f20b05edbc7dcd6828&l=57

To support configurable options, we can extract the strings after "?" and split the strings using base::SplitStringIntoKeyValuePairs: https://cs.chromium.org/chromium/src/base/strings/string_split.h?rcl=0&l=86

@kqyang
Copy link
Contributor

kqyang commented Sep 15, 2016

@sammirata are you still working on it? You may just submit a pull request for your original patch first. I'll make it configurable later.

@sammirata
Copy link
Contributor

I just submitted a pull request for the original patch

@hariszukanovic
Copy link

Hi,
What is the current status of this patch?

@kqyang
Copy link
Contributor

kqyang commented Oct 31, 2016

The patch is already merged, with socket reuse enabled by default. I'll submit another patch shortly - in the new patch, socket reuse is configurable with reuse flag in the url string, something like: udp://224.1.2.30:88?reuse=1 (reuse is set to 0 by default)

@kqyang kqyang closed this as completed in 458fadc Oct 31, 2016
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 19, 2018
@shaka-project shaka-project locked and limited conversation to collaborators Apr 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants