22 #include "config_components.h"
47 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
49 # define S_ISFIFO(m) 0
56 # define S_ISLNK(m) (((m) & S_IFLNK) == S_IFLNK)
65 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
67 # define S_ISSOCK(m) 0
74 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
83 # 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);
200 #ifdef F_DUPFD_CLOEXEC
201 newfd = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
209 if (fcntl(newfd, F_SETFD, FD_CLOEXEC) == -1)
224 if (
c->initial_pos >= 0 && !
h->is_streamed)
225 lseek(
c->fd,
c->initial_pos, SEEK_SET);
239 ret = fstat(
c->fd, &st);
243 ret = lseek(
c->fd,
pos, whence);
248 #if CONFIG_FILE_PROTOCOL
254 const char *filename =
h->filename;
257 ret = rmdir(filename);
258 if (
ret < 0 && (errno == ENOTDIR
263 ret = unlink(filename);
275 const char *filename_src = h_src->
filename;
276 const char *filename_dst = h_dst->
filename;
280 if (rename(filename_src, filename_dst) < 0)
297 access = O_CREAT | O_RDWR;
301 access = O_CREAT | O_WRONLY;
315 h->is_streamed = !fstat(fd, &st) &&
S_ISFIFO(st.st_mode);
320 h->min_packet_size =
h->max_packet_size = 262144;
322 if (
c->seekable >= 0)
323 h->is_streamed = !
c->seekable;
333 c->dir = opendir(
h->filename);
348 char *fullpath =
NULL;
355 dir = readdir(
c->dir);
360 }
while (!strcmp(dir->d_name,
".") || !strcmp(dir->d_name,
".."));
365 if (!lstat(fullpath, &st)) {
366 if (S_ISDIR(st.st_mode))
370 else if (S_ISCHR(st.st_mode))
383 (*next)->group_id = st.st_gid;
384 (*next)->user_id = st.st_uid;
385 (*next)->size = st.st_size;
386 (*next)->filemode = st.st_mode & 0777;
387 (*next)->modification_timestamp = INT64_C(1000000) * st.st_mtime;
388 (*next)->access_timestamp = INT64_C(1000000) * st.st_atime;
389 (*next)->status_change_timestamp = INT64_C(1000000) * st.st_ctime;
414 .url_open = file_open,
421 .url_delete = file_delete,
422 .url_move = file_move,
425 .url_open_dir = file_open_dir,
426 .url_read_dir = file_read_dir,
427 .url_close_dir = file_close_dir,
428 .default_whitelist =
"file,crypto,data"
433 #if CONFIG_PIPE_PROTOCOL
444 fd = strtol(filename, &
final, 10);
445 if((filename ==
final) || *
final ) {
464 .url_open = pipe_open,
472 .default_whitelist =
"crypto,data"
477 #if CONFIG_FD_PROTOCOL
484 if (strcmp(filename,
"fd:") != 0) {
486 " please set it via -fd {num}\n");
497 if (fstat(
c->fd, &st) < 0)
507 c->initial_pos = lseek(
c->fd, 0, SEEK_CUR);
523 .default_whitelist =
"crypto,data"
528 #if CONFIG_ANDROID_CONTENT_PROTOCOL
533 typedef struct JFields {
537 jclass context_class;
538 jmethodID get_content_resolver_id;
540 jclass content_resolver_class;
541 jmethodID open_file_descriptor_id;
543 jclass parcel_file_descriptor_class;
544 jmethodID detach_fd_id;
547 #define OFFSET(x) offsetof(JFields, x)
548 static const struct FFJniField jfields_mapping[] = {
553 {
"android/content/Context",
"getContentResolver",
"()Landroid/content/ContentResolver;",
FF_JNI_METHOD,
OFFSET(get_content_resolver_id), 1 },
556 {
"android/content/ContentResolver",
"openFileDescriptor",
"(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
FF_JNI_METHOD,
OFFSET(open_file_descriptor_id), 1 },
559 {
"android/os/ParcelFileDescriptor",
"detachFd",
"()I",
FF_JNI_METHOD,
OFFSET(detach_fd_id), 1 },
565 static int android_content_open(
URLContext *
h,
const char *filename,
int flags)
570 const char *mode_str =
"r";
573 JFields jfields = { 0 };
574 jobject application_context =
NULL;
578 jobject content_resolver =
NULL;
579 jobject parcel_file_descriptor =
NULL;
593 if (!application_context) {
616 uri = (*env)->CallStaticObjectMethod(env, jfields.uri_class, jfields.parse_id, url);
621 content_resolver = (*env)->CallObjectMethod(env, application_context, jfields.get_content_resolver_id);
626 parcel_file_descriptor = (*env)->CallObjectMethod(env, content_resolver, jfields.open_file_descriptor_id, uri,
mode);
631 fd = (*env)->CallIntMethod(env, parcel_file_descriptor, jfields.detach_fd_id);
636 if (fstat(fd, &st) < 0) {
645 (*env)->DeleteLocalRef(env, url);
646 (*env)->DeleteLocalRef(env,
mode);
647 (*env)->DeleteLocalRef(env, uri);
648 (*env)->DeleteLocalRef(env, content_resolver);
649 (*env)->DeleteLocalRef(env, parcel_file_descriptor);
655 static const AVOption android_content_options[] = {
660 static const AVClass android_content_class = {
663 .option = android_content_options,
669 .url_open = android_content_open,
677 .priv_data_class = &android_content_class,