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
00028
00029
00030
00031 static int file_open(URLContext *h, const char *filename, int flags)
00032 {
00033 int access;
00034 int fd;
00035
00036 av_strstart(filename, "file:", &filename);
00037
00038 if (flags & URL_RDWR) {
00039 access = O_CREAT | O_TRUNC | O_RDWR;
00040 } else if (flags & URL_WRONLY) {
00041 access = O_CREAT | O_TRUNC | O_WRONLY;
00042 } else {
00043 access = O_RDONLY;
00044 }
00045 #ifdef O_BINARY
00046 access |= O_BINARY;
00047 #endif
00048 fd = open(filename, access, 0666);
00049 if (fd < 0)
00050 return AVERROR(ENOENT);
00051 h->priv_data = (void *)(size_t)fd;
00052 return 0;
00053 }
00054
00055 static int file_read(URLContext *h, unsigned char *buf, int size)
00056 {
00057 int fd = (size_t)h->priv_data;
00058 return read(fd, buf, size);
00059 }
00060
00061 static int file_write(URLContext *h, unsigned char *buf, int size)
00062 {
00063 int fd = (size_t)h->priv_data;
00064 return write(fd, buf, size);
00065 }
00066
00067
00068 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
00069 {
00070 int fd = (size_t)h->priv_data;
00071 return lseek(fd, pos, whence);
00072 }
00073
00074 static int file_close(URLContext *h)
00075 {
00076 int fd = (size_t)h->priv_data;
00077 return close(fd);
00078 }
00079
00080 URLProtocol file_protocol = {
00081 "file",
00082 file_open,
00083 file_read,
00084 file_write,
00085 file_seek,
00086 file_close,
00087 };
00088
00089
00090
00091 static int pipe_open(URLContext *h, const char *filename, int flags)
00092 {
00093 int fd;
00094 const char * final;
00095 av_strstart(filename, "pipe:", &filename);
00096
00097 fd = strtol(filename, &final, 10);
00098 if((filename == final) || *final ) {
00099 if (flags & URL_WRONLY) {
00100 fd = 1;
00101 } else {
00102 fd = 0;
00103 }
00104 }
00105 #ifdef O_BINARY
00106 setmode(fd, O_BINARY);
00107 #endif
00108 h->priv_data = (void *)(size_t)fd;
00109 h->is_streamed = 1;
00110 return 0;
00111 }
00112
00113 URLProtocol pipe_protocol = {
00114 "pipe",
00115 pipe_open,
00116 file_read,
00117 file_write,
00118 };