4 * Copyright (C) 2020 William Morrow
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
29 #include "mainerror.h"
30 #include "renderengine.h"
32 #include "edlsession.h"
34 #include "transportque.h"
40 FileREF::FileREF(Asset *asset, File *file)
41 : FileBase(asset, file)
46 samples_position = -1;
56 for( int i=0; i<MAX_CHANNELS; ++i ) samples[i] = 0;
64 int FileREF::open_file(int rd, int wr)
66 if( is_open ) return 1;
68 eprintf(_("Reference files cant be created by rendering\n"));
73 if( file_xml.read_from_file(asset->path) ) return 1;
74 // file_xml.check_version();
75 if( ref ) ref->remove_user();
77 ref->create_objects();
78 ref->load_xml(&file_xml, LOAD_ALL);
79 command = new TransportCommand();
81 command->get_edl()->copy_all(ref);
82 command->command = NORMAL_FWD;
83 command->change_type = CHANGE_ALL;
84 command->realtime = 0;
85 samples_position = -1;
88 render_engine = new RenderEngine(0, file->preferences, 0, 0);
89 render_engine->set_acache(acache = new CICache(file->preferences));
90 render_engine->set_vcache(vcache = new CICache(file->preferences));
91 render_engine->arm_command(command);
97 int FileREF::close_file()
99 if( !is_open ) return 1;
100 if( ref ) ref->remove_user();
102 delete render_engine; render_engine = 0;
103 delete command; command = 0;
104 delete acache; acache = 0;
105 delete vcache; vcache = 0;
106 delete temp; temp = 0;
107 for( int i=0; i<MAX_CHANNELS; ++i ) {
108 delete samples[i]; samples[i] = 0;
113 samples_position = -1;
120 int64_t FileREF::get_video_position()
122 return video_position;
125 int64_t FileREF::get_audio_position()
127 return audio_position;
130 int FileREF::set_video_position(int64_t pos)
132 this->video_position = pos;
135 int FileREF::set_layer(int layer)
141 int FileREF::set_audio_position(int64_t pos)
143 this->audio_position = pos;
146 int FileREF::set_channel(int channel)
148 this->channel = channel;
152 int FileREF::read_samples(double *buffer, int64_t len)
154 int result = len > 0 ? 0 : 1;
155 if( !render_engine || !render_engine->arender ) result = 1;
157 if( samples_length != len ) {
159 for( int i=0; i<MAX_CHANNELS; ++i ) {
160 delete samples[i]; samples[i] = 0;
163 if( samples_length < 0 ) {
164 samples_length = len;
165 int ch = 0, channels = asset->channels;
166 while( ch < channels ) samples[ch++] = new Samples(samples_length);
167 samples_position = -1;
169 if( samples_position != audio_position ) {
170 result = render_engine->arender->process_buffer(samples, len, audio_position);
171 samples_position = audio_position;
174 Samples *cbfr = samples[channel];
175 double *data = cbfr ? cbfr->get_data() : 0;
176 if( !data ) result = 1;
177 int64_t sz = len*(sizeof(*buffer));
179 memcpy(buffer, data, sz);
181 memset(buffer, 0, sz);
185 int FileREF::read_frame(VFrame *frame)
187 int result = render_engine && render_engine->vrender ? 0 : 1;
188 EDLSession *render_session = render_engine->get_edl()->session;
189 int color_model = render_session->color_model;
190 int out_w = render_session->output_w, out_h = render_session->output_h;
191 VFrame *vframe = frame;
192 if( color_model != frame->get_color_model() ||
193 out_w != frame->get_w() || out_h != frame->get_h() ) {
194 VFrame::get_temp(temp, out_w, out_h, color_model);
198 result = render_engine->vrender->process_buffer(vframe, video_position++, 0);
199 if( vframe != frame )
200 frame->transfer_from(vframe);
204 int FileREF::colormodel_supported(int colormodel)
210 int FileREF::get_best_colormodel(Asset *asset, int driver)
212 return BC_RGBA_FLOAT;