FFmpeg
file.c
Go to the documentation of this file.
1 /*
2  * buffered file I/O
3  * Copyright (c) 2001 Fabrice Bellard
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 #include "config_components.h"
23 
24 #include "libavutil/avstring.h"
25 #include "libavutil/file_open.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/opt.h"
29 #include "avio.h"
30 #if HAVE_DIRENT_H
31 #include <dirent.h>
32 #endif
33 #include <fcntl.h>
34 #if HAVE_IO_H
35 #include <io.h>
36 #endif
37 #if HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
40 #include <sys/stat.h>
41 #include <stdlib.h>
42 #include "os_support.h"
43 #include "url.h"
44 
45 /* Some systems may not have S_ISFIFO */
46 #ifndef S_ISFIFO
47 # ifdef S_IFIFO
48 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
49 # else
50 # define S_ISFIFO(m) 0
51 # endif
52 #endif
53 
54 /* Not available in POSIX.1-1996 */
55 #ifndef S_ISLNK
56 # ifdef S_IFLNK
57 # define S_ISLNK(m) (((m) & S_IFLNK) == S_IFLNK)
58 # else
59 # define S_ISLNK(m) 0
60 # endif
61 #endif
62 
63 /* Not available in POSIX.1-1996 */
64 #ifndef S_ISSOCK
65 # ifdef S_IFSOCK
66 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
67 # else
68 # define S_ISSOCK(m) 0
69 # endif
70 #endif
71 
72 /* S_ISREG not available on Windows */
73 #ifndef S_ISREG
74 # ifdef S_IFREG
75 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
76 # else
77 # define S_ISREG(m) 0
78 # endif
79 #endif
80 
81 /* S_ISBLK not available on Windows */
82 #ifndef S_ISBLK
83 # ifdef S_IFBLK
84 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
85 # else
86 # define S_ISBLK(m) 0
87 # endif
88 #endif
89 
90 /* standard file protocol */
91 
92 typedef struct FileContext {
93  const AVClass *class;
94  int fd;
95  int trunc;
96  int blocksize;
97  int pkt_size;
98  int follow;
99  int seekable;
100 #if HAVE_DIRENT_H
101  DIR *dir;
102 #endif
103 } FileContext;
104 
105 static const AVOption file_options[] = {
106  { "truncate", "truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
107  { "blocksize", "set I/O operation maximum block size", offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
108  { "follow", "Follow a file as it is being written", offsetof(FileContext, follow), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
109  { "seekable", "Sets if the file is seekable", offsetof(FileContext, seekable), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
110  { "pkt_size", "Maximum packet size", offsetof(FileContext, pkt_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
111  { NULL }
112 };
113 
114 static const AVOption pipe_options[] = {
115  { "blocksize", "set I/O operation maximum block size", offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
116  { "fd", "set file descriptor", offsetof(FileContext, fd), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
117  { NULL }
118 };
119 
120 static const AVClass file_class = {
121  .class_name = "file",
122  .item_name = av_default_item_name,
123  .option = file_options,
124  .version = LIBAVUTIL_VERSION_INT,
125 };
126 
127 static const AVClass pipe_class = {
128  .class_name = "pipe",
129  .item_name = av_default_item_name,
130  .option = pipe_options,
131  .version = LIBAVUTIL_VERSION_INT,
132 };
133 
134 static const AVClass fd_class = {
135  .class_name = "fd",
136  .item_name = av_default_item_name,
137  .option = pipe_options,
138  .version = LIBAVUTIL_VERSION_INT,
139 };
140 
141 static int file_read(URLContext *h, unsigned char *buf, int size)
142 {
143  FileContext *c = h->priv_data;
144  int ret;
145  size = FFMIN(size, c->blocksize);
146  ret = read(c->fd, buf, size);
147  if (ret == 0 && c->follow)
148  return AVERROR(EAGAIN);
149  if (ret == 0)
150  return AVERROR_EOF;
151  return (ret == -1) ? AVERROR(errno) : ret;
152 }
153 
154 static int file_write(URLContext *h, const unsigned char *buf, int size)
155 {
156  FileContext *c = h->priv_data;
157  int ret;
158  size = FFMIN(size, c->blocksize);
159  ret = write(c->fd, buf, size);
160  return (ret == -1) ? AVERROR(errno) : ret;
161 }
162 
164 {
165  FileContext *c = h->priv_data;
166  return c->fd;
167 }
168 
169 static int file_check(URLContext *h, int mask)
170 {
171  int ret = 0;
172  const char *filename = h->filename;
173  av_strstart(filename, "file:", &filename);
174 
175  {
176 #if HAVE_ACCESS && defined(R_OK)
177  if (access(filename, F_OK) < 0)
178  return AVERROR(errno);
179  if (mask&AVIO_FLAG_READ)
180  if (access(filename, R_OK) >= 0)
181  ret |= AVIO_FLAG_READ;
182  if (mask&AVIO_FLAG_WRITE)
183  if (access(filename, W_OK) >= 0)
184  ret |= AVIO_FLAG_WRITE;
185 #else
186  struct stat st;
187  ret = stat(filename, &st);
188  if (ret < 0)
189  return AVERROR(errno);
190 
191  ret |= st.st_mode&S_IRUSR ? mask&AVIO_FLAG_READ : 0;
192  ret |= st.st_mode&S_IWUSR ? mask&AVIO_FLAG_WRITE : 0;
193 #endif
194  }
195  return ret;
196 }
197 
198 #if CONFIG_FD_PROTOCOL || CONFIG_PIPE_PROTOCOL
199 static int fd_dup(URLContext *h, int oldfd)
200 {
201  int newfd;
202 
203 #ifdef F_DUPFD_CLOEXEC
204  newfd = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
205 #else
206  newfd = dup(oldfd);
207 #endif
208  if (newfd == -1)
209  return newfd;
210 
211 #if HAVE_FCNTL
212  if (fcntl(newfd, F_SETFD, FD_CLOEXEC) == -1)
213  av_log(h, AV_LOG_DEBUG, "Failed to set close on exec\n");
214 #endif
215 
216 #if HAVE_SETMODE
217  setmode(newfd, O_BINARY);
218 #endif
219  return newfd;
220 }
221 #endif
222 
223 static int file_close(URLContext *h)
224 {
225  FileContext *c = h->priv_data;
226  int ret = close(c->fd);
227  return (ret == -1) ? AVERROR(errno) : 0;
228 }
229 
230 /* XXX: use llseek */
231 static int64_t file_seek(URLContext *h, int64_t pos, int whence)
232 {
233  FileContext *c = h->priv_data;
234  int64_t ret;
235 
236  if (c->follow && (whence == SEEK_END || whence == AVSEEK_SIZE))
237  return AVERROR(ENOSYS); /* true size is not known */
238 
239  if (whence == AVSEEK_SIZE) {
240  struct stat st;
241  ret = fstat(c->fd, &st);
242  return ret < 0 ? AVERROR(errno) : (S_ISFIFO(st.st_mode) ? 0 : st.st_size);
243  }
244 
245  ret = lseek(c->fd, pos, whence);
246 
247  return ret < 0 ? AVERROR(errno) : ret;
248 }
249 
250 #if CONFIG_FILE_PROTOCOL
251 
252 static int file_delete(URLContext *h)
253 {
254 #if HAVE_UNISTD_H
255  int ret;
256  const char *filename = h->filename;
257  av_strstart(filename, "file:", &filename);
258 
259  ret = rmdir(filename);
260  if (ret < 0 && (errno == ENOTDIR
261 # ifdef _WIN32
262  || errno == EINVAL
263 # endif
264  ))
265  ret = unlink(filename);
266  if (ret < 0)
267  return AVERROR(errno);
268 
269  return ret;
270 #else
271  return AVERROR(ENOSYS);
272 #endif /* HAVE_UNISTD_H */
273 }
274 
275 static int file_move(URLContext *h_src, URLContext *h_dst)
276 {
277  const char *filename_src = h_src->filename;
278  const char *filename_dst = h_dst->filename;
279  av_strstart(filename_src, "file:", &filename_src);
280  av_strstart(filename_dst, "file:", &filename_dst);
281 
282  if (rename(filename_src, filename_dst) < 0)
283  return AVERROR(errno);
284 
285  return 0;
286 }
287 
288 static int file_open(URLContext *h, const char *filename, int flags)
289 {
290  FileContext *c = h->priv_data;
291  int access;
292  int fd;
293  struct stat st;
294 
295  av_strstart(filename, "file:", &filename);
296 
298  access = O_CREAT | O_RDWR;
299  if (c->trunc)
300  access |= O_TRUNC;
301  } else if (flags & AVIO_FLAG_WRITE) {
302  access = O_CREAT | O_WRONLY;
303  if (c->trunc)
304  access |= O_TRUNC;
305  } else {
306  access = O_RDONLY;
307  }
308 #ifdef O_BINARY
309  access |= O_BINARY;
310 #endif
311  fd = avpriv_open(filename, access, 0666);
312  if (fd == -1)
313  return AVERROR(errno);
314  c->fd = fd;
315 
316  h->is_streamed = !fstat(fd, &st) && S_ISFIFO(st.st_mode);
317 
318  if (c->pkt_size) {
319  h->max_packet_size = c->pkt_size;
320  } else {
321  /* Buffer writes more than the default 32k to improve throughput especially
322  * with networked file systems */
323  if (!h->is_streamed && flags & AVIO_FLAG_WRITE)
324  h->max_packet_size = 262144;
325  }
326  /* Disable per-packet flushing by default to improve throughput especially
327  * with networked file systems */
328  if (!h->is_streamed && flags & AVIO_FLAG_WRITE)
329  h->min_packet_size = h->max_packet_size;
330 
331  if (c->seekable >= 0)
332  h->is_streamed = !c->seekable;
333 
334  return 0;
335 }
336 
337 static int file_open_dir(URLContext *h)
338 {
339 #if HAVE_LSTAT
340  FileContext *c = h->priv_data;
341 
342  c->dir = opendir(h->filename);
343  if (!c->dir)
344  return AVERROR(errno);
345 
346  return 0;
347 #else
348  return AVERROR(ENOSYS);
349 #endif /* HAVE_LSTAT */
350 }
351 
352 static int file_read_dir(URLContext *h, AVIODirEntry **next)
353 {
354 #if HAVE_LSTAT
355  FileContext *c = h->priv_data;
356  struct dirent *dir;
357  char *fullpath = NULL;
358 
359  *next = ff_alloc_dir_entry();
360  if (!*next)
361  return AVERROR(ENOMEM);
362  do {
363  errno = 0;
364  dir = readdir(c->dir);
365  if (!dir) {
366  av_freep(next);
367  return AVERROR(errno);
368  }
369  } while (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."));
370 
371  fullpath = av_append_path_component(h->filename, dir->d_name);
372  if (fullpath) {
373  struct stat st;
374  if (!lstat(fullpath, &st)) {
375  if (S_ISDIR(st.st_mode))
376  (*next)->type = AVIO_ENTRY_DIRECTORY;
377  else if (S_ISFIFO(st.st_mode))
378  (*next)->type = AVIO_ENTRY_NAMED_PIPE;
379  else if (S_ISCHR(st.st_mode))
380  (*next)->type = AVIO_ENTRY_CHARACTER_DEVICE;
381  else if (S_ISBLK(st.st_mode))
382  (*next)->type = AVIO_ENTRY_BLOCK_DEVICE;
383  else if (S_ISLNK(st.st_mode))
384  (*next)->type = AVIO_ENTRY_SYMBOLIC_LINK;
385  else if (S_ISSOCK(st.st_mode))
386  (*next)->type = AVIO_ENTRY_SOCKET;
387  else if (S_ISREG(st.st_mode))
388  (*next)->type = AVIO_ENTRY_FILE;
389  else
390  (*next)->type = AVIO_ENTRY_UNKNOWN;
391 
392  (*next)->group_id = st.st_gid;
393  (*next)->user_id = st.st_uid;
394  (*next)->size = st.st_size;
395  (*next)->filemode = st.st_mode & 0777;
396  (*next)->modification_timestamp = INT64_C(1000000) * st.st_mtime;
397  (*next)->access_timestamp = INT64_C(1000000) * st.st_atime;
398  (*next)->status_change_timestamp = INT64_C(1000000) * st.st_ctime;
399  }
400  av_free(fullpath);
401  }
402 
403  (*next)->name = av_strdup(dir->d_name);
404  return 0;
405 #else
406  return AVERROR(ENOSYS);
407 #endif /* HAVE_LSTAT */
408 }
409 
410 static int file_close_dir(URLContext *h)
411 {
412 #if HAVE_LSTAT
413  FileContext *c = h->priv_data;
414  closedir(c->dir);
415  return 0;
416 #else
417  return AVERROR(ENOSYS);
418 #endif /* HAVE_LSTAT */
419 }
420 
422  .name = "file",
423  .url_open = file_open,
424  .url_read = file_read,
425  .url_write = file_write,
426  .url_seek = file_seek,
427  .url_close = file_close,
428  .url_get_file_handle = file_get_handle,
429  .url_check = file_check,
430  .url_delete = file_delete,
431  .url_move = file_move,
432  .priv_data_size = sizeof(FileContext),
433  .priv_data_class = &file_class,
434  .url_open_dir = file_open_dir,
435  .url_read_dir = file_read_dir,
436  .url_close_dir = file_close_dir,
437  .default_whitelist = "file,crypto,data"
438 };
439 
440 #endif /* CONFIG_FILE_PROTOCOL */
441 
442 #if CONFIG_PIPE_PROTOCOL
443 
444 static int pipe_open(URLContext *h, const char *filename, int flags)
445 {
446  FileContext *c = h->priv_data;
447  int fd;
448  char *final;
449 
450  if (c->fd < 0) {
451  av_strstart(filename, "pipe:", &filename);
452 
453  if (!*filename) {
454  if (flags & AVIO_FLAG_WRITE) {
455  fd = 1;
456  } else {
457  fd = 0;
458  }
459  } else {
460  fd = strtol(filename, &final, 10);
461  if (*final) /* No digits found, or something like 10ab */
462  return AVERROR(EINVAL);
463  }
464  c->fd = fd;
465  }
466 
467  c->fd = fd_dup(h, c->fd);
468  if (c->fd == -1)
469  return AVERROR(errno);
470  h->is_streamed = 1;
471  return 0;
472 }
473 
475  .name = "pipe",
476  .url_open = pipe_open,
477  .url_read = file_read,
478  .url_write = file_write,
479  .url_close = file_close,
480  .url_get_file_handle = file_get_handle,
481  .url_check = file_check,
482  .priv_data_size = sizeof(FileContext),
483  .priv_data_class = &pipe_class,
484  .default_whitelist = "crypto,data"
485 };
486 
487 #endif /* CONFIG_PIPE_PROTOCOL */
488 
489 #if CONFIG_FD_PROTOCOL
490 
491 static int fd_open(URLContext *h, const char *filename, int flags)
492 {
493  FileContext *c = h->priv_data;
494  struct stat st;
495 
496  if (strcmp(filename, "fd:") != 0) {
497  av_log(h, AV_LOG_ERROR, "Doesn't support pass file descriptor via URL,"
498  " please set it via -fd {num}\n");
499  return AVERROR(EINVAL);
500  }
501 
502  if (c->fd < 0) {
503  if (flags & AVIO_FLAG_WRITE) {
504  c->fd = 1;
505  } else {
506  c->fd = 0;
507  }
508  }
509  if (fstat(c->fd, &st) < 0)
510  return AVERROR(errno);
511  h->is_streamed = !(S_ISREG(st.st_mode) || S_ISBLK(st.st_mode));
512  c->fd = fd_dup(h, c->fd);
513  if (c->fd == -1)
514  return AVERROR(errno);
515 
516  return 0;
517 }
518 
519 const URLProtocol ff_fd_protocol = {
520  .name = "fd",
521  .url_open = fd_open,
522  .url_read = file_read,
523  .url_write = file_write,
524  .url_seek = file_seek,
525  .url_close = file_close,
526  .url_get_file_handle = file_get_handle,
527  .url_check = file_check,
528  .priv_data_size = sizeof(FileContext),
529  .priv_data_class = &fd_class,
530  .default_whitelist = "crypto,data"
531 };
532 
533 #endif /* CONFIG_FD_PROTOCOL */
534 
535 #if CONFIG_ANDROID_CONTENT_PROTOCOL
536 #include <jni.h>
537 #include "libavcodec/ffjni.h"
538 #include "libavcodec/jni.h"
539 
540 typedef struct JFields {
541  jclass uri_class;
542  jmethodID parse_id;
543 
544  jclass context_class;
545  jmethodID get_content_resolver_id;
546 
547  jclass content_resolver_class;
548  jmethodID open_file_descriptor_id;
549 
550  jclass parcel_file_descriptor_class;
551  jmethodID detach_fd_id;
552 } JFields;
553 
554 #define OFFSET(x) offsetof(JFields, x)
555 static const struct FFJniField jfields_mapping[] = {
556  { "android/net/Uri", NULL, NULL, FF_JNI_CLASS, OFFSET(uri_class), 1 },
557  { "android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", FF_JNI_STATIC_METHOD, OFFSET(parse_id), 1 },
558 
559  { "android/content/Context", NULL, NULL, FF_JNI_CLASS, OFFSET(context_class), 1 },
560  { "android/content/Context", "getContentResolver", "()Landroid/content/ContentResolver;", FF_JNI_METHOD, OFFSET(get_content_resolver_id), 1 },
561 
562  { "android/content/ContentResolver", NULL, NULL, FF_JNI_CLASS, OFFSET(content_resolver_class), 1 },
563  { "android/content/ContentResolver", "openFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", FF_JNI_METHOD, OFFSET(open_file_descriptor_id), 1 },
564 
565  { "android/os/ParcelFileDescriptor", NULL, NULL, FF_JNI_CLASS, OFFSET(parcel_file_descriptor_class), 1 },
566  { "android/os/ParcelFileDescriptor", "detachFd", "()I", FF_JNI_METHOD, OFFSET(detach_fd_id), 1 },
567 
568  { NULL }
569 };
570 #undef OFFSET
571 
572 static int android_content_open(URLContext *h, const char *filename, int flags)
573 {
574  FileContext *c = h->priv_data;
575  int fd, ret;
576  struct stat st;
577  const char *mode_str = "r";
578 
579  JNIEnv *env;
580  JFields jfields = { 0 };
581  jobject application_context = NULL;
582  jobject url = NULL;
583  jobject mode = NULL;
584  jobject uri = NULL;
585  jobject content_resolver = NULL;
586  jobject parcel_file_descriptor = NULL;
587 
588  env = ff_jni_get_env(c);
589  if (!env) {
590  return AVERROR(EINVAL);
591  }
592 
593  ret = ff_jni_init_jfields(env, &jfields, jfields_mapping, 0, c);
594  if (ret < 0) {
595  av_log(c, AV_LOG_ERROR, "failed to initialize jni fields\n");
596  return ret;
597  }
598 
599  application_context = av_jni_get_android_app_ctx();
600  if (!application_context) {
601  av_log(c, AV_LOG_ERROR, "application context is not set\n");
603  goto done;
604  }
605 
606  url = ff_jni_utf_chars_to_jstring(env, filename, c);
607  if (!url) {
609  goto done;
610  }
611 
613  mode_str = "rw";
614  else if (flags & AVIO_FLAG_WRITE)
615  mode_str = "w";
616 
617  mode = ff_jni_utf_chars_to_jstring(env, mode_str, c);
618  if (!mode) {
620  goto done;
621  }
622 
623  uri = (*env)->CallStaticObjectMethod(env, jfields.uri_class, jfields.parse_id, url);
624  ret = ff_jni_exception_check(env, 1, c);
625  if (ret < 0)
626  goto done;
627 
628  content_resolver = (*env)->CallObjectMethod(env, application_context, jfields.get_content_resolver_id);
629  ret = ff_jni_exception_check(env, 1, c);
630  if (ret < 0)
631  goto done;
632 
633  parcel_file_descriptor = (*env)->CallObjectMethod(env, content_resolver, jfields.open_file_descriptor_id, uri, mode);
634  ret = ff_jni_exception_check(env, 1, c);
635  if (ret < 0)
636  goto done;
637  if (!parcel_file_descriptor) {
638  av_log(c, AV_LOG_ERROR, "file descriptor is null\n");
640  goto done;
641  }
642 
643  fd = (*env)->CallIntMethod(env, parcel_file_descriptor, jfields.detach_fd_id);
644  ret = ff_jni_exception_check(env, 1, c);
645  if (ret < 0)
646  goto done;
647 
648  if (fstat(fd, &st) < 0) {
649  close(fd);
650  return AVERROR(errno);
651  }
652 
653  c->fd = fd;
654  h->is_streamed = !(S_ISREG(st.st_mode) || S_ISBLK(st.st_mode));
655 
656 done:
657  (*env)->DeleteLocalRef(env, url);
658  (*env)->DeleteLocalRef(env, mode);
659  (*env)->DeleteLocalRef(env, uri);
660  (*env)->DeleteLocalRef(env, content_resolver);
661  (*env)->DeleteLocalRef(env, parcel_file_descriptor);
662  ff_jni_reset_jfields(env, &jfields, jfields_mapping, 0, c);
663 
664  return ret;
665 }
666 
667 static const AVOption android_content_options[] = {
668  { "blocksize", "set I/O operation maximum block size", offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
669  { NULL }
670 };
671 
672 static const AVClass android_content_class = {
673  .class_name = "android_content",
674  .item_name = av_default_item_name,
675  .option = android_content_options,
676  .version = LIBAVUTIL_VERSION_INT,
677 };
678 
680  .name = "content",
681  .url_open = android_content_open,
682  .url_read = file_read,
683  .url_write = file_write,
684  .url_seek = file_seek,
685  .url_close = file_close,
686  .url_get_file_handle = file_get_handle,
687  .url_check = NULL,
688  .priv_data_size = sizeof(FileContext),
689  .priv_data_class = &android_content_class,
690 };
691 
692 #endif /* CONFIG_ANDROID_CONTENT_PROTOCOL */
flags
const SwsFlags flags[]
Definition: swscale.c:85
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
S_ISSOCK
#define S_ISSOCK(m)
Definition: file.c:68
URLContext::filename
char * filename
specified URL
Definition: url.h:39
FileContext::pkt_size
int pkt_size
Definition: file.c:97
ff_jni_utf_chars_to_jstring
jstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx)
Definition: ffjni.c:129
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
int64_t
long long int64_t
Definition: coverity.c:34
mask
int mask
Definition: mediacodecdec_common.c:154
file_close
static int file_close(URLContext *h)
Definition: file.c:223
mode
Definition: swscale.c:71
ff_jni_reset_jfields
int ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
Definition: ffjni.c:368
AVOption
AVOption.
Definition: opt.h:429
AVSEEK_SIZE
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
Definition: avio.h:468
AVIO_ENTRY_NAMED_PIPE
@ AVIO_ENTRY_NAMED_PIPE
Definition: avio.h:72
file_check
static int file_check(URLContext *h, int mask)
Definition: file.c:169
URLProtocol
Definition: url.h:51
os_support.h
AVIO_ENTRY_UNKNOWN
@ AVIO_ENTRY_UNKNOWN
Definition: avio.h:68
ff_jni_init_jfields
int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
Definition: ffjni.c:279
av_append_path_component
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
Definition: avstring.c:297
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
AVIO_ENTRY_DIRECTORY
@ AVIO_ENTRY_DIRECTORY
Definition: avio.h:71
trunc
static __device__ float trunc(float a)
Definition: cuda_runtime.h:179
AVIO_ENTRY_CHARACTER_DEVICE
@ AVIO_ENTRY_CHARACTER_DEVICE
Definition: avio.h:70
FF_JNI_CLASS
@ FF_JNI_CLASS
Definition: ffjni.h:91
ff_android_content_protocol
const URLProtocol ff_android_content_protocol
FileContext::blocksize
int blocksize
Definition: file.c:96
file_write
static int file_write(URLContext *h, const unsigned char *buf, int size)
Definition: file.c:154
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
ff_fd_protocol
const URLProtocol ff_fd_protocol
file_read
static int file_read(URLContext *h, unsigned char *buf, int size)
Definition: file.c:141
AVIO_ENTRY_SYMBOLIC_LINK
@ AVIO_ENTRY_SYMBOLIC_LINK
Definition: avio.h:73
FileContext::seekable
int seekable
Definition: file.c:99
S_ISFIFO
#define S_ISFIFO(m)
Definition: file.c:50
avpriv_open
int avpriv_open(const char *filename, int flags,...)
A wrapper for open() setting O_CLOEXEC.
Definition: file_open.c:67
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
FileContext
Definition: file.c:92
pipe_class
static const AVClass pipe_class
Definition: file.c:127
file_open.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
FF_JNI_METHOD
@ FF_JNI_METHOD
Definition: ffjni.h:94
NULL
#define NULL
Definition: coverity.c:32
S_ISBLK
#define S_ISBLK(m)
Definition: file.c:86
FFJniField
Definition: ffjni.h:103
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
AVIO_ENTRY_FILE
@ AVIO_ENTRY_FILE
Definition: avio.h:75
FileContext::fd
int fd
Definition: file.c:94
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:352
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
pipe_options
static const AVOption pipe_options[]
Definition: file.c:114
FileContext::follow
int follow
Definition: file.c:98
ff_file_protocol
const URLProtocol ff_file_protocol
size
int size
Definition: twinvq_data.h:10344
AVIODirEntry
Describes single entry of the directory.
Definition: avio.h:87
avio.h
URLProtocol::name
const char * name
Definition: url.h:52
FileContext::trunc
int trunc
Definition: file.c:95
file_seek
static int64_t file_seek(URLContext *h, int64_t pos, int whence)
Definition: file.c:231
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:36
AVIO_ENTRY_SOCKET
@ AVIO_ENTRY_SOCKET
Definition: avio.h:74
ff_alloc_dir_entry
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
Definition: url.c:327
ff_jni_exception_check
int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx)
Definition: ffjni.c:246
URLContext
Definition: url.h:35
ffjni.h
file_options
static const AVOption file_options[]
Definition: file.c:105
av_jni_get_android_app_ctx
void * av_jni_get_android_app_ctx(void)
internal.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
url.h
file_class
static const AVClass file_class
Definition: file.c:120
S_ISLNK
#define S_ISLNK(m)
Definition: file.c:59
O_BINARY
#define O_BINARY
ff_pipe_protocol
const URLProtocol ff_pipe_protocol
AVIO_ENTRY_BLOCK_DEVICE
@ AVIO_ENTRY_BLOCK_DEVICE
Definition: avio.h:69
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
file_get_handle
static int file_get_handle(URLContext *h)
Definition: file.c:163
pos
unsigned int pos
Definition: spdifenc.c:414
OFFSET
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your see the OFFSET() macro
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
fd_class
static const AVClass fd_class
Definition: file.c:134
ff_jni_get_env
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:53
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
mem.h
S_ISREG
#define S_ISREG(m)
Definition: file.c:77
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FF_JNI_STATIC_METHOD
@ FF_JNI_STATIC_METHOD
Definition: ffjni.h:95
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
avstring.h
jni.h
read
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
Definition: bitstream_template.h:239