Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-23 Thread Nicolas George
nablet developer (2017-11-20):
> regarding re-using functions from network.c (like ff_network_wait_fd, 
> ff_accept, etc)
> is suggested approach acceptable? is it okay to define such socket_api 
> structure and pass to
> network.c calls?

I do not think so. These functions are very specific to the quirks of
the BSD socket API, and not very well designed at that. I would say to
only use them if you actually have a file descriptor. Hopefully, the
library should provide better base APIs, like operations with a timeout.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-21 Thread nablet developer


> On 20 Nov 2017, at 13:35, nablet developer  wrote:
> 
> 
>> 
>> Thanks for explaining. I think it is not the best decision.
>> 
>> The reason the socket API resembles TCP is because all the sockets API
>> resemble each other, since they are based on the old BSD socket API. And
>> the protocol handlers of libavformat too.
>> 
>> Therefore, I think all the trampoline code to allow TCP to call back
>> another protocol plus all the boilerplate code that you need to make
>> opensrc callable from TCP amounts to worse than implementing a protocol
>> directly.
>> 
>> Furthermore, TCP is the most important network protocol for now, while
>> opensrt is still rather obscure, so tying one with the other is not a
>> good idea.
>> 
>> Also, implementing a real protocol from scratch would possibly allow you
>> to make use of extra features of the opensrt API: maybe they have a
>> read-with-timeout function, for example, or something like that.
>> 
>> 
> 
> thanks for the feedback.
> regarding relying on TCP protocol code it's clear - I will implement protocol 
> from scratch next time.
> regarding re-using functions from network.c (like ff_network_wait_fd, 
> ff_accept, etc)
> is suggested approach acceptable? is it okay to define such socket_api 
> structure and pass to
> network.c calls?
> 

ping

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-19 Thread nablet developer

> 
> Thanks for explaining. I think it is not the best decision.
> 
> The reason the socket API resembles TCP is because all the sockets API
> resemble each other, since they are based on the old BSD socket API. And
> the protocol handlers of libavformat too.
> 
> Therefore, I think all the trampoline code to allow TCP to call back
> another protocol plus all the boilerplate code that you need to make
> opensrc callable from TCP amounts to worse than implementing a protocol
> directly.
> 
> Furthermore, TCP is the most important network protocol for now, while
> opensrt is still rather obscure, so tying one with the other is not a
> good idea.
> 
> Also, implementing a real protocol from scratch would possibly allow you
> to make use of extra features of the opensrt API: maybe they have a
> read-with-timeout function, for example, or something like that.
> 
> 

thanks for the feedback.
regarding relying on TCP protocol code it's clear - I will implement protocol 
from scratch next time.
regarding re-using functions from network.c (like ff_network_wait_fd, 
ff_accept, etc)
is suggested approach acceptable? is it okay to define such socket_api 
structure and pass to
network.c calls?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-16 Thread Nicolas George
Le decadi 20 brumaire, an CCXXVI, nablet developer a écrit :
> the idea is to avoid code duplication as much as possible, and try to re-use
> existing, well-maintained and well-tested code.
> this time I've chosen tcp.c rather udp.c for two reasons:
> 1. SRT socket API actually resembles tcp, as it uses connection and related
> methods (connect/listen/accept)
> 2. tcp.c code is much more clean and straightforward rather udp.c
> the first thing which obviously differs between tcp and srt are socket api
> calls, but there is direct mapping for most of them, e.g.:
> socket -> srt_socket
> connect -> srt_connect
> listen -> srt_listen
> very few of srt socket calls are different, e.g. srt doesn't provide
> send/recv, but provides sendmsg/recvmsg, also it doesn't provide poll, but
> has epoll_wait.
> with simple wrappers, it allows to use existing logic of tcp.c and network.c
> without modifications.
> for calling back srt from tcp, that's the second difference - srt has lots
> of additional socket options,
> and some of these socket options has to be set prior to connection, others
> after connection (called pre and post options in srt).
> Haivision explicitly requested to add these options into ffmpeg component.
> so, there are two calls back in tcp_open - to set options just before
> connection, and to set options right after connections.
> if you have some advice on how it can be implemented better, I am open for
> suggestions and advises.

