4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
28 #include "preferences.h"
36 FileDB::FileDB(Asset *asset, File *file)
37 : FileBase(asset, file)
41 if(asset->format == FILE_UNKNOWN)
42 asset->format = FILE_DB;
44 swidth = (SWIDTH+1) & ~1;
45 sheight = (SHEIGHT+1) & ~1;
46 frame_id = clip_size = -1;
48 prefix_size = suffix_offset = -1;
59 int FileDB::check_sig(Asset *asset)
61 return !strncmp(asset->path,"/db:",4);
64 int FileDB::open_file(int rd, int wr)
67 if( mdb->openDb() ) return 1;
72 clip_id = strtol(asset->path+4,&cp,0);
73 if( !cp || cp == asset->path+4 || *cp != 0 ) result = 1;
74 if( !result ) result = mdb->clip_id(clip_id);
76 framerate = mdb->clip_framerate();
77 clip_size = mdb->clip_size();
78 prefix_size = mdb->clip_prefix_size();
79 suffix_offset = mdb->clip_frames() - clip_size;
80 asset->audio_data = 0;
81 asset->video_data = 1;
82 asset->actual_width = swidth;
83 asset->actual_height = sheight;
84 if( !asset->layers ) asset->layers = 1;
85 if( !asset->width ) asset->width = asset->actual_width;
86 if( !asset->height ) asset->height = asset->actual_height;
87 if( !asset->video_length ) asset->video_length = clip_size;
88 if( !asset->frame_rate ) asset->frame_rate = framerate;
102 int FileDB::close_file()
105 FileBase::close_file();
112 int FileDB::get_best_colormodel(Asset *asset, int driver)
117 int FileDB::colormodel_supported(int colormodel)
123 int FileDB::set_video_position(int64_t pos)
125 if( pos < 0 || pos >= asset->video_length )
131 int64_t FileDB::get_memory_usage()
138 int FileDB::write_frames(VFrame ***frames, int len)
145 int FileDB::read_frame(VFrame *frame)
149 int result = seq_no < clip_size ? 0 : 1;
152 if( !n ) { frame_id = -1; }
153 else if( n >= prefix_size ) n += suffix_offset;
154 result = mdb->get_sequences(clip_id, n);
155 if( !result && mdb->timeline_sequence_no() == n )
156 frame_id = mdb->timeline_frame_id();
158 VFrame *fp = frame->get_w() == swidth && frame->get_h() == sheight &&
159 frame->get_color_model() == BC_YUV420P ? frame :
160 !vframe ? (vframe = new VFrame(swidth,sheight,BC_YUV420P)) :
164 memset(fp->get_y(), 0, swidth*sheight);
166 result = mdb->get_image(frame_id, fp->get_y(), sw,sh);
168 //printf("seq_no=%d, result=%d\n",seq_no,result);
171 memset(fp->get_u(),0x80,swidth/2 * sheight/2);
172 memset(fp->get_v(),0x80,swidth/2 * sheight/2);
174 if( !result && fp == vframe ) {
175 BC_CModels::transfer(frame->get_rows(), fp->get_rows(),
176 frame->get_y(), frame->get_u(), frame->get_v(),
177 fp->get_y(), fp->get_u(), fp->get_v(),
178 0, 0, fp->get_w(), fp->get_h(),
179 0, 0, frame->get_w(), frame->get_h(),
180 fp->get_color_model(), frame->get_color_model(), 0,
181 fp->get_bytes_per_line(), swidth);