]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - afh_common.c
server: Store max chunk size in database.
[paraslash.git] / afh_common.c
index f36c32e20ec6332a24720d9bf106ab9b39d756ba..75d8b5118db91586d46f339fff0d1d1f693dfc07 100644 (file)
@@ -295,8 +295,8 @@ int32_t afh_get_start_chunk(int32_t approx_chunk_num,
 
        for (k = PARA_MAX(0, approx_chunk_num); k >= 0; k--)
                if (get_chunk_len(k, afhi) > 0)
-                       break;
-       return k;
+                       return k;
+       return 0;
 }
 
 /**
@@ -374,6 +374,7 @@ unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **re
                "%s: %" PRIu32 "\n" /* seconds total */
                "%s: %lu: %lu\n" /* chunk time */
                "%s: %" PRIu32 "\n" /* num chunks */
+               "%s: %" PRIu32 "\n" /* max chunk size */
                "%s: %s\n" /* techinfo */
                "%s: %s\n" /* artist */
                "%s: %s\n" /* title */
@@ -388,6 +389,7 @@ unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **re
                status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec,
                        (long unsigned)afhi->chunk_tv.tv_usec,
                status_item_list[SI_NUM_CHUNKS], afhi->chunks_total,
+               status_item_list[SI_MAX_CHUNK_SIZE], afhi->max_chunk_size,
                status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "",
                status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "",
                status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "",
@@ -397,6 +399,37 @@ unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **re
        );
 }
 
+/**
+ * Determine the maximal chunk size by investigating the chunk table.
+ *
+ * \param afhi Value/result.
+ *
+ * This function iterates over the chunk table and sets ->max_chunk_size
+ * accordingly. The function exists only for backward compatibility since as of
+ * version 0.6.0, para_server stores the maximal chunk size in its database.
+ * This function is only called if the database value is zero, indicating that
+ * the file was added by an older server version.
+ */
+void set_max_chunk_size(struct afh_info *afhi)
+{
+       uint32_t n, max = 0, old = 0;
+
+       for (n = 0; n <= afhi->chunks_total; n++) {
+               uint32_t val = afhi->chunk_table[n];
+               /*
+                * If the first chunk is the header, do not consider it for the
+                * calculation of the largest chunk size.
+                */
+               if (n == 0 || (n == 1 && afhi->header_len > 0)) {
+                       old = val;
+                       continue;
+               }
+               max = PARA_MAX(max, val - old);
+               old = val;
+       }
+       afhi->max_chunk_size = max;
+}
+
 /**
  * Create a copy of the given file with altered meta tags.
  *