Thanks for explaining. I think it is not the best decision.

The reason the socket API resembles TCP is because all the sockets API
resemble each other, since they are based on the old BSD socket API. And
the protocol handlers of libavformat too.

Therefore, I think all the trampoline code to allow TCP to call back
another protocol plus all the boilerplate code that you need to make
opensrc callable from TCP amounts to worse than implementing a protocol
directly.

Furthermore, TCP is the most important network protocol for now, while
opensrt is still rather obscure, so tying one with the other is not a
good idea.

Also, implementing a real protocol from scratch would possibly allow you
to make use of extra features of the opensrt API: maybe they have a
read-with-timeout function, for example, or something like that.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread nablet developer


On 10-Nov-17 03:35, Nicolas George wrote:

Can you explain the logic of the implementation? I have a hard time
understanding why you call the tcp protocol from here after forcing it
to call back here.

Regards,


the idea is to avoid code duplication as much as possible, and try to 
re-use existing, well-maintained and well-tested code.

this time I've chosen tcp.c rather udp.c for two reasons:
1. SRT socket API actually resembles tcp, as it uses connection and 
related methods (connect/listen/accept)

2. tcp.c code is much more clean and straightforward rather udp.c
the first thing which obviously differs between tcp and srt are socket 
api calls, but there is direct mapping for most of them, e.g.:

socket -> srt_socket
connect -> srt_connect
listen -> srt_listen
very few of srt socket calls are different, e.g. srt doesn't provide 
send/recv, but provides sendmsg/recvmsg, also it doesn't provide poll, 
but has epoll_wait.
with simple wrappers, it allows to use existing logic of tcp.c and 
network.c without modifications.
for calling back srt from tcp, that's the second difference - srt has 
lots of additional socket options,
and some of these socket options has to be set prior to connection, 
others after connection (called pre and post options in srt).

