[FFmpeg-devel] [PATCH 1/2] avformat/libsrt: support bidirectional transmission
"zhilizhao(赵志立)"
quinkblack at foxmail.com
Thu Jun 10 07:13:06 EEST 2021
Ping for review, thanks!
> On May 19, 2021, at 12:03 AM, Zhao Zhili <quinkblack at foxmail.com> wrote:
>
> ---
> There is no good use case yet. Patch 2/2 is only used for test.
>
> libavformat/libsrt.c | 35 +++++++++++++++++++++++++++--------
> 1 file changed, 27 insertions(+), 8 deletions(-)
>
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index c1e96f700e..a05921d9f0 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -163,10 +163,17 @@ static int libsrt_socket_nonblock(int socket, int enable)
> return srt_setsockopt(socket, 0, SRTO_RCVSYN, &blocking, sizeof(blocking));
> }
>
> -static int libsrt_epoll_create(URLContext *h, int fd, int write)
> +static int libsrt_epoll_create(URLContext *h, int fd, int flags)
> {
> - int modes = SRT_EPOLL_ERR | (write ? SRT_EPOLL_OUT : SRT_EPOLL_IN);
> - int eid = srt_epoll_create();
> + int modes;
> + int eid;
> +
> + modes = SRT_EPOLL_ERR;
> + if (flags & AVIO_FLAG_WRITE)
> + modes |= SRT_EPOLL_OUT;
> + if (flags & AVIO_FLAG_READ)
> + modes |= SRT_EPOLL_IN;
> + eid = srt_epoll_create();
> if (eid < 0)
> return libsrt_neterrno(h);
> if (srt_epoll_add_usock(eid, fd, &modes) < 0) {
> @@ -178,14 +185,26 @@ static int libsrt_epoll_create(URLContext *h, int fd, int write)
>
> static int libsrt_network_wait_fd(URLContext *h, int eid, int write)
> {
> - int ret, len = 1, errlen = 1;
> + int ret, len = 1, errlen;
> SRTSOCKET ready[1];
> SRTSOCKET error[1];
> + SRTSOCKET *error_ptr;
> + int *errlen_ptr;
> + if ((h->flags & AVIO_FLAG_READ_WRITE) == AVIO_FLAG_READ_WRITE) {
> + // cannot detect error in this case
> + errlen = 0;
> + error_ptr = NULL;
> + errlen_ptr = NULL;
> + } else {
> + errlen = 1;
> + error_ptr = error;
> + errlen_ptr = &errlen;
> + }
>
> if (write) {
> - ret = srt_epoll_wait(eid, error, &errlen, ready, &len, POLLING_TIME, 0, 0, 0, 0);
> + ret = srt_epoll_wait(eid, error_ptr, errlen_ptr, ready, &len, POLLING_TIME, 0, 0, 0, 0);
> } else {
> - ret = srt_epoll_wait(eid, ready, &len, error, &errlen, POLLING_TIME, 0, 0, 0, 0);
> + ret = srt_epoll_wait(eid, ready, &len, error_ptr, errlen_ptr, POLLING_TIME, 0, 0, 0, 0);
> }
> if (ret < 0) {
> if (srt_getlasterror(NULL) == SRT_ETIMEOUT)
> @@ -435,7 +454,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
> if (libsrt_socket_nonblock(fd, 1) < 0)
> av_log(h, AV_LOG_DEBUG, "libsrt_socket_nonblock failed\n");
>
> - ret = write_eid = libsrt_epoll_create(h, fd, 1);
> + ret = write_eid = libsrt_epoll_create(h, fd, AVIO_FLAG_WRITE);
> if (ret < 0)
> goto fail1;
> if (s->mode == SRT_MODE_LISTENER) {
> @@ -479,7 +498,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
> h->max_packet_size = packet_size;
> }
>
> - ret = eid = libsrt_epoll_create(h, fd, flags & AVIO_FLAG_WRITE);
> + ret = eid = libsrt_epoll_create(h, fd, flags);
> if (eid < 0)
> goto fail1;
>
> --
> 2.25.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-devel
mailing list