4 * Copyright (C) 2009 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
23 #include "bcsignals.h"
26 #include "edlsession.h"
30 #include "playabletracks.h"
31 #include "preferences.h"
32 #include "mainsession.h"
33 #include "trackcanvas.h"
35 #include "transportque.h"
42 VEdit::VEdit(EDL *edl, Edits *edits)
50 int VEdit::load_properties_derived(FileXML *xml)
52 channel = xml->tag.get_property("CHANNEL", (int64_t)0);
56 Asset* VEdit::get_nested_asset(int64_t *source_position,
62 // Make position relative to edit
63 *source_position = position - startproject + startsource;
65 if(debug) printf("VEdit::get_nested_asset %d %jd %jd %jd %jd\n",
66 __LINE__, *source_position, position, startproject, startsource);
68 // Descend into nested EDLs
71 // Convert position to nested EDL rate
72 if(debug) printf("VEdit::get_nested_asset %d\n",
74 int64_t pos = *source_position;
75 if(direction == PLAY_REVERSE && pos > 0) --pos;
76 *source_position = Units::to_int64((double)pos *
77 nested_edl->session->frame_rate /
78 edl->session->frame_rate);
79 PlayableTracks *playable_tracks = new PlayableTracks(
85 if(playable_tracks->size())
87 VTrack *nested_track = (VTrack*)playable_tracks->get(0);
88 VEdit* nested_edit = (VEdit*)nested_track->edits->editof(
94 result = nested_edit->get_nested_asset(
101 delete playable_tracks;
102 if(debug) printf("VEdit::get_nested_asset %d\n",
108 // Convert position to asset rate
109 if(debug) printf("VEdit::get_nested_asset %d %jd %f %f\n",
113 edl->session->frame_rate);
114 int64_t pos = *source_position;
115 if(direction == PLAY_REVERSE && pos > 0) --pos;
116 *source_position = Units::to_int64((double)pos *
118 edl->session->frame_rate);
124 int VEdit::read_frame(VFrame *video_out,
125 int64_t input_position,
130 int use_asynchronous)
134 int64_t source_position = 0;
137 if(use_nudge) input_position += track->nudge;
138 if(debug) printf("VEdit::read_frame %d source_position=%jd input_position=%jd\n",
139 __LINE__, source_position, input_position);
141 Asset *asset = get_nested_asset(&source_position,
144 if( !asset ) result = 1;
146 if(debug) printf("VEdit::read_frame %d source_position=%jd input_position=%jd\n",
147 __LINE__, source_position, input_position);
150 file = cache->check_out(asset, edl);
151 if( !file ) result = 1;
153 if(debug) printf("VEdit::read_frame %d path=%s source_position=%jd\n",
154 __LINE__, asset->path, source_position);
157 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
158 source_position = (direction == PLAY_FORWARD) ?
160 (source_position - 1);
161 if(debug) printf("VEdit::read_frame %d %jd %jd\n",
162 __LINE__, input_position, source_position);
165 file->start_video_decode_thread();
167 file->stop_video_thread();
168 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
170 file->set_layer(channel);
171 //printf("VEdit::read_frame %d %lld\n", __LINE__, source_position);
172 file->set_video_position(source_position, 0);
174 if(use_cache) file->set_cache_frames(use_cache);
175 result = file->read_frame(video_out);
176 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
177 if(use_cache) file->set_cache_frames(0);
179 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
180 cache->check_in(asset);
181 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
184 //for(int i = 0; i < video_out->get_w() * 3 * 20; i++) video_out->get_rows()[0][i] = 128;
188 int VEdit::copy_properties_derived(FileXML *xml, int64_t length_in_selection)
193 int VEdit::dump_derived()
195 printf(" VEdit::dump_derived\n");
196 printf(" startproject %jd\n", startproject);
197 printf(" length %jd\n", length);
201 int64_t VEdit::get_source_end(int64_t default_)
203 if(!nested_edl && !asset) return default_; // Infinity
207 return (int64_t)(nested_edl->tracks->total_playable_length() *
208 edl->session->frame_rate + 0.5);
211 return (int64_t)((double)asset->video_length /
213 edl->session->frame_rate + 0.5);