瀏覽代碼

LibAudio: Add a sample count hinting mechanism to audio encoding

kleines Filmröllchen 2 年之前
父節點
當前提交
b4b411b8a3
共有 2 個文件被更改,包括 7 次插入0 次删除
  1. 4 0
      Userland/Libraries/LibAudio/Encoder.h
  2. 3 0
      Userland/Utilities/aconv.cpp

+ 4 - 0
Userland/Libraries/LibAudio/Encoder.h

@@ -24,6 +24,10 @@ public:
     // This method makes sure that all samples are encoded and written out.
     // This method makes sure that all samples are encoded and written out.
     // This method is called in the destructor, but since this can error, you should call this function yourself before disposing of the decoder.
     // This method is called in the destructor, but since this can error, you should call this function yourself before disposing of the decoder.
     virtual ErrorOr<void> finalize() = 0;
     virtual ErrorOr<void> finalize() = 0;
+
+    // Provides a hint about the total number of samples to the encoder, improving some encoder's performance in various aspects.
+    // Note that the hint does not have to be fully correct; wrong hints never cause errors, not even indirectly.
+    virtual void sample_count_hint([[maybe_unused]] size_t sample_count) { }
 };
 };
 
 
 }
 }

+ 3 - 0
Userland/Utilities/aconv.cpp

@@ -141,6 +141,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
             return 1;
             return 1;
         }
         }
 
 
+        if (writer.has_value())
+            (*writer)->sample_count_hint(input_loader->total_samples());
+
         if (output != "-"sv)
         if (output != "-"sv)
             out("Writing: \033[s");
             out("Writing: \033[s");