Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / vmodule.C
index ce7ecadc59529194233ade5524569f8218d4ab90..1829c404a2b9522cd73a8c10e1a03704316bc19e 100644 (file)
@@ -2,6 +2,7 @@
 /*
  * CINELERRA
  * Copyright (C) 2009-2013 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 2003-2016 Cinelerra CV contributors
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -104,10 +105,10 @@ CICache* VModule::get_cache()
 int VModule::import_frame(VFrame *output, VEdit *current_edit,
        int64_t input_position, double frame_rate, int direction, int use_opengl)
 {
-       int64_t direction_position;
+       int64_t direction_position=0;
 // Translation of edit
-       float in_x, in_y, in_w, in_h;
-       float out_x, out_y, out_w, out_h;
+       float in_x=0.0, in_y=0.0, in_w=0.0, in_h=0.0;
+       float out_x=0.0, out_y=0.0, out_w=0.0, out_h=0.0;
        int result = 0;
        const int debug = 0;
        double edl_rate = get_edl()->session->frame_rate;
@@ -178,7 +179,7 @@ int VModule::import_frame(VFrame *output, VEdit *current_edit,
                                nested_renderengine = 0;
                        }
                        if( !nested_command )
-                               nested_command = new TransportCommand;
+                               nested_command = new TransportCommand(get_preferences());
                        nested_command->command = command;
                        nested_command->get_edl()->copy_all(nested_edl);
                        nested_command->change_type = CHANGE_ALL;
@@ -237,23 +238,18 @@ int VModule::import_frame(VFrame *output, VEdit *current_edit,
 // Make positions based on requested frame rate.
                        int64_t position = Units::to_int64((double)pos * frame_rate / edl_rate);
 
-                       int64_t max_position;
+                       int64_t video_length;
                        int asset_w, asset_h;
                        if( file ) {
                                asset_w = current_edit->asset->width;
                                asset_h = current_edit->asset->height;
-                               max_position = Units::to_int64((double)file->get_video_length() *
-                                       frame_rate / current_edit->asset->frame_rate - 1);
+                               video_length = file->get_video_length();
                        }
                        else {
                                asset_w = nested_edl->session->output_w;
                                asset_h = nested_edl->session->output_h;
-                               max_position = Units::to_int64(nested_edl->tracks->total_length() *
-                                       frame_rate - 1);
+                               video_length = nested_edl->tracks->total_length();
                        }
-                       if( max_position < 0 ) max_position = 0;
-// if we hit the end of stream, freeze at last frame
-                       CLAMP(position, 0, max_position);
 
                        VFrame *&input = commonrender ?
                                ((VRender*)commonrender)->input_temp : // Realtime playback
@@ -302,6 +298,10 @@ int VModule::import_frame(VFrame *output, VEdit *current_edit,
                                                curr_pos += current_edit->startsource;
                                                int64_t norm_pos = Units::to_int64((double)curr_pos *
                                                        current_edit->asset->frame_rate / edl_rate);
+                                               if( norm_pos < 0 || video_length < 0 )
+                                                       norm_pos = 0;
+                                               else if( norm_pos >= video_length )
+                                                       norm_pos = video_length-1;
                                                if( first_frame ) {
                                                        if( file->get_cache_frame(input, norm_pos) )
                                                                break;  // if inside a cache run
@@ -318,6 +318,10 @@ int VModule::import_frame(VFrame *output, VEdit *current_edit,
 
                                int64_t normalized_position = Units::to_int64((double)position *
                                        current_edit->asset->frame_rate / frame_rate);
+                               if( normalized_position < 0 || video_length < 0 )
+                                       normalized_position = 0;
+                               else if( normalized_position >= video_length )
+                                       normalized_position = video_length-1;
 //printf("VModule::import_frame %d %lld %lld\n", __LINE__, position, normalized_position);
                                file->set_layer(current_edit->channel);
                                file->set_video_position(normalized_position, 0);