Haivision explicitly requested to add these options into ffmpeg component.
so, there are two calls back in tcp_open - to set options just before 
connection, and to set options right after connections.
if you have some advice on how it can be implemented better, I am open 
for suggestions and advises.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread Nicolas George
Le nonidi 19 brumaire, an CCXXVI, Nablet Developer a écrit :
> protocol requires libsrt (https://github.com/Haivision/srt) to be
> installed
> 
> Signed-off-by: Nablet Developer 
> ---
>  configure   |  10 ++
>  libavformat/Makefile|   1 +
>  libavformat/opensrt.c   | 418 
> 
>  libavformat/protocols.c |   1 +
>  4 files changed, 430 insertions(+)
>  create mode 100644 libavformat/opensrt.c

Can you explain the logic of the implementation? I have a hard time
understanding why you call the tcp protocol from here after forcing it
to call back here.

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread Kv Pham
Le 9 nov. 2017 10:32 AM, "Nablet Developer"  a écrit :

protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer 
---
 configure   |  10 ++
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 418 ++
++
 libavformat/protocols.c |   1 +
 4 files changed, 430 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/configure b/configure
index f396abd..b44df0e 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protoco [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used
[autodetect]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_LIST="
 openal
 opencl
 opengl
+opensrt
 "

 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3139,6 +3141,8 @@ libsmbclient_protocol_deps="libsmbclient gplv3"
 libssh_protocol_deps="libssh"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -6102,6 +6106,8 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found";
} && enable omx
+#enabled opensrt   && check_lib srt srt/srt.h srt_socket -lsrt
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0"
srt/srt.h srt_socket
 enabled openssl   && { use_pkg_config openssl openssl
openssl/ssl.h OPENSSL_init_ssl ||
use_pkg_config openssl openssl
openssl/ssl.h SSL_library_init ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl -lcrypto ||
@@ -6156,6 +6162,10 @@ if enabled decklink; then
 esac
 fi

+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h
Security/Security.h" "SSLCreateContext SecItemImport"
"-Wl,-framework,CoreFoundation -Wl,-framework,Security" ||
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 146a465..5116d31 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -596,6 +596,7 @@ TLS-OBJS-$(CONFIG_SCHANNEL)  +=
tls_schannel.o
 OBJS-$(CONFIG_TLS_PROTOCOL)  += tls.o $(TLS-OBJS-yes)
 OBJS-$(CONFIG_UDP_PROTOCOL)  += udp.o
 OBJS-$(CONFIG_UDPLITE_PROTOCOL)  += udp.o
+OBJS-$(CONFIG_OPENSRT_PROTOCOL)  += opensrt.o
 OBJS-$(CONFIG_UNIX_PROTOCOL) += unix.o

 # libavdevice dependencies
diff --git a/libavformat/opensrt.c b/libavformat/opensrt.c
new file mode 100644
index 000..bc58368
--- /dev/null
+++ b/libavformat/opensrt.c
@@ -0,0 +1,418 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
+ */
+
+/**
+ * @file
+ * Haivision Open SRT (Secure Reliable Transport) protocol
+ */
+
+#include "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/time.h"
+
+#include "internal.h"
+#include "network.h"
+#include "os_support.h"
+#include "url.h"
+#if HAVE_POLL_H
+#include 
+#endif
+
+#include "tcp.h"
+
+#if CONFIG_OPENSRT_PROTOCOL
+#include 
+#endif
+
+enum SRTMode {
+SRT_MODE_CALLER = 0,
+SRT_MODE_LISTENER = 1,
+SRT_MODE_RENDEZVOUS = 2
+};
+
+typedef struct SRTContext {
+struct TCPContext tcp_context;
+/* SRT socket options (srt/srt.h) */
+int64_t maxbw;
+int pbkeylen;
+char * 

[FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer 
---
 configure   |  10 ++
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 418 
 libavformat/protocols.c |   1 +
 4 files changed, 430 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/configure b/configure
index f396abd..b44df0e 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protoco [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_LIST="
 openal
 opencl
 opengl
+opensrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3139,6 +3141,8 @@ libsmbclient_protocol_deps="libsmbclient gplv3"
 libssh_protocol_deps="libssh"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -6102,6 +6106,8 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags 
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found"; } && 
enable omx
+#enabled opensrt   && check_lib srt srt/srt.h srt_socket -lsrt
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0" 
srt/srt.h srt_socket
 enabled openssl   && { use_pkg_config openssl openssl openssl/ssl.h 
OPENSSL_init_ssl ||
use_pkg_config openssl openssl openssl/ssl.h 
SSL_library_init ||
check_lib openssl openssl/ssl.h 
SSL_library_init -lssl -lcrypto ||
@@ -6156,6 +6162,10 @@ if enabled decklink; then
 esac
 fi
 
+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h Security/Security.h" 
"SSLCreateContext SecItemImport" "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" ||
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 146a465..5116d31 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -596,6 +596,7 @@ TLS-OBJS-$(CONFIG_SCHANNEL)  += tls_schannel.o
 OBJS-$(CONFIG_TLS_PROTOCOL)  += tls.o $(TLS-OBJS-yes)
 OBJS-$(CONFIG_UDP_PROTOCOL)  += udp.o
 OBJS-$(CONFIG_UDPLITE_PROTOCOL)  += udp.o
+OBJS-$(CONFIG_OPENSRT_PROTOCOL)  += opensrt.o
 OBJS-$(CONFIG_UNIX_PROTOCOL) += unix.o
 
 # libavdevice dependencies
diff --git a/libavformat/opensrt.c b/libavformat/opensrt.c
new file mode 100644
index 000..bc58368
--- /dev/null
+++ b/libavformat/opensrt.c
@@ -0,0 +1,418 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Haivision Open SRT (Secure Reliable Transport) protocol
+ */
+
+#include "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/time.h"
+
+#include "internal.h"
+#include "network.h"
+#include "os_support.h"
+#include "url.h"
+#if HAVE_POLL_H
+#include 
+#endif
+
+#include "tcp.h"
+
+#if CONFIG_OPENSRT_PROTOCOL
+#include 
+#endif
+
+enum SRTMode {
+SRT_MODE_CALLER = 0,
+SRT_MODE_LISTENER = 1,
+SRT_MODE_RENDEZVOUS = 2
+};
+
+typedef struct SRTContext {
+struct TCPContext tcp_context;
+/* SRT socket options (srt/srt.h) */
+int64_t maxbw;
+int pbkeylen;
+char * passphrase;
+int mss;
+int fc;
+int ipttl;
+int