22 #include "config_components.h"
48 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
50 # define S_ISFIFO(m) 0
57 # define S_ISLNK(m) (((m) & S_IFLNK) == S_IFLNK)
66 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
68 # define S_ISSOCK(m) 0
75 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
84 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
145 if (
ret == 0 &&
c->follow)
170 const char *filename =
h->filename;
174 #if HAVE_ACCESS && defined(R_OK)
175 if (access(filename, F_OK) < 0)
178 if (access(filename, R_OK) >= 0)
181 if (access(filename, W_OK) >= 0)
185 ret = stat(filename, &st);
196 #if CONFIG_FD_PROTOCOL || CONFIG_PIPE_PROTOCOL
201 #ifdef F_DUPFD_CLOEXEC
202 newfd = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
210 if (fcntl(newfd, F_SETFD, FD_CLOEXEC) == -1)
224 int ret = close(
c->fd);
236 ret = fstat(
c->fd, &st);
240 ret = lseek(
c->fd,
pos, whence);
245 #if CONFIG_FILE_PROTOCOL
251 const char *filename =
h->filename;
254 ret = rmdir(filename);
255 if (
ret < 0 && (errno == ENOTDIR
260 ret = unlink(filename);
272 const char *filename_src = h_src->
filename;
273 const char *filename_dst = h_dst->
filename;
277 if (rename(filename_src, filename_dst) < 0)
293 access = O_CREAT | O_RDWR;
297 access = O_CREAT | O_WRONLY;
311 h->is_streamed = !fstat(fd, &st) &&
S_ISFIFO(st.st_mode);
316 h->min_packet_size =
h->max_packet_size = 262144;
318 if (
c->seekable >= 0)
319 h->is_streamed = !
c->seekable;
329 c->dir = opendir(
h->filename);
344 char *fullpath =
NULL;
351 dir = readdir(
c->dir);
356 }
while (!strcmp(dir->d_name,
".") || !strcmp(dir->d_name,
".."));
361 if (!lstat(fullpath, &st)) {
362 if (S_ISDIR(st.st_mode))
366 else if (S_ISCHR(st.st_mode))
379 (*next)->group_id = st.st_gid;
380 (*next)->user_id = st.st_uid;
381 (*next)->size = st.st_size;
382 (*next)->filemode = st.st_mode & 0777;
383 (*next)->modification_timestamp = INT64_C(1000000) * st.st_mtime;
384 (*next)->access_timestamp = INT64_C(1000000) * st.st_atime;
385 (*next)->status_change_timestamp = INT64_C(1000000) * st.st_ctime;
410 .url_open = file_open,
417 .url_delete = file_delete,
418 .url_move = file_move,
421 .url_open_dir = file_open_dir,
422 .url_read_dir = file_read_dir,
423 .url_close_dir = file_close_dir,
424 .default_whitelist =
"file,crypto,data"
429 #if CONFIG_PIPE_PROTOCOL
447 fd = strtol(filename, &
final, 10);
454 c->fd = fd_dup(
h,
c->fd);
463 .url_open = pipe_open,
471 .default_whitelist =
"crypto,data"
476 #if CONFIG_FD_PROTOCOL
483 if (strcmp(filename,
"fd:") != 0) {
485 " please set it via -fd {num}\n");
496 if (fstat(
c->fd, &st) < 0)
499 c->fd = fd_dup(
h,
c->fd);
517 .default_whitelist =
"crypto,data"
522 #if CONFIG_ANDROID_CONTENT_PROTOCOL
527 typedef struct JFields {
531 jclass context_class;
532 jmethodID get_content_resolver_id;
534 jclass content_resolver_class;
535 jmethodID open_file_descriptor_id;
537 jclass parcel_file_descriptor_class;
538 jmethodID detach_fd_id;
541 #define OFFSET(x) offsetof(JFields, x)
542 static const struct FFJniField jfields_mapping[] = {
547 {
"android/content/Context",
"getContentResolver",
"()Landroid/content/ContentResolver;",
FF_JNI_METHOD,
OFFSET(get_content_resolver_id), 1 },
550 {
"android/content/ContentResolver",
"openFileDescriptor",
"(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
FF_JNI_METHOD,
OFFSET(open_file_descriptor_id), 1 },
553 {
"android/os/ParcelFileDescriptor",
"detachFd",
"()I",
FF_JNI_METHOD,
OFFSET(detach_fd_id), 1 },
559 static int android_content_open(
URLContext *
h,
const char *filename,
int flags)
564 const char *mode_str =
"r";
567 JFields jfields = { 0 };
568 jobject application_context =
NULL;
572 jobject content_resolver =
NULL;
573 jobject parcel_file_descriptor =
NULL;
587 if (!application_context) {
610 uri = (*env)->CallStaticObjectMethod(env, jfields.uri_class, jfields.parse_id, url);
615 content_resolver = (*env)->CallObjectMethod(env, application_context, jfields.get_content_resolver_id);
620 parcel_file_descriptor = (*env)->CallObjectMethod(env, content_resolver, jfields.open_file_descriptor_id, uri,
mode);
625 fd = (*env)->CallIntMethod(env, parcel_file_descriptor, jfields.detach_fd_id);
630 if (fstat(fd, &st) < 0) {
639 (*env)->DeleteLocalRef(env, url);
640 (*env)->DeleteLocalRef(env,
mode);
641 (*env)->DeleteLocalRef(env, uri);
642 (*env)->DeleteLocalRef(env, content_resolver);
643 (*env)->DeleteLocalRef(env, parcel_file_descriptor);
649 static const AVOption android_content_options[] = {
654 static const AVClass android_content_class = {
657 .option = android_content_options,
663 .url_open = android_content_open,
671 .priv_data_class = &android_content_class,