allow ffmpeg video to resample curr_pos, add bluray format
[goodguy/history.git] / cinelerra-5.0 / cinelerra / assets.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "asset.h"
23 #include "assets.h"
24 #include "awindowgui.inc"
25 #include "batch.h"
26 #include "cache.h"
27 #include "bchash.h"
28 #include "edl.h"
29 #include "file.h"
30 #include "filexml.h"
31 #include "filesystem.h"
32 #include "indexfile.h"
33 #include "quicktime.h"
34 #include "mainsession.h"
35 #include "threadindexer.h"
36 #include <string.h>
37
38 Assets::Assets(EDL *edl) : List<Asset>()
39 {
40         this->edl = edl;
41 }
42
43 Assets::~Assets()
44 {
45         delete_all();
46 }
47
48 int Assets::load(FileXML *file, uint32_t load_flags)
49 {
50         int result = 0;
51
52         while(!result)
53         {
54                 result = file->read_tag();
55                 if(!result)
56                 {
57                         if(file->tag.title_is("/ASSETS"))
58                         {
59                                 result = 1;
60                         }
61                         else
62                         if(file->tag.title_is("ASSET"))
63                         {
64                                 const char *path = file->tag.get_property("SRC");
65                                 if(path && path[0] != 0)
66                                 {
67                                         Asset *new_asset = new Asset(path);
68                                         new_asset->read(file);
69                                         Asset *asset = update(new_asset);
70                                         asset->copy_from(new_asset,1);
71                                         new_asset->Garbage::remove_user();
72                                 }
73                         }
74                 }
75         }
76         return 0;
77 }
78
79 int Assets::save(FileXML *file, char *path)
80 {
81         file->tag.set_title("ASSETS");
82         file->append_tag();
83         file->append_newline();
84
85         for(Asset* current = first; current; current = NEXT)
86         {
87                 current->write(file, 
88                         0, 
89                         path);
90         }
91
92         file->tag.set_title("/ASSETS");
93         file->append_tag();
94         file->append_newline(); 
95         file->append_newline(); 
96         return 0;
97 }
98
99 void Assets::copy_from(Assets *assets)
100 {
101         delete_all();
102
103         for(Asset *current = assets->first; current; current = NEXT)
104         {
105                 Asset *new_asset;
106                 append(new_asset = new Asset);
107                 new_asset->copy_from(current, 1);
108         }
109 }
110
111 Assets& Assets::operator=(Assets &assets)
112 {
113 printf("Assets::operator= 1\n");
114         copy_from(&assets);
115         return *this;
116 }
117
118
119 void Assets::update_index(Asset *asset)
120 {
121         if(!asset) return;
122         for(Asset* current = first; current; current = NEXT)
123         {
124                 if(current->test_path(asset->path))
125                 {
126                         current->update_index(asset);
127                 }
128         }
129 }
130
131 Asset* Assets::update(Asset *asset)
132 {
133         if(!asset) return 0;
134
135         for(Asset* current = first; current; current = NEXT)
136         {
137 // Asset already exists.
138                 if(current->test_path(asset->path)) 
139                 {
140                         return current;
141                 }
142         }
143
144 // Asset doesn't exist.
145         Asset *asset_copy = new Asset(*asset);
146         append(asset_copy);
147         return asset_copy;
148 }
149
150 int Assets::delete_all()
151 {
152         while(first) 
153         {
154                 remove_asset(first);
155         }
156         return 0;
157 }
158
159 Asset* Assets::update(const char *path)
160 {
161         Asset* current = first;
162
163         while(current)
164         {
165                 if(current->test_path(path)) 
166                 {
167                         return current;
168                 }
169                 current = NEXT;
170         }
171
172         return append(new Asset(path));
173 }
174
175 Asset* Assets::get_asset(const char *filename)
176 {
177         Asset* current = first;
178         Asset* result = 0;
179
180         while(current)
181         {
182 //printf("Assets::get_asset %p %s\n", filename, filename);
183                 if(current->test_path(filename))
184                 {
185                         result = current;
186                         break;
187                 }
188                 current = current->next;
189         }
190
191         return result;  
192 }
193
194 void Assets::remove_asset(Asset *asset)
195 {
196         remove_pointer(asset);
197         asset->Garbage::remove_user();
198 }
199
200
201 int Assets::number_of(Asset *asset)
202 {
203         int i;
204         Asset *current;
205
206         for(i = 0, current = first; current && current != asset; i++, current = NEXT)
207                 ;
208
209         return i;
210 }
211
212 Asset* Assets::asset_number(int number)
213 {
214         int i;
215         Asset *current;
216
217         for(i = 0, current = first; i < number && current; i++, current = NEXT)
218                 ;
219         
220         return current;
221 }
222
223 int Assets::update_old_filename(char *old_filename, char *new_filename)
224 {
225         for(Asset* current = first; current; current = NEXT)
226         {
227                 if(!strcmp(current->path, old_filename))
228                 {
229                         current->update_path(new_filename);
230                 }
231         }
232         return 0;
233 }
234
235
236 int Assets::dump(FILE *fp)
237 {
238         for(Asset *current = first; current; current = NEXT)
239         {
240                 current->dump(fp);
241         }
242         return 0;
243 }
244
245