-Wwrite-strings
-fstack-protector
--param=ssp-buffer-size=4)
+endif()
+
+set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -DDEBUG=1")
+set(CMAKE_C_FLAGS_RELEASE "-O2")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
+if (CMAKE_COMPILER_IS_GNUCC)
if (STRICT_COMPILATION_CHECKS)
- add_flags(CMAKE_C_FLAGS
+ add_flags(STRICT_FLAGS
-Werror
# NOTE: Vanilla libusb-1.0.8 can't live with -pedantic-errors
-pedantic-errors
# NOTE: GCC >= 4.6 is needed for -Wunused-but-set-variable
-Wunused-but-set-variable)
+
+ add_flags(CMAKE_C_FLAGS_DEBUG ${STRICT_FLAGS})
+ add_flags(CMAKE_C_FLAGS_RELEASE ${STRICT_FLAGS})
+ add_flags(CMAKE_C_FLAGS_RELWITHDEBINFO ${STRICT_FLAGS})
endif()
endif()
-set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -DDEBUG=1")
-set(CMAKE_C_FLAGS_RELEASE "-O2")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
-
# Add library project
add_subdirectory(src)
add_subdirectory(examples)
$ mkdir build
$ cd build
- $ cmake ../ -DCMAKE_BUILD_TYPE=debug -DSTRICT_COMPILATION_CHECKS=ON
+ $ cmake -D CMAKE_BUILD_TYPE=debug -D STRICT_COMPILATION_CHECKS=ON ../
$ make
If you want to check the code with the ''sparse'' static analysis tool you
$ mkdir build
$ cd build
- $ cmake ../ -DCMAKE_C_COMPILER=cgcc
+ $ cmake -D CMAKE_C_COMPILER=cgcc ../
$ make
+=== Cross Builds
+
+If you want to build for MS Windows:
+
+ $ sudo aptitude install mingw-w64
+ $ mkdir build
+ $ cd build
+ $ wget -nv http://sourceforge.net/projects/libusbx/files/releases/1.0.11/Windows/libusbx-1.0.11-win.7z
+ $ 7z -olibusbx-1.0.11-win x libusbx-1.0.11-win.7z
+ $ cmake \
+ -D GNU_HOST=i686-w64-mingw32 \
+ -D CMAKE_TOOLCHAIN_FILE=../cmake_modules/mingw_cross_toolchain.cmake \
+ -D CMAKE_INSTALL_PREFIX=libam7xxx-win/ \
+ -D LIBUSB_1_INCLUDE_DIR=libusbx-1.0.11-win/include/libusbx-1.0 \
+ -D LIBUSB_1_LIBRARY=libusbx-1.0.11-win/MinGW32/dll/libusb-1.0.dll \
+ -D BUILD_AM7XXX-PLAY:BOOL=FALSE \
+ ../
+ $ make
+
+After that you will find libam7xxx.dll in lib/ and picoproj.exe in the bin/
+directory.
+
=== Valgrind
You can run the test program under the http://valgrind.org/[valgrind]
# old version of ffmpeg put header in $prefix/include/[ffmpeg]
# so try to find header in include directory
FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS ${headername}
- PATHS
+ HINTS
${FFMPEG_ROOT}/include
$ENV{FFMPEG_DIR}/include
$ENV{OSGDIR}/include
$ENV{OSG_ROOT}/include
+ PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
# so try to find lib${shortname}/header in include directory
IF(NOT FFMPEG_${varname}_INCLUDE_DIRS)
FIND_PATH(FFMPEG_${varname}_INCLUDE_DIRS lib${shortname}/${headername}
+ HINTS
${FFMPEG_ROOT}/include
$ENV{FFMPEG_DIR}/include
$ENV{OSGDIR}/include
$ENV{OSG_ROOT}/include
+ PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include
FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
NAMES ${shortname}
- PATHS
+ HINTS
${FFMPEG_ROOT}/lib
$ENV{FFMPEG_DIR}/lib
$ENV{OSGDIR}/lib
$ENV{OSG_ROOT}/lib
+ PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/lib
--- /dev/null
+SET(CMAKE_SYSTEM_NAME Windows)
+include(CMakeForceCompiler)
+IF("${GNU_HOST}" STREQUAL "")
+ SET(GNU_HOST i586-mingw32msvc)
+ENDIF()
+# Prefix detection only works with compiler id "GNU"
+CMAKE_FORCE_C_COMPILER(${GNU_HOST}-gcc GNU)
+# CMake doesn't automatically look for prefixed 'windres', do it manually:
+SET(CMAKE_RC_COMPILER ${GNU_HOST}-windres)
+include(CheckSymbolExists)
add_definitions("-D_POSIX_C_SOURCE=2") # for getopt()
add_definitions("-D_POSIX_SOURCE") # for sigaction
add_definitions("-D_BSD_SOURCE") # for strdup
include_directories(${CMAKE_SOURCE_DIR}/src/)
# Build a test app that sends a single picture
-add_executable(picoproj picoproj.c)
-target_link_libraries(picoproj am7xxx)
-install(TARGETS picoproj
- DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+option(BUILD_PICOPROJ "Build a test app that sends a single picture" TRUE)
+if(BUILD_PICOPROJ)
+ add_executable(picoproj picoproj.c)
+ target_link_libraries(picoproj am7xxx)
+ install(TARGETS picoproj
+ DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+endif()
# Build a more complete example
-find_package(FFmpeg REQUIRED)
+option(BUILD_AM7XXX-PLAY "Build a more complete example: am7xxx-play" TRUE)
+if(BUILD_AM7XXX-PLAY)
+ find_package(FFmpeg REQUIRED)
+ set(CMAKE_REQUIRED_LIBRARIES ${FFMPEG_LIBRARIES})
+ set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
+ check_symbol_exists(avformat_open_input
+ "${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat/avformat.h"
+ HAVE_AVFORMAT_OPEN_INPUT)
+ if(NOT HAVE_AVFORMAT_OPEN_INPUT)
+ message(FATAL_ERROR
+ "Function avformat_open_input missing. Please use a newer FFmpeg release.")
+ endif()
-include_directories(${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS})
-include_directories(${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
-include_directories(${FFMPEG_LIBSWSCALE_INCLUDE_DIRS})
+ include_directories(${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS})
+ include_directories(${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS})
+ include_directories(${FFMPEG_LIBSWSCALE_INCLUDE_DIRS})
-# xcb is used to retrieve the full screen dimensions when using x11grab
-# as input format
-find_package(XCB)
-if (XCB_FOUND)
- add_definitions("${LIBXCB_DEFINITIONS} -DHAVE_XCB")
- include_directories(${LIBXCB_INCLUDE_DIRS})
-endif()
+ # xcb is used to retrieve the full screen dimensions when using x11grab
+ # as input format
+ find_package(XCB)
+ if (XCB_FOUND)
+ add_definitions("${LIBXCB_DEFINITIONS} -DHAVE_XCB")
+ include_directories(${LIBXCB_INCLUDE_DIRS})
+ endif()
-add_executable(am7xxx-play am7xxx-play.c)
+ add_executable(am7xxx-play am7xxx-play.c)
-target_link_libraries(am7xxx-play am7xxx
- ${FFMPEG_LIBRARIES}
- ${FFMPEG_LIBSWSCALE_LIBRARIES}
- ${LIBXCB_LIBRARIES})
-install(TARGETS am7xxx-play
- DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+ target_link_libraries(am7xxx-play am7xxx
+ ${FFMPEG_LIBRARIES}
+ ${FFMPEG_LIBSWSCALE_LIBRARIES}
+ ${LIBXCB_LIBRARIES})
+ install(TARGETS am7xxx-play
+ DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+endif()
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int opt;
char filename[FILENAME_MAX] = {0};
- int image_fd;
+ FILE *image_fp;
struct stat st;
am7xxx_context *ctx;
am7xxx_device *dev;
while ((opt = getopt(argc, argv, "f:F:l:p:W:H:h")) != -1) {
switch (opt) {
case 'f':
+ if (filename[0] != '\0')
+ fprintf(stderr, "Warning: image file already specified\n");
strncpy(filename, optarg, FILENAME_MAX);
break;
case 'F':
goto out;
}
- image_fd = open(filename, O_RDONLY);
- if (image_fd < 0) {
- perror("open");
+ image_fp = fopen(filename, "rb");
+ if (image_fp == NULL) {
+ perror("fopen");
exit_code = EXIT_FAILURE;
goto out;
}
- if (fstat(image_fd, &st) < 0) {
+ if (fstat(fileno(image_fp), &st) < 0) {
perror("fstat");
exit_code = EXIT_FAILURE;
- goto out_close_image_fd;
+ goto out_close_image_fp;
}
size = st.st_size;
- image = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, image_fd, 0);
+ image = malloc(size * sizeof(unsigned char));
if (image == NULL) {
- perror("mmap");
+ perror("malloc");
exit_code = EXIT_FAILURE;
- goto out_close_image_fd;
+ goto out_close_image_fp;
+ }
+
+ ret = fread(image, size, 1, image_fp);
+ if (ret != 1) {
+ if (feof(image_fp))
+ fprintf(stderr, "Unexpected end of file.\n");
+ else if (ferror(image_fp))
+ perror("fread");
+ else
+ fprintf(stderr, "Unexpected error condition.\n");
+
+ goto out_free_image;
}
ret = am7xxx_init(&ctx);
if (ret < 0) {
perror("am7xxx_init");
exit_code = EXIT_FAILURE;
- goto out_munmap;
+ goto out_free_image;
}
am7xxx_set_log_level(ctx, log_level);
ret = am7xxx_get_device_info(dev, &device_info);
if (ret < 0) {
- perror("am7xxx_get_info");
+ perror("am7xxx_get_device_info");
exit_code = EXIT_FAILURE;
goto cleanup;
}
cleanup:
am7xxx_shutdown(ctx);
-out_munmap:
- ret = munmap(image, size);
- if (ret < 0)
- perror("munmap");
+out_free_image:
+ free(image);
-out_close_image_fd:
- ret = close(image_fd);
- if (ret < 0)
- perror("close");
+out_close_image_fp:
+ ret = fclose(image_fp);
+ if (ret == EOF)
+ perror("fclose");
out:
exit(exit_code);
install(TARGETS am7xxx-static
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
-find_library(MATH_LIB m)
+if(NOT WIN32)
+ find_library(MATH_LIB m)
+else()
+ # not needed on windows
+ set(MATH_LIB "")
+endif()
target_link_libraries(am7xxx ${MATH_LIB} ${LIBUSB_1_LIBRARIES})
target_link_libraries(am7xxx-static ${MATH_LIB} ${LIBUSB_1_LIBRARIES})
trace_dump_buffer(dev->ctx, "sending -->", buffer, len);
- ret = libusb_bulk_transfer(dev->usb_device, 1, buffer, len, &transferred, 0);
+ ret = libusb_bulk_transfer(dev->usb_device, 0x1, buffer, len, &transferred, 0);
if (ret != 0 || (unsigned int)transferred != len) {
error(dev->ctx, "ret: %d\ttransferred: %d (expected %u)\n",
ret, transferred, len);
goto out;
}
- libusb_set_configuration((*dev)->usb_device, 1);
+ libusb_set_configuration((*dev)->usb_device, 2);
libusb_claim_interface((*dev)->usb_device, 0);
goto out;
}
*/
#include <string.h>
+
+#ifdef __MINGW32__
+#define le32toh(x) (x)
+#define htole32(x) (x)
+#else
#include <endian.h>
+#endif
#include "serialize.h"