wip: fastvideo decoder building but not linking on deb stable.
authorCarl Hetherington <cth@carlh.net>
Mon, 10 Aug 2020 21:01:33 +0000 (23:01 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 13 Sep 2020 18:22:43 +0000 (20:22 +0200)
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/fastvideo.cc [new file with mode: 0644]
src/lib/fastvideo.h [new file with mode: 0644]
wscript

index 3991c57b97ab98608ed280d02d581827fecdfae5..4df170717b3fb313f2f408b8e8a5aa8eff94e8f1 100644 (file)
@@ -138,3 +138,10 @@ VerifyError::VerifyError (string m, int n)
 
 }
 
+
+FastvideoError::FastvideoError (string s)
+       : runtime_error (String::compose("Fastvideo error in %1", s))
+{
+
+}
+
index 05cda9659f2c63a5b104d6fccbe896e0294e4457..acb2ea9e64b0f6d108f210cb95b3cc2312e1597b 100644 (file)
@@ -379,4 +379,11 @@ public:
                {}
 };
 
+
+class FastvideoError : public std::runtime_error
+{
+public:
+       explicit FastvideoError (std::string s);
+};
+
 #endif
diff --git a/src/lib/fastvideo.cc b/src/lib/fastvideo.cc
new file mode 100644 (file)
index 0000000..0e94419
--- /dev/null
@@ -0,0 +1,167 @@
+#include "exceptions.h"
+#include "fastvideo.h"
+#include <fastvideo_decoder_j2k.h>
+
+
+using boost::shared_ptr;
+
+
+shared_ptr<OpenJPEGImage>
+fastvideo_decompess_j2k (dcp::Data data, int reduce)
+{
+       fastJ2kImageInfo_t info;
+       fastStatus_t r = fastDecoderJ2kPredecode(&info, data.data().get(), data.size());
+       if (r != FAST_OK) {
+               throw FastvideoError ("J2kPredecode");
+       }
+
+       /* Init */
+
+       fastDecoderJ2kStaticParameters_t parameters;
+       memset(&parameters, 0, sizeof(fastDecoderJ2kStaticParameters_t));
+
+       parameters.ResolutionLevels = 5 - reduce;
+       parameters.verboseLevel = 1;
+       parameters.enableROI = 0;
+
+       parameters.maxTileHeight = info.width;
+       parameters.maxTileWidth = info.height;
+
+       parameters.windowX0 = 0;
+       parameters.windowY0 = 0;
+       parameters.windowWidth = info.width;
+       parameters.windowHeight = info.height;
+
+       parameters.truncationLength = 0;
+       parameters.truncationMode = 0;
+       parameters.truncationRate = 0;
+
+       parameters.DecodePasses = 0;
+       parameters.imageInfo = &info;
+       parameters.maxStreamSize = info.streamSize;
+
+       fastDecoderJ2kHandle_t decoder;
+       fastDeviceSurfaceBufferHandle_t buffer;
+       r = fastDecoderJ2kCreate(
+                       &decoder,
+                       &parameters,
+                       FAST_RGB8, info.width, info.height,
+                       1,
+                       &buffer
+                       );
+       if (r != FAST_OK) {
+               throw FastvideoError ("J2kCreate");
+       }
+
+       unsigned long long requested_mem_size = 0;
+
+       {
+               unsigned long long component_mem_size = 0;
+               r = fastDecoderJ2kGetAllocatedGpuMemorySize(decoder, &component_mem_size);
+               if (r != FAST_OK) {
+                       throw FastvideoError ("J2kGetAllocatedGpuMemorySize");
+               }
+               requested_mem_size += component_mem_size;
+       }
+
+       fastExportToHostHandle_t adapter;
+       fastSurfaceFormat_t surface_format;
+       r = fastExportToHostCreate(&adapter, &surface_format, buffer);
+       if (r != FAST_OK) {
+               throw FastvideoError ("ExportToHostCreate");
+       }
+
+       {
+               unsigned int component_mem_size = 0;
+               r = fastExportToHostGetAllocatedGpuMemorySize(adapter, &component_mem_size);
+               if (r != FAST_OK) {
+                       throw FastvideoError ("ExportToHostGetAllocatedGpuMemorySize");
+               }
+               requested_mem_size += component_mem_size;
+       }
+
+       const double gigabyte = 1024.0 * 1024.0 * 1024.0;
+       printf("\nRequested GPU memory size: %.2lf GB\n", requested_mem_size / gigabyte);
+
+       /* Transform */
+
+       double total_time = 0;
+       fastGpuTimerHandle_t device_to_host_timer = 0;
+       fastGpuTimerCreate(&device_to_host_timer);
+
+       fastDecoderJ2kReport_t report;
+
+       fastExportParameters_t export_parameters;
+       export_parameters.convert = FAST_CONVERT_NONE;
+
+       int aligned_width = info.width * 3;
+       aligned_width += 4 - (aligned_width % FAST_ALIGNMENT);
+       size_t decoded_size = info.height * aligned_width;
+       uint8_t* decoded = 0;
+       r = fastMalloc(reinterpret_cast<void**>(&decoded), decoded_size);
+       if (r != FAST_OK) {
+               throw FastvideoError ("fastMalloc");
+       }
+
+       r = fastDecoderJ2kTransform (decoder, decoded, decoded_size, &report);
+       if (r != FAST_OK) {
+               throw FastvideoError ("J2kTransform");
+       }
+
+       total_time += report.elapsedTime;
+
+       fastGpuTimerStart(device_to_host_timer);
+       r = fastExportToHostCopy(adapter, decoded, info.width, aligned_width, info.height, &export_parameters);
+       if (r != FAST_OK) {
+               throw FastvideoError ("ExportToHostCopy");
+       }
+
+       float elapsed_time_gpu = 0.;
+       fastGpuTimerStop(device_to_host_timer);
+       fastGpuTimerGetTime(device_to_host_timer, &elapsed_time_gpu);
+
+       total_time += elapsed_time_gpu / 1000.0;
+
+       if (report.codeblockCount > 0) {
+               printf("Input image : (%dx%d pixels; %d %d-bit channel(s))\n", info.width, info.height, report.channels, report.bitsPerChannel);
+               printf("Tile count: %d (%dx%d)\n", report.tileCount, report.tilesX, report.tilesY);
+               printf("Window mode disabled: decode full image\n");
+               printf("Resolution levels: %d\n", report.resolutionLevels);
+               printf("Codeblock size: %dx%d\n", report.cbX, report.cbY);
+
+               const double megabyte = 1024.0 * 1024.0;
+               printf("%7.2f ms 1) Tier-2 time (%d codeblocks)\n", report.s1_tier2 * 1000.0, report.codeblockCount);
+               printf("%7.2f ms 2) CPU->GPU copy time (%.2lf MB, %.2lf MB/s)\n",
+                       report.s2_copy * 1000.0,
+                       report.copyToGpu_size / megabyte,
+                       report.copyToGpu_size == 0 ? 0 : (report.copyToGpu_size / report.s2_copy / megabyte));
+               printf("%7.2f ms 3) Tier-1 time\n", report.s3_tier1 * 1000.0);
+               printf("%7.2f ms 4) DWT time\n", report.s6_dwt * 1000.0);
+               printf("%7.2f ms 5) Postprocessing time (MCT, DC-shift)\n", report.s7_postprocessing * 1000.0);
+               printf("              Output size = ");
+               if (report.outStreamSize < 1024)
+                       printf("%lld bytes", report.outStreamSize);
+               else
+                       printf("%.0f KB", report.outStreamSize / 1024.0f);
+               printf(" (%.1f:1)\n", report.outStreamSize == 0 ? 0 : (float)report.outStreamSize / report.inStreamSize);
+       }
+
+       printf("Total decode time for %d images = %.1f ms; %.1f FPS;\n", 1,
+               total_time * 1000.0, 1 / total_time);
+
+       fastGpuTimerDestroy(device_to_host_timer);
+
+       /* Close */
+
+       r = fastDecoderJ2kDestroy(decoder);
+       if (r != FAST_OK) {
+               throw FastvideoError ("J2kDestroy");
+       }
+       r = fastExportToHostDestroy(adapter);
+       if (r != FAST_OK) {
+               throw FastvideoError ("ExportToHostDestroy");
+       }
+
+       fastFree(decoded);
+}
+
diff --git a/src/lib/fastvideo.h b/src/lib/fastvideo.h
new file mode 100644 (file)
index 0000000..6717bde
--- /dev/null
@@ -0,0 +1,6 @@
+#include <dcp/data.h>
+#include <boost/shared_ptr.hpp>
+
+class OpenJPEGImage;
+
+boost::shared_ptr<OpenJPEGImage> fastvideo_decompess_j2k (dcp::Data data, int reduce);
diff --git a/wscript b/wscript
index 95e45fec38539f3065c7dca230ab171507a00d1b..010fe8791193599b4a38911849411eb668cec7bd 100644 (file)
--- a/wscript
+++ b/wscript
@@ -569,7 +569,9 @@ def configure(conf):
 
     # fastvideo
     if conf.options.fastvideo_sdk is not None:
-        conf.env.INCLUDES = [ os.path.join(conf.options.fastvideo_sdk, "fastvideo_sdk", "inc") ]
+        conf.env.INCLUDES_FASTVIDEO = [os.path.join(conf.options.fastvideo_sdk, "fastvideo_sdk", "inc") ]
+        conf.env.LIBPATH_FASTVIDEO = [ os.path.join(conf.options.fastvideo_sdk, "fastvideo_sdk", "lib") ]
+        conf.env.LIB_FASTVIDEO = [ 'fastvideo_decoder_j2k', 'fastvideo_sdk', 'cuda', 'cudart' ]
 
 
     # Other stuff