diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a81965..a485363 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,8 @@ if (WIN32) endif (WIN32) if (UNIX) - SET(COMPILER_FLAGS "-fPIC" ) - SET(COMPILER_FLAGS_W_OMP "-fopenmp") + SET(COMPILER_FLAGS -fPIC -O3) + SET(COMPILER_FLAGS_W_OMP -fopenmp -O3) SET(ADDITIONAL_LIBS "-luuid -lpthread -lgomp") SET(TOY_LIBS "-lm") endif (UNIX) diff --git a/Codec/decoder.c b/Codec/decoder.c index 9078be9..7714c3f 100644 --- a/Codec/decoder.c +++ b/Codec/decoder.c @@ -13146,9 +13146,10 @@ void ComputeOutputDimensions(DECODER *decoder, int frame, #if (1 && DEBUG) FILE *logfile = decoder->logfile; +#endif CODEC_STATE *codec = &decoder->codec; int num_channels = codec->num_channels; -#endif + FRAME_INFO *info = &decoder->frame; //int progressive = codec->progressive; @@ -13177,13 +13178,17 @@ void ComputeOutputDimensions(DECODER *decoder, int frame, { case DECODED_RESOLUTION_FULL: case DECODED_RESOLUTION_HALF_HORIZONTAL: +#if DEBUG assert(AllTransformBandsValid(transform_array, num_channels, frame)); +#endif decoded_scale = 2; wavelet = transform_array[0]->wavelet[0]; break; case DECODED_RESOLUTION_HALF: +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame)); +#endif decoded_scale = 1; wavelet = transform_array[0]->wavelet[0]; break; @@ -13191,7 +13196,9 @@ void ComputeOutputDimensions(DECODER *decoder, int frame, case DECODED_RESOLUTION_QUARTER: if(decoder->codec.encoded_format == ENCODED_FORMAT_BAYER) { +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame)); +#endif decoded_scale = 1; wavelet = transform_array[0]->wavelet[0]; } @@ -13390,7 +13397,9 @@ void ReconstructSampleFrameToBuffer(DECODER *decoder, int frame, uint8_t *output { case DECODED_RESOLUTION_FULL: case DECODED_RESOLUTION_HALF_HORIZONTAL_DEBAYER: +#if DEBUG assert(AllTransformBandsValid(transform_array, num_channels, frame)); +#endif wavelet = transform_array[0]->wavelet[0]; // Get the decoded frame dimensions assert(wavelet != NULL); @@ -13401,7 +13410,9 @@ void ReconstructSampleFrameToBuffer(DECODER *decoder, int frame, uint8_t *output break; case DECODED_RESOLUTION_HALF: +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame)); +#endif wavelet = transform_array[0]->wavelet[0]; // Get the decoded frame dimensions assert(wavelet != NULL); @@ -13412,7 +13423,9 @@ void ReconstructSampleFrameToBuffer(DECODER *decoder, int frame, uint8_t *output break; case DECODED_RESOLUTION_HALF_HORIZONTAL: +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame)); +#endif wavelet = transform_array[0]->wavelet[0]; // Get the decoded frame dimensions assert(wavelet != NULL); @@ -13425,7 +13438,9 @@ void ReconstructSampleFrameToBuffer(DECODER *decoder, int frame, uint8_t *output case DECODED_RESOLUTION_QUARTER: if(decoder->codec.encoded_format == ENCODED_FORMAT_BAYER) { +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame)); +#endif wavelet = transform_array[0]->wavelet[0]; } else @@ -16485,8 +16500,9 @@ void ReconstructQuarterFrame(DECODER *decoder, int num_channels, PIXEL *channel_row_ptr[CODEC_MAX_CHANNELS]; // Check that there is enough space for the intermediate results from each channel +#if DEBUG assert(output_width * sizeof(PIXEL) < buffer_size); - +#endif ComputeCube(decoder); // Get pointers into the wavelets for each channel @@ -21309,7 +21325,9 @@ void TransformInverseFrameToYUV(TRANSFORM *transform[], int frame_index, int num assert(0 < num_channels && num_channels <= TRANSFORM_MAX_CHANNELS); // Check that the buffer is large enough +#if DEBUG assert((2 * num_channels * temporal_row_size) <= buffer_size); +#endif // Allocate buffers for a single row of lowpass and highpass temporal coefficients // and initialize the arrays of row pointers into the horizontal transform bands @@ -21854,7 +21872,9 @@ void TransformInverseFrameToRow16u(DECODER *decoder, TRANSFORM *transform[], int // Buffer must be large enough for two rows of temporal coefficients (lowpass and highpass) // plus the buffer used by the inverse horizontal transform for its intermediate results +#if DEBUG assert((2 * temporal_row_size) <= buffer_size); +#endif // Allocate buffers for one row of lowpass and highpass temporal coefficients temporal_lowpass = (PIXEL *)&buffer[0]; @@ -22452,7 +22472,9 @@ void TransformInverseFrameToBuffer(TRANSFORM *transform[], int frame_index, int // Allocate buffer space for the intermediate YUV data yuv_buffer = buffer + temporal_buffer_size; yuv_buffer_size = buffer_size - temporal_buffer_size; +#if DEBUG assert(yuv_buffer_size >= 2 * yuv_row_size); +#endif if (inverted) { @@ -24171,19 +24193,25 @@ void GetDecodedFrameDimensions(TRANSFORM **transform_array, { case DECODED_RESOLUTION_FULL_DEBAYER: case DECODED_RESOLUTION_HALF_HORIZONTAL_DEBAYER: +#if DEBUG assert(AllTransformBandsValid(transform_array, num_channels, frame_index)); +#endif decoded_scale = 2; wavelet = transform_array[0]->wavelet[0]; break; case DECODED_RESOLUTION_FULL: +#if DEBUG assert(AllTransformBandsValid(transform_array, num_channels, frame_index)); +#endif decoded_scale = 2; wavelet = transform_array[0]->wavelet[0]; break; case DECODED_RESOLUTION_HALF_NODEBAYER: case DECODED_RESOLUTION_HALF: +#if DEBUG assert(AllLowpassBandsValid(transform_array, num_channels, frame_index)); +#endif decoded_scale = 1; wavelet = transform_array[0]->wavelet[0]; break; diff --git a/Codec/encoder.c b/Codec/encoder.c index 21b8dd8..1d6eb4b 100644 --- a/Codec/encoder.c +++ b/Codec/encoder.c @@ -7087,7 +7087,9 @@ void EncodeQuantizedGroup(ENCODER *encoder, TRANSFORM *transform[], int num_tran int subband = 0; // Verify that the codebooks are valid +#if DEBUG assert(ValidCodebooks()); +#endif // Verify that there are three channels assert(num_transforms == 3); @@ -7485,7 +7487,9 @@ void EncodeQuantizedGroup(ENCODER *encoder, TRANSFORM *transform[], int num_tran // Verify that the codebooks are valid - assert(ValidCodebooks()); +#if DEBUG + assert(ValidCodebooks());; +#endif // Verify that there are three channels //assert(num_transforms == 3); //DAN06302004 @@ -10610,7 +10614,9 @@ void EncodeQuantizedGroupThreaded(ENCODER *encoder, TRANSFORM *transform[], int int subband = 0; // Verify that the codebooks are valid - assert(ValidCodebooks()); +#if DEBUG + assert(ValidCodebooks());; +#endif // Verify that there are three channels assert(num_transforms == 3); @@ -10878,7 +10884,9 @@ void EncodeQuantizedChannel(ENCODER *encoder, TRANSFORM *transform, int channel, int subband = 0; // Verify that the codebooks are valid +#if DEBUG assert(ValidCodebooks()); +#endif // Verify that there are three channels //assert(num_transforms == 3); diff --git a/Codec/wavelet.c b/Codec/wavelet.c index 826c1b6..c588462 100644 --- a/Codec/wavelet.c +++ b/Codec/wavelet.c @@ -3023,8 +3023,10 @@ void TransformForwardSpatialBYR3(uint8_t *input, int input_pitch, FRAME_INFO *fr #endif // Check the input dimensions +#if DEBUG assert(roi.width == frame_width); assert(roi.height == frame_height); +#endif for (channel = 0; channel < num_channels; channel++) { @@ -3640,8 +3642,10 @@ void TransformForwardSpatialRGB30(uint8_t *input, int input_pitch, FRAME_INFO *f // Check the input dimensions +#if DEBUG assert(roi.width == frame_width); assert(roi.height == frame_height); +#endif for (channel = 0; channel < num_channels; channel++) { diff --git a/EncoderSDK/CFHDEncoderPool.cpp b/EncoderSDK/CFHDEncoderPool.cpp index 3d7255e..16cf0ba 100644 --- a/EncoderSDK/CFHDEncoderPool.cpp +++ b/EncoderSDK/CFHDEncoderPool.cpp @@ -766,11 +766,14 @@ CFHD_ReleaseEncoderPool(CFHD_EncoderPoolRef encoderPoolRef) try { CEncoderPool *encoderPool = GetEncoderPool(encoderPoolRef); - delete encoderPool; +#ifdef _WINDOWS + delete encoderPool; //TODO need find out why this isn't working on Linux. +#endif return CFHD_ERROR_OKAY; } catch (...) { + printf("CFHD_ReleaseEncoderPool error\n"); return CFHD_ERROR_UNEXPECTED; } } diff --git a/Example/TestCFHD.cpp b/Example/TestCFHD.cpp index 608b2e1..e99924c 100644 --- a/Example/TestCFHD.cpp +++ b/Example/TestCFHD.cpp @@ -33,7 +33,7 @@ #include "CFHDMetadata.h" -#include "MP4reader.h" +#include "mp4reader.h" #define QBIST_SEED 50 #define ENABLE_3D 0 //2D or 3D-stereoscope encodign @@ -69,7 +69,7 @@ #define BASENAME_OUT "OUTD" #else #define MAX_DEC_FRAMES 5 -#define MAX_ENC_FRAMES 250 +#define MAX_ENC_FRAMES 500 #define MAX_QUAL_FRAMES 10 #define POOL_THREADS 16 #define POOL_QUEUE_LENGTH 24 @@ -413,7 +413,11 @@ CFHD_Error DecodeMOVIE(char *filename, char *ext) float length; void *handle; +#ifdef _WINDOWS if (0 == stricmp("AVI", ext)) AVI = 1; +#else + if (0 == strcasecmp("AVI", ext)) AVI = 1; +#endif if(AVI) handle = OpenAVISource(filename, AVI_TRAK_TYPE, AVI_TRAK_SUBTYPE); @@ -1066,18 +1070,23 @@ CFHD_Error EncodeDecodeQualityTest() int main(int argc, char **argv) { + int showusage = 0; CFHD_Error error = CFHD_ERROR_OKAY; - if (argc == 1) + if (argc != 2) { -#if DO_DECODE - error = EncodeDecodeQualityTest(); -#else - error = EncodeSpeedTest(); -#endif - if (error) printf("error code: %d\n", error); + showusage = 1; } - else + else if (argv[1][0] == '-') + { + if (argv[1][1] == 'd' || argv[1][1] == 'D') + error = EncodeDecodeQualityTest(); + else if (argv[1][1] == 'e' || argv[1][1] == 'E') + error = EncodeSpeedTest(); + else + showusage = 1; + } + else { char ext[4] = ""; int len = strlen(argv[1]); @@ -1092,6 +1101,13 @@ int main(int argc, char **argv) error = DecodeMOVIE(argv[1], ext); } + if (showusage) + { + printf("usage: %s [switches] or \n", argv[0]); + printf(" -D = decoder tester\n"); + printf(" -E = encoder tester\n"); + } + if (error) printf("error code: %d\n", error); return error; } diff --git a/Example/mp4reader.cpp b/Example/mp4reader.cpp index 13de1bd..21b1fd7 100644 --- a/Example/mp4reader.cpp +++ b/Example/mp4reader.cpp @@ -99,7 +99,7 @@ void *OpenMP4Source(char *filename, uint32_t traktype, uint32_t traksubtype) // #ifdef _WINDOWS fopen_s(&mp4->mediafp, filename, "rb"); #else - mediafp = fopen(filename, "rb"); + mp4->mediafp = fopen(filename, "rb"); #endif if (mp4->mediafp) @@ -478,6 +478,11 @@ void *OpenMP4Source(char *filename, uint32_t traktype, uint32_t traksubtype) // } } while (len > 0); } + else + { + printf("Could not open %s for input\n", filename); + exit(1); + } return (void *)mp4; } diff --git a/Example/readavi.cpp b/Example/readavi.cpp index 7aa13f4..6edcd27 100644 --- a/Example/readavi.cpp +++ b/Example/readavi.cpp @@ -16,8 +16,11 @@ This code falls under the BSD license. #include "fileio.h" #include "mp4reader.h" +#ifdef _WINDOWS #define STRINGCASECOMPARE _stricmp -//#define STRINGCASECOMPARE STRINGCASECOMPARE +#else +#define STRINGCASECOMPARE strcasecmp +#endif #define PRINT_AVI_STRUCTURE 0 @@ -624,7 +627,7 @@ void *OpenAVISource(char *filename, uint32_t traktype, uint32_t subtype) #ifdef _WINDOWS fopen_s(&mp4->mediafp, filename, "rb"); #else - mediafp = fopen(filename, "rb"); + mp4->mediafp = fopen(filename, "rb"); #endif if (mp4->mediafp == 0)