inter-view map media popup tweaks, new vicon mode/size prefs
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / filemediadb.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 "commercials.h"
24 #include "filebase.h"
25 #include "file.h"
26 #include "filemediadb.h"
27 #include "mwindow.h"
28 #include "preferences.h"
29 #include "vframe.h"
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <unistd.h>
34
35
36 FileMediaDb::FileMediaDb(Asset *asset, File *file)
37  : FileBase(asset, file)
38 {
39         reset_parameters();
40         if(asset->format == FILE_UNKNOWN)
41                 asset->format = FILE_MEDIADB;
42         clip_id = -1;
43         swidth = (SWIDTH+1) & ~1;
44         sheight = (SHEIGHT+1) & ~1;
45         seq_no = frame_id = frames = -1;
46         framerate = offset = -1;;
47         title[0] = 0;
48 }
49
50 FileMediaDb::~FileMediaDb()
51 {
52         close_file();
53 }
54
55 int FileMediaDb::check_sig(Asset *asset)
56 {
57         return !strncmp(asset->path,"/mediadb:",9);
58 }
59
60 int FileMediaDb::open_file(int rd, int wr)
61 {
62         int result = 0;
63
64         if(rd) {
65                 char *cp = 0;
66                 clip_id = strtol(asset->path+9,&cp,0);
67                 if( !cp || cp == asset->path+9 || *cp != 0 ) result = 1;
68                 if( !result ) result = MWindow::commercials->
69                         get_clip_set(clip_id, title, framerate, frames);
70                 if( !result ) {
71                         asset->audio_data = 0;
72                         asset->video_data = 1;
73                         asset->actual_width = swidth;
74                         asset->actual_height = sheight;
75                         if( !asset->layers ) asset->layers = 1;
76                         if( !asset->width ) asset->width = asset->actual_width;
77                         if( !asset->height ) asset->height = asset->actual_height;
78                         if( !asset->video_length ) asset->video_length = frames;
79                         if( !asset->frame_rate ) asset->frame_rate = framerate;
80                 }
81         }
82
83         if(!result && wr ) {
84                 result = 1;
85         }
86
87         return result;
88 }
89
90 int FileMediaDb::close_file()
91 {
92         reset_parameters();
93
94         FileBase::close_file();
95         return 0;
96 }
97
98 int FileMediaDb::get_best_colormodel(Asset *asset, int driver)
99 {
100         return BC_YUV420P;
101 }
102
103 int FileMediaDb::colormodel_supported(int colormodel)
104 {
105         return BC_YUV420P;
106 }
107
108
109 int FileMediaDb::set_video_position(int64_t pos)
110 {
111         if( pos < 0 || pos >= asset->video_length )
112                 return 1;
113         seq_no = pos-1;
114         return 0;
115 }
116
117 int64_t FileMediaDb::get_memory_usage()
118 {
119         return 0;
120 }
121
122
123
124 int FileMediaDb::write_frames(VFrame ***frames, int len)
125 {
126         int result = 0;
127         return result;
128 }
129
130
131 int FileMediaDb::read_frame(VFrame *frame)
132 {
133         int sw, sh;
134         int result = MWindow::commercials->
135                 get_clip_seq_no(clip_id, seq_no, offset, frame_id);
136         if( !result ) result = MWindow::commercials->
137                 get_image(frame_id, frame->get_y(), sw,sh);
138         if( !result ) {
139                 memset(frame->get_u(),0x80,swidth/2 * sheight/2);
140                 memset(frame->get_v(),0x80,swidth/2 * sheight/2);
141         }
142         return result;
143 }
144
145