00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022 #include "avstring.h"
00023 #include <fcntl.h>
00024 #include <unistd.h>
00025 #include <sys/time.h>
00026 #include <stdlib.h>
00027 #include "os_support.h"
00028
00029
00030
00031
00032 static int file_open(URLContext *h, const char *filename, int flags)
00033 {
00034 int access;
00035 int fd;
00036
00037 av_strstart(filename, "file:", &filename);
00038
00039 if (flags & URL_RDWR) {
00040 access = O_CREAT | O_TRUNC | O_RDWR;
00041 } else if (flags & URL_WRONLY) {
00042 access = O_CREAT | O_TRUNC | O_WRONLY;
00043 } else {
00044 access = O_RDONLY;
00045 }
00046 #ifdef O_BINARY
00047 access |= O_BINARY;
00048 #endif
00049 fd = open(filename, access, 0666);
00050 if (fd < 0)
00051 return AVERROR(ENOENT);
00052 h->priv_data = (void *)(size_t)fd;
00053 return 0;
00054 }
00055
00056 static int file_read(URLContext *h, unsigned char *buf, int size)
00057 {
00058 int fd = (size_t)h->priv_data;
00059 return read(fd, buf, size);
00060 }
00061
00062 static int file_write(URLContext *h, unsigned char *buf, int size)
00063 {
00064 int fd = (size_t)h->priv_data;
00065 return write(fd, buf, size);
00066 }
00067
00068
00069 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
00070 {
00071 int fd = (size_t)h->priv_data;
00072 return lseek(fd, pos, whence);
00073 }
00074
00075 static int file_close(URLContext *h)
00076 {
00077 int fd = (size_t)h->priv_data;
00078 return close(fd);
00079 }
00080
00081 URLProtocol file_protocol = {
00082 "file",
00083 file_open,
00084 file_read,
00085 file_write,
00086 file_seek,
00087 file_close,
00088 };
00089
00090
00091
00092 static int pipe_open(URLContext *h, const char *filename, int flags)
00093 {
00094 int fd;
00095 const char * final;
00096 av_strstart(filename, "pipe:", &filename);
00097
00098 fd = strtol(filename, &final, 10);
00099 if((filename == final) || *final ) {
00100 if (flags & URL_WRONLY) {
00101 fd = 1;
00102 } else {
00103 fd = 0;
00104 }
00105 }
00106 #ifdef O_BINARY
00107 setmode(fd, O_BINARY);
00108 #endif
00109 h->priv_data = (void *)(size_t)fd;
00110 h->is_streamed = 1;
00111 return 0;
00112 }
00113
00114 URLProtocol pipe_protocol = {
00115 "pipe",
00116 pipe_open,
00117 file_read,
00118 file_write,
00119 };