1 /*
2 * Input cache protocol.
3 * Copyright (c) 2011 Michael Niedermayer
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 * Based on file.c by Fabrice Bellard
22 */
23
24 /**
25 * @TODO
26 * support non continuous caching
27 * support keeping files
28 * support filling with a background thread
29 */
30
35 #include <fcntl.h>
36 #if HAVE_IO_H
37 #include <io.h>
38 #endif
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42 #include <sys/stat.h>
43 #include <stdlib.h>
46
53
55 {
56 char *buffername;
58
60
65 }
66
67 unlink(buffername);
69
71 }
72
74 {
77
80 if(r>0)
83 }else{
85 if(r > 0){
86 int r2= write(c->
fd, buf, r);
87 av_assert0(r2==r);
// FIXME handle cache failure
90 }
92 }
93 }
94
96 {
98
101 if(pos <= 0){
104 if(pos <= 0)
106 }
107 return pos;
108 }
109
110 pos= lseek(c->
fd, pos, whence);
111 if(pos<0){
112 return pos;
113 }
else if(pos <= c->
end){
115 return pos;
116 }else{
117 if(lseek(c->
fd, c->
pos, SEEK_SET) < 0) {
119 }
121 }
122 }
123
125 {
129
130 return 0;
131 }
132
139 .priv_data_size =
sizeof(
Context),
140 };