allow ffmpeg video to resample curr_pos, add bluray format
[goodguy/history.git] / cinelerra-5.0 / cinelerra / fileserver.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "file.inc"
23
24 #ifdef USE_FILEFORK
25
26 #include "bcresources.h"
27 #include "bcsignals.h"
28 #include "filefork.h"
29 #include "fileserver.h"
30 #include "mutex.h"
31
32
33 #include <unistd.h>
34
35
36 FileServer::FileServer(Preferences *preferences) : ForkWrapper()
37 {
38         this->preferences = preferences;
39         lock = new Mutex("FileServer::lock");
40 }
41
42 FileServer::~FileServer()
43 {
44         stop();
45         delete lock;
46 }
47
48 void FileServer::init_child()
49 {
50         BC_WindowBase::get_resources()->vframe_shm = 1;
51 //printf("FileServer::init_child %d %d\n", __LINE__, getpid());
52 }
53
54 int FileServer::handle_command()
55 {
56         const int debug = 0;
57         switch(command_token)
58         {
59                 case NEW_FILEFORK:
60                 {
61                         FileFork *file_fork = new FileFork(this);
62                         file_fork->start();
63                         unsigned char buffer[sizeof(FileFork*) + sizeof(int)];
64                         FileFork **ffbfr = (FileFork **)buffer;
65                         *ffbfr = file_fork;
66                         int *ibfr = (int *)&ffbfr[1];
67                         *ibfr = file_fork->pid;
68
69                         if(debug) printf("FileServer::handle_command NEW_FILEFORK %d parent_fd=%d file_fork=%p\n",
70                                 __LINE__,
71                                 file_fork->parent_fd,
72                                 file_fork);
73                         send_fd(file_fork->parent_fd);
74                         send_result(0, buffer, sizeof(FileFork*) + sizeof(int));
75                         break;
76                 }
77
78                 case DELETE_FILEFORK:
79                 {
80                         FileFork **ffbfr = (FileFork **)command_data;
81                         FileFork *file_fork = *ffbfr;
82                         if(debug) printf("FileServer::handle_command DELETE_FILEFORK %d file_fork=%p\n",
83                                 __LINE__,
84                                 file_fork);
85                         delete file_fork;
86                         break;
87                 }
88         }
89
90         return 0;
91 }
92
93 FileFork* FileServer::new_filefork()
94 {
95         lock->lock("FileServer::open_file");
96         FileFork *dummy_fork = new FileFork(this);
97 // Create real file fork on the server
98         send_command(FileServer::NEW_FILEFORK, 0, 0);
99
100         int parent_fd = get_fd();
101         read_result();
102
103 // Transfer fd to dummy file fork
104         dummy_fork->start_dummy(parent_fd, *(int*)(result_data + sizeof(FileFork*)));
105         dummy_fork->real_fork = *(FileFork**)result_data;
106 // printf("FileServer::new_filefork %d parent_fd=%d real_fork=%p\n",
107 // __LINE__,
108 // parent_fd,
109 // dummy_fork->real_fork);
110         lock->unlock();
111         return dummy_fork;
112 }
113
114 void FileServer::delete_filefork(FileFork *file_fork)
115 {
116         lock->lock("FileServer::close_file");
117 // Delete filefork on server
118         unsigned char buffer[sizeof(FileFork*)];
119         FileFork **ffbfr = (FileFork **)buffer;
120         *ffbfr = file_fork;
121         send_command(FileServer::DELETE_FILEFORK, buffer, sizeof(FileFork*));
122         lock->unlock();
123 }
124
125 #endif // USE_FILEFORK
126
127
128
129
130