Merge commit '605387582bd35920b83a26dabbe1c0601f425621'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Aug 2013 13:32:12 +0000 (15:32 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Aug 2013 13:33:12 +0000 (15:33 +0200)
* commit '605387582bd35920b83a26dabbe1c0601f425621':
  lavf: Support unix sockets

Conflicts:
configure

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
configure
doc/protocols.texi
libavformat/Makefile
libavformat/allformats.c
libavformat/unix.c

diff --cc configure
+++ b/configure
@@@ -1535,9 -1354,8 +1535,10 @@@ HAVE_LIST=
      sys_select_h
      sys_soundcard_h
      sys_time_h
+     sys_un_h
      sys_videoio_h
 +    termios_h
 +    texi2html
      threads
      unistd_h
      usleep
@@@ -2128,66 -1875,25 +2129,68 @@@ tcp_protocol_select="network
  tls_protocol_deps_any="openssl gnutls"
  tls_protocol_select="tcp_protocol"
  udp_protocol_select="network"
+ unix_protocol_deps="sys_un_h"
+ unix_protocol_select="network"
  
  # filters
 +aconvert_filter_deps="swresample"
 +amovie_filter_deps="avcodec avformat"
 +aresample_filter_deps="swresample"
 +ass_filter_deps="libass"
 +asyncts_filter_deps="avresample"
 +atempo_filter_deps="avcodec rdft"
 +azmq_filter_deps="libzmq"
  blackframe_filter_deps="gpl"
  boxblur_filter_deps="gpl"
 +colormatrix_filter_deps="gpl"
  cropdetect_filter_deps="gpl"
 +dctdnoiz_filter_deps="avcodec fft"
  delogo_filter_deps="gpl"
 +deshake_filter_deps="avcodec"
 +deshake_filter_select="dsputil"
  drawtext_filter_deps="libfreetype"
 -frei0r_filter_deps="frei0r dlopen strtok_r"
 +ebur128_filter_deps="gpl"
 +flite_filter_deps="libflite"
 +frei0r_filter_deps="frei0r dlopen"
  frei0r_filter_extralibs='$ldl'
 -frei0r_src_filter_deps="frei0r dlopen strtok_r"
 +frei0r_src_filter_deps="frei0r dlopen"
  frei0r_src_filter_extralibs='$ldl'
 +geq_filter_deps="gpl"
 +histeq_filter_deps="gpl"
  hqdn3d_filter_deps="gpl"
 +hue_filter_deps="gpl"
  interlace_filter_deps="gpl"
 +kerndeint_filter_deps="gpl"
 +mcdeint_filter_deps="avcodec gpl"
 +movie_filter_deps="avcodec avformat"
 +mp_filter_deps="gpl avcodec swscale inline_asm"
 +mpdecimate_filter_deps="gpl avcodec"
 +mptestsrc_filter_deps="gpl"
 +negate_filter_deps="lut_filter"
 +noise_filter_deps="gpl"
 +perspective_filter_deps="gpl"
  resample_filter_deps="avresample"
  ocv_filter_deps="libopencv"
 +owdenoise_filter_deps="gpl"
 +pan_filter_deps="swresample"
 +pp_filter_deps="gpl postproc"
 +removelogo_filter_deps="avcodec avformat swscale"
 +sab_filter_deps="gpl swscale"
  scale_filter_deps="swscale"
 +smartblur_filter_deps="gpl swscale"
 +showspectrum_filter_deps="avcodec rdft"
 +spp_filter_deps="gpl avcodec fft"
 +stereo3d_filter_deps="gpl"
 +subtitles_filter_deps="avformat avcodec libass"
 +super2xsai_filter_deps="gpl"
 +tinterlace_filter_deps="gpl"
 +vidstabdetect_filter_deps="libvidstab"
 +vidstabtransform_filter_deps="libvidstab"
  yadif_filter_deps="gpl"
 +pixfmts_super2xsai_test_deps="super2xsai_filter"
 +tinterlace_merge_test_deps="tinterlace_filter"
 +tinterlace_pad_test_deps="tinterlace_filter"
 +zmq_filter_deps="libzmq"
  
  # libraries
  avcodec_deps="avutil"
@@@ -4064,7 -3660,7 +4067,8 @@@ check_header sys/param.
  check_header sys/resource.h
  check_header sys/select.h
  check_header sys/time.h
+ check_header sys/un.h
 +check_header termios.h
  check_header unistd.h
  check_header vdpau/vdpau.h
  check_header vdpau/vdpau_x11.h
@@@ -934,7 -623,27 +934,27 @@@ ffmpeg -i @var{input} -f mpegts udp://@
  
  To receive over UDP from a remote endpoint:
  @example
 -avconv -i udp://[@var{multicast-address}]:@var{port}
 +ffmpeg -i udp://[@var{multicast-address}]:@var{port}
  @end example
  
+ @section unix
+ Unix local socket
+ The required syntax for a Unix socket URL is:
+ @example
+ unix://@var{filepath}
+ @end example
+ The following parameters can be set via command line options
+ (or in code via @code{AVOption}s):
+ @table @option
+ @item timeout
+ Timeout in ms.
+ @item listen
+ Create the Unix socket in listening mode.
+ @end table
  @c man end PROTOCOLS
Simple merge
@@@ -335,12 -281,9 +335,13 @@@ void av_register_all(void
      REGISTER_PROTOCOL(TCP,              tcp);
      REGISTER_PROTOCOL(TLS,              tls);
      REGISTER_PROTOCOL(UDP,              udp);
+     REGISTER_PROTOCOL(UNIX,             unix);
  
      /* external libraries */
 +    REGISTER_DEMUXER (LIBGME,           libgme);
 +    REGISTER_DEMUXER (LIBMODPLUG,       libmodplug);
 +    REGISTER_MUXDEMUX(LIBNUT,           libnut);
 +    REGISTER_DEMUXER (LIBQUVI,          libquvi);
      REGISTER_PROTOCOL(LIBRTMP,          librtmp);
      REGISTER_PROTOCOL(LIBRTMPE,         librtmpe);
      REGISTER_PROTOCOL(LIBRTMPS,         librtmps);
index 0000000,167efab..dd481a1
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,156 +1,156 @@@
 - * This file is part of Libav.
+ /*
+  * Unix socket protocol
+  * Copyright (c) 2013 Luca Barbato
+  *
 - * Libav is free software; you can redistribute it and/or
++ * This file is part of FFmpeg.
+  *
 - * Libav is distributed in the hope that it will be useful,
++ * 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.
+  *
 - * License along with Libav; if not, write to the Free Software
++ * 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
+  *
+  * Unix socket url_protocol
+  *
+  */
+ #include <sys/un.h>
+ #include "libavutil/avstring.h"
+ #include "libavutil/opt.h"
+ #include "os_support.h"
+ #include "network.h"
+ #include "url.h"
+ typedef struct UnixContext {
+     const AVClass *class;
+     struct sockaddr_un addr;
+     int timeout;
+     int listen;
+     int type;
+     int fd;
+ } UnixContext;
+ #define OFFSET(x) offsetof(UnixContext, x)
+ #define ED AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_ENCODING_PARAM
+ static const AVOption unix_options[] = {
+     { "listen",    "Open socket for listening",             OFFSET(listen),  AV_OPT_TYPE_INT,   { .i64 = 0 },                    0,       1, ED },
+     { "timeout",   "Timeout in ms",                         OFFSET(timeout), AV_OPT_TYPE_INT,   { .i64 = -1 },                  -1, INT_MAX, ED },
+     { "type",      "Socket type",                           OFFSET(type),    AV_OPT_TYPE_INT,   { .i64 = SOCK_STREAM },    INT_MIN, INT_MAX, ED, "type" },
+     { "stream",    "Stream (reliable stream-oriented)",     0,               AV_OPT_TYPE_CONST, { .i64 = SOCK_STREAM },    INT_MIN, INT_MAX, ED, "type" },
+     { "datagram",  "Datagram (unreliable packet-oriented)", 0,               AV_OPT_TYPE_CONST, { .i64 = SOCK_DGRAM },     INT_MIN, INT_MAX, ED, "type" },
+     { "seqpacket", "Seqpacket (reliable packet-oriented",   0,               AV_OPT_TYPE_CONST, { .i64 = SOCK_SEQPACKET }, INT_MIN, INT_MAX, ED, "type" },
+     { NULL }
+ };
+ static const AVClass unix_class = {
+     .class_name = "unix",
+     .item_name  = av_default_item_name,
+     .option     = unix_options,
+     .version    = LIBAVUTIL_VERSION_INT,
+ };
+ static int unix_open(URLContext *h, const char *filename, int flags)
+ {
+     UnixContext *s = h->priv_data;
+     int fd, ret;
+     av_strstart(filename, "unix:", &filename);
+     s->addr.sun_family = AF_UNIX;
+     av_strlcpy(s->addr.sun_path, filename, sizeof(s->addr.sun_path));
+     if ((fd = socket(AF_UNIX, s->type, 0)) < 0)
+         return ff_neterrno();
+     if (s->listen) {
+         fd = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
+                             sizeof(s->addr), s->timeout, h);
+         if (fd < 0) {
+             ret = fd;
+             goto fail;
+         }
+     } else {
+         ret = ff_listen_connect(fd, (struct sockaddr *)&s->addr,
+                                 sizeof(s->addr), s->timeout, h);
+         if (ret < 0)
+             goto fail;
+     }
+     s->fd = fd;
+     return 0;
+ fail:
+     if (s->listen && ret != EADDRINUSE)
+         unlink(s->addr.sun_path);
+     if (fd >= 0)
+         closesocket(fd);
+     return ret;
+ }
+ static int unix_read(URLContext *h, uint8_t *buf, int size)
+ {
+     UnixContext *s = h->priv_data;
+     int ret;
+     if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
+         ret = ff_network_wait_fd(s->fd, 0);
+         if (ret < 0)
+             return ret;
+     }
+     ret = recv(s->fd, buf, size, 0);
+     return ret < 0 ? ff_neterrno() : ret;
+ }
+ static int unix_write(URLContext *h, const uint8_t *buf, int size)
+ {
+     UnixContext *s = h->priv_data;
+     int ret;
+     if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
+         ret = ff_network_wait_fd(s->fd, 1);
+         if (ret < 0)
+             return ret;
+     }
+     ret = send(s->fd, buf, size, 0);
+     return ret < 0 ? ff_neterrno() : ret;
+ }
+ static int unix_close(URLContext *h)
+ {
+     UnixContext *s = h->priv_data;
+     if (s->listen)
+         unlink(s->addr.sun_path);
+     closesocket(s->fd);
+     return 0;
+ }
+ static int unix_get_file_handle(URLContext *h)
+ {
+     UnixContext *s = h->priv_data;
+     return s->fd;
+ }
+ URLProtocol ff_unix_protocol = {
+     .name                = "unix",
+     .url_open            = unix_open,
+     .url_read            = unix_read,
+     .url_write           = unix_write,
+     .url_close           = unix_close,
+     .url_get_file_handle = unix_get_file_handle,
+     .priv_data_size      = sizeof(UnixContext),
+     .priv_data_class     = &unix_class,
+     .flags               = URL_PROTOCOL_FLAG_NETWORK,
+ };