1 /*
2 * Unix socket protocol
3 * Copyright (c) 2013 Luca Barbato
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 *
25 * Unix socket url_protocol
26 */
27
32 #include <sys/un.h>
34
43
44 #define OFFSET(x) offsetof(UnixContext, x)
45 #define ED AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_ENCODING_PARAM
50 {
"stream",
"Stream (reliable stream-oriented)", 0,
AV_OPT_TYPE_CONST, { .i64 = SOCK_STREAM }, INT_MIN, INT_MAX,
ED, .unit =
"type" },
51 {
"datagram",
"Datagram (unreliable packet-oriented)", 0,
AV_OPT_TYPE_CONST, { .i64 = SOCK_DGRAM }, INT_MIN, INT_MAX,
ED, .unit =
"type" },
52 {
"seqpacket",
"Seqpacket (reliable packet-oriented", 0,
AV_OPT_TYPE_CONST, { .i64 = SOCK_SEQPACKET }, INT_MIN, INT_MAX,
ED, .unit =
"type" },
54 };
55
61 };
62
64 {
67
69 s->addr.sun_family = AF_UNIX;
70 av_strlcpy(
s->addr.sun_path, filename,
sizeof(
s->addr.sun_path));
71
74
75 if (
s->timeout < 0 &&
h->rw_timeout)
76 s->timeout =
h->rw_timeout / 1000;
77
80 sizeof(
s->addr),
s->timeout,
h);
84 } else {
86 sizeof(
s->addr),
s->timeout,
h, 0);
89 }
90
92
93 return 0;
94
97 unlink(
s->addr.sun_path);
98 if (fd >= 0)
99 closesocket(fd);
101 }
102
104 {
107
112 }
114 if (!
ret &&
s->type == SOCK_STREAM)
117 }
118
120 {
123
128 }
131 }
132
134 {
137 unlink(
s->addr.sun_path);
139 return 0;
140 }
141
143 {
146 }
147
158 };