diff --git a/configure.ac b/configure.ac index c76bd5a35..937312385 100644 --- a/configure.ac +++ b/configure.ac @@ -1275,6 +1275,7 @@ then JPEG_COMMON_OBJ="src/video_compress/jpeg.o libgpujpeg/libgpujpeg.a" JPEG_DECOMPRESS_OBJ="src/video_decompress/jpeg.o " LINKER=$CXX + AC_DEFINE([HAVE_CUDA], [1], [CUDA is present on the system]) AC_DEFINE([HAVE_JPEG], [1], [Build with JPEG support]) AC_SUBST(JPEG_COMPRESS_LIB_TARGET, "lib/ultragrid/vcompress_jpeg.so.$video_compress_abi_version") AC_SUBST(JPEG_DECOMPRESS_LIB_TARGET, "lib/ultragrid/vdecompress_jpeg.so.$video_decompress_abi_version") diff --git a/src/host.h b/src/host.h index 518eed610..a61a017fc 100644 --- a/src/host.h +++ b/src/host.h @@ -63,4 +63,6 @@ extern void (*exit_uv)(int status); extern unsigned int audio_capture_channels; +extern unsigned int cuda_device; + #endif diff --git a/src/main.c b/src/main.c index e28290360..29b655fc1 100644 --- a/src/main.c +++ b/src/main.c @@ -55,10 +55,15 @@ #include #include #include +#ifdef HAVE_CONFIG_H #include "config.h" #include "config_unix.h" #include "config_win32.h" +#endif // HAVE_CONFIG_H #include "debug.h" +#ifdef HAVE_CUDA +#include "libgpujpeg/gpujpeg_common.h" +#endif // HAVE_CUDA #include "perf.h" #include "rtp/decoders.h" #include "rtp/rtp.h" @@ -103,6 +108,7 @@ #define AUDIO_CAPTURE_CHANNELS (('a' << 8) | 'c') #define AUDIO_SCALE (('a' << 8) | 's') #define ECHO_CANCELLATION (('E' << 8) | 'C') +#define CUDA_DEVICE (('C' << 8) | 'D') struct state_uv { int recv_port_number; @@ -149,6 +155,7 @@ volatile int wait_to_finish = FALSE; volatile int threads_joined = FALSE; static int exit_status = EXIT_SUCCESS; +unsigned int cuda_device = 0; unsigned int audio_capture_channels = 2; uint32_t RTT = 0; /* this is computed by handle_rr in rtp_callback */ @@ -261,8 +268,11 @@ static void usage(void) printf("\t \tHow many of input channels should be captured (default 2).\n"); printf("\t \t\n"); printf("\n"); + printf("\n"); printf("\t--echo-cancellation \tapply acustic echo cancellation to audio\n"); printf("\n"); + printf("\t--cuda-device [|help]\tuse specified CUDA device\n"); + printf("\n"); printf("\taddress(es) \tdestination address\n"); printf("\n"); printf("\t \tIf comma-separated list of addresses\n"); @@ -836,6 +846,7 @@ int main(int argc, char *argv[]) {"audio-scale", required_argument, 0, AUDIO_SCALE}, {"audio-capture-channels", required_argument, 0, AUDIO_CAPTURE_CHANNELS}, {"echo-cancellation", no_argument, 0, ECHO_CANCELLATION}, + {"cuda-device", required_argument, 0, CUDA_DEVICE}, {0, 0, 0, 0} }; int option_index = 0; @@ -969,6 +980,19 @@ int main(int argc, char *argv[]) case ECHO_CANCELLATION: echo_cancellation = true; break; + case CUDA_DEVICE: +#ifdef HAVE_CUDA + if(strcmp("help", optarg) == 0) { + printf("\nCUDA devices:\n"); + gpujpeg_print_devices_info(); + } else { + cuda_device = atoi(optarg); + } + break; +#else + fprintf(stderr, "CUDA support is not enabled!\n"); + return EXIT_FAIL_USAGE; +#endif // HAVE_CUDA default: usage(); return EXIT_FAIL_USAGE; diff --git a/src/video_compress/jpeg.c b/src/video_compress/jpeg.c index cd8419578..ec5e6c969 100644 --- a/src/video_compress/jpeg.c +++ b/src/video_compress/jpeg.c @@ -224,9 +224,7 @@ void * jpeg_compress_init(char * opts) if(opts && strcmp(opts, "help") == 0) { printf("JPEG comperssion usage:\n"); - printf("\t-c JPEG[:][:]]\n"); - printf("\nCUDA devices:\n"); - gpujpeg_print_devices_info(); + printf("\t-c JPEG[:]\n"); return NULL; } @@ -235,22 +233,13 @@ void * jpeg_compress_init(char * opts) gpujpeg_set_default_parameters(&s->encoder_param); tok = strtok_r(opts, ":", &save_ptr); s->encoder_param.quality = atoi(tok); - tok = strtok_r(NULL, ":", &save_ptr); - if(tok) { - int ret; - ret = gpujpeg_init_device(atoi(tok), TRUE); + int ret; + printf("Initializing CUDA device %d...\n", cuda_device); + ret = gpujpeg_init_device(cuda_device, TRUE); - if(ret != 0) { - fprintf(stderr, "[JPEG] initializing CUDA device %d failed.\n", atoi(tok)); - return NULL; - } - } else { - printf("Initializing CUDA device 0...\n"); - int ret = gpujpeg_init_device(0, TRUE); - if(ret != 0) { - fprintf(stderr, "[JPEG] initializing default CUDA device failed.\n"); - return NULL; - } + if(ret != 0) { + fprintf(stderr, "[JPEG] initializing CUDA device %d failed.\n", cuda_device); + return NULL; } tok = strtok_r(NULL, ":", &save_ptr); if(tok) { diff --git a/src/video_decompress/jpeg.c b/src/video_decompress/jpeg.c index c344a0ace..376c09887 100644 --- a/src/video_decompress/jpeg.c +++ b/src/video_decompress/jpeg.c @@ -45,14 +45,18 @@ * */ +#ifdef HAVE_CONFIG_H #include "config.h" #include "config_unix.h" +#include "config_win32.h" +#endif // HAVE_CONFIG_H #include "debug.h" +#include "host.h" +#include "video_codec.h" #include "video_decompress.h" #include "libgpujpeg/gpujpeg_decoder.h" //#include "compat/platform_semaphore.h" -#include "video_codec.h" #include #include #include "video_decompress/jpeg.h" @@ -93,12 +97,22 @@ static int configure_with(struct state_decompress_jpeg *s, struct video_desc des void * jpeg_decompress_init(void) { struct state_decompress_jpeg *s; - - s = (struct state_decompress_jpeg *) malloc(sizeof(struct state_decompress_jpeg)); - s->decoder = NULL; + s = (struct state_decompress_jpeg *) malloc(sizeof(struct state_decompress_jpeg)); + + s->decoder = NULL; s->pitch = 0; + int ret; + printf("Initializing CUDA device %d...\n", cuda_device); + ret = gpujpeg_init_device(cuda_device, TRUE); + if(ret != 0) { + fprintf(stderr, "[JPEG] initializing CUDA device %d failed.\n", cuda_device); + free(s); + return NULL; + } + + return s; }