Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -227,6 +227,7 @@ External library support: |
227 | 227 |
--enable-librtmp enable RTMP[E] support via librtmp [no] |
228 | 228 |
--enable-libschroedinger enable Dirac de/encoding via libschroedinger [no] |
229 | 229 |
--enable-libshine enable fixed-point MP3 encoding via libshine [no] |
230 |
+ --enable-libsmbclient enable Samba protocol via libsmbclient [no] |
|
230 | 231 |
--enable-libsoxr enable Include libsoxr resampling [no] |
231 | 232 |
--enable-libspeex enable Speex de/encoding via libspeex [no] |
232 | 233 |
--enable-libssh enable SFTP protocol via libssh [no] |
... | ... |
@@ -1349,6 +1350,7 @@ EXTERNAL_LIBRARY_LIST=" |
1349 | 1349 |
librtmp |
1350 | 1350 |
libschroedinger |
1351 | 1351 |
libshine |
1352 |
+ libsmbclient |
|
1352 | 1353 |
libsoxr |
1353 | 1354 |
libspeex |
1354 | 1355 |
libssh |
... | ... |
@@ -2472,6 +2474,7 @@ librtmpe_protocol_deps="librtmp" |
2472 | 2472 |
librtmps_protocol_deps="librtmp" |
2473 | 2473 |
librtmpt_protocol_deps="librtmp" |
2474 | 2474 |
librtmpte_protocol_deps="librtmp" |
2475 |
+libsmbclient_protocol_deps="libsmbclient gplv3" |
|
2475 | 2476 |
libssh_protocol_deps="libssh" |
2476 | 2477 |
mmsh_protocol_select="http_protocol" |
2477 | 2478 |
mmst_protocol_select="network" |
... | ... |
@@ -4240,6 +4243,7 @@ die_license_disabled_gpl() { |
4240 | 4240 |
|
4241 | 4241 |
die_license_disabled gpl frei0r |
4242 | 4242 |
die_license_disabled gpl libcdio |
4243 |
+die_license_disabled gpl libsmbclient |
|
4243 | 4244 |
die_license_disabled gpl libutvideo |
4244 | 4245 |
die_license_disabled gpl libvidstab |
4245 | 4246 |
die_license_disabled gpl libx264 |
... | ... |
@@ -4256,6 +4260,7 @@ enabled gpl && die_license_disabled_gpl nonfree openssl |
4256 | 4256 |
|
4257 | 4257 |
die_license_disabled version3 libopencore_amrnb |
4258 | 4258 |
die_license_disabled version3 libopencore_amrwb |
4259 |
+die_license_disabled version3 libsmbclient |
|
4259 | 4260 |
die_license_disabled version3 libvo_aacenc |
4260 | 4261 |
die_license_disabled version3 libvo_amrwbenc |
4261 | 4262 |
|
... | ... |
@@ -4744,6 +4749,9 @@ enabled libquvi && require_pkg_config libquvi quvi/quvi.h quvi_init |
4744 | 4744 |
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket |
4745 | 4745 |
enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init |
4746 | 4746 |
enabled libshine && require_pkg_config shine shine/layer3.h shine_encode_buffer |
4747 |
+enabled libsmbclient && { { check_pkg_config smbclient libsmbclient.h smbc_init && |
|
4748 |
+ require_pkg_config smbclient libsmbclient.h smbc_init; } || |
|
4749 |
+ require smbclient libsmbclient.h smbc_init -lsmbclient; } |
|
4747 | 4750 |
enabled libsoxr && require libsoxr soxr.h soxr_create -lsoxr |
4748 | 4751 |
enabled libssh && require_pkg_config libssh libssh/sftp.h sftp_init |
4749 | 4752 |
enabled libspeex && require libspeex speex/speex.h speex_decoder_init -lspeex |
... | ... |
@@ -537,6 +537,35 @@ The Real-Time Messaging Protocol tunneled through HTTPS (RTMPTS) is used |
537 | 537 |
for streaming multimedia content within HTTPS requests to traverse |
538 | 538 |
firewalls. |
539 | 539 |
|
540 |
+@section libsmbclient |
|
541 |
+ |
|
542 |
+libsmbclient permits to manipulate CIFS/SMB network resources. |
|
543 |
+ |
|
544 |
+Following syntax is required. |
|
545 |
+ |
|
546 |
+@example |
|
547 |
+smb://[[domain:]user[:password@@]]server[/share[/path[/file]]] |
|
548 |
+@end example |
|
549 |
+ |
|
550 |
+This protocol accepts the following options. |
|
551 |
+ |
|
552 |
+@table @option |
|
553 |
+@item timeout |
|
554 |
+Set timeout in miliseconds of socket I/O operations used by the underlying |
|
555 |
+low level operation. By default it is set to -1, which means that the timeout |
|
556 |
+is not specified. |
|
557 |
+ |
|
558 |
+@item truncate |
|
559 |
+Truncate existing files on write, if set to 1. A value of 0 prevents |
|
560 |
+truncating. Default value is 1. |
|
561 |
+ |
|
562 |
+@item workgroup |
|
563 |
+Set the workgroup used for making connections. By default workgroup is not specified. |
|
564 |
+ |
|
565 |
+@end table |
|
566 |
+ |
|
567 |
+For more information see: @url{http://www.samba.org/}. |
|
568 |
+ |
|
540 | 569 |
@section libssh |
541 | 570 |
|
542 | 571 |
Secure File Transfer Protocol via libssh |
... | ... |
@@ -459,6 +459,7 @@ OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o |
459 | 459 |
OBJS-$(CONFIG_LIBQUVI_DEMUXER) += libquvi.o |
460 | 460 |
OBJS-$(CONFIG_LIBRTMP) += librtmp.o |
461 | 461 |
OBJS-$(CONFIG_LIBSSH_PROTOCOL) += libssh.o |
462 |
+OBJS-$(CONFIG_LIBSMBCLIENT_PROTOCOL) += libsmbclient.o |
|
462 | 463 |
|
463 | 464 |
# protocols I/O |
464 | 465 |
OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += hlsproto.o |
380 | 381 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,207 @@ |
0 |
+/* |
|
1 |
+ * Copyright (c) 2014 Lukasz Marek <lukasz.m.luki@gmail.com> |
|
2 |
+ * |
|
3 |
+ * This file is part of FFmpeg. |
|
4 |
+ * |
|
5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
7 |
+ * License as published by the Free Software Foundation; either |
|
8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
9 |
+ * |
|
10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
+ * Lesser General Public License for more details. |
|
14 |
+ * |
|
15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#include <libsmbclient.h> |
|
21 |
+#include "libavutil/avstring.h" |
|
22 |
+#include "libavutil/opt.h" |
|
23 |
+#include "avformat.h" |
|
24 |
+#include "internal.h" |
|
25 |
+#include "url.h" |
|
26 |
+ |
|
27 |
+typedef struct { |
|
28 |
+ const AVClass *class; |
|
29 |
+ SMBCCTX *ctx; |
|
30 |
+ int fd; |
|
31 |
+ int64_t filesize; |
|
32 |
+ int trunc; |
|
33 |
+ int timeout; |
|
34 |
+ char *workgroup; |
|
35 |
+} LIBSMBContext; |
|
36 |
+ |
|
37 |
+static void libsmbc_get_auth_data(SMBCCTX *c, const char *server, const char *share, |
|
38 |
+ char *workgroup, int workgroup_len, |
|
39 |
+ char *username, int username_len, |
|
40 |
+ char *password, int password_len) |
|
41 |
+{ |
|
42 |
+ /* Do nothing yet. Credentials are passed via url. |
|
43 |
+ * Callback must exists, there might be a segmentation fault otherwise. */ |
|
44 |
+} |
|
45 |
+ |
|
46 |
+static av_cold int libsmbc_connect(URLContext *h) |
|
47 |
+{ |
|
48 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
49 |
+ |
|
50 |
+ libsmbc->ctx = smbc_new_context(); |
|
51 |
+ if (!libsmbc->ctx) { |
|
52 |
+ av_log(h, AV_LOG_ERROR, "Cannot create context: %s.\n", strerror(errno)); |
|
53 |
+ return AVERROR(errno); |
|
54 |
+ } |
|
55 |
+ if (!smbc_init_context(libsmbc->ctx)) { |
|
56 |
+ av_log(h, AV_LOG_ERROR, "Cannot initialize context: %s.\n", strerror(errno)); |
|
57 |
+ return AVERROR(errno); |
|
58 |
+ } |
|
59 |
+ smbc_set_context(libsmbc->ctx); |
|
60 |
+ |
|
61 |
+ smbc_setOptionUserData(libsmbc->ctx, h); |
|
62 |
+ smbc_setFunctionAuthDataWithContext(libsmbc->ctx, libsmbc_get_auth_data); |
|
63 |
+ |
|
64 |
+ if (libsmbc->timeout != -1) |
|
65 |
+ smbc_setTimeout(libsmbc->ctx, libsmbc->timeout); |
|
66 |
+ if (libsmbc->workgroup) |
|
67 |
+ smbc_setWorkgroup(libsmbc->ctx, libsmbc->workgroup); |
|
68 |
+ |
|
69 |
+ if (smbc_init(NULL, 0) < 0) { |
|
70 |
+ av_log(h, AV_LOG_ERROR, "Initialization failed: %s\n", strerror(errno)); |
|
71 |
+ return AVERROR(errno); |
|
72 |
+ } |
|
73 |
+ return 0; |
|
74 |
+} |
|
75 |
+ |
|
76 |
+static av_cold int libsmbc_close(URLContext *h) |
|
77 |
+{ |
|
78 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
79 |
+ if (libsmbc->fd >= 0) { |
|
80 |
+ smbc_close(libsmbc->fd); |
|
81 |
+ libsmbc->fd = -1; |
|
82 |
+ } |
|
83 |
+ if (libsmbc->ctx) { |
|
84 |
+ smbc_free_context(libsmbc->ctx, 1); |
|
85 |
+ libsmbc->ctx = NULL; |
|
86 |
+ } |
|
87 |
+ return 0; |
|
88 |
+} |
|
89 |
+ |
|
90 |
+static av_cold int libsmbc_open(URLContext *h, const char *url, int flags) |
|
91 |
+{ |
|
92 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
93 |
+ int access, ret; |
|
94 |
+ struct stat st; |
|
95 |
+ |
|
96 |
+ libsmbc->fd = -1; |
|
97 |
+ libsmbc->filesize = -1; |
|
98 |
+ |
|
99 |
+ if ((ret = libsmbc_connect(h)) < 0) |
|
100 |
+ goto fail; |
|
101 |
+ |
|
102 |
+ if ((flags & AVIO_FLAG_WRITE) && (flags & AVIO_FLAG_READ)) { |
|
103 |
+ access = O_CREAT | O_RDWR; |
|
104 |
+ if (libsmbc->trunc) |
|
105 |
+ access |= O_TRUNC; |
|
106 |
+ } else if (flags & AVIO_FLAG_WRITE) { |
|
107 |
+ access = O_CREAT | O_WRONLY; |
|
108 |
+ if (libsmbc->trunc) |
|
109 |
+ access |= O_TRUNC; |
|
110 |
+ } else |
|
111 |
+ access = O_RDONLY; |
|
112 |
+ |
|
113 |
+ /* 0666 = -rw-rw-rw- = read+write for everyone, minus umask */ |
|
114 |
+ if ((libsmbc->fd = smbc_open(url, access, 0666)) < 0) { |
|
115 |
+ ret = AVERROR(errno); |
|
116 |
+ av_log(h, AV_LOG_ERROR, "File open failed: %s\n", strerror(errno)); |
|
117 |
+ goto fail; |
|
118 |
+ } |
|
119 |
+ |
|
120 |
+ if (smbc_fstat(libsmbc->fd, &st) < 0) |
|
121 |
+ av_log(h, AV_LOG_WARNING, "Cannot stat file: %s\n", strerror(errno)); |
|
122 |
+ else |
|
123 |
+ libsmbc->filesize = st.st_size; |
|
124 |
+ |
|
125 |
+ return 0; |
|
126 |
+ fail: |
|
127 |
+ libsmbc_close(h); |
|
128 |
+ return ret; |
|
129 |
+} |
|
130 |
+ |
|
131 |
+static int64_t libsmbc_seek(URLContext *h, int64_t pos, int whence) |
|
132 |
+{ |
|
133 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
134 |
+ int64_t newpos; |
|
135 |
+ |
|
136 |
+ if (whence == AVSEEK_SIZE) { |
|
137 |
+ if (libsmbc->filesize == -1) { |
|
138 |
+ av_log(h, AV_LOG_ERROR, "Error during seeking: filesize is unknown.\n"); |
|
139 |
+ return AVERROR(EIO); |
|
140 |
+ } else |
|
141 |
+ return libsmbc->filesize; |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ if ((newpos = smbc_lseek(libsmbc->fd, pos, whence)) < 0) { |
|
145 |
+ int err = errno; |
|
146 |
+ av_log(h, AV_LOG_ERROR, "Error during seeking: %s\n", strerror(err)); |
|
147 |
+ return AVERROR(err); |
|
148 |
+ } |
|
149 |
+ |
|
150 |
+ return newpos; |
|
151 |
+} |
|
152 |
+ |
|
153 |
+static int libsmbc_read(URLContext *h, unsigned char *buf, int size) |
|
154 |
+{ |
|
155 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
156 |
+ int bytes_read; |
|
157 |
+ |
|
158 |
+ if ((bytes_read = smbc_read(libsmbc->fd, buf, size)) < 0) { |
|
159 |
+ av_log(h, AV_LOG_ERROR, "Read error: %s\n", strerror(errno)); |
|
160 |
+ return AVERROR(errno); |
|
161 |
+ } |
|
162 |
+ |
|
163 |
+ return bytes_read; |
|
164 |
+} |
|
165 |
+ |
|
166 |
+static int libsmbc_write(URLContext *h, const unsigned char *buf, int size) |
|
167 |
+{ |
|
168 |
+ LIBSMBContext *libsmbc = h->priv_data; |
|
169 |
+ int bytes_written; |
|
170 |
+ |
|
171 |
+ if ((bytes_written = smbc_write(libsmbc->fd, buf, size)) < 0) { |
|
172 |
+ av_log(h, AV_LOG_ERROR, "Write error: %s\n", strerror(errno)); |
|
173 |
+ return AVERROR(errno); |
|
174 |
+ } |
|
175 |
+ |
|
176 |
+ return bytes_written; |
|
177 |
+} |
|
178 |
+ |
|
179 |
+#define OFFSET(x) offsetof(LIBSMBContext, x) |
|
180 |
+#define D AV_OPT_FLAG_DECODING_PARAM |
|
181 |
+#define E AV_OPT_FLAG_ENCODING_PARAM |
|
182 |
+static const AVOption options[] = { |
|
183 |
+ {"timeout", "set timeout in ms of socket I/O operations", OFFSET(timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E }, |
|
184 |
+ {"truncate", "truncate existing files on write", OFFSET(trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, E }, |
|
185 |
+ {"workgroup", "set the workgroup used for making connections", OFFSET(workgroup), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, |
|
186 |
+ {NULL} |
|
187 |
+}; |
|
188 |
+ |
|
189 |
+static const AVClass libsmbclient_context_class = { |
|
190 |
+ .class_name = "libsmbc", |
|
191 |
+ .item_name = av_default_item_name, |
|
192 |
+ .option = options, |
|
193 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
194 |
+}; |
|
195 |
+ |
|
196 |
+URLProtocol ff_libsmbclient_protocol = { |
|
197 |
+ .name = "smb", |
|
198 |
+ .url_open = libsmbc_open, |
|
199 |
+ .url_read = libsmbc_read, |
|
200 |
+ .url_write = libsmbc_write, |
|
201 |
+ .url_seek = libsmbc_seek, |
|
202 |
+ .url_close = libsmbc_close, |
|
203 |
+ .priv_data_size = sizeof(LIBSMBContext), |
|
204 |
+ .priv_data_class = &libsmbclient_context_class, |
|
205 |
+ .flags = URL_PROTOCOL_FLAG_NETWORK, |
|
206 |
+}; |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/version.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVFORMAT_VERSION_MAJOR 55 |
33 |
-#define LIBAVFORMAT_VERSION_MINOR 45 |
|
33 |
+#define LIBAVFORMAT_VERSION_MINOR 46 |
|
34 | 34 |
#define LIBAVFORMAT_VERSION_MICRO 100 |
35 | 35 |
|
36 | 36 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |