batchrender cleanup, bd/dvd create upgrades, remote ctrl booby fix
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / packagingengine.C
index 778d4e6..222f8d3 100644 (file)
@@ -45,12 +45,9 @@ PackagingEngineDefault::~PackagingEngineDefault()
 }
 
 
-int PackagingEngineDefault::create_packages_single_farm(
-               EDL *edl,
-               Preferences *preferences,
-               Asset *default_asset,
-               double total_start,
-               double total_end)
+int PackagingEngineDefault::create_packages_single_farm(EDL *edl,
+               Preferences *preferences, Asset *default_asset,
+               double total_start, double total_end)
 {
        this->total_start = total_start;
        this->total_end = total_end;
@@ -62,6 +59,7 @@ int PackagingEngineDefault::create_packages_single_farm(
        audio_end = Units::to_int64(total_end * default_asset->sample_rate);
        video_end = Units::to_int64(total_end * default_asset->frame_rate);
        current_package = 0;
+       current_position = 0;
 
        double total_len = total_end - total_start;
        total_packages = preferences->renderfarm_job_count;
@@ -70,146 +68,119 @@ int PackagingEngineDefault::create_packages_single_farm(
        package_len = total_len / total_packages;
        min_package_len = 2.0 / edl->session->frame_rate;
 
-
-//printf("PackageDispatcher::create_packages: %f / %d = %f\n", total_len, total_packages, package_len);
        int current_number;    // The number being injected into the filename.
        int number_start;      // Character in the filename path at which the number begins
        int total_digits;      // Total number of digits including padding the user specified.
 
        Render::get_starting_number(default_asset->path,
-               current_number,
-               number_start,
-               total_digits,
-               3);
+               current_number, number_start, total_digits, 3);
 
-       for(int i = 0; i < total_allocated; i++)
-       {
+       for( int i=0; i<total_allocated; ++i ) {
                RenderPackage *package = packages[i] = new RenderPackage;
 
 // Create file number differently if image file sequence
-               Render::create_filename(package->path,
-                       default_asset->path,
-                       current_number,
-                       total_digits,
-                       number_start);
+               Render::create_filename(package->path, default_asset->path,
+                       current_number, total_digits, number_start);
                current_number++;
        }
        return 0;
 }
 
 RenderPackage* PackagingEngineDefault::get_package_single_farm(double frames_per_second,
-               int client_number,
-               int use_local_rate)
+               int client_number, int use_local_rate)
 {
-
-//printf("PackageDispatcher::get_package %ld %ld %ld %ld\n", audio_position, video_position, audio_end, video_end);
-
-               RenderPackage *result = 0;
-               float avg_frames_per_second = preferences->get_avg_rate(use_local_rate);
-
-               if(audio_position < audio_end ||
-                       video_position < video_end)
-               {
+       RenderPackage *result = 0;
+       float avg_frames_per_second = preferences->get_avg_rate(use_local_rate);
+       double length = package_len;
+       int scaled_length = 0;
+
+       if( (default_asset->audio_data &&
+               (audio_position < audio_end && !EQUIV(audio_position, audio_end))) ||
+           (default_asset->video_data &&
+               (video_position < video_end && !EQUIV(video_position, video_end))) ) {
 // Last package
-                       double scaled_len;
-                       result = packages[current_package];
-                       result->audio_start = audio_position;
-                       result->video_start = video_position;
-                       result->video_do = default_asset->video_data;
-                       result->audio_do = default_asset->audio_data;
-
-                       if(current_package >= total_allocated - 1)
-                       {
-                               result->audio_end = audio_end;
-                               result->video_end = video_end;
-                               audio_position = result->audio_end;
-                               video_position = result->video_end;
+               result = packages[current_package];
+               result->audio_start = audio_position;
+               result->video_start = video_position;
+               result->video_do = default_asset->video_data;
+               result->audio_do = default_asset->audio_data;
+
+               if( current_package >= total_allocated-1 ) {
+                       result->audio_end = audio_end;
+                       result->video_end = video_end;
+                       audio_position = result->audio_end;
+                       video_position = result->video_end;
+               }
+               else {
+                       if( frames_per_second > 0 && 
+                           !EQUIV(frames_per_second, 0) && !EQUIV(avg_frames_per_second, 0) ) {
+// package size to fit the requestor.
+                               length *= frames_per_second / avg_frames_per_second;
+                               scaled_length = 1;
                        }
-                       else
-// No useful speed data.  May get infinity for real fast jobs.
-                       if(frames_per_second > 0x7fffff || frames_per_second < 0 ||
-                               EQUIV(frames_per_second, 0) ||
-                               EQUIV(avg_frames_per_second, 0))
-                       {
-                               scaled_len = MAX(package_len, min_package_len);
-
-                               result->audio_end = audio_position +
-                                       Units::round(scaled_len * default_asset->sample_rate);
-                               result->video_end = video_position +
-                                       Units::round(scaled_len * default_asset->frame_rate);
-
-// If we get here without any useful speed data render the whole thing.
-                               if(current_package >= total_packages - 1)
-                               {
-                                       result->audio_end = audio_end;
-                                       result->video_end = video_end;
-                               }
-                               else
-                               {
-                                       result->audio_end = MIN(audio_end, result->audio_end);
-                                       result->video_end = MIN(video_end, result->video_end);
-                               }
-
-                               audio_position = result->audio_end;
-                               video_position = result->video_end;
+                       if( length < min_package_len )
+                               length = min_package_len;
+                       double end_position = current_position + length;
+
+                       if( result->video_do ) {
+                               int64_t video_end = end_position * default_asset->frame_rate;
+                               result->video_end = MIN(this->video_end, video_end);
+                               end_position = video_end / default_asset->frame_rate;
                        }
-                       else
-// Useful speed data and future packages exist.  Scale the
-// package size to fit the requestor.
-                       {
-                               scaled_len = package_len *
-                                       frames_per_second /
-                                       avg_frames_per_second;
-                               scaled_len = MAX(scaled_len, min_package_len);
-
-                               result->audio_end = result->audio_start +
-                                       Units::to_int64(scaled_len * default_asset->sample_rate);
-                               result->video_end = result->video_start +
-                                       Units::to_int64(scaled_len * default_asset->frame_rate);
-
-                               result->audio_end = MIN(audio_end, result->audio_end);
-                               result->video_end = MIN(video_end, result->video_end);
-
-                               audio_position = result->audio_end;
-                               video_position = result->video_end;
+                       if( result->audio_do ) {
+                               int64_t audio_end = end_position * default_asset->sample_rate;
+                               result->audio_end = MIN(this->audio_end, audio_end);
+                       }
+                       audio_position = result->audio_end;
+                       video_position = result->video_end;
+                       current_position = end_position;
 
 // Package size is no longer touched between total_packages and total_allocated
-                               if(current_package < total_packages - 1)
-                               {
-                                       package_len = (double)(audio_end - audio_position) /
-                                               (double)default_asset->sample_rate /
-                                               (double)(total_packages - current_package);
+                       if( scaled_length && current_package < total_packages-1 ) {
+                               double remaining =
+                                       result->audio_do ? (double)(audio_end - audio_position) /
+                                               default_asset->sample_rate :
+                                       result->video_do ? (double)(video_end - video_position) /
+                                               default_asset->frame_rate : 0;
+                               if( remaining > 0 ) {
+                                       int jobs = total_packages - current_package;
+                                       package_len = remaining / jobs;
                                }
-
                        }
-
-                       current_package++;
-//printf("Dispatcher::get_package 50 %lld %lld %lld %lld\n",
-//result->audio_start,
-//result->video_start,
-//result->audio_end,
-//result->video_end);
                }
-               return result;
 
+               current_package++;
+//printf("Dispatcher::get_package 50 %lld %lld %lld %lld\n",
+// result->audio_start, result->video_start, result->audio_end, result->video_end);
+       }
+       return result;
 }
 
 void PackagingEngineDefault::get_package_paths(ArrayList<char*> *path_list)
 {
-       for(int i = 0; i < total_allocated; i++)
-       {
+       for( int i=0; i<total_allocated; ++i ) {
                path_list->append(strdup(packages[i]->path));
        }
        path_list->set_free();
 }
 
+int PackagingEngineDefault::get_asset_list(ArrayList<Indexable *> &idxbls)
+{
+       for( int i=0; i<current_package; ++i ) {
+               Asset *asset = new Asset;
+               asset->copy_from(default_asset, 1);
+               strcpy(asset->path, packages[i]->path);
+               asset->video_length = packages[i]->video_end - packages[i]->video_start;
+               asset->audio_length = packages[i]->audio_end - packages[i]->audio_start;
+               idxbls.append(asset);
+       }
+       return current_package;
+}
+
 int64_t PackagingEngineDefault::get_progress_max()
 {
-       return Units::to_int64(default_asset->sample_rate *
-                       (total_end - total_start)) +
-               Units::to_int64(preferences->render_preroll *
-                       2 *
-                       default_asset->sample_rate);
+       return Units::to_int64(default_asset->sample_rate * (total_end - total_start)) +
+               Units::to_int64(preferences->render_preroll * 2 * default_asset->sample_rate);
 }
 
 int PackagingEngineDefault::packages_are_done()
@@ -217,6 +188,3 @@ int PackagingEngineDefault::packages_are_done()
        return 0;
 }
 
-
-
-