├── .github └── workflows │ └── cineform.yml ├── .gitignore ├── AUTHORS.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Codec ├── DemoasicFrames.cpp ├── DemoasicFrames.h ├── InvertHorizontalStrip16s.c ├── RGB2YUV.c ├── RGB2YUV.h ├── allocator.c ├── allocator.h ├── bandfile.c ├── bandfile.h ├── bayer.c ├── bayer.h ├── bitstream.c ├── bitstream.h ├── buffer.c ├── buffer.h ├── codebooks.c ├── codebooks.h ├── codec.c ├── codec.h ├── color.h ├── config.h ├── convert.c ├── convert.h ├── counter.h ├── cpuid.c ├── cpuid.h ├── debug.c ├── debug.h ├── decoder.c ├── decoder.h ├── dither.c ├── dither.h ├── draw.c ├── draw.h ├── dump.c ├── dump.h ├── encoder.c ├── encoder.h ├── entropy_threading.c ├── error.h ├── exception.cpp ├── exception.h ├── filter.c ├── filter.h ├── frame.c ├── frame.h ├── image.c ├── image.h ├── keyframes.c ├── keyframes.h ├── lutpath.cpp ├── lutpath.h ├── metadata.c ├── metadata.h ├── quantize.c ├── quantize.h ├── recursive.c ├── recursive.h ├── scanner.c ├── scanner.h ├── spatial.c ├── spatial.h ├── stats.c ├── stats.h ├── stdafx.h ├── swap.c ├── swap.h ├── temporal.c ├── temporal.h ├── thread.c ├── thread.h ├── thumbnail.c ├── thumbnail.h ├── timing.c ├── timing.h ├── vlc.c ├── vlc.h ├── wavelet.c └── wavelet.h ├── Common ├── AVIExtendedHeader.h ├── CFHDAllocator.h ├── CFHDDecoder.h ├── CFHDEncoder.h ├── CFHDError.h ├── CFHDMetadata.h ├── CFHDMetadataTags.h ├── CFHDSampleHeader.h ├── CFHDTypes.h ├── Condition.h ├── IAllocator.h ├── Lock.h ├── MessageQueue.cpp ├── MessageQueue.h ├── SampleMetadata.h ├── StdAfx.h ├── ThreadMessage.cpp ├── ThreadMessage.h ├── ThreadPool.cpp ├── ThreadPool.h ├── fsm17.inc ├── fsm18.inc ├── fsm9.inc ├── macdefs.h ├── table17.inc ├── table18.inc ├── table9.inc └── ver.h ├── ConvertLib ├── Bilinear.cpp ├── Bilinear.h ├── ColorFlags.h ├── ColorMatrix.cpp ├── ColorMatrix.h ├── ConvertLib.h ├── ConvertYUV8.cpp ├── ConvertYUV8.h ├── DPXConverter.cpp ├── DPXConverter.h ├── ImageConverter.cpp ├── ImageConverter.h ├── ImageScaler.cpp ├── ImageScaler.h ├── MemAlloc.cpp ├── MemAlloc.h └── StdAfx.h ├── DecoderSDK ├── CFHDDecoder.cpp ├── CFHDMetadata.cpp ├── Conversion.cpp ├── Conversion.h ├── ISampleDecoder.cpp ├── ISampleDecoder.h ├── SampleDecoder.cpp ├── SampleDecoder.h ├── SampleMetadata.cpp ├── SampleMetadata.h ├── StdAfx.h ├── resource.h └── ver.h ├── EncoderSDK ├── Allocator.h ├── AsyncEncoder.cpp ├── AsyncEncoder.h ├── CFHDEncoder.cpp ├── CFHDEncoderMetadata.cpp ├── CFHDEncoderPool.cpp ├── EncoderPool.cpp ├── EncoderPool.h ├── EncoderQueue.cpp ├── EncoderQueue.h ├── Interface.h ├── MetadataWriter.cpp ├── MetadataWriter.h ├── SampleEncoder.cpp ├── SampleEncoder.h ├── StdAfx.h ├── VideoBuffers.cpp ├── VideoBuffers.h └── ver.h ├── Example ├── TestCFHD.cpp ├── WaveletDemo │ ├── makefile │ ├── utils.c │ ├── utils.h │ └── wavelets.c ├── avi.h ├── classicQBist.cpp ├── fileio.cpp ├── fileio.h ├── misc │ ├── CFHDDecoderStub.cpp │ └── CFHDEncoderStub.cpp ├── mp4reader.cpp ├── mp4reader.h ├── qbist.cpp ├── qbist.h ├── readavi.cpp ├── stdafx.h ├── targetver.h ├── utils.cpp ├── utils.h └── videos │ ├── CFHDsample422.AVI │ └── CFHDsample444.AVI ├── GPDeps ├── LICENSE-APACHE ├── LICENSE-MIT ├── LICENSE.txt ├── README.md ├── WarpLib ├── GeoMesh.c ├── GeoMesh.h ├── GeoMeshApply.c ├── GeoMeshApply.h ├── GeoMeshCache.c ├── GeoMeshGoPro.c ├── GeoMeshInterp.c ├── GeoMeshInterp.h ├── GeoMeshIpl.h ├── GeoMeshPrivate.h ├── GeoMeshTransform.c ├── GeoMeshYuy2.c ├── GeoMeshYuy2.h ├── WarpLib.h └── sse_types.h ├── data ├── readmegfx │ ├── level1-640.png │ ├── level1D-640.png │ ├── level2-640.png │ ├── level3-640.png │ └── source-640.png └── testpatt.pgm ├── docs ├── README.md ├── _config.yml ├── favicon.png └── readmegfx │ ├── CF-Logo-960.png │ ├── CF-Logo-OLDsm.png │ ├── CF-Logo-oldest.png │ ├── level1-640.png │ ├── level1D-640.png │ ├── level2-640.png │ ├── level3-640.png │ └── source-640.png ├── libcineformsdk.pc.cmake └── ucm.cmake /.github/workflows/cineform.yml: -------------------------------------------------------------------------------- 1 | name: cineform 2 | on: 3 | push: 4 | pull_request: 5 | 6 | env: 7 | DEBIAN_FRONTEND: noninteractive 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | include: 15 | - os: ubuntu-18.04 16 | CC: ccache gcc 17 | CXX: ccache g++ 18 | - os: ubuntu-18.04 19 | CC: ccache clang 20 | CXX: ccache clang++ 21 | - os: macos-10.15 22 | CC: ccache clang 23 | CXX: ccache clang++ 24 | runs-on: ${{ matrix.os }} 25 | env: 26 | CC: ${{ matrix.CC }} 27 | CXX: ${{ matrix.CXX }} 28 | steps: 29 | - name: Install dependencies (ubuntu) 30 | if: matrix.os == 'ubuntu-18.04' 31 | run: | 32 | sudo apt-get update 33 | sudo -E apt-get -yq install ccache uuid-dev 34 | case "$CC" in 35 | *gcc) sudo -E apt-get -yq install gcc g++ ;; 36 | *clang) sudo -E apt-get -yq install clang ;; 37 | esac 38 | $CC --version 39 | cmake --version 40 | ccache --version 41 | - name: Install dependencies (mac) 42 | if: matrix.os == 'macos-10.15' 43 | run: | 44 | brew update 45 | brew install ccache 46 | $CC --version 47 | ccache --version 48 | - uses: actions/checkout@v2 49 | - name: Cache ccache files 50 | uses: actions/cache@v1.1.2 51 | with: 52 | path: ~/.ccache 53 | key: ${{ runner.os }}-${{ matrix.CC }}-${{ hashFiles('**/*.c') }}-${{ hashFiles('**/*.cpp') }} 54 | - name: Run CMake 55 | run: | 56 | [ -d "$HOME/.ccache" ] && sudo chown -R "$USER": "$HOME/.ccache" 57 | cmake -S . -B build 58 | - name: Run make 59 | run: | 60 | sudo make -j "$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)" -C build 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | *.zip 34 | *.rar 35 | 36 | # Folders 37 | *build* 38 | *.dir 39 | *Win32* 40 | *x64* 41 | *xcode* 42 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # CineForm-SDK Authors List 2 | 3 | ##### Please add entries to the bottom of the list in the following format 4 | * `@GitHub UserName (Required) - [Name and/or Organization](link)` 5 | 6 | # Authors 7 | * @dnewman-gpsw - [GoPro, Inc.](https://github.com/GoPro/cineform-sdk) 8 | 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Want to contribute to cineform-sdk? Please take a moment to review this document in order to make your contribution and the process around it easier and more effective for everyone. 4 | 5 | ## Issue tracker 6 | 7 | The [issue tracker](https://www.github.com/gopro/cineform-sdk/issues) is the best place to report a bug. Please make sure to check the following guide on how to use the issue tracker : 8 | 9 | ### Reporting a bug 10 | 11 | - If you really think it is a bug, consult the list of issues and make sure nobody has reported it yet. This will avoid duplication of effort. 12 | - If it hasn't been reported yet, submit a new issue. 13 | 14 | ### Suggesting a feature 15 | 16 | - Consult the roadmap within [projects](https://github.com/gopro/cineform-sdk/projects) to know if it is planned. 17 | - Consult the list of things that **won't** be implemented. 18 | - Read up on what type of feature requests are accepted. 19 | - See if anybody has not requested the feature yet. 20 | - If it hasn't beed requested yet, submit a new request as an issue. 21 | 22 | ### Submitting a pull-request 23 | 24 | - All contributors must sign a [contributor license agreement (CLA)](https://cla.gopro.com). Your code will not be reviewed and accepted by the Admins until this has been received. 25 | - To be sure your changes could be interesting and accepted, ask about your patch on Discourse. 26 | - Fork the repository and work on the `master` branch, while respecting the imposed guidelines. 27 | - Add tests if needed, and make sure that all of them pass. 28 | - Document the code according to the guidelines, and make sure the build is OK. If you encounter some problem with the Closure Compiler part, don't hesitate to ask. 29 | - Submit a pull request for your changes. 30 | - The Admins will review your work and may optionally request conformance, functional or other changes. Work with them to resolve any issues. 31 | - Upon acceptance, your code will be added to the main branch and available for all. 32 | -------------------------------------------------------------------------------- /Codec/DemoasicFrames.h: -------------------------------------------------------------------------------- 1 | /*! @file DemoasicFrames.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _DEMOSAICFRAMESLIB_H 23 | #define _DEMOSAICFRAMESLIB_H 24 | 25 | #include "../Common/AVIExtendedHeader.h" 26 | #include "codec.h" 27 | 28 | typedef int DEBAYER_ORDERING; 29 | 30 | #define BAYER_FORMAT_RED_GRN 0 31 | #define BAYER_FORMAT_GRN_RED 1 32 | #define BAYER_FORMAT_GRN_BLU 2 33 | #define BAYER_FORMAT_BLU_GRN 3 34 | 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | void DebayerLine(int width, int height, int linenum, 41 | unsigned short *bayer_source, 42 | DEBAYER_ORDERING order, 43 | unsigned short *RGB_output, 44 | int highquality, 45 | int sharpening); 46 | 47 | void ColorDifference2Bayer(int width, 48 | unsigned short *srcptr, 49 | int bayer_pitch, 50 | int bayer_format); 51 | 52 | void BayerRippleFilter( int width, 53 | unsigned short *srcptr, 54 | int bayer_pitch, 55 | int bayer_formatm, 56 | unsigned short *srcbase); 57 | 58 | float *LoadCube64_3DLUT(DECODER *decoder, CFHDDATA *cfhddata, int *lutsize); 59 | float *ResetCube64_3DLUT(DECODER *decoder, int cube_base); 60 | 61 | void VerticalOnlyDebayerLine(int width, int height, int linenum, 62 | unsigned short *bayer_source, 63 | DEBAYER_ORDERING order, 64 | unsigned short *RGB_output, 65 | int highquality, 66 | int sharpening); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /Codec/RGB2YUV.h: -------------------------------------------------------------------------------- 1 | /*! @file RGB2YUV.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | 24 | #ifndef COLOR_SPACE_BT_601 25 | #define COLOR_SPACE_BT_601 1 26 | #define COLOR_SPACE_BT_709 2 // BT 709 versus 601 YUV source 27 | #define COLOR_SPACE_VS_RGB 4 // RGB that ranges normally from 16 to 235 just like luma 28 | #define COLOR_SPACE_422_TO_444 8 29 | #define COLOR_SPACE_8_PIXEL_PLANAR 16 30 | 31 | #define COLOR_SPACE_VS_709 (COLOR_SPACE_BT_709 | COLOR_SPACE_VS_RGB) 32 | #define COLOR_SPACE_VS_601 (COLOR_SPACE_BT_601 | COLOR_SPACE_VS_RGB) 33 | #define COLOR_SPACE_CG_709 (COLOR_SPACE_BT_709) 34 | #define COLOR_SPACE_CG_601 (COLOR_SPACE_BT_601) 35 | 36 | #define COLOR_SPACE_DEFAULT COLOR_SPACE_CG_709 37 | #endif 38 | 39 | #define COLOR_SPACE_MASK (COLOR_SPACE_BT_601|COLOR_SPACE_BT_709|COLOR_SPACE_VS_RGB) 40 | 41 | 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | //TODO: Use standard integer datatypes for the function parameters 48 | 49 | void UpShift16(unsigned short *in_rgb16, int pixels, int upshift, int saturate); 50 | void ChannelYUYV16toPlanarYUV16(unsigned short *planar_output[], unsigned short *out_YUV, int width, int colorspace); 51 | void ChunkyRGB16toPlanarRGB16(unsigned short *in_rgb16, unsigned short *out_rgb16, int width); 52 | void ChunkyRGB8toPlanarRGB16(unsigned char *in_rgb8, unsigned short *out_rgb16, int width); 53 | void ChunkyRGB8toChunkyRGB16(unsigned char *in_rgb8, unsigned short *out_rgb16, int width); 54 | void ChunkyBGR8toPlanarRGB16(unsigned char *in_rgb8, unsigned short *out_rgb16, int width); 55 | void ChunkyBGRA8toPlanarRGB16(unsigned char *in_rgb8, unsigned short *out_rgb16, int width); 56 | void ChunkyARGB8toPlanarRGB16(unsigned char *in_rgb8, unsigned short *out_rgb16, int width); 57 | void PlanarRGB16toChunkyRGB16(unsigned short *in_rgb16, unsigned short *out_rgb16, int width); 58 | void PlanarYUV16toChunkyYUYV16(unsigned short *in_YUV, unsigned short *out_YUYV, int width, int colorspace); 59 | void PlanarYUV16toChunkyYUYV8(unsigned short *in_YUV, unsigned char *out_YUYV, int width, int colorspace); 60 | void PlanarYUV16toChannelYUYV16(unsigned short *in_YUV, unsigned short *planar_output[], int width, int colorspace, int shift); 61 | void ChunkyYUYV16toPlanarYUV16(unsigned short *in_YUYV, unsigned short *out_YUV, int width, int colorspace); 62 | void ChunkyYUYV8toPlanarYUV16(uint8_t *in_YUYV, uint8_t *out_YUV, int width, int colorspace); 63 | void ChunkyRGB16toChunkyYUV16(unsigned short *in_RGB48, unsigned short *out_YUV48, int width, int colorspace); 64 | 65 | void PlanarRGB16toPlanarYUV16(unsigned short *linebufRGB, unsigned short *linebufYUV, int width, int colorspace); 66 | void PlanarYUV16toPlanarRGB16(unsigned short *linebufYUV, unsigned short *linebufRGB, int width, int colorspace); 67 | 68 | void ChunkyRGB16toChunkyYUYV16(int width, int height, 69 | unsigned short *rgb16, int RGBpitch, 70 | unsigned short *yuyv16, int YUVpitch, 71 | unsigned short *scratch, int scratchsize, 72 | int colorspace); 73 | 74 | void ChunkyYUYV16toChunkyRGB16(int width, int height, 75 | unsigned short *yuyv16, int YUVpitch, 76 | unsigned short *rgb16, int RGBpitch, 77 | unsigned short *scratch, int scratchsize, 78 | int colorspace); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /Codec/allocator.c: -------------------------------------------------------------------------------- 1 | /*! @file allocator 2 | 3 | * @brief Memory tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "stdafx.h" 22 | #include "allocator.h" 23 | -------------------------------------------------------------------------------- /Codec/bandfile.h: -------------------------------------------------------------------------------- 1 | /*! @file bandilfe.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _BANDFILE_H 23 | #define _BANDFILE_H 24 | 25 | /*! @file bandfile.h 26 | 27 | Declaration of the data structures and functions for reading 28 | and writing binary files that contain band data (for debugging). 29 | 30 | The band file can contain band data from multiple frames and any 31 | combination of bands can be written for each frame. 32 | */ 33 | 34 | /*! 35 | @brief Declaration of the band file data structure 36 | 37 | @todo Replace the Boolean flags that are currently defined to 38 | be one byte with a 32-bit word using one bit per flag. 39 | */ 40 | #pragma pack(push, 1) 41 | 42 | typedef struct _bandfile 43 | { 44 | FILE *file; //!< Current open band file 45 | uint32_t frame; //!< Most recent frame number 46 | uint16_t channel; //!< Most recent channel index 47 | uint16_t wavelet; //!< Most recent wavelet index 48 | uint16_t band; //!< Most recent band index 49 | uint16_t type; //!< Data type of the most recent band 50 | uint32_t size; //!< Size of the most recent band (in bytes) 51 | 52 | // Dimensions of the most recent band 53 | uint16_t width; 54 | uint16_t height; 55 | 56 | // Largest dimensions of the bands in the band file 57 | uint16_t max_band_width; 58 | uint16_t max_band_height; 59 | 60 | // Maximum size of the bands in the band file 61 | uint32_t max_band_size; 62 | 63 | // Flags that indicate the state of the band data file 64 | uint8_t file_header_flag; //!< Has the file header been written? 65 | uint8_t frame_header_flag; //!< Has the frame header been written? 66 | uint8_t channel_header_flag; //!< Has the channel header been written? 67 | uint8_t wavelet_header_flag; //!< Has the wavelet header been written? 68 | uint8_t band_header_flag; //!< Has the band header been written? 69 | 70 | uint8_t padding[3]; // Pad the structure to a multiple of four bytes 71 | 72 | } BANDFILE; 73 | 74 | #pragma pack(pop) 75 | 76 | //#define BANDFILE_INITIALIZER {NULL} 77 | 78 | /*! 79 | @brief Data type of the data for a band in the band file 80 | */ 81 | typedef enum 82 | { 83 | BAND_TYPE_UINT16 = 0, 84 | BAND_TYPE_SINT16, 85 | 86 | // Reserve a block of values for encoded bands 87 | BAND_TYPE_ENCODED = 16, 88 | BAND_TYPE_ENCODED_RUNLENGTHS, // Encoding method used by the codec 89 | 90 | } BAND_TYPE; 91 | 92 | 93 | #ifdef __cplusplus 94 | extern "C" { 95 | #endif 96 | 97 | CODEC_ERROR OpenBandFile(BANDFILE *bandfile, const char *pathname); 98 | 99 | CODEC_ERROR FindNextBand(BANDFILE *bandfile); 100 | 101 | CODEC_ERROR ReadFileHeader(BANDFILE *bandfile); 102 | 103 | CODEC_ERROR ReadFrameHeader(BANDFILE *bandfile); 104 | 105 | CODEC_ERROR ReadChannelHeader(BANDFILE *bandfile); 106 | 107 | CODEC_ERROR ReadWaveletHeader(BANDFILE *bandfile); 108 | 109 | CODEC_ERROR ReadBandHeader(BANDFILE *bandfile); 110 | 111 | CODEC_ERROR ReadBandData(BANDFILE *bandfile, void *data, size_t size); 112 | 113 | 114 | CODEC_ERROR CreateBandFile(BANDFILE *bandfile, const char *pathname); 115 | 116 | CODEC_ERROR WriteFileHeader(BANDFILE *bandfile, int max_band_width, int max_band_height); 117 | 118 | CODEC_ERROR WriteWaveletBand(BANDFILE *bandfile, 119 | int frame, 120 | int channel, 121 | int wavelet, 122 | int band, 123 | int type, 124 | int width, 125 | int height, 126 | void *data, 127 | size_t size); 128 | 129 | CODEC_ERROR WriteFrameHeader(BANDFILE *bandfile, int frame); 130 | 131 | CODEC_ERROR WriteChannelHeader(BANDFILE *bandfile, int channel); 132 | 133 | CODEC_ERROR WriteWaveletHeader(BANDFILE *bandfile, int wavelet); 134 | 135 | CODEC_ERROR WriteBandHeader(BANDFILE *bandfile, int band, int type, int width, int height, size_t size); 136 | 137 | CODEC_ERROR WriteBandData(BANDFILE *bandfile, void *data, size_t size); 138 | 139 | CODEC_ERROR CloseBandFile(BANDFILE *bandfile); 140 | 141 | 142 | CODEC_ERROR WriteDecodedBandFile(DECODER *decoder, 143 | int channel_index, 144 | uint32_t subband_mask, 145 | const char *pathname); 146 | 147 | CODEC_ERROR WriteDecodedWaveletBandFile(DECODER *decoder, 148 | int channel_index, 149 | int wavelet_index, 150 | uint32_t band_mask, 151 | const char *pathname); 152 | 153 | CODEC_ERROR WriteDecodedTransformBandFile(DECODER *decoder, 154 | int channel_index, 155 | uint32_t wavelet_mask, 156 | uint32_t wavelet_band_mask, 157 | const char *pathname); 158 | 159 | CODEC_ERROR WriteDecodedTransformBands(DECODER *decoder, 160 | uint32_t channel_mask, 161 | uint32_t channel_wavelet_mask, 162 | uint32_t wavelet_band_mask, 163 | const char *pathname); 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif 170 | -------------------------------------------------------------------------------- /Codec/bayer.h: -------------------------------------------------------------------------------- 1 | /*! @file bayer.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "image.h" 29 | #include "filter.h" 30 | #include "codec.h" 31 | 32 | #define ACTIVEMETADATA_PRESATURATED 1 // already saturated in ActiveMetaData 33 | #define ACTIVEMETADATA_PLANAR 2 // Data convert to scanline Planar RRRR...GGGG...BBBB 34 | #define ACTIVEMETADATA_COLORFORMATDONE 4 // Color format handled by 3DLUT 35 | #define ACTIVEMETADATA_SRC_8PIXEL_PLANAR 8 // Color format handled by 3DLUT 36 | 37 | //Convert any decompressed planar ROWs of PIXEL16U into most output formats. 38 | void ConvertRow16uToOutput(DECODER *decoder, int frame_index, int num_channels, 39 | uint8_t *output, int pitch, FRAME_INFO *info, 40 | int chroma_offset, int precision); 41 | 42 | // Convert packed Bayer data to an image with the specified pixel format 43 | void ConvertPackedBayerToRGB32(PIXEL16U *input_buffer, FRAME_INFO *info, int input_pitch, uint8_t *output_buffer, int output_pitch, int width, int height); 44 | void ConvertPackedBayerToRGB24(PIXEL16U *input_buffer, FRAME_INFO *info, int input_pitch, uint8_t *output_buffer, int output_pitch, int width, int height); 45 | 46 | // Convert planes of Bayer data to the specified pixel format 47 | void ConvertPlanarBayerToRGB32(PIXEL16U *g1_plane, int g1_pitch, PIXEL16U *rg_plane, int rg_pitch, 48 | PIXEL16U *bg_plane, int bg_pitch, PIXEL16U *g2_plane, int g2_pitch, 49 | uint8_t *output_buffer, int pitch, int width, int height); 50 | 51 | void InvertHorizontalStrip16sBayerThruLUT(HorizontalFilterParams); 52 | 53 | void InvertHorizontalStrip16s444ThruLUT(HorizontalFilterParams); 54 | 55 | void InvertHorizontalStrip16s422ThruLUT(HorizontalFilterParams); 56 | 57 | //unsigned short *ApplyActiveMetaData(DECODER *decoder, int width, int height, int y, unsigned short *src, unsigned short *dst, int colorformat, int *whitebitdepth, int *flags); 58 | void *ApplyActiveMetaData(DECODER *decoder, int width, int height, int y, uint32_t *src, uint32_t *dst, int colorformat, int *whitebitdepth, int *flags); 59 | 60 | void ConvertLinesToOutput(DECODER *decoder, int width, int height, int linenum, unsigned short *src, uint8_t *outA8, int pitch, 61 | int colorformat, int whitepoint, int flags); 62 | 63 | void Convert4444LinesToOutput(DECODER *decoder, int width, int height, int linenum, unsigned short *src, uint8_t *outA8, int pitch, 64 | int colorformat, int whitepoint, int flags); 65 | 66 | void FastBlendWP13(short *Aptr, short *Bptr, short *output, int bytes); 67 | 68 | void FastBlurV(unsigned short *Aptr, unsigned short *Bptr, unsigned short *Cptr, 69 | unsigned short *output, int pixels); 70 | 71 | void FastSharpeningBlurV(unsigned short *Aptr, 72 | unsigned short *Bptr, 73 | unsigned short *Cptr, 74 | unsigned short *Dptr, 75 | unsigned short *Eptr, 76 | unsigned short *output, int pixels, int sharpness); 77 | 78 | void ComputeCube(DECODER *decoder); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /Codec/buffer.c: -------------------------------------------------------------------------------- 1 | /*! @file buffer.c 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include "buffer.h" 25 | #include "image.h" 26 | #include "config.h" 27 | 28 | #include // Intel aligned malloc and free 29 | 30 | #include // Get definition of memset 31 | 32 | // Initialize a scratch buffer 33 | void InitScratchBuffer(SCRATCH *scratch, char *base, size_t size) 34 | { 35 | scratch->base_ptr = base; 36 | scratch->free_ptr = base; 37 | scratch->free_size = size; 38 | scratch->next_ptr = NULL; 39 | } 40 | 41 | // Initialize a local section within the scratch buffer 42 | void PushScratchBuffer(SCRATCH *section, const SCRATCH *scratch) 43 | { 44 | section->base_ptr = scratch->free_ptr; 45 | section->free_ptr = scratch->free_ptr; 46 | section->free_size = scratch->free_size; 47 | section->next_ptr = NULL; 48 | } 49 | 50 | // Utility routine for subdividing scratch space into buffers 51 | char *AllocScratchBuffer(SCRATCH *scratch, size_t request) 52 | { 53 | char *buffer = NULL; // Allocated portion of scratch space 54 | 55 | // Check that scratch space has been allocated 56 | assert(scratch->base_ptr != NULL); 57 | 58 | // Is there enough scratch space for the new allocation? 59 | if (request <= scratch->free_size) { 60 | buffer = scratch->free_ptr; 61 | scratch->free_ptr += request; 62 | scratch->free_size -= request; 63 | } 64 | 65 | // Check that the requested amount of scratch space was allocated 66 | assert(buffer != NULL); 67 | 68 | // Return the allocated portion of scratch space 69 | return buffer; 70 | } 71 | 72 | // Aligned allocation of a scratch buffer 73 | char *AllocAlignedBuffer(SCRATCH *scratch, size_t request, int alignment) 74 | { 75 | char *buffer; 76 | 77 | // Compute the prefix required for the specified alignment 78 | int prefix = alignment - ((uintptr_t)scratch->free_ptr % alignment); 79 | 80 | // Allocate a block large enough for the requested allocation with alignment 81 | request += prefix; 82 | buffer = AllocScratchBuffer(scratch, request); 83 | 84 | // Check that the requested amount of scratch space was allocated 85 | assert(buffer != NULL); 86 | 87 | if (buffer != NULL) 88 | { 89 | // Force the required alignment 90 | buffer += prefix; 91 | 92 | // Check that the pointer into the buffer is properly aligned 93 | assert(ISALIGNED(buffer, alignment)); 94 | } 95 | 96 | // Return the aligned pointer into the buffer 97 | return buffer; 98 | } 99 | 100 | #if 0 // not used 101 | // Allocate scratch space for intermediate results 102 | void AllocScratchSpace(SCRATCH *scratch, size_t size, void *allocator) 103 | { 104 | char *buffer; 105 | 106 | // Has scratch space already been allocated? 107 | if (scratch->base_ptr != NULL) 108 | { 109 | // Is the scratch space large enough? 110 | //if (decoder->buffer_size < size) 111 | { 112 | // Free the entire scratch space allocation 113 | MEMORY_ALIGNED_FREE(scratch->base_ptr); 114 | } 115 | //else return; 116 | } 117 | 118 | // Allocate scratch space 119 | buffer = (char *)MEMORY_ALIGNED_ALLOC(size, _CACHE_LINE_SIZE); 120 | assert(buffer != NULL); 121 | 122 | InitScratchBuffer(scratch, buffer, size); 123 | } 124 | #endif 125 | 126 | #if 0 127 | // Free all scratch space used for intermediate results 128 | void ReleaseScratchSpace(SCRATCH *scratch) 129 | { 130 | // Has scratch space been allocated? 131 | if (scratch->base_ptr != NULL) 132 | { 133 | // Free the entire scratch space allocation 134 | MEMORY_ALIGNED_FREE(scratch->base_ptr); 135 | } 136 | 137 | // Clear all fields in the scratch space descriptor 138 | memset(scratch, 0, sizeof(SCRATCH)); 139 | } 140 | #endif 141 | 142 | // Force alignment of the remaining free space 143 | void AlignScratchSpace(SCRATCH *scratch, int alignment) 144 | { 145 | // Compute the prefix required for the specified alignment 146 | int prefix = alignment - ((uintptr_t)scratch->free_ptr % alignment); 147 | 148 | // Reduce the remaining free space to force alignment 149 | scratch->free_ptr += prefix; 150 | scratch->free_size -= prefix; 151 | 152 | // Check that scratch space is properly aligned 153 | assert(ISALIGNED(scratch->free_ptr, alignment)); 154 | } 155 | -------------------------------------------------------------------------------- /Codec/buffer.h: -------------------------------------------------------------------------------- 1 | /*! @file buffer.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _BUFFER_H 23 | #define _BUFFER_H 24 | 25 | // Use the same structure packing as the Intel C/C++ compiler 26 | //#pragma pack(push) 27 | //#pragma pack(16) 28 | #pragma pack(push, 16) 29 | 30 | typedef struct section // Definition of the buffer data structure 31 | { 32 | char *base_ptr; // Base address of the buffer (before subdivision) 33 | char *free_ptr; // Pointer to the free area in the buffer 34 | size_t free_size; // Size of the free space in the buffer 35 | char *next_ptr; // Pointer to the overflow block 36 | 37 | } SCRATCH; 38 | 39 | // Macro for initializing a buffer data structure 40 | #define SCRATCH_INITIALIZER(buffer, size) {(char *)(buffer), (char *)(buffer), (size), NULL} 41 | 42 | #pragma pack(pop) 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | // Initialize a scratch buffer 49 | void InitScratchBuffer(SCRATCH *scratch, char *base, size_t size); 50 | 51 | // Initialize a local section within the scratch buffer 52 | void PushScratchBuffer(SCRATCH *section, const SCRATCH *scratch); 53 | 54 | // Routine for allocating a scratch buffer 55 | char *AllocScratchBuffer(SCRATCH *scratch, size_t request); 56 | 57 | // Aligned allocation of a scratch buffer 58 | char *AllocAlignedBuffer(SCRATCH *scratch, size_t request, int alignment); 59 | 60 | // Allocate scratch space for intermediate results 61 | void AllocScratchSpace(SCRATCH *scratch, size_t size, void *allocator); 62 | 63 | // Free all scratch space used for intermediate results 64 | void ReleaseScratchSpace(SCRATCH *scratch); 65 | 66 | // Force alignment of the remaining free space 67 | void AlignScratchSpace(SCRATCH *scratch, int alignment); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Codec/codebooks.h: -------------------------------------------------------------------------------- 1 | /*! @file codebooks.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _CODEBOOKS_H 23 | #define _CODEBOOKS_H 24 | 25 | #include "vlc.h" 26 | #include "allocator.h" 27 | 28 | //num of codeset used by decoder and encoder 29 | #define CODEC_NUM_CODESETS 3 //DAN20041024 30 | 31 | //#define CURRENT_CODESET &cs7 // Codeset that is currently used 32 | //#define CURRENT_CODESET &cs9 33 | #define CURRENT_CODESET cs9 34 | #define SECOND_CODESET cs17 35 | #define THIRD_CODESET cs18 36 | 37 | 38 | //#define CURRENT_CODESET &cs10 39 | //#define CURRENT_CODESET &cs11 40 | //#define CURRENT_CODESET &cs12 // couldn't get it working 41 | 42 | 43 | // Forward reference 44 | struct decoder; 45 | 46 | 47 | // Collection of codebooks that are used by the encoder and decoder. 48 | // The codeset is a consistent set of codebooks for encoding and decoding. 49 | typedef struct codeset { 50 | char *title; // Identifying string for the codeset 51 | VLCBOOK *magsbook; // Codebook used for magnitudes 52 | RLCBOOK *zerobook; // Codebook used for runs of zeros 53 | uint32_t *tagsbook; // Codebook used for special codes (band_end) 54 | RMCBOOK *src_codebook; // Pair of codebooks used for encoding (from tables) 55 | // RMCBOOK *codebook; // Pair of codebooks used for encoding (computed from tables, active) 56 | RLCBOOK *codebook_runbook; // Codebook for the run length 57 | VLCBOOK *codebook_magbook; 58 | RLVBOOK *runsbook; // Computed Decoding book for runs and magnitudes 59 | FLCBOOK *fastbook; // Computed Lookup table for faster decoding 60 | VALBOOK *valuebook; // Computed Fast indexable codebook for signed values 61 | FSMTABLE *fsm_table; // Finite state machine 62 | const FSMARRAY *fsm_array; 63 | uint32_t flags; 64 | } CODESET; 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | 70 | extern CODESET cs18; // 256 element codebook (optimized for subbands 7,8,9,10,12,15 -- HAAR differenced bands) 71 | extern CODESET cs17; // 256 element codebook (optimized for subbands 7,8,9,10,12,15 -- HAAR differenced bands) 72 | extern CODESET cs11; // code tables and FSM, longest zero run is 2880 73 | extern CODESET cs10; // code tables and FSM, longest zero run is 720 74 | //extern CODESET cs12; // 75 | extern CODESET cs9; // code tables automatically generated, compliant with the FSM 76 | extern CODESET cs8; 77 | extern CODESET cs7; // Codeset with extra codes for bitstream markers 78 | extern CODESET cs6; // Newer codeset used for encoding and decoding 79 | extern CODESET cs5; // Older codeset used for encoding and decoding 80 | 81 | // The codebook of markers uses extra codes from the codeset 82 | extern VLC markbook[]; 83 | 84 | #if _ALLOCATOR 85 | bool InitCodebooks(ALLOCATOR *allocator, CODESET *cs); 86 | #else 87 | bool InitCodebooks(CODESET *cs); 88 | #endif 89 | 90 | bool InitDecoderFSM(struct decoder *decoder, CODESET *cs); 91 | 92 | void FreeCodebooks(struct decoder *decoder /*, CODESET *cs */); 93 | 94 | #if 0 95 | void FillRunLengthCodeTable(RLC *input_codes, int input_length, RLC *output_codes, int output_length, 96 | uint32_t zero_code, int zero_size); 97 | #else 98 | #if _ALLOCATOR 99 | void ComputeRunLengthCodeTable(ALLOCATOR *allocator, 100 | RLE *input_codes, int input_length, 101 | RLC *output_codes, int output_length, 102 | uint32_t zero_code, int zero_size); 103 | #else 104 | void ComputeRunLengthCodeTable(RLE *input_codes, int input_length, 105 | RLC *output_codes, int output_length, 106 | uint32_t zero_code, int zero_size); 107 | #endif 108 | void SortDecreasingRunLength(RLC *codebook, int length); 109 | void FillRunLengthCodeTable(RLC *codebook, int codebook_length, RLC *table, int table_length); 110 | #endif 111 | 112 | void FillCodeLookupTable(RLV *codebook, int length, FLC *table, int size); 113 | int MatchBitPattern(uint32_t word, int width, RLV *codebook, int length, FLC *match); 114 | void FillScanLookupTable(RLV *codebook, int length, FLC *table, int size); 115 | void FillVlcTable(VLCBOOK *codebook, VLC *table, int size, int flags); 116 | void FillVleTable(VLCBOOK *codebook, VLE *table, int size, int flags); 117 | 118 | // Create a finite state machine table from an array of entries 119 | bool FillFSM(struct decoder *decoder, FSMTABLE *fsm_table, const FSMARRAY *fsm_array); 120 | 121 | // Initialize a finite state machine to work with the specified table 122 | void InitFSM(FSM *fsm, FSMTABLE *table); 123 | 124 | #if _COMPANDING 125 | void ScaleFSM(FSMTABLE *fsm_table); 126 | #endif 127 | 128 | 129 | #if _TEST 130 | 131 | // Print a codebook lookup table 132 | void PrintCodeLookupTable(FILE *logfile, FLC *table, int size); 133 | 134 | // Print the codebook used for fast encoding of run lengths 135 | void PrintRunLengthTable(FILE *logfile, RLCBOOK *runsbook); 136 | void PrintFastLookupTable(FILE *logfile, FLCBOOK *fastbook); 137 | void PrintValueCodebook(FILE *logfile, VALBOOK *codebook); 138 | 139 | // Routine for testing a code set 140 | BOOL TestCodeSet(CODESET *cs); 141 | 142 | #endif 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /Codec/counter.h: -------------------------------------------------------------------------------- 1 | /*! @file counter.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #ifndef _COUNTER_H 22 | #define _COUNTER_H 23 | 24 | // The counter is a large integer 25 | typedef __int64 COUNTER; 26 | 27 | #define COUNTER_INITIALIZER (0) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Codec/cpuid.c: -------------------------------------------------------------------------------- 1 | /*! @file cpuid.c 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | // Adapted from Microsoft Visual Studio .NET sample code 23 | 24 | #ifdef _WIN32 25 | #include 26 | #elif __APPLE__ 27 | #include "macdefs.h" 28 | #endif 29 | 30 | #include 31 | 32 | #include "cpuid.h" 33 | 34 | 35 | // These are the bit flags that get set on calling cpuid with register eax set to 1 36 | #define _MMX_FEATURE_BIT 0x00800000 37 | #define _SSE_FEATURE_BIT 0x02000000 38 | #define _SSE2_FEATURE_BIT 0x04000000 39 | 40 | // This bit is set when cpuid is called with register set to 80000001h (only applicable to AMD) 41 | #define _3DNOW_FEATURE_BIT 0x80000000 42 | 43 | #ifdef _WIN32 44 | 45 | int GetProcessorCount() 46 | { 47 | SYSTEM_INFO cSystem_info; 48 | GetSystemInfo(&cSystem_info); 49 | return cSystem_info.dwNumberOfProcessors; 50 | } 51 | 52 | #elif __APPLE__ 53 | 54 | #include 55 | #include 56 | 57 | int GetProcessorCount() 58 | { 59 | int mib[2]; 60 | int processor_count; 61 | size_t length; 62 | 63 | mib[0] = CTL_HW; 64 | mib[1] = HW_NCPU; 65 | length = sizeof(processor_count); 66 | 67 | //sysctl(mib, 2, &processor_count, &length, NULL, 0); 68 | sysctlbyname("hw.physicalcpu", &processor_count, &length, NULL, 0); 69 | 70 | return processor_count; 71 | } 72 | 73 | #else // Linux 74 | 75 | #include 76 | //#include 77 | #include 78 | 79 | int GetProcessorCount() 80 | { 81 | #if 0 82 | uint64_t cpu_mask; 83 | sched_getaffinity(0, sizeof(cpu_mask), &cpu_mask); 84 | 85 | int cpu_count = 0; 86 | while (cpu_mask != 0) { 87 | cpu_mask >>= 1; 88 | cpu_count++; 89 | } 90 | #else 91 | int cpu_count = sysconf(_SC_NPROCESSORS_ONLN); 92 | #endif 93 | 94 | return cpu_count; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /Codec/cpuid.h: -------------------------------------------------------------------------------- 1 | /*! @file cpuid.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | // Adapted from Microsoft Visual Studio .NET sample code 22 | 23 | #ifndef _CPUID_H 24 | #define _CPUID_H 25 | 26 | #define _CPU_FEATURE_MMX 0x0001 27 | #define _CPU_FEATURE_SSE 0x0002 28 | #define _CPU_FEATURE_SSE2 0x0004 29 | #define _CPU_FEATURE_3DNOW 0x0008 30 | 31 | #define _MAX_VNAME_LEN 13 32 | #define _MAX_MNAME_LEN 30 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | int GetProcessorCount(); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Codec/debug.c: -------------------------------------------------------------------------------- 1 | /*! @file debug.c 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "config.h" 23 | #include "debug.h" 24 | 25 | #if _DEBUG 26 | 27 | FILE *debugfile = NULL; // Debug output file 28 | char debug[256]; // Array of debug flags 29 | 30 | void InitDebugFlags(char *flags) 31 | { 32 | unsigned int chr; 33 | 34 | for (chr = 0; chr < sizeof(debug)/sizeof(debug[0]); chr++) { 35 | debug[chr] = 0; 36 | } 37 | 38 | SetDebugFlags(flags); 39 | } 40 | 41 | void SetDebugFlags(const char *flags) 42 | { 43 | while (*flags != '\0') { 44 | uint8_t index = (uint8_t)(*(flags++)); 45 | debug[index] = 1; 46 | } 47 | } 48 | 49 | void ClearDebugFlags(const char *flags) 50 | { 51 | while (*flags != '\0') { 52 | uint8_t index = (uint8_t)(*(flags++)); 53 | debug[index]= 0; 54 | } 55 | } 56 | 57 | void GetDebugFlags(char *flags) 58 | { 59 | unsigned int chr = 1; // Skip the nul character 60 | 61 | for (; chr < sizeof(debug)/sizeof(debug[0]); chr++) { 62 | if (debug[chr]) *(flags++) = chr; 63 | } 64 | 65 | // Terminate the string 66 | *flags = '\0'; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Codec/debug.h: -------------------------------------------------------------------------------- 1 | /*! @file debug.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _DEBUG_H 23 | #define _DEBUG_H 24 | 25 | #if _DEBUG 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | extern FILE *debugfile; // Debug output file 34 | extern char debug[256]; // Array of debug flags 35 | 36 | void InitDebugFlags(char *flags); 37 | void SetDebugFlags(const char *flags); 38 | void ClearDebugFlags(const char *flags); 39 | void GetDebugFlags(char *flags); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #else 46 | 47 | #define InitDebugFlags(flags) 48 | #define SetDebugFlags(flags) 49 | #define ClearDebugFlags(flags) 50 | #define GetDebugFlags(flags) 51 | 52 | #endif 53 | 54 | #endif -------------------------------------------------------------------------------- /Codec/dither.h: -------------------------------------------------------------------------------- 1 | /*! @file dither.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _DITHER_H 23 | #define _DITHER_H 24 | 25 | typedef struct color_matrix 26 | { 27 | float array[3][4]; // The last column is the offset 28 | float scale; // Amplitude of the coefficients 29 | 30 | // Record the color space used to fill the color matrix 31 | COLOR_SPACE color_space; 32 | 33 | } COLOR_MATRIX; 34 | 35 | 36 | typedef struct color_conversion 37 | { 38 | int array[3][4]; // The last column is the offset 39 | int shift; // Scale of the coefficients 40 | 41 | int luma_offset; // Offset for video safe luma 42 | 43 | // Record the color space used to fill the color matrix 44 | int color_space; 45 | 46 | } COLOR_CONVERSION; 47 | 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | // Compute integer color conversion coefficients for the specified color space 54 | 55 | void ComputeColorCoefficientsRGBToYUV(COLOR_CONVERSION *conversion, 56 | int color_space); 57 | 58 | void ComputeColorCoefficientsYUVToRGB(COLOR_CONVERSION *conversion, 59 | int color_space); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /Codec/draw.h: -------------------------------------------------------------------------------- 1 | /*! @file draw.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _DRAW_H 23 | #define _DRAW_H 24 | 25 | #if _GRAPHICS 26 | 27 | typedef enum { 28 | JUSTIFY_CENTER = 0, 29 | JUSTIFY_LEFT = 1, 30 | JUSTIFY_RIGHT = 2, 31 | JUSTIFY_TOP = 4, 32 | JUSTIFY_TL = 5, 33 | JUSTIFY_TR = 6, 34 | JUSTIFY_BOTTOM = 8, 35 | JUSTIFY_BL = 9, 36 | JUSTIFY_BR = 10, 37 | 38 | } JUSTICATION; 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | int DrawOpen(DECODER *decoder); 45 | void DrawClose(DECODER *decoder); 46 | void DrawInit(DECODER *decoder); 47 | void DrawSafeMarkers(DECODER *decoder); 48 | void DrawMetadataObjects(DECODER *decoder); 49 | void DrawMetadataString(DECODER *decoder, unsigned char type, int size, void *data, int parallax); 50 | // scale = 1.0, match PNG size 51 | void DrawPNG(DECODER *decoder, char *path, float scaleX, float scaleY, int parameter, int *ret_width, int *ret_height, char *ret_path); 52 | void DrawPrepareTool(DECODER *decoder, char *tool, char *subtype, float scaleX, float scaleY, int parameter); 53 | 54 | void DrawScreen(DECODER *decoder, uint8_t *output, int pitch, int output_format); 55 | void DrawHistogram(DECODER *decoder, int parallax); 56 | void DrawWaveform(DECODER *decoder, int parallax); 57 | void DrawVectorscope(DECODER *decoder, int parallax); 58 | void DrawGrid(DECODER *decoder, int parallax); 59 | void DrawStartThreaded(DECODER *decoder); 60 | void DrawWaitThreaded(DECODER *decoder); 61 | 62 | //void HistogramRender(DECODER *decoder, uint8_t *output, int pitch, int output_format, int x, int targetW, int targetH); 63 | 64 | void GetDisplayParameters(DECODER *decoder, unsigned char *ptr, int len); 65 | //void GetCurrentID(DECODER *decoder, unsigned char *ptr, int len, char *id); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Codec/dump.h: -------------------------------------------------------------------------------- 1 | /*! @file dump.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef _DUMP 25 | #if !_DEBUG 26 | #define _DUMP 0 // Always disable the dump facility in production builds 27 | #else 28 | #define _DUMP 0 // Disable the dump facility in all builds by default 29 | #endif 30 | #endif 31 | 32 | #if _DUMP 33 | 34 | #include 35 | #include 36 | #include 37 | #include "wavelet.h" 38 | 39 | // Dump files are placed in the root directory of the default drive 40 | // if no directory is provided or if the directory is the null string 41 | 42 | #define DUMP_ENCODER_DIRECTORY "C:/Cedoc/Dump/Encoder" 43 | #define DUMP_DECODER_DIRECTORY "C:/Cedoc/Dump/Decoder" 44 | 45 | #define DUMP_DEFAULT_FILENAME "f%04dc%1dw%1db%1d.pgm" 46 | 47 | typedef struct dump 48 | { 49 | BOOL enabled; // Switch that controls debug output 50 | // BOOL decode; 51 | 52 | DWORD channel_mask; // Bitmask for selecting which channels to output 53 | DWORD wavelet_mask; // Bitmask for selecting which wavelet bands to output 54 | 55 | char directory[_MAX_PATH]; 56 | char filename[_MAX_PATH]; 57 | 58 | } DUMP_INFO; 59 | 60 | // Forward reference 61 | typedef struct codec CODEC; 62 | 63 | #if __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | BOOL SetDumpDirectory(CODEC *codec, char *directory); 68 | BOOL SetDumpFilename(CODEC *codec, char *filename); 69 | BOOL SetDumpChannelMask(CODEC *codec, DWORD mask); 70 | BOOL SetDumpWaveletMask(CODEC *codec, DWORD mask); 71 | BOOL DumpTransformBands(CODEC *codec, TRANSFORM *transform, int channel, BOOL requantize); 72 | BOOL DumpWaveletBand(IMAGE *wavelet, int band, BOOL requantize, FILE *file); 73 | 74 | #if __cplusplus 75 | } 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Codec/exception.cpp: -------------------------------------------------------------------------------- 1 | /*! @file exception.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef _WIN32 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #if _STACKWALKER 29 | #include "../../gopro-contrib-win-stackwalker/StackWalker.h" 30 | #endif 31 | #include "exception.h" 32 | 33 | 34 | /*! 35 | @brief Trap system exceptions and throw an exception class instance 36 | 37 | This function is called when a system exception occurs in C/C++ code. 38 | An instance of a user-defined C++ class is created to hold information 39 | collected from the exception record and context record and the object 40 | is throw to signal the exception. 41 | 42 | Must call the function _set_se_translator in every thread where any 43 | system exception should be trapped and the code must be compiled with 44 | the asynchronous exception switch /EHa which is not set by default. 45 | 46 | Asynchronous exceptions may result in larger code, so it may be best 47 | to use this technique in a special build for debugging system errors. 48 | 49 | The exception handler should not try to allocate memory or perform any 50 | input or output or do anything that may cause another system exception. 51 | 52 | The exception code passed as the first argument should equal the exception 53 | code in the exception record: pe->ExceptionRecord->ExceptionCode. 54 | */ 55 | void DefaultExceptionHandler(unsigned int code, EXCEPTION_POINTERS *pe) 56 | { 57 | #if 0 58 | //printf("Inside exception translator\n"); 59 | 60 | // The first argument is the exception code 61 | uint32_t exception_code = code; 62 | 63 | if (pe && pe->ContextRecord) 64 | { 65 | // Use the context record to output a stack trace 66 | StackWalker sw; 67 | sw.ShowCallstack(GetCurrentThread(), pe->ContextRecord); 68 | } 69 | 70 | // Use the information in the exception record (if available) 71 | if (pe && pe->ExceptionRecord) 72 | { 73 | void *exception_address = pe->ExceptionRecord->ExceptionAddress; 74 | throw SystemException(exception_code, exception_address); 75 | } 76 | else 77 | { 78 | throw SystemException(exception_code); 79 | } 80 | #endif 81 | } 82 | 83 | /*! 84 | @brief Set the exception handler for trapping system errors 85 | 86 | The old exteption handler is returned so that it may be restored 87 | after the new exception handler is no longer needed. 88 | */ 89 | ExceptionHandlerProc *SetExceptionHandler(ExceptionHandlerProc handler) 90 | { 91 | #if 0 92 | return _set_se_translator(handler); 93 | #else 94 | return NULL; 95 | #endif 96 | } 97 | #endif 98 | 99 | // Suppress warnings about redundant specification of calling conventions 100 | #pragma warning(disable: 791) 101 | 102 | // Hide the stack walker from the rest of the codec 103 | #if _STACKWALKER 104 | #include "../../contrib/StackWalker/StackWalker.cpp" 105 | #else 106 | #include "exception.h" 107 | 108 | void DefaultExceptionHandler() 109 | { 110 | } 111 | 112 | void *SetExceptionHandler() 113 | { 114 | return 0; 115 | } 116 | #endif 117 | -------------------------------------------------------------------------------- /Codec/exception.h: -------------------------------------------------------------------------------- 1 | /*! @file exception.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #if defined(__APPLE__) 25 | 26 | #include 27 | #include 28 | #include 29 | #include "macdefs.h" 30 | 31 | #define EXCEPTION_POINTERS int 32 | 33 | #elif defined(__GNUC__) 34 | 35 | #include 36 | #include 37 | 38 | #endif 39 | 40 | #ifdef __cplusplus 41 | 42 | /*! 43 | @brief Class for representing system exceptions in a C++ catch or throw 44 | 45 | The exception includes an error code that is defined in winnt.h and the address 46 | at which the exception occurred, but I do not know whether this address is code 47 | or data. The context record contains the instruction pointer for the program 48 | location at which the error occurred as well as the other registers, including 49 | the stack pointer. 50 | 51 | Other information is available in the exception and context records that are 52 | passed to the exception handler. 53 | */ 54 | class SystemException 55 | { 56 | public: 57 | 58 | SystemException(uint32_t exception_code, void *exception_address = NULL) : 59 | code(exception_code), 60 | address(exception_address) 61 | { 62 | } 63 | 64 | // Information obtained from the exception record and context 65 | uint32_t code; 66 | void *address; 67 | 68 | }; 69 | 70 | extern "C" { 71 | 72 | #endif 73 | 74 | #if defined(__APPLE__) || defined(__GNUC__) 75 | 76 | typedef void ExceptionHandlerProc(); 77 | 78 | // Platform-independent function to set the exception handler 79 | void *SetExceptionHandler(); 80 | 81 | // Translate system exceptions into C++ exceptions 82 | void DefaultExceptionHandler(); 83 | 84 | // Set the default handler for system exceptions 85 | static void SetDefaultExceptionHandler() 86 | { 87 | SetExceptionHandler(); 88 | } 89 | 90 | #else 91 | 92 | // Declaration for exception handlers 93 | typedef void ExceptionHandlerProc(unsigned int, struct _EXCEPTION_POINTERS*); 94 | 95 | // Platform-independent function to set the exception handler 96 | ExceptionHandlerProc *SetExceptionHandler(ExceptionHandlerProc handler); 97 | 98 | // Translate system exceptions into C++ exceptions 99 | void DefaultExceptionHandler(unsigned int u, struct _EXCEPTION_POINTERS *pe); 100 | 101 | // Set the default handler for system exceptions 102 | static void SetDefaultExceptionHandler() 103 | { 104 | SetExceptionHandler(DefaultExceptionHandler); 105 | } 106 | 107 | #endif 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | -------------------------------------------------------------------------------- /Codec/keyframes.h: -------------------------------------------------------------------------------- 1 | /*! @file keyframes.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | void NewControlPoint(DECODER *decoder, unsigned char *ptr, int len, int delta, int priority); 27 | void KeyframesReleaseAll(DECODER *decoder); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /Codec/lutpath.h: -------------------------------------------------------------------------------- 1 | /*! @file lutpath.h 2 | 3 | * @brief Active MetadataTools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef _WIN32 25 | 26 | // Define strings for the database locations on Windows 27 | #define OVERRIDE_PATH_STRING "C:/Users/Public/CineForm" 28 | #define LUT_PATH_STRING "C:/Users/Public/CineForm/LUTs" 29 | #define DATABASE_PATH_STRING "db" 30 | #define SETTINGS_PATH_STRING "C:/Users/Public/CineForm/dbsettings" 31 | 32 | #elif __APPLE_REMOVE__ 33 | 34 | //TODO: Define strings for the database locations on Macintosh 35 | 36 | #else 37 | 38 | // Define strings for the database locations on Linux 39 | #define OVERRIDE_PATH_STRING "/var/cineform/public" 40 | #define LUT_PATH_STRING "/var/cineform/public/LUTs" 41 | #define DATABASE_PATH_STRING "db" 42 | #define SETTINGS_PATH_STRING "/etc/cineform/dbsettings" 43 | 44 | #endif 45 | 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | // Open the logfile used for reporting errors 52 | FILE *OpenLogFile(); 53 | 54 | // Routine that initializes the LUT paths in the decoder 55 | void InitLUTPaths(struct decoder *decoder); 56 | 57 | // Newer name for the decoder LUT paths routine 58 | void InitLUTPathsDec(struct decoder *decoder); 59 | 60 | // Routine that initializes the LUT paths in the encoder 61 | void InitLUTPathsEnc(struct encoder *encoder); 62 | void WriteLastGUIDAndFrame(DECODER *decoder, int checkdiskinfotime); 63 | void OverrideCFHDDATA(struct decoder *decoder, unsigned char *lpCurrentBuffer, int nWordsUsed); 64 | void OverrideCFHDDATAUsingParent(struct decoder *decoder, struct decoder *parentDecoder, unsigned char *lpCurrentBuffer, int nWordsUsed); 65 | 66 | #if !defined(_WIN32) && !defined(__APPLE_REMOVE__) 67 | 68 | // Use the lexical scanner to parse the user preferences file on Linux 69 | #include "scanner.h" 70 | 71 | // Parse the LUT and database path strings from the user preferences file 72 | CODEC_ERROR ParseUserMetadataPrefs(FILE *file, 73 | SCANNER *scanner, 74 | char *lut_pathname_string, 75 | size_t lut_pathname_size, 76 | char *database_filename_string, 77 | size_t database_filename_size); 78 | 79 | #endif 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | 86 | #ifdef __cplusplus 87 | 88 | extern "C" 89 | FILE *OpenUserPrefsFile(char *actual_pathname = NULL, //!< Return the actual pathname 90 | size_t actual_size = 0 //!< Return the pathname size (in bytes) 91 | ); 92 | #else 93 | 94 | FILE *OpenUserPrefsFile(char *actual_pathname, //!< Return the actual pathname 95 | size_t actual_size //!< Return the pathname size (in bytes) 96 | ); 97 | #endif 98 | -------------------------------------------------------------------------------- /Codec/recursive.h: -------------------------------------------------------------------------------- 1 | /*! @file recursive.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _RECURSIVE_H 23 | #define _RECURSIVE_H 24 | 25 | #include "config.h" 26 | #include "image.h" 27 | #include "encoder.h" 28 | #include "wavelet.h" 29 | 30 | void InitTransformState(TRANSFORM_STATE *state, TRANSFORM *transform); 31 | void ClearTransformState(TRANSFORM_STATE *state); 32 | 33 | // Copy the quantization divisors into the transform state 34 | //void SetTransformStateQuantization(TRANSFORM *transform); 35 | 36 | // Initialize the vector of descriptors that specifies the sequence of transforms 37 | void SetTransformDescriptors(ENCODER *encoder, TRANSFORM *transform); 38 | 39 | // Allocate processing buffers using the input level and input dimensions 40 | BYTE *AllocateTransformStateBuffers(TRANSFORM_STATE *state, int width, int height, 41 | int level, int type, BYTE *buffer); 42 | 43 | // Called with the next row to perform the recursive wavelet transform 44 | void FilterSpatialRecursiveRow(TRANSFORM_STATE *state, PIXEL *input, int width, BYTE *buffer, FILE *logfile); 45 | 46 | // Initialize the encoder 47 | //void InitEncoder(ENCODER *encoder, FILE *logfile, int width, int height, int num_levels, BYTE *buffer); 48 | 49 | // Allocate data structures for the recursive wavelet transforms 50 | BYTE *AllocateRecursiveTransform(TRANSFORM *transform, int width, int height, int num_levels, BYTE *buffer); 51 | //void AllocateRecursiveWavelets(ENCODER *encoder, BYTE *buffer); 52 | 53 | // Entry point for beginning the recursive wavelet transform 54 | void FilterSpatialRecursive(TRANSFORM *transform, PIXEL *image, int width, int height, int pitch, BYTE *buffer); 55 | 56 | // Entry point for the intermediate levels in the recursive wavelet transform 57 | //void FilterSpatialRecursiveAux(TRANSFORM *transform, PIXEL *input, int width, int level, BYTE *buffer); 58 | void FilterRecursive(TRANSFORM *transform, PIXEL *input, int width, int level, BYTE *buffer); 59 | 60 | //void OutputWaveletBandRows(ENCODER *encoder, PIXEL *wavelet[NUM_WAVELET_BANDS], int width, int level); 61 | void StoreWaveletBandRows(TRANSFORM *transform, PIXEL *result[NUM_WAVELET_BANDS], int width, int level); 62 | 63 | void StoreWaveletHighpassRows(TRANSFORM *transform, 64 | PIXEL *lowlow_result, PIXEL *lowhigh_result, 65 | PIXEL *highlow_result, PIXEL *highhigh_result, 66 | int width, int level); 67 | 68 | //void PrintRecursiveWavelets(ENCODER *encoder); 69 | 70 | // Perform the full intra frame transform on a progressive frame using recursive wavelets 71 | void TransformForwardProgressiveIntraFrameRecursive(ENCODER *encoder, IMAGE *image, 72 | TRANSFORM *transform, int channel, 73 | BYTE *buffer, size_t buffer_size); 74 | 75 | // Perform the full intra frame recursive transform on a progressive frame of packed YUV 76 | void TransformForwardProgressiveIntraFrameRecursiveYUV(ENCODER *encoder, BYTE *frame, 77 | int width, int height, int pitch, 78 | TRANSFORM *transform_array[], int num_transforms, 79 | BYTE *buffer, size_t buffer_size); 80 | 81 | // Perform a recursive transform on a packed YUV frame 82 | void TransformForwardRecursiveYUYV(ENCODER *encoder, BYTE *frame, int frame_index, 83 | int width, int height, int pitch, 84 | TRANSFORM *transform_array[], int num_transforms, 85 | BYTE *buffer, size_t buffer_size); 86 | #endif 87 | -------------------------------------------------------------------------------- /Codec/scanner.h: -------------------------------------------------------------------------------- 1 | /*! @file scanner.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | typedef enum error 25 | { 26 | SCANNER_ERROR_OKAY = 0, 27 | SCANNER_ERROR_EOF, 28 | SCANNER_ERROR_OVERFLOW, 29 | SCANNER_ERROR_QUOTE, 30 | SCANNER_ERROR_KEYWORD, 31 | 32 | } SCANNER_ERROR; 33 | 34 | // Scanner state 35 | typedef struct scanner 36 | { 37 | FILE *file; 38 | char c; // Last character read from the file 39 | int error; // Error code from the last operation 40 | int line; // Line number where the error occurred 41 | 42 | } SCANNER; 43 | 44 | // Token table entry 45 | typedef struct token 46 | { 47 | char *string; // The token keyword 48 | int value; // The opcode for the token 49 | 50 | } TOKEN; 51 | 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | int InitScanner(SCANNER *scanner, FILE *file); 58 | 59 | int SkipBlanks(SCANNER *scanner); 60 | 61 | int SkipLine(SCANNER *scanner); 62 | 63 | int ScanKeyword(SCANNER *scanner, char *keyword, int keyword_length); 64 | 65 | int CopyQuotedString(SCANNER *scanner, char *result_string, int result_length); 66 | 67 | int CopyTrimmedString(SCANNER *scanner, char *result_string, int result_length); 68 | 69 | int Lookup(const char *keyword, 70 | TOKEN *token_table, 71 | int token_table_length); 72 | 73 | const char *Keyword(int opcode, 74 | TOKEN *token_table, 75 | int token_table_length); 76 | 77 | const char *Message(int error); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | -------------------------------------------------------------------------------- /Codec/stats.h: -------------------------------------------------------------------------------- 1 | /*! @file stats.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _STATS_H 23 | #define _STATS_H 24 | 25 | #include "wavelet.h" 26 | #include "image.h" 27 | 28 | // Generates encoding statistics that are used to optimize the codebooks 29 | 30 | //#ifndef _STATS 31 | //#define _STATS _DEBUG 32 | //#endif 33 | 34 | // Sets of statistics are identified by an opaque integer identifier so 35 | // that the routines can support multiple sets of histograms in the future 36 | 37 | #define STATS_DEFAULT 0 38 | 39 | 40 | void DumpString(char *txt); 41 | 42 | #if (_STATS || 0) 43 | 44 | void ReadStats(int stats); 45 | //void CountValues(int stats, int count, int value); 46 | void CountValues(int stats, int value, int num); 47 | void CountRuns(int stats, int count); 48 | void UpdateStats(int stats); 49 | void NewSubBand(int width,int height,int first, int bits, int overhead); 50 | void SetQuantStats(int quantization); 51 | void StatsAverageLevels(IMAGE *frame); 52 | void StatsMemoryAlloc(int size, char *func); 53 | void DumpText(char *txt, int hex); 54 | void DumpData(int a, int b, int c); 55 | 56 | #else 57 | 58 | #define ReadStats(stats) 59 | //#define CountValues(stats, count, value) 60 | #define CountValues(stats, value, num) 61 | #define CountRuns(stats, count) 62 | #define UpdateStats(stats) 63 | #define NewSubBand(width, height, first, bits, overhead) 64 | #define SetQuantStats(quantization) 65 | #define StatsAverageLevels(frame) 66 | #define StatsMemoryAlloc(size, func) 67 | #define DumpText(txt, hex) 68 | #define DumpData(a, b, c); 69 | 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /Codec/stdafx.h: -------------------------------------------------------------------------------- 1 | /*! @file stdafx.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #define __STDC_LIMIT_MACROS 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | //#include // SSE2 intrinsics 36 | 37 | #ifdef _WIN32 38 | #include 39 | #include 40 | #ifdef __cplusplus 41 | // #include // Required for VS2005 but not 2003 42 | #include 43 | #endif 44 | #elif __APPLE__ 45 | #include 46 | #include // for _mkdir() 47 | #include // for usleep() 48 | #include // for propertylist/preferences 49 | #else 50 | #include // for _mkdir() 51 | #include // for usleep() 52 | #include // for isalpha() 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | 57 | //#include 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /Codec/swap.c: -------------------------------------------------------------------------------- 1 | /*! @file swap.c 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "swap.h" 23 | 24 | -------------------------------------------------------------------------------- /Codec/swap.h: -------------------------------------------------------------------------------- 1 | /*! @file swap.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef SWAP_H 23 | #define SWAP_H 24 | 25 | // Need to define the byte swapping intrinsic 26 | #if __cplusplus 27 | extern "C" 28 | #endif 29 | 30 | // Define a platform independent byte swapping routine 31 | 32 | #ifdef _WIN32 33 | #if _MSC_VER 34 | #define _bswap(x) _byteswap_ulong(x) 35 | #endif 36 | #define SwapInt32(x) _byteswap_ulong(x) 37 | #define SwapInt16(x) _byteswap_ushort(x) 38 | 39 | // Define byte swapping routines for the native format (Windows) 40 | #define SwapInt32BtoN(x) SwapInt32(x) 41 | #define SwapInt32LtoN(x) (x) 42 | #define SwapInt32NtoB(x) SwapInt32(x) 43 | #define SwapInt32NtoL(x) (x) 44 | 45 | 46 | 47 | #elif __APPLE__ 48 | #include "CoreFoundation/CoreFoundation.h" 49 | #define _bswap(x) _OSSwapInt32(x) 50 | #define SwapInt32(x) _OSSwapInt32(x) 51 | #define SwapInt16(x) _OSSwapInt16(x) 52 | 53 | #define SwapInt32BtoN(x) SwapInt32(x) 54 | #define SwapInt32LtoN(x) (x) 55 | #define SwapInt32NtoB(x) SwapInt32(x) 56 | #define SwapInt32NtoL(x) (x) 57 | 58 | #else 59 | 60 | // Use the GCC byte swapping macros 61 | 62 | #include 63 | 64 | #define SwapInt16(x) bswap_16(x) 65 | #define SwapInt32(x) bswap_32(x) 66 | 67 | // Define byte swapping routines for the native format (Windows) 68 | #define SwapInt32BtoN(x) SwapInt32(x) 69 | #define SwapInt32LtoN(x) (x) 70 | #define SwapInt32NtoB(x) SwapInt32(x) 71 | #define SwapInt32NtoL(x) (x) 72 | 73 | //TODO: Replace uses of _bswap with SwapInt32 74 | #define _bswap(x) SwapInt32(x) 75 | 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Codec/thread.c: -------------------------------------------------------------------------------- 1 | /*! @file thread.c 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include 23 | 24 | #include "thread.h" 25 | 26 | #ifndef _WIN32 27 | 28 | //TODO: How to set the thread affinity on Macintosh and Linux? 29 | void SetThreadAffinityMask(pthread_t thread, uint32_t *thread_affinity_mask) 30 | { 31 | (void) thread; 32 | (void) thread_affinity_mask; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Codec/thumbnail.h: -------------------------------------------------------------------------------- 1 | /*! @file thumbnail.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _THUMBNAIL_H 23 | #define _THUMBNAIL_H 24 | 25 | // Flags passed to the routine for generating thumbnails 26 | typedef enum thumbnail_flags 27 | { 28 | // The low eight bits determine the type of thumbnail 29 | THUMBNAIL_FLAGS_NONE = 0, 30 | THUMBNAIL_FLAGS_ENABLE = 1, 31 | THUMBNAIL_FLAGS_DPXC = 2, 32 | 33 | // Default thumbnail flags none provided 34 | THUMBNAIL_FLAGS_DEFAULT = THUMBNAIL_FLAGS_ENABLE, 35 | 36 | // The high eight bits determine the type of watermark 37 | THUMBNAIL_WATERMARK_MASK = 0x0F, 38 | THUMBNAIL_WATERMARK_SHIFT = 8, 39 | 40 | // Watermark bits in the high eight bits of the thumbnail flags 41 | THUMBNAIL_WATERMARK_EXPIRED = 1, 42 | THUMBNAIL_WATERMARK_444 = 2, 43 | THUMBNAIL_WATERMARK_RAW = 4, 44 | THUMBNAIL_WATERMARK_1080P = 8, 45 | THUMBNAIL_WATERMARK_3D = 16, 46 | 47 | } THUMBNAIL_FLAGS; 48 | 49 | // Watermark flags within the thumbnail flags 50 | typedef enum thumbnail_watermark 51 | { 52 | THUMBNAIL_WATERMARK_NONE = 0, 53 | 54 | //TODO: Finish the definitions of the watermark flags 55 | 56 | } THUMBNAIL_WATERMARK; 57 | 58 | // Table of channels offsets in a stereo sample 59 | typedef struct channel_offsets 60 | { 61 | int offset_count; 62 | int left_channel_offsets[CODEC_MAX_CHANNELS]; 63 | int right_channel_offsets[CODEC_MAX_CHANNELS]; 64 | 65 | //TODO: May need to modify this struct if the SAMPLE_HEADER changes 66 | 67 | } CHANNEL_OFFSETS; 68 | 69 | // Flags that control modifications to the lowpass values 70 | typedef enum modify_lowpass_flags 71 | { 72 | MODIFY_LOWPASS_DISABLE = 0, 73 | MODIFY_LOWPASS_ENABLE = 1, 74 | 75 | } MODIFY_LOWPASS_FLAGS; 76 | 77 | 78 | #ifdef __cplusplus 79 | extern "C" { 80 | #endif 81 | 82 | bool GetThumbnailInfo(void *sample_ptr, 83 | size_t sample_size, 84 | uint32_t flags, 85 | size_t *actual_width_out, 86 | size_t *actual_height_out, 87 | size_t *actual_size_out); 88 | 89 | bool GenerateThumbnail(void *sample_ptr, 90 | size_t sample_size, 91 | void *output_buffer, 92 | size_t output_size, 93 | uint32_t flags, 94 | size_t *actual_width_out, 95 | size_t *actual_height_out, 96 | size_t *actual_size_out); 97 | 98 | // Get the lowpass image with the encoded dimensions and format 99 | bool GetLowpassThumbnail(void *sample_ptr, 100 | size_t sample_size, 101 | void *output_buffer, 102 | size_t output_size, 103 | size_t *actual_width_out, 104 | size_t *actual_height_out, 105 | size_t *actual_size_out, 106 | int *actual_format_out); 107 | 108 | // Get the lowpass stereo thumbnail (left image over right image) 109 | bool GetStereoThumbnail(void *sample_ptr, 110 | size_t sample_size, 111 | void *output_buffer, 112 | size_t output_size, 113 | size_t *actual_width_out, 114 | size_t *actual_height_out, 115 | size_t *actual_size_out, 116 | int *actual_format_out, 117 | CHANNEL_OFFSETS *channel_offsets_out); 118 | 119 | void ChangeLowpassColumnValues(void *sample_buffer, 120 | size_t sample_size, 121 | int width, 122 | int height, 123 | int *channel_offsets, 124 | uint16_t *y_column_values, 125 | uint16_t *u_column_values, 126 | uint16_t *v_column_values); 127 | 128 | void ModifyLowpassColumnValues(void *sample_buffer, 129 | size_t sample_size, 130 | int width, 131 | int height, 132 | int *channel_offsets, 133 | uint16_t *y_column_flags, 134 | uint16_t *u_column_flags, 135 | uint16_t *v_column_flags); 136 | 137 | // Get the information about the lowpass image in the sample 138 | bool GetLowpassInfo(void *sample_ptr, 139 | size_t sample_size, 140 | size_t *actual_width_out, 141 | size_t *actual_height_out, 142 | size_t *actual_size_out, 143 | int *actual_format_out); 144 | 145 | // Get the lowpass image from the sample in its encoded format 146 | bool GetLowpassImage(void *sample_ptr, 147 | size_t sample_size, 148 | void *output_buffer); 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /Codec/timing.h: -------------------------------------------------------------------------------- 1 | /*! @file timing.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _TIMING_H 23 | #define _TIMING_H 24 | 25 | // Enable timing by default if in debug mode 26 | #ifdef _WIN32 27 | #ifndef _TIMING 28 | #if defined(_DEBUG) 29 | #define _TIMING _DEBUG 30 | #endif 31 | #endif 32 | #endif 33 | 34 | #if _TIMING 35 | 36 | #ifdef _WIN32 37 | 38 | #include 39 | #include 40 | 41 | // Filename used for importing into Excel 42 | #define TIMING_CSV_FILENAME "c:/Cedoc/Results/timing.csv" 43 | 44 | // The timer is a large integer as used by QueryPerformanceCounter 45 | typedef __int64 TIMER; 46 | 47 | // Construct for initializing timers 48 | #define TIMER_INITIALIZER 0 49 | 50 | // Conversion to units of milliseconds 51 | #define SEC(timer) ((float)timer / (float)frequency) 52 | #define MS(timer) (1000 * SEC(timer)) 53 | 54 | #else 55 | 56 | #include 57 | 58 | #if __APPLE__ 59 | #include "macdefs.h" 60 | #endif 61 | 62 | // Use the absolute timer on the Macintosh 63 | #include 64 | 65 | // The Macintosh absolute timer returns an unsigned 64-bit integer 66 | typedef uint64_t TIMER; 67 | 68 | #define TIMER_INITIALIZER 0 69 | 70 | // Conversion to units of milliseconds 71 | #define SEC(timer) AbsoluteTimeInSeconds(timer) 72 | #define MS(timer) (1000 * SEC(timer)) 73 | 74 | #endif 75 | 76 | 77 | // The counter is an unsigned doubleword integer 78 | typedef uint32_t COUNTER; 79 | 80 | // Construct for initializing counters 81 | #define COUNTER_INITIALIZER 0 82 | 83 | 84 | #ifdef __cplusplus 85 | extern "C" { 86 | #endif 87 | 88 | BOOL InitTiming(void); 89 | void StartTimer(TIMER *timer); 90 | void StopTimer(TIMER *timer); 91 | void DoThreadTiming(int startend); 92 | 93 | #ifdef _WIN32 94 | void PrintStatistics(FILE *logfile, int frame_count, HWND hwnd, char *results); 95 | #else 96 | void PrintStatistics(FILE *logfile, int frame_count, void *unused, char *results); 97 | float AbsoluteTimeInSeconds(TIMER timer); 98 | float AbsoluteTimerResolution(); 99 | #endif 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | // Define the timer start/stop macros if the configuration includes timing 106 | 107 | #define START(timer) {if (TIMING) StartTimer(&timer);} 108 | #define STOP(timer) {if (TIMING) StopTimer(&timer);} 109 | 110 | #else 111 | 112 | // Define null macros for the start and stop timer functions 113 | 114 | #define START(timer) 115 | #define STOP(timer) 116 | 117 | #endif 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /Common/CFHDAllocator.h: -------------------------------------------------------------------------------- 1 | /*! @file CFHDAllocator.h 2 | * 3 | * @brief Setting up and controlling the Allocator used within the CineForm SDKs 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #pragma once 22 | #ifndef CFHD_ALLOCATOR_H 23 | #define CFHD_ALLOCATOR_H 24 | 25 | typedef void * (* UnalignedAllocProc)(void *allocator, size_t size); 26 | typedef void * (* AlignedAllocProc)(void *allocator, size_t size, size_t alignment); 27 | typedef void (* UnalignedFreeProc)(void *allocator, void *block); 28 | typedef void (* AlignedFreeProc)(void *allocator, void *block); 29 | 30 | 31 | // Table of function pointers in an instance of a C++ allocator interface 32 | struct cfhd_allocator_vtable 33 | { 34 | // Do not change the order of the procedure pointers 35 | UnalignedAllocProc unaligned_malloc; 36 | UnalignedFreeProc unaligned_free; 37 | AlignedAllocProc aligned_malloc; 38 | AlignedFreeProc aligned_free; 39 | }; 40 | 41 | typedef struct cfhd_allocator 42 | { 43 | // Pointer to the vtable in the allocator interface 44 | struct cfhd_allocator_vtable *vtable; 45 | 46 | // Add member variables here if they are accessed in the C code 47 | 48 | } ALLOCATOR; 49 | 50 | #define CFHD_ALLOCATOR ALLOCATOR 51 | 52 | #endif // CFHD_ALLOCATOR_H 53 | -------------------------------------------------------------------------------- /Common/CFHDError.h: -------------------------------------------------------------------------------- 1 | /*! @file CFHDError.h 2 | * 3 | * @brief List of error codes returned from the CineForm codec SDKs. 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #pragma once 22 | #ifndef CFHD_ERROR_H 23 | #define CFHD_ERROR_H 24 | 25 | typedef enum CFHD_Error 26 | { 27 | CFHD_ERROR_OKAY = 0, 28 | CFHD_ERROR_INVALID_ARGUMENT, 29 | CFHD_ERROR_OUTOFMEMORY, 30 | CFHD_ERROR_BADFORMAT, 31 | CFHD_ERROR_BADSCALING, 32 | CFHD_ERROR_BADSAMPLE, 33 | CFHD_ERROR_INTERNAL, 34 | CFHD_ERROR_METADATA_CLASS, 35 | CFHD_ERROR_METADATA_UNDEFINED, 36 | CFHD_ERROR_METADATA_END, 37 | CFHD_ERROR_UNEXPECTED, 38 | CFHD_ERROR_BAD_RESOLUTION, 39 | CFHD_ERROR_BAD_PIXEL_SIZE, 40 | CFHD_ERROR_NOT_FINISHED, 41 | CFHD_ERROR_ENCODING_NOT_STARTED, 42 | CFHD_ERROR_METADATA_ATTACHED, 43 | CFHD_ERROR_BAD_METADATA, 44 | CFHD_ERROR_THREAD_CREATE_FAILED, 45 | CFHD_ERROR_THREAD_WAIT_FAILED, 46 | CFHD_ERROR_UNKNOWN_TAG, 47 | CFHD_ERROR_LICENSING, 48 | 49 | // Error codes returned by the codec library 50 | CFHD_ERROR_CODEC_ERROR = 2048, 51 | CFHD_ERROR_DECODE_BUFFER_SIZE, 52 | 53 | // Error codes used by the sample code distributed with the codec SDK 54 | CFHD_ERROR_SAMPLE_CODE = 4096, 55 | CFHD_ERROR_FILE_CREATE, 56 | CFHD_ERROR_FILE_OPEN, 57 | CFHD_ERROR_BADFILE, 58 | CFHD_ERROR_READ_FAILURE, 59 | CFHD_ERROR_WRITE_FAILURE, 60 | CFHD_ERROR_FILE_SIZE, 61 | CFHD_ERROR_END_OF_FILE, 62 | CFHD_ERROR_END_OF_DATABASE, 63 | CFHD_ERROR_THREAD, 64 | 65 | // CFHD codec error codes in the Macintosh coding style 66 | kCFHDErrorOkay = CFHD_ERROR_OKAY, 67 | kCFHDErrorInvalidArgument = CFHD_ERROR_INVALID_ARGUMENT, 68 | kCFHDErrorOutOfMemory = CFHD_ERROR_OUTOFMEMORY, 69 | kCFHDErrorBadFormat = CFHD_ERROR_BADFORMAT, 70 | kCFHDErrorBadScaling = CFHD_ERROR_BADSCALING, 71 | kCFHDErrorBadSample = CFHD_ERROR_BADSAMPLE, 72 | kCFHDErrorCodecError = CFHD_ERROR_CODEC_ERROR, 73 | kCFHDErrorInternal = CFHD_ERROR_INTERNAL, 74 | kCFHDErrorMetadataClass = CFHD_ERROR_METADATA_CLASS, 75 | kCFHDErrorMetadataUndefined = CFHD_ERROR_METADATA_UNDEFINED, 76 | 77 | // Error codes used by the sample code (Macintosh style) 78 | kCFHDErrorBadFile = CFHD_ERROR_BADFILE, 79 | kCFHDErrorReadFailure = CFHD_ERROR_READ_FAILURE, 80 | kCFHDErrorWriteFailure = CFHD_ERROR_WRITE_FAILURE, 81 | 82 | } CFHD_Error; 83 | 84 | #endif // CFHD_ERROR_H 85 | -------------------------------------------------------------------------------- /Common/CFHDMetadata.h: -------------------------------------------------------------------------------- 1 | /*! @file CFHDMetadata.h 2 | * 3 | * @brief Metadata parsing functions. 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #pragma once 22 | #ifndef CFHD_METADATA_H 23 | #define CFHD_METADATA_H 24 | 25 | #include "CFHDError.h" 26 | #include "CFHDTypes.h" 27 | #include "CFHDMetadataTags.h" 28 | 29 | #ifdef _WIN32 30 | #ifndef DYNAMICLIB 31 | #define CFHDMETADATA_API 32 | #else 33 | #ifdef METADATADLL_EXPORTS 34 | // Export the entry points for the metadata interface 35 | #define CFHDMETADATA_API __declspec(dllexport) 36 | #else 37 | // Declare the entry points to the metadata interface 38 | #define CFHDMETADATA_API __declspec(dllimport) 39 | #endif 40 | #endif 41 | #else 42 | #ifdef METADATADLL_EXPORTS 43 | #define CFHDMETADATA_API __attribute__((visibility("default"))) 44 | #else 45 | #define CFHDMETADATA_API 46 | #endif 47 | #endif 48 | 49 | 50 | // Opaque datatype for the CineForm HD metadata 51 | typedef void *CFHD_MetadataRef; 52 | 53 | // Interface to the codec library for use with either C or C++ 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | 59 | #if DYNAMICALLY_LINK 60 | 61 | // Open an interface to the CineForm HD metadata 62 | CFHD_Error 63 | CFHD_OpenMetadataStub(CFHD_MetadataRef *metadataRefOut); 64 | 65 | // Initial the metadata interface for a particular sample and metadata track 66 | CFHD_Error 67 | CFHD_InitSampleMetadataStub(CFHD_MetadataRef metadataRef, 68 | CFHD_MetadataTrack track, 69 | void *sampleData, 70 | size_t sampleSize); 71 | 72 | // Read the block of metadata 73 | CFHD_Error 74 | CFHD_ReadMetadataFromSampleStub(CFHD_MetadataRef metadataRef, 75 | void **data, 76 | CFHD_MetadataSize *size); 77 | 78 | 79 | // Read the next tag, size & value from the metadata 80 | CFHD_Error 81 | CFHD_ReadMetadataStub(CFHD_MetadataRef metadataRef, 82 | unsigned int *tag, 83 | CFHD_MetadataType *type, 84 | void **data, 85 | CFHD_MetadataSize *size); 86 | 87 | // Find a particular tag, size & value from the metadata 88 | CFHD_Error 89 | CFHD_FindMetadataStub(CFHD_MetadataRef metadataRef, 90 | unsigned int tag, 91 | CFHD_MetadataType *type, 92 | void **data, 93 | CFHD_MetadataSize *size); 94 | 95 | // Close an interface to the CineForm HD metadata 96 | CFHD_Error 97 | CFHD_CloseMetadataStub(CFHD_MetadataRef metadataRef); 98 | 99 | #define CFHD_OpenMetadata CFHD_OpenMetadataStub 100 | #define CFHD_InitSampleMetadata CFHD_InitSampleMetadataStub 101 | #define CFHD_ReadMetadataFromSample CFHD_ReadMetadataFromSampleStub 102 | #define CFHD_ReadMetadata CFHD_ReadMetadataStub 103 | #define CFHD_FindMetadata CFHD_FindMetadataStub 104 | #define CFHD_CloseMetadata CFHD_CloseMetadataStub 105 | 106 | #else // DYNAMICALLY_LINK 107 | 108 | // Open an interface to the CineForm HD metadata 109 | CFHDMETADATA_API CFHD_Error 110 | CFHD_OpenMetadata(CFHD_MetadataRef *metadataRefOut); 111 | 112 | // Initial the metadata interface for a particular sample and metadata track 113 | CFHDMETADATA_API CFHD_Error 114 | CFHD_InitSampleMetadata(CFHD_MetadataRef metadataRef, 115 | CFHD_MetadataTrack track, 116 | void *sampleData, 117 | size_t sampleSize); 118 | 119 | // Read the block of metadata 120 | CFHDMETADATA_API CFHD_Error 121 | CFHD_ReadMetadataFromSample(CFHD_MetadataRef metadataRef, 122 | void **dataOut, 123 | size_t *sizeOut); 124 | 125 | // Read the next tag, size & value from the metadata 126 | CFHDMETADATA_API CFHD_Error 127 | CFHD_ReadMetadata(CFHD_MetadataRef metadataRef, 128 | CFHD_MetadataTag *tag, 129 | CFHD_MetadataType *type, 130 | void **data, 131 | CFHD_MetadataSize *size); 132 | 133 | // Find a particular metadata tag and return the size and value 134 | CFHDMETADATA_API CFHD_Error 135 | CFHD_FindMetadata(CFHD_MetadataRef metadataRef, 136 | CFHD_MetadataTag tag, 137 | CFHD_MetadataType *type, 138 | void **data, 139 | CFHD_MetadataSize *size); 140 | 141 | // Close an interface to the CineForm HD metadata 142 | CFHDMETADATA_API CFHD_Error 143 | CFHD_CloseMetadata(CFHD_MetadataRef metadataRef); 144 | 145 | #endif // DYNAMICALLY_LINK 146 | 147 | #ifdef __cplusplus 148 | } 149 | #endif 150 | 151 | #endif // CFHD_METADATA_H 152 | -------------------------------------------------------------------------------- /Common/CFHDSampleHeader.h: -------------------------------------------------------------------------------- 1 | /*! @file CFHDSampleHeader.h 2 | * 3 | * @brief Utilities for parsing the compressed sample header for a CineForm compressed frame. 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #pragma once 22 | #ifndef CFHD_SAMPLE_HEADER_H 23 | #define CFHD_SAMPLE_HEADER_H 24 | 25 | /*! 26 | @brief Information obtained by parsing the sample header 27 | 28 | @todo Add more fields from the sample header to this class as 29 | private data and define public get and set methods to access 30 | the data. 31 | */ 32 | class CFHD_SampleHeader 33 | { 34 | public: 35 | 36 | CFHD_SampleHeader() : 37 | m_encodedFormat(CFHD_ENCODED_FORMAT_YUV_422), 38 | m_fieldType(CFHD_FIELD_TYPE_UNKNOWN), 39 | m_width(0), 40 | m_height(0) 41 | { 42 | } 43 | 44 | CFHD_Error SetEncodedFormat(CFHD_EncodedFormat encodedFormat) 45 | { 46 | m_encodedFormat = encodedFormat; 47 | return CFHD_ERROR_OKAY; 48 | } 49 | 50 | CFHD_Error GetEncodedFormat(CFHD_EncodedFormat *encodedFormatOut) 51 | { 52 | *encodedFormatOut = m_encodedFormat; 53 | return CFHD_ERROR_OKAY; 54 | } 55 | 56 | CFHD_Error SetFieldType(CFHD_FieldType fieldType) 57 | { 58 | m_fieldType = fieldType; 59 | return CFHD_ERROR_OKAY; 60 | } 61 | 62 | CFHD_Error GetFieldType(CFHD_FieldType *fieldTypeOut) 63 | { 64 | *fieldTypeOut = m_fieldType; 65 | return CFHD_ERROR_OKAY; 66 | } 67 | 68 | CFHD_Error SetFrameSize(int width, int height) 69 | { 70 | m_width = width; 71 | m_height = height; 72 | return CFHD_ERROR_OKAY; 73 | } 74 | 75 | CFHD_Error GetFrameSize(int *widthOut, int *heightOut) 76 | { 77 | *widthOut = m_width; 78 | *heightOut = m_height; 79 | return CFHD_ERROR_OKAY; 80 | } 81 | 82 | private: 83 | CFHD_EncodedFormat m_encodedFormat; 84 | CFHD_FieldType m_fieldType; 85 | int m_width; 86 | int m_height; 87 | }; 88 | 89 | #endif // CFHD_SAMPLE_HEADER_H 90 | -------------------------------------------------------------------------------- /Common/Condition.h: -------------------------------------------------------------------------------- 1 | /*! @file Condition.h 2 | 3 | * @brief Threading tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | // Control use of the new Windows condition variable primitives 25 | //#define _CONDITION_VARIABLE 26 | 27 | /*! 28 | @Brief Use a condition variable to wait until some predicate is true 29 | */ 30 | class ConditionVariable 31 | { 32 | static const unsigned long DEFAULT_TIMEOUT = 100; 33 | 34 | public: 35 | #ifdef _CONDITION_VARIABLE 36 | ConditionVariable() 37 | { 38 | InitializeConditionVariable(&condition); 39 | } 40 | #elif _WIN32 41 | ConditionVariable() : 42 | handle(NULL) 43 | { 44 | // Use an automatic reset event to implement a condition variable 45 | handle = CreateEvent(NULL, FALSE, FALSE, NULL); 46 | assert(handle != NULL); 47 | } 48 | 49 | ~ConditionVariable() 50 | { 51 | CloseHandle(handle); 52 | handle = NULL; 53 | } 54 | #else 55 | ConditionVariable() 56 | { 57 | pthread_cond_init(&cond, NULL); 58 | } 59 | #endif 60 | 61 | bool Wait(CSimpleLock &mutex, unsigned long timeout = DEFAULT_TIMEOUT) 62 | { 63 | #ifdef _CONDITION_VARIABLE 64 | return SleepConditionVariableCS(&condition, &mutex.lock, timeout); 65 | #elif _WIN32 66 | mutex.Unlock(); 67 | DWORD result = WaitForSingleObject(handle, timeout); 68 | mutex.Lock(); 69 | return (result == WAIT_OBJECT_0); 70 | #else 71 | return pthread_cond_wait(&cond, &mutex.lock); 72 | #endif 73 | } 74 | 75 | void Wake() 76 | { 77 | #ifdef _CONDITION_VARIABLE 78 | WakeConditionVariable(&condition); 79 | #elif _WIN32 80 | SetEvent(handle); 81 | #else 82 | pthread_cond_signal(&cond); 83 | #endif 84 | } 85 | 86 | private: 87 | 88 | #ifdef _CONDITION_VARIABLE 89 | CONDITION_VARIABLE condition; 90 | #elif _WIN32 91 | HANDLE handle; 92 | #else 93 | pthread_cond_t cond; 94 | #endif 95 | 96 | }; 97 | -------------------------------------------------------------------------------- /Common/IAllocator.h: -------------------------------------------------------------------------------- 1 | /*! @file IAllocator.h 2 | 3 | * @brief Memory tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #pragma once 22 | 23 | #ifdef _WIN32 24 | // Force use of the normal C language calling conventions 25 | #define CALLTYPE_(type) type __cdecl 26 | #else 27 | // Use the default calling conventions the Macintosh 28 | #define CALLTYPE_(type) type 29 | #endif 30 | 31 | 32 | /*! 33 | @brief Interface to a memory allocator 34 | 35 | The definitions in this class must match the definitions in the 36 | struct for defining allocators in the C interface. 37 | */ 38 | class IAllocator 39 | { 40 | public: 41 | // Do not change the order of these virtual methods 42 | virtual CALLTYPE_(void *) Alloc(size_t size) = 0; 43 | virtual CALLTYPE_(void) Free(void *block) = 0; 44 | virtual CALLTYPE_(void *) AlignedAlloc(size_t size, size_t alignment) = 0; 45 | virtual CALLTYPE_(void) AlignedFree(void *block) = 0; 46 | 47 | // Define virtual destructor so the destructor in derived classes is called 48 | virtual ~IAllocator() {} 49 | }; 50 | -------------------------------------------------------------------------------- /Common/Lock.h: -------------------------------------------------------------------------------- 1 | /*! @file Lock.h 2 | 3 | * @brief Threading tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #pragma once 22 | 23 | 24 | /*! 25 | @brief Simple lock for controlling access to a critical section 26 | 27 | This class is called a simple lock as there can be other kinds of locks. 28 | All lock classes should provide lock and unlock methods and be derived 29 | from a common base class. 30 | */ 31 | #ifdef _WIN32 32 | 33 | class CSimpleLock 34 | { 35 | friend class ConditionVariable; 36 | 37 | public: 38 | 39 | CSimpleLock() 40 | { 41 | InitializeCriticalSection(&lock); 42 | } 43 | 44 | ~CSimpleLock() 45 | { 46 | DeleteCriticalSection(&lock); 47 | } 48 | 49 | void Lock() 50 | { 51 | EnterCriticalSection(&lock); 52 | } 53 | 54 | void Unlock() 55 | { 56 | LeaveCriticalSection(&lock); 57 | } 58 | 59 | private: 60 | 61 | CRITICAL_SECTION lock; 62 | }; 63 | 64 | #elif __APPLE__ || __GNUC__ 65 | 66 | #include "pthread.h" 67 | 68 | class CSimpleLock 69 | { 70 | friend class ConditionVariable; 71 | 72 | public: 73 | 74 | CSimpleLock() 75 | { 76 | pthread_mutex_init(&lock, NULL); 77 | } 78 | 79 | ~CSimpleLock() 80 | { 81 | pthread_mutex_destroy(&lock); 82 | } 83 | 84 | void Lock() 85 | { 86 | pthread_mutex_lock(&lock); 87 | } 88 | 89 | void Unlock() 90 | { 91 | pthread_mutex_unlock(&lock); 92 | } 93 | 94 | private: 95 | 96 | pthread_mutex_t lock; 97 | }; 98 | 99 | #endif 100 | 101 | 102 | /*! 103 | @brief Lock access to a critical section with automatic unlocking 104 | 105 | Acquire access to a critical section and relinquish access when the 106 | class instance is destroyed. The typical use case is to allocate an 107 | instance of this class on the stack so that the lock is automatically 108 | relinquished when enclosing lexical scope is released. 109 | 110 | Future versions may support automatic unlocking of other types of locks. 111 | In this case, the constructor and member variable should be changed to 112 | accept the base class for all locks as an argument. 113 | */ 114 | class CAutoLock 115 | { 116 | public: 117 | 118 | CAutoLock(CSimpleLock *lock) : 119 | m_lock(lock) 120 | { 121 | m_lock->Lock(); 122 | } 123 | 124 | CAutoLock(CSimpleLock &lock) : 125 | m_lock(&lock) 126 | { 127 | m_lock->Lock(); 128 | } 129 | 130 | ~CAutoLock() 131 | { 132 | m_lock->Unlock(); 133 | } 134 | 135 | private: 136 | 137 | CSimpleLock *m_lock; 138 | 139 | }; 140 | -------------------------------------------------------------------------------- /Common/MessageQueue.cpp: -------------------------------------------------------------------------------- 1 | /*! @file MesssageQueue.pp 2 | 3 | * @brief Threading tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "StdAfx.h" 22 | 23 | #undef DEBUG 24 | #define DEBUG (1 && _DEBUG) 25 | 26 | #ifndef ASSERT 27 | #define ASSERT(x) assert(x) 28 | #endif 29 | 30 | #include "CFHDError.h" 31 | #include "Lock.h" 32 | #include "ThreadMessage.h" 33 | #include "MessageQueue.h" 34 | 35 | 36 | // Initialize the counting semaphore for the number of messages in the queue 37 | template 38 | MessageQueue::MessageQueue() : 39 | m_messageSema(MESSAGE_QUEUE_MAX_COUNT) 40 | { 41 | } 42 | 43 | template 44 | MessageQueue::~MessageQueue() 45 | { 46 | // There should not be any messages remaining in the queue 47 | assert(Length() == 0); 48 | } 49 | 50 | template 51 | CFHD_Error 52 | MessageQueue::AddMessage(const MessageType &message) 53 | { 54 | // Lock access to the message queue 55 | CAutoLock lock(&m_queueMutex); 56 | 57 | //fprintf(stderr, "Posting new message\n"); 58 | 59 | // Add the message to the queue 60 | m_messageQueue.push(message); 61 | 62 | // Signal that a new message is available 63 | if (!m_messageSema.Post()) { 64 | fprintf(stderr, "Message queue semaphore post returned false\n"); 65 | } 66 | 67 | return CFHD_ERROR_OKAY; 68 | } 69 | 70 | template 71 | CFHD_Error 72 | MessageQueue::WaitForMessage(MessageType &message) 73 | { 74 | //CFHD_Error error = CFHD_ERROR_OKAY; 75 | 76 | // Wait for a message in the queue 77 | //ASSERT(m_messageSema.Wait()); 78 | //while (Length() == 0) 79 | // continue; 80 | 81 | if (!m_messageSema.Wait()) { 82 | ASSERT(0); 83 | fprintf(stderr, "Message queue semaphore wait returned false\n"); 84 | } 85 | 86 | // Lock access to the message queue 87 | CAutoLock lock(&m_queueMutex); 88 | 89 | // There should be at least one message in the queue 90 | ASSERT(Length() > 0); 91 | if (! (Length() > 0)) { 92 | fprintf(stderr, "Message queue length not positive: %ld\n", Length()); 93 | } 94 | 95 | // Remove the first message from the queue 96 | message = m_messageQueue.front(); 97 | m_messageQueue.pop(); 98 | 99 | #if (0 && DEBUG && _WIN32) 100 | // Check the order in which messages are removed from the queue 101 | char string[256]; 102 | sprintf_s(string, sizeof(string), "Message number: %d\n", message->MessageNumber()); 103 | OutputDebugString(string); 104 | #endif 105 | 106 | return CFHD_ERROR_OKAY; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Common/MessageQueue.h: -------------------------------------------------------------------------------- 1 | /*! @file MessageQueue.h 2 | 3 | * @brief Threading tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | 25 | // Forward reference to the thread message 26 | //class CThreadMessage; 27 | 28 | #ifdef __APPLE__ 29 | #include 30 | #endif 31 | 32 | 33 | class CMessageSemaphore 34 | { 35 | #ifdef _WIN32 36 | 37 | public: 38 | 39 | CMessageSemaphore(long maximum_count) : 40 | handle(NULL) 41 | { 42 | handle = CreateSemaphore(NULL, 0, maximum_count, NULL); 43 | assert(handle != NULL); 44 | } 45 | 46 | ~CMessageSemaphore() 47 | { 48 | if (handle) 49 | { 50 | CloseHandle(handle); 51 | handle = NULL; 52 | } 53 | } 54 | 55 | bool Wait() 56 | { 57 | if (handle) 58 | { 59 | // Wait for the semaphore indefinitely 60 | DWORD result = WaitForSingleObject(handle, INFINITE); 61 | return result == WAIT_OBJECT_0; 62 | } 63 | //return WAIT_ABANDONED; 64 | return false; 65 | } 66 | 67 | bool Post() 68 | { 69 | if (handle) 70 | { 71 | long count; 72 | BOOL result = ReleaseSemaphore(handle, 1, &count); 73 | assert(result); 74 | return result != 0; 75 | } 76 | return false; 77 | } 78 | 79 | private: 80 | 81 | HANDLE handle; 82 | 83 | 84 | #elif defined (__APPLE__) 85 | 86 | 87 | public: 88 | 89 | CMessageSemaphore(long maximum_count) 90 | { 91 | //int result = sem_init(&sema, 0, 0); 92 | semaphore = dispatch_semaphore_create(0); 93 | //printf("sem_init %d\n", result); 94 | //assert(result == 0); 95 | } 96 | 97 | ~CMessageSemaphore() 98 | { 99 | dispatch_semaphore_signal(semaphore); 100 | //int result = sem_destroy(&sema); 101 | //assert(result == 0); 102 | } 103 | 104 | bool Wait() 105 | { 106 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 107 | //int result = sem_wait(&sema); 108 | //assert(result == 0); 109 | //return (result == 0); 110 | return true; 111 | } 112 | 113 | bool Post() 114 | { 115 | dispatch_semaphore_signal(semaphore); 116 | //int result = sem_post(&sema); 117 | //assert(result == 0); 118 | //return (result == 0); 119 | return true; 120 | } 121 | 122 | private: 123 | 124 | //sem_t sema; 125 | dispatch_semaphore_t semaphore; 126 | 127 | #else 128 | 129 | public: 130 | 131 | CMessageSemaphore(long maximum_count) 132 | { 133 | int result = sem_init(&sema, 0, 0); 134 | assert(result == 0); 135 | } 136 | 137 | ~CMessageSemaphore() 138 | { 139 | int result = sem_destroy(&sema); 140 | assert(result == 0); 141 | } 142 | 143 | bool Wait() 144 | { 145 | int result = sem_wait(&sema); 146 | assert(result == 0); 147 | return (result == 0); 148 | } 149 | 150 | bool Post() 151 | { 152 | int result = sem_post(&sema); 153 | assert(result == 0); 154 | return (result == 0); 155 | } 156 | 157 | private: 158 | 159 | sem_t sema; 160 | 161 | #endif 162 | }; 163 | 164 | /*! 165 | @brief Thread-safe message queue 166 | 167 | Implements a message queue using the queue container from the 168 | standard template library by adding a mutex to control access 169 | to the critical section and a counting semaphore for the number 170 | of messages in the queue. 171 | */ 172 | template class MessageQueue 173 | { 174 | //! Maximum number of messages in the queue 175 | static const long MESSAGE_QUEUE_MAX_COUNT = 1024; 176 | 177 | public: 178 | 179 | MessageQueue(); 180 | 181 | ~MessageQueue(); 182 | 183 | //! Add a message to the message queue 184 | CFHD_Error AddMessage(const MessageType &message); 185 | 186 | //! Wait for a message and return the next message 187 | CFHD_Error WaitForMessage(MessageType &message); 188 | 189 | //! Return the number of messages in the queue 190 | size_t Length() 191 | { 192 | return m_messageQueue.size(); 193 | } 194 | 195 | protected: 196 | 197 | std::queue m_messageQueue; // 30 | 31 | // Includes required for Visual Studio 2005 (not required for Visual Studio 2003) 32 | //#include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef _WIN32 40 | #define __STDC_LIMIT_MACROS 41 | #include 42 | #endif 43 | 44 | #else 45 | 46 | // Hack to eliminate conflict with the codec CODESET data type 47 | #define _LANGINFO_H 1 48 | 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #ifndef __APPLE__ 55 | #include 56 | #endif 57 | 58 | #include 59 | #include 60 | #include 61 | 62 | #define __STDC_LIMIT_MACROS 63 | #include 64 | 65 | //#if __APPLE__ 66 | //#include "macdefs.h" 67 | //#endif 68 | 69 | #include 70 | #include 71 | 72 | #endif 73 | 74 | // The encoder and thread pools use the vector data type from the standard template library 75 | #include 76 | 77 | // The encoder job queue uses a deque from the standard template library 78 | #include 79 | 80 | // The message queue for the worker threads uses a queue from the standard template library 81 | #include 82 | 83 | // TODO: reference additional headers your program requires here 84 | -------------------------------------------------------------------------------- /Common/ThreadMessage.cpp: -------------------------------------------------------------------------------- 1 | /*! @file ThreadMessage.cpp 2 | 3 | * @brief Thread Library Tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "StdAfx.h" 22 | #include "Lock.h" 23 | #include "ThreadMessage.h" 24 | 25 | 26 | #if _DEBUG 27 | ThreadSafeCounter ThreadMessage::counter; 28 | #endif 29 | -------------------------------------------------------------------------------- /Common/ThreadMessage.h: -------------------------------------------------------------------------------- 1 | /*! @file ThreadMessage.h 2 | 3 | * @brief Thread Library Tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | 25 | /*! 26 | @brief Thread-safe counter 27 | 28 | The thread-safe counter wraps an integer counter in a class 29 | with a lock that controls concurrent access to the counter. 30 | */ 31 | class ThreadSafeCounter 32 | { 33 | public: 34 | 35 | ThreadSafeCounter() : 36 | counter(0) 37 | { 38 | } 39 | 40 | ~ThreadSafeCounter() 41 | { 42 | } 43 | 44 | int GetNextNumber() 45 | { 46 | CAutoLock lock(mutex); 47 | 48 | counter++; 49 | int number = counter; 50 | 51 | return number; 52 | } 53 | 54 | private: 55 | 56 | int counter; //!< Current value of the counter 57 | CSimpleLock mutex; //!< Lock access to the counter 58 | }; 59 | 60 | 61 | /*! 62 | @brief Base class for thread messages 63 | 64 | This base class provides the member variable for the thread command 65 | that is common to all thread messages and defines the enumeration 66 | for the thread commands. 67 | */ 68 | class ThreadMessage 69 | { 70 | public: 71 | 72 | enum ThreadCommand 73 | { 74 | THREAD_COMMAND_NULL = 0, 75 | THREAD_COMMAND_START, 76 | THREAD_COMMAND_STOP, 77 | THREAD_COMMAND_ENCODE, 78 | }; 79 | 80 | ThreadMessage() : 81 | command(THREAD_COMMAND_NULL) 82 | { 83 | #if _DEBUG 84 | number = counter.GetNextNumber(); 85 | #endif 86 | } 87 | 88 | ThreadMessage(ThreadCommand command) : 89 | command(command) 90 | { 91 | #if _DEBUG 92 | number = counter.GetNextNumber(); 93 | #endif 94 | } 95 | 96 | // Must define a copy constructor 97 | ThreadMessage(const ThreadMessage& message) : 98 | command(message.command) 99 | { 100 | #if _DEBUG 101 | number = message.number; 102 | #endif 103 | } 104 | 105 | #if 0 106 | virtual ~ThreadMessage() 107 | { 108 | } 109 | #endif 110 | 111 | const ThreadMessage& operator= (const ThreadMessage& message) 112 | { 113 | if (&message != this) 114 | { 115 | command = message.command; 116 | #if _DEBUG 117 | number = message.number; 118 | #endif 119 | } 120 | return *this; 121 | } 122 | 123 | ThreadCommand Command() 124 | { 125 | return command; 126 | } 127 | 128 | private: 129 | 130 | ThreadCommand command; 131 | 132 | #if _DEBUG 133 | public: 134 | int MessageNumber() 135 | { 136 | return (int)number; 137 | } 138 | private: 139 | size_t number; //!< Each message is numbered for debugging 140 | /*DAN static */ ThreadSafeCounter counter; //!< Thread-safe counter used to count messages 141 | #endif 142 | }; 143 | 144 | #if 0 145 | /*! 146 | @brief Derived class for the thread process message 147 | 148 | This class sets the thread command member to the process command 149 | and provides the procedure that is called by the worker thread 150 | to process the message. The parameter in the process message is 151 | passed to the process message procedure. 152 | 153 | This class should be subclassed to provide the specific message 154 | processing functionality. The subclass must implement the virtual 155 | ProcessMessage method to process the message. 156 | */ 157 | class CProcessMessage : public CThreadMessage 158 | { 159 | protected: 160 | 161 | CProcessMessage(void *param) : 162 | CThreadMessage(THREAD_COMMAND_PROCESS), 163 | m_param(param), 164 | m_result(0) 165 | { 166 | } 167 | 168 | virtual ~CProcessMessage() 169 | { 170 | } 171 | 172 | public: 173 | 174 | //! Procedure for processing the message 175 | virtual int ProcessMessage(void *param = NULL) = 0; 176 | 177 | private: 178 | 179 | //! Parameter passed to the process message procedure 180 | void *m_param; 181 | 182 | //! Result from processing this message (returned by ProcessMessage) 183 | int m_result; 184 | 185 | }; 186 | #endif 187 | -------------------------------------------------------------------------------- /Common/ThreadPool.cpp: -------------------------------------------------------------------------------- 1 | /*! @file ThreadPool.cpp 2 | 3 | * @brief Thread Library Tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "StdAfx.h" 22 | 23 | #undef DEBUG 24 | #define DEBUG (1 && _DEBUG) 25 | 26 | #ifndef ASSERT 27 | #define ASSERT(x) assert(x) 28 | #endif 29 | 30 | #include "CFHDError.h" 31 | #include "Lock.h" 32 | #include "ThreadMessage.h" 33 | #include "MessageQueue.h" 34 | #include "ThreadPool.h" 35 | 36 | /*! 37 | @brief Create the thread pool 38 | 39 | Note that the locks must be created and the message queue must be initialized 40 | before the threads are created since the threads will immediately begin execution 41 | and wait for a message in the queue. 42 | */ 43 | template 44 | CThreadPool::CThreadPool(size_t threadCount) : 45 | m_threadPool(threadCount) 46 | { 47 | CFHD_Error error = CFHD_ERROR_OKAY; 48 | 49 | #if 0 50 | if (m_threadCount > THREAD_POOL_MAX_THREADS) { 51 | m_threadCount = THREAD_POOL_MAX_THREADS; 52 | } 53 | 54 | // Check that the thread count does not exceed the allocated size of the thread pool 55 | ASSERT(0 < m_threadCount && m_threadCount <= THREAD_POOL_MAX_THREADS); 56 | #endif 57 | } 58 | 59 | template 60 | CThreadPool::~CThreadPool() 61 | { 62 | // Check that the thread count does not exceed the allocated size of the thread pool 63 | //ASSERT(0 < m_threadCount && m_threadCount <= THREAD_POOL_MAX_THREADS); 64 | 65 | // Stop all of the worker threads in the pool 66 | StopWorkerThreads(); 67 | 68 | /* 69 | The deallocator for each thread will be called when the array of 70 | threads that is a member variable of this class is deallocated. 71 | */ 72 | } 73 | 74 | #if 0 75 | CFHD_Error CThreadPool::StartWorkerThreads(WorkerThreadProc threadProc, void *param) 76 | { 77 | //TODO: Need to check that this routine is only executed once 78 | 79 | // Check that the thread count does not exceed the allocated size of the thread pool 80 | //ASSERT(0 < m_threadCount && m_threadCount <= THREAD_POOL_MAX_THREADS); 81 | 82 | // Initialize the pool of worker threads 83 | for (int i = 0; i < m_threadPool.size(); i++) 84 | { 85 | // Create each thread in the pool 86 | m_threadPool[i].Start(threadProc, param); 87 | } 88 | 89 | // The threads will start running as soon as they are created 90 | 91 | return CFHD_ERROR_OKAY; 92 | } 93 | #endif 94 | 95 | template 96 | CFHD_Error 97 | CThreadPool::StartWorkerThread(size_t index, 98 | WorkerThreadProc threadProc, 99 | void *param) 100 | { 101 | // Check that the index is in range 102 | ASSERT(index < m_threadPool.size()); 103 | if (! (index < m_threadPool.size())) { 104 | return CFHD_ERROR_INVALID_ARGUMENT; 105 | } 106 | 107 | #if 0 108 | // Check that the thread has not already been started 109 | ASSERT(m_threadPool[index].HasStarted() == false); 110 | if (! (m_threadPool[index].HasStarted() == false)) 111 | #else 112 | // Check that the thread has not already been started 113 | ASSERT(m_threadPool[index].IsRunning() == false); 114 | if (! (m_threadPool[index].IsRunning() == false)) 115 | #endif 116 | { 117 | return CFHD_ERROR_UNEXPECTED; 118 | } 119 | 120 | // Create the worker thread 121 | m_threadPool[index].Start(threadProc, param); 122 | 123 | // The thread will start running as soon as it is created 124 | 125 | return CFHD_ERROR_OKAY; 126 | } 127 | 128 | template 129 | CFHD_Error 130 | CThreadPool::StopWorkerThreads() 131 | { 132 | // Post stop messages for all of the worker threads 133 | for (int i = 0; i < m_threadPool.size(); i++) 134 | { 135 | ThreadMessage *message = new ThreadMessage(ThreadMessage::THREAD_COMMAND_STOP); 136 | AddMessage(message); 137 | } 138 | 139 | // Wait for the threads to terminate 140 | for (int i = 0; i < m_threadPool.size(); i++) 141 | { 142 | m_threadPool[i].Wait(); 143 | } 144 | 145 | return CFHD_ERROR_OKAY; 146 | } 147 | 148 | #if 0 149 | int CThreadLimiter::GetProcessorCount() 150 | { 151 | SYSTEM_INFO cSystem_info; 152 | GetSystemInfo(&cSystem_info); 153 | return cSystem_info.dwNumberOfProcessors; 154 | } 155 | #endif 156 | -------------------------------------------------------------------------------- /Common/macdefs.h: -------------------------------------------------------------------------------- 1 | /*! @file macdefs.h 2 | 3 | * @brief Apple stuff 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _MACDEFS_H 23 | #define _MACDEFS_H 24 | 25 | 26 | // Override symbols used in Windows programming 27 | 28 | #ifdef WINAPI 29 | #undef WINAPI 30 | #endif 31 | 32 | #define WINAPI 33 | 34 | #ifndef _MAX_PATH 35 | #define _MAX_PATH 256 36 | #endif 37 | 38 | #define BAYER_SUPPORT 1 39 | 40 | // Define data types used in the codec that are not defined on the Macintosh 41 | 42 | typedef unsigned char BYTE; 43 | typedef unsigned char *PBYTE; 44 | typedef unsigned char *LPBYTE; 45 | 46 | typedef unsigned short WORD; 47 | 48 | typedef long LONG; 49 | typedef unsigned long DWORD; 50 | typedef unsigned long ULONG; 51 | 52 | typedef void VOID; 53 | typedef void *HANDLE; 54 | typedef void *LPVOID; 55 | 56 | #ifdef __INTEL_COMPILER 57 | #else 58 | typedef long long __int64; 59 | #endif 60 | 61 | typedef char INT8; 62 | typedef unsigned char UINT8; 63 | 64 | typedef short INT16; 65 | typedef unsigned short UINT16; 66 | 67 | typedef long INT32; 68 | typedef unsigned long UINT32; 69 | 70 | typedef unsigned long FOURCC; 71 | 72 | #ifndef _OBJC_OBJC_H_ 73 | typedef int BOOL; 74 | #endif 75 | 76 | //enum {FALSE = 0, TRUE = 1}; 77 | #ifndef TRUE 78 | #define TRUE 1 79 | #endif 80 | 81 | #ifndef FALSE 82 | #define FALSE 0 83 | #endif 84 | 85 | #define INFINITE 0xFFFFFFFF // Infinite timeout 86 | 87 | #define CopyMemory(dst, src, length) memcpy(dst, src, length) 88 | #define ZeroMemory(dst, length) memset(dst, 0, length) 89 | 90 | #if defined(HRESULT) 91 | #undef HRESULT 92 | typedef int32_t HRESULT; 93 | #endif 94 | 95 | #if !defined(FAILED) 96 | #define FAILED(hr) (((HRESULT)(hr)) < 0) 97 | #endif 98 | 99 | #if !defined(SUCCEEDED) 100 | #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) 101 | #endif 102 | 103 | #if !defined(_HRESULT_TYPEDEF) 104 | #define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc) 105 | #endif 106 | 107 | #if !defined(E_UNEXPECTED) 108 | #define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL) 109 | #endif 110 | 111 | #if !defined(E_INVALIDARG) 112 | #define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L) 113 | #endif 114 | 115 | #if !defined(E_POINTER) 116 | #define E_POINTER _HRESULT_TYPEDEF_(0x80004003L) 117 | #endif 118 | 119 | #if !defined(E_FAIL) 120 | #define E_FAIL _HRESULT_TYPEDEF_(0x80004005L) 121 | #endif 122 | 123 | #if !defined(E_OUTOFMEMORY) 124 | #define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL) 125 | #endif 126 | 127 | #if !defined(S_OK) 128 | #define S_OK ((HRESULT) 0L) 129 | #endif 130 | 131 | #if !defined(S_FALSE) 132 | #define S_FALSE ((HRESULT 1L) 133 | #endif 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /Common/ver.h: -------------------------------------------------------------------------------- 1 | /*! @file ver.h 2 | 3 | * @brief Version labelling 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #ifndef _VER_H 22 | #define _VER_H 23 | 24 | // Definitions used in the Macintosh resource file 25 | #define kCFHDCodecVersionMajor 10 26 | #define kCFHDCodecVersionMinor 1 27 | #define kCFHDCodecVersionRevision 0 28 | #define kCFHDCodecVersionBuild 693 29 | 30 | #define FILE_VERSION_NUMERIC 10,1,0,693 31 | #define FILE_VERSION_STRING "10, 1, 0, 693\0" 32 | 33 | #define CINEFORM_DESCRIPTION_L L"GoPro CineForm Codec v10.1.0" 34 | #define CINEFORM_DESCRIPTION_x64_L L"GoPro CineForm Codec (x64) v10.1.0" 35 | #define CONTROL_PANEL_DESCRIPTION "GoPro CineForm Codec v10.1.0" 36 | #define CINEFORM_COPYRIGHT "Copyright 2001-2021 GoPro Inc. All rights reserved.", 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ConvertLib/Bilinear.h: -------------------------------------------------------------------------------- 1 | /*! @file Bilinear.h 2 | 3 | * @brief Scaling tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | typedef unsigned char uint8_t; 22 | 23 | 24 | // Fast image scalers that use bilinear interpolation 25 | class CBilinearScaler : public CImageScaler 26 | { 27 | public: 28 | 29 | CBilinearScaler(IMemAlloc *pMemAlloc) : 30 | CImageScaler(pMemAlloc) 31 | { 32 | } 33 | 34 | ~CBilinearScaler() 35 | { 36 | // Free the scratch buffers used by the scaling routines 37 | //FreeScratchMemory(); 38 | } 39 | 40 | protected: 41 | 42 | #if 0 43 | // Allocate scratch memory used by the scaling routines 44 | bool AllocScratchMemory(int outputWidth, int inputHeight) 45 | { 46 | size_t horizontal_scale_size = outputWidth * inputHeight * 6; 47 | 48 | horizontalscale = (unsigned short *)Alloc(horizontal_scale_size); 49 | if (horizontalscale == NULL) return false; 50 | 51 | // Scratch memory has been successfully allocated 52 | return true; 53 | } 54 | 55 | // Free scratch memory used by the scaling routines 56 | void FreeScratchMemory() 57 | { 58 | if(horizontalscale) { 59 | Free((char *)horizontalscale); 60 | horizontalscale = NULL; 61 | } 62 | } 63 | #endif 64 | #if 0 65 | // Compute the scale factors for interpolating along a row 66 | void ComputeRowScaleFactors(short *scaleFactors, int inputWidth, int outputWidth); 67 | 68 | // Compute the scale factors for interpolating down a column 69 | int ComputeColumnScaleFactors(int row, int inputWidth, int outputWidth, 70 | int renderFieldType, lanczosmix *lmY); 71 | 72 | // Compute the interpolation coefficients 73 | int LanczosCoeff(int inputsize, int outputsize, int line, lanczosmix *lm, 74 | bool changefielddominance, bool interlaced, int lobes); 75 | #endif 76 | 77 | protected: 78 | 79 | // Scratch memory for use by the interpolator 80 | //float curve2pt2lin[4096]; 81 | 82 | }; 83 | 84 | class CBilinearScalerRGB32 : public CBilinearScaler 85 | { 86 | public: 87 | 88 | CBilinearScalerRGB32(IMemAlloc *pMemAlloc) : 89 | CBilinearScaler(pMemAlloc) 90 | { 91 | } 92 | 93 | #if 0 94 | ~CBilinearScalerRGB32() 95 | { 96 | //FreeScratchMemory(); 97 | } 98 | #endif 99 | 100 | void ScaleToBGRA(uint8_t *inputBuffer, 101 | int inputWidth, 102 | int inputHeight, 103 | int inputPitch, 104 | uint8_t *outputBuffer, 105 | int outputWidth, 106 | int outputHeight, 107 | int outputPitch, 108 | int flippedFlag, 109 | int reorderFlag); 110 | 111 | //TODO: Remove references to QuickTime from the method names 112 | void ScaleToQuickTimeBGRA(uint8_t *inputBuffer, 113 | int inputWidth, 114 | int inputHeight, 115 | int inputPitch, 116 | uint8_t *outputBuffer, 117 | int outputWidth, 118 | int outputHeight, 119 | int outputPitch) 120 | { 121 | ScaleToBGRA(inputBuffer, inputWidth, inputHeight, inputPitch, 122 | outputBuffer, outputWidth, outputHeight, outputPitch, true, false); 123 | } 124 | 125 | //TODO: Make sure that the BGRA scaling routine works for ARGB 126 | void ScaleToQuickTimeARGB(uint8_t *inputBuffer, 127 | int inputWidth, 128 | int inputHeight, 129 | int inputPitch, 130 | uint8_t *outputBuffer, 131 | int outputWidth, 132 | int outputHeight, 133 | int outputPitch) 134 | { 135 | ScaleToBGRA(inputBuffer, inputWidth, inputHeight, inputPitch, 136 | outputBuffer, outputWidth, outputHeight, outputPitch, true, true); 137 | } 138 | 139 | }; 140 | -------------------------------------------------------------------------------- /ConvertLib/ColorFlags.h: -------------------------------------------------------------------------------- 1 | /*! @file ColorFlags.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | // Color conversion flag bits 25 | 26 | #define VSRGB 1 // Video safe range (versus full range) 27 | #define CS709 2 // Color space is 709 (versus 601) 28 | 29 | #define COLOR_FLAGS_MASK 0x03 30 | 31 | typedef enum color_flags 32 | { 33 | COLOR_FLAGS_BT601 = 0, 34 | COLOR_FLAGS_VSRGB = VSRGB, 35 | COLOR_FLAGS_CS709 = CS709, 36 | COLOR_FLAGS_VS709 = VSRGB+CS709, 37 | 38 | // Other names for the folor flags 39 | COLOR_FLAGS_CS_601 = COLOR_FLAGS_BT601, 40 | COLOR_FLAGS_CS_709 = COLOR_FLAGS_CS709, 41 | COLOR_FLAGS_VS_601 = COLOR_FLAGS_VSRGB, 42 | COLOR_FLAGS_VS_709 = COLOR_FLAGS_VS709, 43 | 44 | // Default color space is 709 and not video safe 45 | COLOR_FLAGS_DEFAULT = COLOR_FLAGS_CS_709 46 | 47 | } COLOR_FLAGS; 48 | 49 | typedef COLOR_FLAGS ColorFlags; 50 | -------------------------------------------------------------------------------- /ConvertLib/ColorMatrix.cpp: -------------------------------------------------------------------------------- 1 | /*! @file ColorMatrix.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "StdAfx.h" 23 | #include "ColorFlags.h" 24 | #include "ColorMatrix.h" 25 | 26 | 27 | template 28 | void ColorMatrix::Convert(PixelType p1, PixelType p2, PixelType p3, 29 | PixelType *c1_out, PixelType *c2_out, PixelType *c3_out) 30 | { 31 | *c1_out = m[0][0] * p1 + m[0][1] * p2 + m[0][2] * p3 + m[0][3]; 32 | *c2_out = m[1][0] * p1 + m[1][1] * p2 + m[1][2] * p3 + m[1][3]; 33 | *c3_out = m[2][0] * p1 + m[2][1] * p2 + m[2][2] * p3 + m[2][3]; 34 | } 35 | 36 | // Instantiate color conversion for the floating-point pixel type 37 | template class ColorMatrix; 38 | 39 | 40 | RGBToYCbCr::RGBToYCbCr(ColorFlags color_flags, 41 | int luma_offset, 42 | int chroma_offset, 43 | int descale_shift, 44 | float scale_factor) : 45 | FloatColorMatrix(color_flags, scale_factor, 0.0), 46 | luma_offset(luma_offset), 47 | chroma_offset(chroma_offset), 48 | descale_shift(descale_shift) 49 | { 50 | // Computer systems 601 color space 51 | static const float cs601[3][4] = 52 | { 53 | {0.257f, 0.504f, 0.098f, 16.0f/255.0f}, 54 | {-0.148f, -0.291f, 0.439f, 128.0f/255.0f}, 55 | {0.439f, -0.368f, -0.071f, 128.0f/255.0f} 56 | }; 57 | 58 | // Computer systems 709 color space 59 | static const float cs709[3][4] = 60 | { 61 | {0.183f, 0.614f, 0.062f, 16.0f/255.0f}, 62 | {-0.101f, -0.338f, 0.439f, 128.0f/255.0f}, 63 | {0.439f, -0.399f, -0.040f, 128.0f/255.0f} 64 | }; 65 | 66 | // Video safe 601 color space 67 | static const float vs601[3][4] = 68 | { 69 | {0.299f, 0.587f, 0.114f, 0}, 70 | {-0.172f, -0.339f, 0.511f, 128.0f/255.0f}, 71 | {0.511f, -0.428f, -0.083f, 128.0f/255.0f} 72 | }; 73 | 74 | // Video safe 709 color space 75 | static const float vs709[3][4] = 76 | { 77 | {0.213f, 0.715f, 0.072f, 0}, 78 | {-0.117f, -0.394f, 0.511f, 128.0f/255.0f}, 79 | {0.511f, -0.464f, -0.047f, 128.0f/255.0f} 80 | }; 81 | 82 | // Use the color conversion matrix that matches the color flags 83 | switch (color_flags) 84 | { 85 | case COLOR_FLAGS_CS_601: 86 | memcpy(m, cs601, sizeof(m)); 87 | break; 88 | 89 | case COLOR_FLAGS_CS_709: 90 | memcpy(m, cs709, sizeof(m)); 91 | break; 92 | 93 | case COLOR_FLAGS_VS_601: 94 | memcpy(m, vs601, sizeof(m)); 95 | break; 96 | 97 | case COLOR_FLAGS_VS_709: 98 | memcpy(m, vs709, sizeof(m)); 99 | break; 100 | 101 | default: 102 | assert(0); 103 | break; 104 | } 105 | 106 | // Scale the coefficients for this color matrix instance 107 | for (int i = 0; i < 3; i++) 108 | { 109 | for (int j = 0; j < 3; j++) 110 | { 111 | m[i][j] *= scale_factor; 112 | } 113 | 114 | m[i][3] *= scale_offset; 115 | } 116 | } 117 | 118 | void RGBToYCbCr::Convert(uint16_t R, uint16_t G, uint16_t B, 119 | uint16_t *Y_out, uint16_t *Cb_out, uint16_t *Cr_out) 120 | { 121 | float Y_float, Cb_float, Cr_float; 122 | 123 | // Apply the color conversion matrix 124 | ColorMatrix::Convert(R, G, B, &Y_float, &Cb_float, &Cr_float); 125 | 126 | // Convert to integers and apply the luma and chroma offsets 127 | int Y = (static_cast(Y_float) >> descale_shift) + luma_offset; 128 | int Cb = (static_cast(Cb_float) >> descale_shift) + chroma_offset; 129 | int Cr = (static_cast(Cr_float) >> descale_shift) + chroma_offset; 130 | 131 | // Check that the luma and chroma results are 16-bit values 132 | assert(0 <= Y && Y <= UINT16_MAX); 133 | assert(0 <= Cb && Cb <= UINT16_MAX); 134 | assert(0 <= Cr && Cr <= UINT16_MAX); 135 | 136 | *Y_out = Y; 137 | *Cb_out = Cb; 138 | *Cr_out = Cr; 139 | } 140 | -------------------------------------------------------------------------------- /ConvertLib/ColorMatrix.h: -------------------------------------------------------------------------------- 1 | /*! @file ColorMatrix.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | template 23 | class ColorMatrix 24 | { 25 | public: 26 | 27 | ColorMatrix(ColorFlags color_flags = COLOR_FLAGS_DEFAULT, 28 | float scale_factor = 64.0, 29 | float scale_offset = 16384.0) : 30 | color_flags(color_flags), 31 | scale_factor(scale_factor), 32 | scale_offset(scale_offset) 33 | { 34 | } 35 | 36 | // Convert the three tuple of pixels to converted values 37 | void Convert(PixelType p1, PixelType p2, PixelType p3, 38 | PixelType *c1_out, PixelType *c2_out, PixelType *c3_out); 39 | 40 | protected: 41 | 42 | // Color conversion matrix (fourth column is the offset) 43 | PixelType m[3][4]; 44 | 45 | // Color space flags used to select the conversion matrix 46 | ColorFlags color_flags; 47 | 48 | float scale_factor; 49 | float scale_offset; 50 | 51 | }; 52 | 53 | typedef ColorMatrix FloatColorMatrix; 54 | 55 | 56 | /*! 57 | @brief RGB to YCbCr color space conversion for 16-bit unsigned pixels 58 | 59 | @description The computer safe region uses the full pixel range while 60 | video safe uses a limited range that allows for super blacks and whites. 61 | 62 | 63 | The floating-point and fixed-point coefficients for each color space. 64 | 65 | Y = 0.257 * R + 0.504 * G + 0.098 * B + 16.5; 66 | Cb =-0.148 * R - 0.291 * G + 0.439 * B + 128.5; 67 | Cr = 0.439 * R - 0.368 * G - 0.071 * B + 128.5; 68 | 69 | Fixed point approximation (8-bit) is 70 | 71 | Y = ( 66 * R + 129 * G + 25 * B + 4224) >> 8; 72 | Cb = (-38 * R - 74 * G + 112 * B + 32896) >> 8; 73 | Cr = (112 * R - 94 * G - 18 * B + 32896) >> 8; 74 | 75 | 76 | Computer safe 601 color space: 77 | 78 | Y = 0.257R + 0.504G + 0.098B + 16; 79 | Cb = -0.148R - 0.291G + 0.439B + 128; 80 | Cr = 0.439R - 0.368G - 0.071B + 128; 81 | 82 | 83 | Video safe 601 color space: 84 | 85 | Y = 0.299R + 0.587G + 0.114B 86 | Cb = -0.172R - 0.339G + 0.511B + 128 87 | Cr = 0.511R - 0.428G - 0.083B + 128 88 | 89 | 90 | Compute safe 709 color space: 91 | 92 | Y = 0.183R + 0.614G + 0.062B + 16 93 | Cb = -0.101R - 0.338G + 0.439B + 128 94 | Cr = 0.439R - 0.399G - 0.040B + 128 95 | 96 | 97 | Video safe 709 color space: 98 | 99 | Y = 0.213R + 0.715G + 0.072B 100 | Cb = -0.117R - 0.394G + 0.511B + 128 101 | Cr = 0.511R - 0.464G - 0.047B + 128 102 | 103 | */ 104 | class RGBToYCbCr : public FloatColorMatrix 105 | { 106 | public: 107 | 108 | // Initialize a color converter with 16-bit precision by default 109 | RGBToYCbCr(ColorFlags color_flags, 110 | int luma_offset = (16 << 8), 111 | int chroma_offset = (128 << 8), 112 | int descale_shift = 6, 113 | float scale_factor = 64.0); 114 | 115 | //TODO: Define a constructor that comutes the scale factors from the precision 116 | RGBToYCbCr(int input_precision, 117 | int output_precision, 118 | ColorFlags color_flags); 119 | 120 | //TODO: Make the input and output pixel type a template parameter 121 | 122 | // Convert the three tuple of 16-bit pixels 123 | void Convert(uint16_t R, uint16_t G, uint16_t B, 124 | uint16_t *Y_out, uint16_t *Cb_out, uint16_t *Cr_out); 125 | 126 | private: 127 | 128 | int luma_offset; // The luma offset is determined by the range of the luma values 129 | int chroma_offset; // The chroma offset is determined by the rangte of the chroma values 130 | int descale_shift; // Descale the pixels by this amount before applying the offsets 131 | 132 | }; 133 | -------------------------------------------------------------------------------- /ConvertLib/ConvertYUV8.h: -------------------------------------------------------------------------------- 1 | /*! @file ConvertYUV.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | void ConvertCbYCrY_8bitToNV12(void *input_buffer, int input_pitch, 25 | void *output_buffer, int output_pitch, 26 | int width, int height); 27 | 28 | 29 | void ConvertYCrYCb_8bitToNV12(void *input_buffer, int input_pitch, 30 | void *output_buffer, int output_pitch, 31 | int width, int height); 32 | -------------------------------------------------------------------------------- /ConvertLib/MemAlloc.cpp: -------------------------------------------------------------------------------- 1 | /*! @file MemAlloc.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "StdAfx.h" 23 | #include "MemAlloc.h" 24 | 25 | void *CMemAlloc::Alloc(size_t size) 26 | { 27 | #ifdef _WIN32 28 | void *block = _aligned_malloc(size, m_alignment); 29 | #else 30 | #ifdef __APPLE__ 31 | void *block = malloc(size); 32 | #else 33 | void *block = _mm_malloc(size, m_alignment); 34 | #endif 35 | #endif 36 | 37 | #if _DEBUG 38 | if (m_allocationCount < sizeof(m_allocationTable) / sizeof(m_allocationTable[0])) 39 | { 40 | m_allocationTable[m_allocationCount].block = block; 41 | m_allocationTable[m_allocationCount].size = size; 42 | m_allocationCount++; 43 | } 44 | #endif 45 | 46 | return block; 47 | } 48 | 49 | void CMemAlloc::Free(void *block) 50 | { 51 | #ifdef _WIN32 52 | _aligned_free(block); 53 | #else 54 | #ifdef __APPLE__ 55 | free(block); 56 | #else 57 | _mm_free(block); 58 | #endif 59 | #endif 60 | 61 | #if _DEBUG 62 | bool found = false; 63 | 64 | for (size_t i = 0; i < m_allocationCount; i++) 65 | { 66 | // The index should not exceed the allocated size of the table 67 | assert(i < sizeof(m_allocationTable)/sizeof(m_allocationTable[0])); 68 | 69 | // Found the block in the table? 70 | if (m_allocationTable[i].block == block) 71 | { 72 | //m_allocationTable[i].block = NULL; 73 | //m_allocationTable[i].size = 0; 74 | 75 | // Shift the remaining entries in the table 76 | for (size_t j = i + 1; j < m_allocationCount; j++) 77 | { 78 | // The index should not exceed the allocated size of the table 79 | assert(j < sizeof(m_allocationTable)/sizeof(m_allocationTable[0])); 80 | 81 | m_allocationTable[i].block = m_allocationTable[j].block; 82 | m_allocationTable[i].size = m_allocationTable[j].size; 83 | 84 | // Advance the index to the next table entry to fill 85 | i = j; 86 | } 87 | 88 | m_allocationTable[i].block = NULL; 89 | m_allocationTable[i].size = 0; 90 | 91 | // Reduce the number of entries in the table 92 | m_allocationCount--; 93 | 94 | // Done searching for the allocation table entry 95 | found = true; 96 | break; 97 | } 98 | 99 | // Should have found the allocated block in the table 100 | assert(found); 101 | } 102 | #endif 103 | } 104 | -------------------------------------------------------------------------------- /ConvertLib/MemAlloc.h: -------------------------------------------------------------------------------- 1 | /*! @file MemAlloc.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #pragma once 22 | 23 | // Any memory allocator must provide methods to allocate and free memory 24 | class IMemAlloc 25 | { 26 | public: 27 | virtual void *Alloc(size_t size) = 0; 28 | virtual void Free(void *block) = 0; 29 | 30 | // Must declare virtual destructor for gcc 31 | virtual ~IMemAlloc() {}; 32 | }; 33 | 34 | // Default memory allocator provided by the conversion library 35 | class CMemAlloc : public IMemAlloc 36 | { 37 | public: 38 | 39 | //CMemAlloc(int alignment) 40 | //{ 41 | // m_alignment = alignment; 42 | //} 43 | 44 | #if _DEBUG 45 | CMemAlloc() : 46 | m_allocationCount(0) 47 | { 48 | memset(m_allocationTable, 0, sizeof(m_allocationTable)); 49 | } 50 | 51 | virtual ~CMemAlloc() 52 | { 53 | // assert(m_allocationCount == 0); 54 | } 55 | #endif 56 | 57 | // Implementation of the memory allocator interface 58 | void *Alloc(size_t size); 59 | void Free(void *block); 60 | 61 | private: 62 | 63 | // Byte alignment of allocated memory blocks 64 | static const int m_alignment = 16; 65 | 66 | private: 67 | 68 | #if _DEBUG 69 | typedef struct 70 | { 71 | void *block; 72 | size_t size; 73 | 74 | } AllocatedBlock; 75 | 76 | // Table for recording allocated memory blocks for debugging 77 | AllocatedBlock m_allocationTable[100]; 78 | 79 | size_t m_allocationCount; 80 | 81 | //TODO: Replace this data structure with an STL array 82 | #endif 83 | }; 84 | -------------------------------------------------------------------------------- /ConvertLib/StdAfx.h: -------------------------------------------------------------------------------- 1 | /*! @file StdAfx.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #if _WIN32 25 | #include 26 | //#include 27 | #include 28 | //#include 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include // SSE2 intrinsics 39 | 40 | //#include 41 | //#include 42 | //#include 43 | //#include 44 | 45 | #ifdef __APPLE__ 46 | #include "CoreFoundation/CoreFoundation.h" 47 | #endif 48 | 49 | #ifdef _WIN32 50 | 51 | #if 0 52 | // Windows does not have the standard integer types 53 | typedef signed char int8_t; 54 | typedef unsigned char uint8_t; 55 | typedef short int16_t; 56 | typedef unsigned short uint16_t; 57 | typedef int int32_t; 58 | typedef unsigned uint32_t; 59 | typedef __int64 int64_t; 60 | typedef unsigned __int64 uint64_t; 61 | #else 62 | #define __STDC_LIMIT_MACROS 63 | #include 64 | #endif 65 | 66 | #else 67 | 68 | // The standard integer types should be available on most platforms 69 | #define __STDC_LIMIT_MACROS 70 | #include 71 | 72 | #if !defined(_WIN32) && !defined(__APPLE__) 73 | // Use byte swapping functions on Linux 74 | #include 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /DecoderSDK/Conversion.h: -------------------------------------------------------------------------------- 1 | /*! @file Conversion.h 2 | 3 | @brief Interface for the sample decoder class. 4 | 5 | This class is used internally by CineForm software and is not currently 6 | mentioned in the documentation provided to customers. Modify this comment 7 | and add tags for Doxygen to publish this interface in customer documentation. 8 | 9 | The interface uses pure virtual methods to isolate applications that use the 10 | CineForm decoder from changes to the codec library. The interface includes 11 | macros (methods defined in the class declaration) for common calculations 12 | involving pixel formats. 13 | 14 | * 15 | * @version 1.0.0 16 | * 17 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 18 | * 19 | * Licensed under either: 20 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 21 | * - MIT license, http://opensource.org/licenses/MIT 22 | * at your option. 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an "AS IS" BASIS, 26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | * 30 | */ 31 | 32 | #pragma once 33 | 34 | #ifndef FOURCC 35 | #define FOURCC(x) (int)(((x) >> 24) & 0xFF), (int)(((x) >> 16) & 0xFF), (int)(((x) >> 8) & 0xFF), (int)((x) & 0xFF) 36 | #endif 37 | 38 | // Some pixel formats are not defined in the QuickTime header files 39 | #define k4444YpCbCrA32RPixelFormat 'r4fl' 40 | 41 | #ifdef __cplusplus 42 | extern "C" 43 | { 44 | #endif 45 | 46 | static bool IsPrintableFourCC(char *fourcc) 47 | { 48 | int i; 49 | 50 | // Check that all of the characters are printable 51 | for (i = 0; i < 4; i++) 52 | { 53 | #if _WIN32 54 | if (isspace(fourcc[i]) || !isprint(fourcc[i])) { 55 | #else 56 | if( (fourcc[i]<=32) || ((unsigned char)fourcc[i]>127)) { 57 | #endif 58 | return false; 59 | } 60 | } 61 | 62 | return true; 63 | } 64 | 65 | __inline static const char *CStringFromOSType(unsigned int fourcc) 66 | { 67 | //static char string[16]; 68 | static char string[8]; 69 | //Boolean isPrintable = true; 70 | //int i; 71 | 72 | #if _WIN32 73 | sprintf_s(string, sizeof(string), "%c%c%c%c", FOURCC(fourcc)); 74 | #else 75 | sprintf(string, "%c%c%c%c", FOURCC(fourcc)); 76 | #endif 77 | 78 | if (!IsPrintableFourCC(string)) { 79 | //sprintf(string, "0x%08X", (unsigned int)fourcc); 80 | #if _WIN32 81 | sprintf_s(string, sizeof(string), "%d", (int)fourcc); 82 | #else 83 | sprintf(string, "%d", (int)fourcc); 84 | #endif 85 | } 86 | 87 | return string; 88 | } 89 | 90 | // Convert the input image format to the output format 91 | CFHD_Error ConvertToOutputBuffer(void *inputBuffer, int inputPitch, int inputFormat, 92 | void *outputBuffer, int outputPitch, CFHD_PixelFormat outputFormat, 93 | int width, int height, int byte_swap_flag); 94 | 95 | // Scale the input image to fit the dimensions of the output image 96 | CFHD_Error ScaleToOutputBuffer(void *inputBuffer, int inputWidth, int inputHeight, 97 | int inputPitch, int inputFormat, 98 | void *outputBuffer, int outputWidth, int outputHeight, 99 | int outputPitch, CFHD_PixelFormat outputFormat, 100 | int byte_swap_flag); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | -------------------------------------------------------------------------------- /DecoderSDK/ISampleDecoder.cpp: -------------------------------------------------------------------------------- 1 | /*! @file ISampleDecoder.cpp 2 | 3 | @brief Interface for the sample decoder class. 4 | 5 | This class is used internally by CineForm software and is not currently 6 | mentioned in the documentation provided to customers. Modify this comment 7 | and add tags for Doxygen to publish this interface in customer documentation. 8 | 9 | The interface uses pure virtual methods to isolate applications that use the 10 | CineForm decoder from changes to the codec library. The interface includes 11 | macros (methods defined in the class declaration) for common calculations 12 | involving pixel formats. 13 | 14 | * 15 | * @version 1.0.0 16 | * 17 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 18 | * 19 | * Licensed under either: 20 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 21 | * - MIT license, http://opensource.org/licenses/MIT 22 | * at your option. 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an "AS IS" BASIS, 26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | * 30 | */ 31 | 32 | #include "StdAfx.h" 33 | 34 | #if _WIN32 35 | 36 | // Export the interface to the decoder 37 | #define DECODERDLL_EXPORTS 1 38 | 39 | #elif __APPLE__ 40 | 41 | 42 | #ifdef DECODERDLL_API 43 | #undef DECODERDLL_API 44 | #endif 45 | 46 | #define DECODERDLL_API __attribute__((visibility("default"))) 47 | #include 48 | 49 | #else 50 | 51 | // Code required by GCC on Linux to define the entry points 52 | 53 | #ifdef DECODERDLL_API 54 | #undef DECODERDLL_API 55 | #endif 56 | 57 | #define DECODERDLL_API __attribute__((visibility("default"))) 58 | 59 | #endif 60 | 61 | 62 | #if defined(__APPLE__) 63 | #include "decoder.h" 64 | #endif 65 | 66 | #include "CFHDDecoder.h" 67 | #include "SampleDecoder.h" 68 | #include "ISampleDecoder.h" 69 | 70 | CFHDDECODER_API ISampleDecoder *CFHD_CreateSampleDecoder(IAllocator *allocator, CFHD_LicenseKey license, FILE *logfile) 71 | { 72 | // No longer supporting this type of codec interface, it was only used by the old Premiere importers. 73 | return CSampleDecoder::CreateSampleDecoder(allocator, license, logfile); 74 | } -------------------------------------------------------------------------------- /DecoderSDK/StdAfx.h: -------------------------------------------------------------------------------- 1 | /*! @file StdAfx.h 2 | 3 | * @brief 4 | * 5 | * Interface to the CineForm HD decoder. The decoder API uses an opaque 6 | * data type to represent an instance of a decoder. The decoder reference 7 | * is returned by the call to CFHD_OpenDecoder. 8 | * 9 | * @version 1.0.0 10 | * 11 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 12 | * 13 | * Licensed under either: 14 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 15 | * - MIT license, http://opensource.org/licenses/MIT 16 | * at your option. 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | 26 | #pragma once 27 | 28 | #if _WIN32 29 | 30 | // Windows header files (required for registry access) 31 | #include 32 | 33 | // Includes required for Visual Studio 2005 (not required for Visual Studio 2003) 34 | //#include 35 | #include 36 | 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include "../Common/ver.h" 51 | 52 | //TODO: reference additional headers your program requires here 53 | 54 | -------------------------------------------------------------------------------- /DecoderSDK/resource.h: -------------------------------------------------------------------------------- 1 | /*! @file resource.h 2 | 3 | * @brief Internal routines used for processing sample metadata. 4 | * 5 | * Interface to the CineForm HD decoder. The decoder API uses an opaque 6 | * data type to represent an instance of a decoder. The decoder reference 7 | * is returned by the call to CFHD_OpenDecoder. 8 | * 9 | * @version 1.0.0 10 | * 11 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 12 | * 13 | * Licensed under either: 14 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 15 | * - MIT license, http://opensource.org/licenses/MIT 16 | * at your option. 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * 24 | */ 25 | 26 | //{{NO_DEPENDENCIES}} 27 | // Microsoft Visual C++ generated include file. 28 | // Used by DecoderDLL.rc 29 | 30 | // Next default values for new objects 31 | // 32 | #ifdef APSTUDIO_INVOKED 33 | #ifndef APSTUDIO_READONLY_SYMBOLS 34 | #define _APS_NEXT_RESOURCE_VALUE 101 35 | #define _APS_NEXT_COMMAND_VALUE 40001 36 | #define _APS_NEXT_CONTROL_VALUE 1001 37 | #define _APS_NEXT_SYMED_VALUE 101 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /DecoderSDK/ver.h: -------------------------------------------------------------------------------- 1 | /*! @file ver.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #pragma once 22 | 23 | // OBSELETE use ../common/ver.h 24 | #include "../common/ver.h" 25 | -------------------------------------------------------------------------------- /EncoderSDK/Allocator.h: -------------------------------------------------------------------------------- 1 | /*! @file Allocator.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef _WIN32 25 | 26 | // Override the default calling convention so the virtual methods are C callable 27 | #define CALLTYPE __stdcall 28 | 29 | #else 30 | 31 | #define CALLTYPE 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /EncoderSDK/AsyncEncoder.cpp: -------------------------------------------------------------------------------- 1 | /*! @file AsyncEncoder.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #include "StdAfx.h" 23 | 24 | // Include files from the codec library 25 | #include "encoder.h" 26 | 27 | // Include files for the encoder DLL 28 | #include "Allocator.h" 29 | #include "CFHDError.h" 30 | #include "CFHDTypes.h" 31 | #include "SampleMetadata.h" 32 | #include "VideoBuffers.h" 33 | #include "SampleEncoder.h" 34 | 35 | // Include the declarations for the thread pool 36 | #include "Lock.h" 37 | #include "Condition.h" 38 | #include "ThreadMessage.h" 39 | #include "MessageQueue.h" 40 | #include "ThreadPool.h" 41 | 42 | // Include the declarations for the sample encoder and encoder metadata 43 | #include "MetadataWriter.h" 44 | #include "SampleEncoder.h" 45 | 46 | // Include the declarations for the asynchronous encoder 47 | #include "EncoderQueue.h" 48 | #include "AsyncEncoder.h" 49 | 50 | // Include the declarations for the encoder pool 51 | #include "EncoderPool.h" 52 | 53 | 54 | CThread::ThreadReturnType STDCALL CAsyncEncoder::WorkerThreadProc(void *param) 55 | { 56 | //CFHD_Error error = CFHD_ERROR_OKAY; 57 | 58 | // The thread parameter is the asynchronous encoder for this worker thread 59 | CAsyncEncoder *encoder = reinterpret_cast(param); 60 | assert(encoder != NULL); 61 | if (! (encoder != NULL)) { 62 | return (CThread::ThreadReturnType)CFHD_ERROR_UNEXPECTED; 63 | } 64 | 65 | // Process messages that are sent to this asynchronous encoder 66 | return (CThread::ThreadReturnType)encoder->MessageLoop(); 67 | } 68 | 69 | CFHD_Error CAsyncEncoder::MessageLoop() 70 | { 71 | CFHD_Error error = CFHD_ERROR_OKAY; 72 | 73 | for (;;) 74 | { 75 | EncoderMessage message; 76 | EncoderJob *job = NULL; 77 | 78 | error = queue.WaitForMessage(message); 79 | if (error != CFHD_ERROR_OKAY) { 80 | return error; 81 | } 82 | 83 | switch (message.Command()) 84 | { 85 | case ThreadMessage::THREAD_COMMAND_NULL: 86 | case ThreadMessage::THREAD_COMMAND_START: 87 | // Ignore this message 88 | break; 89 | 90 | case ThreadMessage::THREAD_COMMAND_STOP: 91 | // Terminate this thread 92 | return CFHD_ERROR_OKAY; 93 | break; 94 | 95 | case ThreadMessage::THREAD_COMMAND_ENCODE: 96 | job = message.Job(); 97 | assert(job != NULL); 98 | error = EncodeSample(job); 99 | job->error = error; 100 | if (error == CFHD_ERROR_OKAY) 101 | { 102 | // Record the encoded sample in the job 103 | CSampleBuffer *sampleBuffer = NULL; 104 | error = GetSampleBuffer(&sampleBuffer); 105 | if (error != CFHD_ERROR_OKAY) { 106 | return error; 107 | } 108 | job->sampleBuffer = sampleBuffer; 109 | } 110 | 111 | // Done encoding the frame 112 | job->status = ENCODER_JOB_STATUS_FINISHED; 113 | 114 | // Signal that the encoder job has finished 115 | pool->SignalJobFinished(); 116 | } 117 | } 118 | } 119 | 120 | #if 0 121 | CFHD_Error CAsyncEncoder::HandleMetadata(CSampleEncodeMetadata *metadata) 122 | { 123 | CFHD_Error error = CFHD_ERROR_OKAY; 124 | 125 | // Merge the global and local metadata into the metadata stored in this encoder 126 | error = MergeMetadata(metadata->m_metadataGlobal, metadata->m_metadataGlobalSize, 127 | metadata->m_metadataLocal, metadata->m_metadataLocalSize); 128 | if (error != CFHD_ERROR_OKAY) { 129 | return error; 130 | } 131 | 132 | // Tell the sample encoder to use the metadata 133 | return CSampleEncoder::HandleMetadata(); 134 | } 135 | #endif 136 | 137 | CFHD_Error CAsyncEncoder::ApplyMetadata(CSampleEncodeMetadata *metadata) 138 | { 139 | return CSampleEncoder::ApplyMetadata(&metadata->global[0], &metadata->local); 140 | } 141 | 142 | //! Encode the frame after attaching the metadata to the encoder 143 | CFHD_Error CAsyncEncoder::EncodeSample(void *frameBuffer, 144 | int framePitch, 145 | bool keyFrame, 146 | CSampleEncodeMetadata *encoderMetadata, 147 | CFHD_EncodingQuality frameQuality) 148 | { 149 | CFHD_Error error = CFHD_ERROR_OKAY; 150 | 151 | // Use the metadata from the encoder job for encoding this frame 152 | //error = HandleMetadata(encoderMetadata); 153 | error = ApplyMetadata(encoderMetadata); 154 | if (error != CFHD_ERROR_OKAY) { 155 | return error; 156 | } 157 | 158 | // Encode the frame 159 | error = CSampleEncoder::EncodeSample(frameBuffer, framePitch, frameQuality); 160 | 161 | // Free the local metadata even if the encoder returned an error 162 | CFHD_Error error_free = FreeLocalMetadata(); 163 | 164 | // Return the error code from the encoder or freeing the metadata 165 | return (error != CFHD_ERROR_OKAY) ? error : error_free; 166 | } 167 | -------------------------------------------------------------------------------- /EncoderSDK/AsyncEncoder.h: -------------------------------------------------------------------------------- 1 | /*! @file AsyncEncoder.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | 25 | // Forward reference to the encoder pool 26 | class CEncoderPool; 27 | 28 | 29 | /*! 30 | @brief Asynchronous encoder with a message queue of encoder jobs 31 | 32 | Each asynchronous encoder is associated with a worker thread that allows 33 | frames to be encoded asynchronously. The asynchronous encoder extends the 34 | sample encoder with a message queue that contains encoding jobs assigned to 35 | the encoder and control messages that start and stop the work thread. 36 | 37 | The message queue allows one or more encoding jobs to be assigned to the 38 | asynchronous encoder without waiting for the encoder to finish the current 39 | encoding job. 40 | */ 41 | class CAsyncEncoder : public CSampleEncoder 42 | { 43 | public: 44 | 45 | CAsyncEncoder(CEncoderPool *encoderPool, CFHD_ALLOCATOR *allocator) : 46 | pool(encoderPool), 47 | CSampleEncoder(allocator) 48 | { 49 | } 50 | 51 | ~CAsyncEncoder() 52 | { 53 | // The message queue should be empty 54 | //assert(m_encoderMessageQueue.size() == 0); 55 | } 56 | 57 | //! Start the worker thread for this asynchronous encoder 58 | CFHD_Error Start(void *param) 59 | { 60 | return thread.Start(WorkerThreadProc, param); 61 | } 62 | 63 | //! Stop the worker thread associated with the asynchronous encoder 64 | CFHD_Error Stop() 65 | { 66 | EncoderMessage message(ThreadMessage::THREAD_COMMAND_STOP); 67 | return queue.AddMessage(message); 68 | } 69 | 70 | //! Wait for the worker thread to terminate 71 | CFHD_Error Wait() 72 | { 73 | return thread.Wait(); 74 | } 75 | 76 | //! Post an encoder message to the queue for this asynchronous encoder 77 | CFHD_Error SendMessage(EncoderMessage &message) 78 | { 79 | return queue.AddMessage(message); 80 | } 81 | 82 | protected: 83 | 84 | //! Procedure executed by the worker thread for this asynchronous encoder 85 | static CThread::ThreadReturnType STDCALL WorkerThreadProc(void *param); 86 | 87 | //! Process messages sent to this asynchronous encoder 88 | CFHD_Error MessageLoop(); 89 | 90 | //! Attach the metadata for encoding the next frame 91 | //CFHD_Error HandleMetadata(CSampleEncodeMetadata *encoderMetadata); 92 | 93 | //! Use the metadata for encoding the next frame 94 | CFHD_Error ApplyMetadata(CSampleEncodeMetadata *metadata); 95 | 96 | CFHD_Error EncodeSample(EncoderJob *job) 97 | { 98 | if (job == NULL) { 99 | return CFHD_ERROR_UNEXPECTED; 100 | } 101 | assert(job->framePitch <= INT_MAX); 102 | return EncodeSample(job->frameBuffer, (int)job->framePitch, job->keyFrame, job->encoderMetadata, job->frameQuality); 103 | } 104 | 105 | //! Encode the frame after attaching the metadata to the encoder 106 | CFHD_Error EncodeSample(void *frameBuffer, 107 | int framePitch, 108 | bool keyFrame, 109 | CSampleEncodeMetadata *encoderMetadata, 110 | CFHD_EncodingQuality frameQuality = CFHD_ENCODING_QUALITY_FIXED); 111 | 112 | private: 113 | 114 | //! Encoder pool that manages this asynchronous encoder 115 | CEncoderPool *pool; 116 | 117 | //! Queue of control messages and encoding requests 118 | CEncoderMessageQueue queue; 119 | 120 | //! Worker thread for this asynchronous encoder 121 | CThread thread; 122 | }; 123 | -------------------------------------------------------------------------------- /EncoderSDK/EncoderQueue.cpp: -------------------------------------------------------------------------------- 1 | /*! @file EncoderQueue.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | 23 | 24 | #include "StdAfx.h" 25 | #include "Allocator.h" 26 | #include "CFHDError.h" 27 | #include "CFHDTypes.h" 28 | #include "VideoBuffers.h" 29 | #include "Lock.h" 30 | #include "Condition.h" 31 | #include "MetadataWriter.h" 32 | #include "ThreadMessage.h" 33 | #include "MessageQueue.h" 34 | #include "EncoderQueue.h" 35 | 36 | 37 | // Include the template class methods that are not defined in the header file 38 | #include "../Common/MessageQueue.cpp" 39 | 40 | // Force instantiation of the encoder message queue 41 | template class MessageQueue; 42 | -------------------------------------------------------------------------------- /EncoderSDK/Interface.h: -------------------------------------------------------------------------------- 1 | /*! @file Interface.h 2 | 3 | * @brief Define macros that are used to specify external entry points. 4 | * 5 | * Some platforms such as Windows require special attribute declarations 6 | * that determine whether a routine is beining imported or exported as an 7 | * external entry point. This file defines the interface macros used in 8 | * the declarations of routines that imported or exported. 9 | * 10 | * @version 1.0.0 11 | * 12 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 13 | * 14 | * Licensed under either: 15 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 16 | * - MIT license, http://opensource.org/licenses/MIT 17 | * at your option. 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | */ 26 | #pragma once 27 | 28 | #ifdef _WIN32 29 | 30 | // Export the interface to the encoder 31 | #ifndef ENCODERDLL_EXPORTS 32 | #define ENCODERDLL_EXPORTS 1 33 | #endif 34 | 35 | #elif __APPLE__ 36 | 37 | #ifndef ENCODERDLL_EXPORTS 38 | #define ENCODERDLL_EXPORTS 1 39 | #endif 40 | 41 | #include 42 | #include 43 | 44 | #else 45 | 46 | //TODO: Change this code to define CFHDENCODER_API instead of ENCODERDLL_API 47 | 48 | #ifdef ENCODERDLL_API 49 | #undef ENCODERDLL_API 50 | #endif 51 | 52 | #define ENCODERDLL_API __attribute__((visibility("default"))) 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /EncoderSDK/MetadataWriter.h: -------------------------------------------------------------------------------- 1 | /*! @file MetadataWriter.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | // Use the metadata routines in the codec library 25 | #include "metadata.h" 26 | 27 | 28 | // Forward reference to the decoder metadata 29 | class CSampleMetadata; 30 | 31 | 32 | class CSampleEncodeMetadata 33 | { 34 | public: 35 | 36 | CSampleEncodeMetadata() : 37 | m_allocator(NULL), 38 | //m_privateAllocatorFlag(false),//(true), 39 | m_selectedEye(0) 40 | { 41 | #if 0 42 | // Create a default allocator 43 | m_allocator = new CMemAlloc; 44 | assert(m_allocator); 45 | #endif 46 | //CreateLock(&m_lock); 47 | 48 | // Initialize the global metadata 49 | memset(&local, 0, sizeof(METADATA)); 50 | for(int i=0; i<5; i++) 51 | memset(&global[i], 0, sizeof(METADATA)); 52 | } 53 | 54 | /* CSampleEncodeMetadata(IMemAlloc *allocator) : 55 | m_allocator(allocator), 56 | m_privateAllocatorFlag(false), 57 | m_metadataChanged(true), 58 | m_selectedEye(0) 59 | { 60 | //CreateLock(&m_lock); 61 | memset(&local, 0, sizeof(METADATA)); 62 | for(int i=0; i<5; i++) 63 | memset(&global[i], 0, sizeof(METADATA)); 64 | } */ 65 | 66 | CSampleEncodeMetadata(const CSampleEncodeMetadata *metadata) : 67 | m_allocator(NULL), 68 | //m_privateAllocatorFlag(false), 69 | m_metadataChanged(true), 70 | m_selectedEye(0) 71 | { 72 | memset(&local, 0, sizeof(METADATA)); 73 | for(int i=0; i<5; i++) 74 | memset(&global[i], 0, sizeof(METADATA)); 75 | 76 | m_allocator = metadata->m_allocator; 77 | //m_privateAllocatorFlag = metadata->m_privateAllocatorFlag; 78 | m_metadataChanged = metadata->m_metadataChanged; 79 | m_selectedEye = metadata->m_selectedEye; 80 | 81 | 82 | // Make a deep copy of the global metadata 83 | //if (metadata->m_metadataGlobal && metadata->m_metadataGlobalSize > 0) 84 | if (metadata->global[0].block != NULL && metadata->global[0].size > 0) 85 | { 86 | #if _ALLOCATOR 87 | AllocMetadata(metadata->global[0].allocator, &global[0], metadata->global[0].size); 88 | #else 89 | AllocMetadata(&global[0], metadata->global[0].size); 90 | #endif 91 | //if (m_metadataGlobal) 92 | if (global[0].block) 93 | { 94 | //memcpy(m_metadataGlobal, metadata->m_metadataGlobal, metadata->m_metadataGlobalSize); 95 | //m_metadataGlobalSize = metadata->m_metadataGlobalSize; 96 | memcpy(global[0].block, metadata->global[0].block, metadata->global[0].size); 97 | global[0].size = metadata->global[0].size; 98 | } 99 | } 100 | 101 | // Make a deep copy of the local metadata 102 | //if (metadata->m_metadataLocal && metadata->m_metadataLocalSize > 0) 103 | if (metadata->local.block != NULL && metadata->local.size > 0) 104 | { 105 | #if _ALLOCATOR 106 | AllocMetadata(metadata->local.allocator, &local, metadata->local.size); 107 | #else 108 | AllocMetadata(&local, metadata->local.size); 109 | #endif 110 | //if (m_metadataLocal) 111 | if (local.block) 112 | { 113 | //memcpy(m_metadataLocal, metadata->m_metadataLocal, metadata->m_metadataLocalSize); 114 | //m_metadataLocalSize = metadata->m_metadataLocalSize; 115 | memcpy(local.block, metadata->local.block, metadata->local.size); 116 | local.size = metadata->local.size; 117 | } 118 | } 119 | } 120 | 121 | ~CSampleEncodeMetadata() 122 | { 123 | // Release resources allocated by the encoder 124 | //if (m_metadataGlobal) 125 | for(int i=0; i<5; i++) 126 | { 127 | if (global[i].block) 128 | { 129 | ReleaseMetadata(&global[i]); 130 | } 131 | } 132 | if (local.block) 133 | { 134 | ReleaseMetadata(&local); 135 | } 136 | 137 | // Release the allocator if it is only referenced by this sample encoder 138 | // if (m_allocator && m_privateAllocatorFlag) { 139 | // //delete m_allocator; 140 | // m_allocator = NULL; 141 | // } 142 | } 143 | 144 | CFHD_Error SetAllocator(CFHD_ALLOCATOR * allocator) 145 | { 146 | m_allocator = allocator; 147 | return CFHD_ERROR_OKAY; 148 | } 149 | 150 | CFHD_Error GetAllocator(CFHD_ALLOCATOR ** allocator) 151 | { 152 | *allocator = m_allocator; 153 | return CFHD_ERROR_OKAY; 154 | } 155 | 156 | 157 | CFHD_Error AddGUID(); 158 | CFHD_Error AddLookFile(METADATA_TYPE type, METADATA_SIZE size, uint32_t *data); 159 | CFHD_Error AddTimeStamp(const char *date, const char *time); 160 | CFHD_Error AddTimeCode(const char *timecode, bool local_metadata = false); 161 | CFHD_Error AddFrameNumber(uint32_t framenum, bool local_metadata = false); 162 | 163 | //TODO: Make the following member variables protected or private 164 | 165 | CSimpleLock m_lock; 166 | 167 | bool m_metadataChanged; 168 | 169 | uint32_t m_selectedEye; 170 | 171 | //uint32_t *m_metadataGlobal; 172 | //size_t m_metadataGlobalSize; 173 | //uint32_t *m_metadataLocal; 174 | //size_t m_metadataLocalSize; 175 | METADATA global[5]; // 0-both, 1-left, 2-right, 3-diffLeft, 4-dffRight 176 | METADATA local; 177 | 178 | // Attach metadata to this sample encoder 179 | CFHD_Error AttachMetadata(CSampleMetadata *metadata); 180 | 181 | protected: 182 | 183 | static void ReleaseMetadata(METADATA *metadata); 184 | 185 | private: 186 | 187 | //IMemAlloc *m_allocator; 188 | CFHD_ALLOCATOR *m_allocator; 189 | 190 | // The destructor should release the allocator if it is private 191 | //bool m_privateAllocatorFlag; 192 | 193 | //TODO: Move the private allocator flag into the allocator class 194 | }; 195 | -------------------------------------------------------------------------------- /EncoderSDK/StdAfx.h: -------------------------------------------------------------------------------- 1 | /*! @file StdAfx.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef _WIN32 25 | 26 | // Exclude rarely-used stuff from Windows headers 27 | //#define WIN32_LEAN_AND_MEAN 28 | 29 | // Windows header files 30 | #include 31 | 32 | // Includes required for Visual Studio 2005 (not required for Visual Studio 2003) 33 | //#include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef _WIN32 41 | #define __STDC_LIMIT_MACROS 42 | #include 43 | #endif 44 | 45 | #else 46 | 47 | // Hack to eliminate conflict with the codec CODESET data type 48 | #define _LANGINFO_H 1 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | #ifndef _WIN32 56 | #include 57 | #endif 58 | 59 | #ifndef __APPLE__ 60 | #include 61 | #endif 62 | 63 | #include 64 | #include 65 | #include 66 | 67 | #define __STDC_LIMIT_MACROS 68 | #include 69 | 70 | //#if __APPLE__ 71 | //#include "macdefs.h" 72 | //#endif 73 | 74 | #include 75 | #include 76 | 77 | #endif 78 | 79 | // The encoder and thread pools use the vector data type from the standard template library 80 | #include 81 | 82 | // The encoder job queue uses a deque from the standard template library 83 | #include 84 | 85 | // The message queue for the worker threads uses a queue from the standard template library 86 | #include 87 | 88 | // TODO: reference additional headers your program requires here 89 | -------------------------------------------------------------------------------- /EncoderSDK/VideoBuffers.cpp: -------------------------------------------------------------------------------- 1 | /*! @file VideoBuffers.cpp 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include "StdAfx.h" 22 | 23 | #undef DEBUG 24 | #define DEBUG (1 && _DEBUG) 25 | 26 | #ifndef ASSERT 27 | #define ASSERT(x) assert(x) 28 | #endif 29 | 30 | #if _ALLOCATOR 31 | #include "IAllocator.h" 32 | #endif 33 | #include "CFHDTypes.h" 34 | #include "VideoBuffers.h" 35 | 36 | //! Return true if a buffer with the specified size was allocated 37 | bool CGenericBuffer::Alloc(size_t size, 38 | size_t alignment) 39 | { 40 | if (size == 0) 41 | { 42 | assert(m_dataBuffer == NULL && m_bufferSize == 0); 43 | return true; 44 | } 45 | 46 | if (m_dataBuffer) 47 | { 48 | if (m_bufferSize < size || m_alignment < alignment) 49 | { 50 | // Free the buffer so that a larger buffer can be allocated 51 | Release(); 52 | } 53 | else 54 | { 55 | // Use the existing buffer 56 | return true; 57 | } 58 | } 59 | 60 | if (alignment > 0) 61 | { 62 | // Use the allocator to obtain an aligned memory block 63 | m_dataBuffer = AlignedAlloc(size, alignment); 64 | } 65 | else 66 | { 67 | // Use the allocator to obtain an unaligned memory block 68 | m_dataBuffer = UnalignedAlloc(size); 69 | } 70 | 71 | assert(m_dataBuffer); 72 | if (m_dataBuffer) 73 | { 74 | m_bufferSize = size; 75 | m_alignment = alignment; 76 | return true; 77 | } 78 | else 79 | { 80 | m_bufferSize = 0; 81 | m_alignment = 0; 82 | return false; 83 | } 84 | } 85 | 86 | bool CGenericBuffer::Release() 87 | { 88 | if (m_dataBuffer) 89 | { 90 | if (m_alignment > 0) 91 | { 92 | // Use the allocator to free an aligned memory block 93 | AlignedFree(m_dataBuffer); 94 | } 95 | else 96 | { 97 | // Use the allocator to free an unaligned memory block 98 | UnalignedFree(m_dataBuffer); 99 | } 100 | 101 | m_dataBuffer = NULL; 102 | m_bufferSize = 0; 103 | m_alignment = 0; 104 | } 105 | 106 | return true; 107 | } 108 | 109 | /*! 110 | Return the pixel size of the specified format (in bytes) 111 | 112 | The code for computing the pixel size was copied from ISampleDecoder.h 113 | */ 114 | size_t CFrameBuffer::PixelSize(CFHD_PixelFormat format) 115 | { 116 | size_t pixelSize = 0; 117 | 118 | // Compute the pixel size 119 | switch (format) 120 | { 121 | case CFHD_PIXEL_FORMAT_2VUY: 122 | case CFHD_PIXEL_FORMAT_YUYV: 123 | case CFHD_PIXEL_FORMAT_YUY2: 124 | pixelSize = 2; 125 | break; 126 | 127 | case CFHD_PIXEL_FORMAT_BGRA: 128 | pixelSize = 4; 129 | break; 130 | 131 | case CFHD_PIXEL_FORMAT_RG24: 132 | pixelSize = 3; 133 | break; 134 | 135 | case CFHD_PIXEL_FORMAT_B64A: 136 | case CFHD_PIXEL_FORMAT_W13A: 137 | pixelSize = 8; 138 | break; 139 | 140 | case CFHD_PIXEL_FORMAT_YU64: 141 | pixelSize = 4; 142 | break; 143 | 144 | case CFHD_PIXEL_FORMAT_RG48: 145 | case CFHD_PIXEL_FORMAT_WP13: 146 | pixelSize = 6; 147 | break; 148 | 149 | case CFHD_PIXEL_FORMAT_DPX0: 150 | pixelSize = 4; 151 | break; 152 | 153 | case CFHD_PIXEL_FORMAT_BYR4: 154 | pixelSize = 2; 155 | break; 156 | 157 | // Avid pixel formats 158 | case CFHD_PIXEL_FORMAT_CT_UCHAR: // Avid 8-bit CbYCrY 4:2:2 (no alpha) 159 | pixelSize = 2; 160 | break; 161 | case CFHD_PIXEL_FORMAT_CT_10BIT_2_8: // Two planes of 8-bit and 2-bit pixels 162 | break; 163 | case CFHD_PIXEL_FORMAT_CT_SHORT_2_14: // Avid fixed point 2.14 pixel format 164 | pixelSize = 4; 165 | break; 166 | case CFHD_PIXEL_FORMAT_CT_USHORT_10_6: // Avid fixed point 10.6 pixel format 167 | pixelSize = 4; 168 | break; 169 | case CFHD_PIXEL_FORMAT_CT_SHORT: // Avid 16-bit signed pixels 170 | pixelSize = 4; 171 | break; 172 | 173 | //TODO: Add more pixel formats defined in CFHDDecoder.h 174 | 175 | case CFHD_PIXEL_FORMAT_R210: 176 | case CFHD_PIXEL_FORMAT_RG30: 177 | case CFHD_PIXEL_FORMAT_AR10: 178 | case CFHD_PIXEL_FORMAT_AB10: 179 | pixelSize = 4; 180 | break; 181 | 182 | case CFHD_PIXEL_FORMAT_RG64: 183 | pixelSize = 8; 184 | break; 185 | 186 | case CFHD_PIXEL_FORMAT_BYR2: 187 | case CFHD_PIXEL_FORMAT_V210: 188 | 189 | 190 | default: 191 | assert(0); 192 | //throw CFHD_ERROR_BADFORMAT; 193 | break; 194 | } 195 | 196 | // Must return a valid pixel size 197 | ASSERT(pixelSize > 0); 198 | return pixelSize; 199 | } 200 | -------------------------------------------------------------------------------- /EncoderSDK/ver.h: -------------------------------------------------------------------------------- 1 | /*! @file ver.h 2 | 3 | * @brief 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #pragma once 23 | 24 | // obselete use ../common/ver.h instead. 25 | -------------------------------------------------------------------------------- /Example/WaveletDemo/makefile: -------------------------------------------------------------------------------- 1 | wavelets : wavelets.o utils.o 2 | gcc -o wavelets wavelets.o utils.o -lm 3 | 4 | wavelets.o : wavelets.c 5 | gcc -c wavelets.c 6 | utils.o : utils.c 7 | gcc -c utils.c 8 | clean : 9 | rm wavelets wavelets.o utils.o 10 | -------------------------------------------------------------------------------- /Example/WaveletDemo/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /*! @file utils.h 3 | 4 | * @brief wavelet demo 5 | * 6 | * @version 1.0.0 7 | * 8 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 9 | * 10 | * Licensed under either: 11 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 12 | * - MIT license, http://opensource.org/licenses/MIT 13 | * at your option. 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | * 21 | */ 22 | 23 | typedef struct quantizer_stats { 24 | int min; 25 | int max; 26 | int minq; 27 | int maxq; 28 | int total; 29 | int overflow; 30 | int energy; 31 | unsigned short invnonlinearquant[256]; 32 | unsigned short nonlinearquant[1025]; 33 | } quantizer_stats; 34 | 35 | 36 | void QuantValue(int *src, int w, int x, int y, int multiplier, int midpoint, quantizer_stats *s); 37 | 38 | void QuantizeHighpass(int *src, int w, int h, int regw, int regh, int qh, int qv, int qd, quantizer_stats *s); 39 | 40 | void InvQuantValue(int *src, int w, int x, int y, int q, quantizer_stats *s); 41 | 42 | void InverseQuantizeHighpass(int *src, int w, int h, int regw, int regh, int qh, int qv, int qd, quantizer_stats *s); 43 | 44 | void OffsetBuffer(int *src, int w, int h, int regw, int regh, int offset); 45 | 46 | void V22Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 47 | 48 | void InvertV22Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 49 | 50 | void H26Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 51 | 52 | void InvertH26Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 53 | 54 | void Limit(int *dest, int w, int h, int max); 55 | 56 | void V26Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 57 | 58 | void InvertV26Wavelet(int *src, int *dest, int w, int h, int regw, int regh); 59 | 60 | void PrescaleLowPass(int *dest, int w, int h, int regw, int regh, int shift); 61 | 62 | void OutputSubbands(char *filename, int *src, int w, int h, int regw, int regh, int level); 63 | 64 | void CopyBuff(int *src, int *dest, int w, int h); 65 | 66 | void Stats(int *src, int w, int h, int regw, int regh); 67 | 68 | double psnr(int *lptr, int *lptr2, int w, int h, int depth); 69 | 70 | void ExportPGM(char *filename, unsigned char *frameBuffer, int frameWidth, int frameHeight); 71 | 72 | void DiffBuffers(int *lptr, int *lptr2, unsigned char *cptr, int w, int h, int depth, int errorgain); 73 | 74 | void ScaleBuffers(int *lptr, unsigned char *cptr, int w, int h, int scale); 75 | 76 | void ScaleThumbnail(int *lptr, unsigned char *cptr, int w, int h, int lowpass_w, int lowpass_h, int scaleLow); 77 | 78 | void GenerateDeepBufferFrom8bit(int *lptr, unsigned char *cptr, int source_w, int source_h, int w, int h, int depth); 79 | 80 | void Init(quantizer_stats *s); -------------------------------------------------------------------------------- /Example/avi.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | readavi - Copyright 2004-2013 by Michael Kohn 4 | For more info please visit http://www.mikekohn.net/ 5 | 6 | This code falls under the BSD license. 7 | 8 | */ 9 | 10 | struct avi_header_t 11 | { 12 | int TimeBetweenFrames; 13 | int MaximumDataRate; 14 | int PaddingGranularity; 15 | int Flags; 16 | int TotalNumberOfFrames; 17 | int NumberOfInitialFrames; 18 | int NumberOfStreams; 19 | int SuggestedBufferSize; 20 | int Width; 21 | int Height; 22 | int TimeScale; 23 | int DataRate; 24 | int StartTime; 25 | int DataLength; 26 | }; 27 | 28 | struct stream_header_t 29 | { 30 | char DataType[5]; 31 | char DataHandler[5]; 32 | int Flags; 33 | int Priority; 34 | int InitialFrames; 35 | int TimeScale; 36 | int DataRate; 37 | int StartTime; 38 | int DataLength; 39 | int SuggestedBufferSize; 40 | int Quality; 41 | int SampleSize; 42 | }; 43 | 44 | struct stream_format_t 45 | { 46 | int header_size; 47 | int image_width; 48 | int image_height; 49 | int number_of_planes; 50 | int bits_per_pixel; 51 | int compression_type; 52 | int image_size_in_bytes; 53 | int x_pels_per_meter; 54 | int y_pels_per_meter; 55 | int colors_used; 56 | int colors_important; 57 | int *palette; 58 | }; 59 | 60 | struct stream_header_auds_t 61 | { 62 | int format_type; 63 | int number_of_channels; 64 | int sample_rate; 65 | int bytes_per_second; 66 | int block_size_of_data; 67 | int bits_per_sample; 68 | int byte_count_extended; 69 | }; 70 | 71 | struct stream_format_auds_t 72 | { 73 | int header_size; 74 | int format; 75 | int channels; 76 | int samples_per_second; 77 | int bytes_per_second; 78 | int block_size_of_data; 79 | int bits_per_sample; 80 | int extended_size; 81 | }; 82 | 83 | struct index_entry_t 84 | { 85 | char ckid[5]; 86 | int dwFlags; 87 | int dwChunkOffset; 88 | int dwChunkLength; 89 | }; 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Example/classicQBist.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/Example/classicQBist.cpp -------------------------------------------------------------------------------- /Example/fileio.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | readavi - Copyright 2004-2013 by Michael Kohn 4 | For more info please visit http://www.mikekohn.net/ 5 | 6 | This code falls under the BSD license. 7 | 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | int write_long(FILE *out, int n) 14 | { 15 | putc((n&255),out); 16 | putc(((n>>8)&255),out); 17 | putc(((n>>16)&255),out); 18 | putc(((n>>24)&255),out); 19 | 20 | return 0; 21 | } 22 | 23 | int write_word(FILE *out, int n) 24 | { 25 | putc((n&255),out); 26 | putc(((n>>8)&255),out); 27 | 28 | return 0; 29 | } 30 | 31 | int read_long(FILE *in) 32 | { 33 | int c; 34 | 35 | c=getc(in); 36 | c=c+(getc(in)<<8); 37 | c=c+(getc(in)<<16); 38 | c=c+(getc(in)<<24); 39 | 40 | return c; 41 | } 42 | 43 | int read_word(FILE *in) 44 | { 45 | int c; 46 | 47 | c=getc(in); 48 | c=c+(getc(in)<<8); 49 | 50 | return c; 51 | } 52 | 53 | int read_chars(FILE *in, char *s, int count) 54 | { 55 | int t; 56 | 57 | for (t=0; t 4 | For more info please visit http://www.mikekohn.net/ 5 | 6 | This code falls under the BSD license. 7 | 8 | */ 9 | 10 | int write_long(FILE *out, int n); 11 | int write_word(FILE *out, int n); 12 | 13 | int read_long(FILE *in); 14 | int read_word(FILE *in); 15 | 16 | int read_chars(FILE *in, char *s, int count); 17 | int read_chars_bin(FILE *in, char *s, int count); 18 | int write_chars(FILE *out, char *s); 19 | int write_chars_bin(FILE *out, char *s, int count); 20 | 21 | -------------------------------------------------------------------------------- /Example/mp4reader.h: -------------------------------------------------------------------------------- 1 | /*! @file mp4reader.h 2 | * 3 | * @brief Way Too Crude MP4|MOV reader 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef _MP4READER_H 23 | #define _MP4READER_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct media_header 30 | { 31 | uint8_t version_flags[4]; 32 | uint32_t creation_time; 33 | uint32_t modification_time; 34 | uint32_t time_scale; 35 | uint32_t duration; 36 | uint16_t language; 37 | uint16_t quality; 38 | } media_header; 39 | 40 | 41 | typedef struct SampleToChunk 42 | { 43 | uint32_t chunk_num; 44 | uint32_t samples; 45 | uint32_t id; 46 | } SampleToChunk; 47 | 48 | 49 | typedef struct videoobject 50 | { 51 | uint32_t *metasizes; 52 | uint32_t metasize_count; 53 | uint64_t *metaoffsets; 54 | SampleToChunk *metastsc; 55 | uint32_t metastsc_count; 56 | uint32_t indexcount; 57 | float videolength; 58 | float metadatalength; 59 | uint32_t clockdemon, clockcount; 60 | uint32_t trak_clockdemon, trak_clockcount; 61 | uint32_t meta_clockdemon, meta_clockcount; 62 | uint32_t basemetadataduration; 63 | uint32_t basemetadataoffset; 64 | FILE *mediafp; 65 | } videoobject; 66 | 67 | #define MAKEID(a,b,c,d) (((d&0xff)<<24)|((c&0xff)<<16)|((b&0xff)<<8)|(a&0xff)) 68 | #define STR2FOURCC(s) ((s[0]<<0)|(s[1]<<8)|(s[2]<<16)|(s[3]<<24)) 69 | 70 | #define BYTESWAP64(a) (((a&0xff)<<56)|((a&0xff00)<<40)|((a&0xff0000)<<24)|((a&0xff000000)<<8) | ((a>>56)&0xff)|((a>>40)&0xff00)|((a>>24)&0xff0000)|((a>>8)&0xff000000) ) 71 | #define BYTESWAP32(a) (((a&0xff)<<24)|((a&0xff00)<<8)|((a>>8)&0xff00)|((a>>24)&0xff)) 72 | #define BYTESWAP16(a) ((((a)>>8)&0xff)|(((a)<<8)&0xff00)) 73 | #define NOSWAP8(a) (a) 74 | 75 | #define MOV_TRAK_TYPE MAKEID('v', 'i', 'd', 'e') // track is the type for video 76 | #define MOV_TRAK_SUBTYPE MAKEID('C', 'F', 'H', 'D') // subtype is CineForm HD 77 | #define AVI_TRAK_TYPE MAKEID('v', 'i', 'd', 's') // track is the type for video 78 | #define AVI_TRAK_SUBTYPE MAKEID('c', 'f', 'h', 'd') // subtype is CineForm HD 79 | 80 | #define NESTSIZE(x) { int i = nest; while (i > 0 && nestsize[i] > 0) { nestsize[i] -= x; if(nestsize[i]>=0 && nestsize[i] <= 8) { nestsize[i]=0; nest--; } i--; } } 81 | 82 | #define VALID_FOURCC(a) (((((a>>24)&0xff)>='a'&&((a>>24)&0xff)<='z') || (((a>>24)&0xff)>='A'&&((a>>24)&0xff)<='Z') || (((a>>24)&0xff)>='0'&&((a>>24)&0xff)<='9') || (((a>>24)&0xff)==' ') ) && \ 83 | ( (((a>>16)&0xff)>='a'&&((a>>24)&0xff)<='z') || (((a>>16)&0xff)>='A'&&((a>>16)&0xff)<='Z') || (((a>>16)&0xff)>='0'&&((a>>16)&0xff)<='9') || (((a>>16)&0xff)==' ') ) && \ 84 | ( (((a>>8)&0xff)>='a'&&((a>>24)&0xff)<='z') || (((a>>8)&0xff)>='A'&&((a>>8)&0xff)<='Z') || (((a>>8)&0xff)>='0'&&((a>>8)&0xff)<='9') || (((a>>8)&0xff)==' ') ) && \ 85 | ( (((a>>0)&0xff)>='a'&&((a>>24)&0xff)<='z') || (((a>>0)&0xff)>='A'&&((a>>0)&0xff)<='Z') || (((a>>0)&0xff)>='0'&&((a>>0)&0xff)<='9') || (((a>>0)&0xff)==' ') )) 86 | 87 | void *OpenMP4Source(char *filename, uint32_t traktype, uint32_t subtype); 88 | void *OpenAVISource(char *filename, uint32_t traktype, uint32_t subtype); 89 | void CloseSource(void *handle); 90 | float GetDuration(void *handle); 91 | uint32_t GetNumberPayloads(void *handle); 92 | uint32_t *GetPayload(void *handle, uint32_t *lastpayload, uint32_t index); 93 | void FreePayload(uint32_t *lastpayload); 94 | uint32_t GetPayloadSize(void *handle, uint32_t index); 95 | uint32_t GetPayloadTime(void *handle, uint32_t index, float *in, float *out); //MP4 timestamps for the payload 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /Example/qbist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CFHDTypes.h" 4 | 5 | unsigned int GetRand(unsigned int seed); 6 | void initBaseTransform(void); 7 | void makeVariations(void); 8 | void modifyQBistGenes(void); 9 | void RunQBist(int width, int height, int pitch, CFHD_PixelFormat pixelFormat, int alpha, unsigned char *ptr); 10 | void QBist(float x, float y, unsigned short *r, unsigned short *g, unsigned short *b); -------------------------------------------------------------------------------- /Example/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | #include "utils.h" 20 | #include "qbist.h" 21 | -------------------------------------------------------------------------------- /Example/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | #ifdef _WIN32 8 | #include 9 | #endif -------------------------------------------------------------------------------- /Example/utils.h: -------------------------------------------------------------------------------- 1 | /*! @file utils.h 2 | 3 | * @brief Exerciser and example for using the CineForm SDK 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | #include "CFHDTypes.h" 26 | 27 | // required to support the orginal qBist code 28 | typedef struct { int x, y; } Point; 29 | typedef bool Boolean; 30 | 31 | #define BYTESWAP32(a) (((a&0xff)<<24)|((a&0xff00)<<8)|((a>>8)&0xff00)|((a>>24)&0xff)) 32 | 33 | unsigned int GetRand(unsigned int seed); 34 | unsigned int myRand(); 35 | 36 | 37 | int ChannelsInPixelFormat(CFHD_PixelFormat pixelFormat); 38 | int DepthInPixelFormat(CFHD_PixelFormat pixelFormat); 39 | int InvertedPixelFormat(CFHD_PixelFormat pixelFormat); 40 | int FramePitch4PixelFormat(CFHD_PixelFormat pixelFormat, int frameWidth); 41 | 42 | void ExportPPM(char *filename, char *metadata, void *frameBuffer, int frameWidth, int frameHeight, int framePitch, CFHD_PixelFormat pixelFormat); 43 | 44 | float PSNR(void *A, void *B, int width, int height, CFHD_PixelFormat pixelFormat, int scale); 45 | -------------------------------------------------------------------------------- /Example/videos/CFHDsample422.AVI: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/Example/videos/CFHDsample422.AVI -------------------------------------------------------------------------------- /Example/videos/CFHDsample444.AVI: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/Example/videos/CFHDsample444.AVI -------------------------------------------------------------------------------- /GPDeps: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "info": { 4 | "type": "lib", 5 | "visibility": "public", 6 | "platforms": ["macos", "win", "linux"] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright 2017 GoPro, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included 11 | in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /WarpLib/GeoMeshApply.h: -------------------------------------------------------------------------------- 1 | /*! @file GeoMeshApply.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #ifndef GEOMESH_YUY2_H 22 | #define GEOMESH_YUY2_H 23 | 24 | 25 | #endif /* GEOMESH_YUY2_H */ 26 | 27 | -------------------------------------------------------------------------------- /WarpLib/GeoMeshInterp.h: -------------------------------------------------------------------------------- 1 | /*! @file GeoMeshInterp.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 6 | * 7 | * Licensed under either: 8 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 9 | * - MIT license, http://opensource.org/licenses/MIT 10 | * at your option. 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | #ifndef GEOMESH_INTERP_H 21 | #define GEOMESH_INTERP_H 22 | 23 | // 24 | // estimate the source image x and y location corresponding to a (floating point) 25 | // row and column location in the destination image 26 | // 27 | 28 | int geomesh_interp_bilinear(void *opaque, float row, float col, float *x, float *y); 29 | 30 | #endif /* GEOMESH_INTERP_H */ 31 | 32 | -------------------------------------------------------------------------------- /WarpLib/GeoMeshPrivate.h: -------------------------------------------------------------------------------- 1 | /*! @file GeoMeshPrivate.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #ifndef GEOMESH_PRIV_H 22 | #define GEOMESH_PRIV_H 23 | 24 | // 25 | // private interface for functions internal to the library 26 | // 27 | 28 | // this struct is what is given to users as the opaque pointer 29 | 30 | typedef struct geomesh_tag 31 | { 32 | unsigned int srcformat; // source image format 33 | int srcwidth; // pixels 34 | int srcheight; // pixels 35 | int srcstride; // bytes 36 | int srcbpp; // bytes per pixel (implied from format) 37 | int srcsubsampled; // 0 - not, 1 - 4:2:2 38 | int srcchannels; // channels (implied from format) 39 | int srcsigned; // signed data pixel format 40 | unsigned int destformat; // dest image format 41 | int destwidth; // pixels 42 | int destheight; // pixels 43 | int deststride; // bytes 44 | int destbpp; // bytes per pixel (implied from format) 45 | int destchannels;// channels (implied from format) 46 | int destsubsampled; // 0 - not, 1 - 4:2:2 47 | int destsigned; // signed data pixel format 48 | int meshwidth; // number of mesh points in x direction 49 | int meshheight; // number of mesh points in y direction 50 | int separable; // only some transforms result in a separable mesh 51 | int backgroundfill; // 0 - black, 1 - extend edges 52 | float lensCustomSRC[6]; // Custom lens curve 53 | float lensCustomDST[6]; // Custom lens curve 54 | 55 | float *meshx; // store mesh node values 56 | float *meshy; 57 | int *cache; // store image-sized acceleration cache 58 | // internal consistency metadata 59 | char signature[8]; 60 | char mesh_allocated; 61 | char mesh_initialized; 62 | char num_elements_allocated; 63 | char cache_initialized; 64 | 65 | float xstep; // step to bridge the discrepancy between the destination width and the mesh width 66 | float ystep; // step to bridge the discrepancy between the destination height and the mesh height 67 | 68 | } geomesh_t; 69 | 70 | int geomesh_alloc_mesh(geomesh_t *gm); 71 | int geomesh_dealloc_mesh(geomesh_t *gm); 72 | int geomesh_alloc_cache(geomesh_t *gm); 73 | int geomesh_dealloc_cache(geomesh_t *gm); 74 | 75 | // debugging facilities 76 | 77 | #define GEOMESH_SIGNATURE "GeoMesh" 78 | 79 | #define GEOMESH_CHECK_OBJ_EXISTS 0x01 80 | #define GEOMESH_CHECK_MESH_EXISTS 0x02 81 | #define GEOMESH_CHECK_MESH_INITIALIZED 0x04 82 | #define GEOMESH_CHECK_CACHE_EXISTS 0x08 83 | #define GEOMESH_CHECK_CACHE_INITIALIZED 0x10 84 | 85 | #ifdef DEBUG 86 | #define GEOMESH_CHECK(gm,t) geomesh_check(gm, t) 87 | #define CHECK_OBJ_EXISTS(gm) geomesh_check(gm, GEOMESH_CHECK_OBJ_EXISTS) 88 | #define CHECK_MESH_EXISTS(gm) geomesh_check(gm, GEOMESH_CHECK_OBJ_EXISTS | GEOMESH_CHECK_MESH_EXISTS) 89 | #define CHECK_MESH_INIT(gm) geomesh_check(gm, GEOMESH_CHECK_OBJ_EXISTS | GEOMESH_CHECK_MESH_EXISTS | GEOMESH_CHECK_MESH_INITIALIZED) 90 | #define CHECK_CACHE_EXISTS(gm) geomesh_check(gm, GEOMESH_CHECK_OBJ_EXISTS | GEOMESH_CHECK_CACHE_EXISTS) 91 | #define CHECK_CACHE_INIT(gm) geomesh_check(gm, GEOMESH_CHECK_OBJ_EXISTS | GEOMESH_CHECK_CACHE_EXISTS | GEOMESH_CHECK_CACHE_INITIALIZED) 92 | #else 93 | #define GEOMESH_CHECK(gm,t) (void)0 94 | #define CHECK_OBJ(gm) (void)0 95 | #define CHECK_MESH_EXISTS(gm) (void)0 96 | #define CHECK_MESH_INIT(gm) (void)0 97 | #define CHECK_CACHE_EXISTS(gm) (void)0 98 | #define CHECK_CACHE_INIT(gm) (void)0 99 | #endif 100 | 101 | int geomesh_check(void *opaque, unsigned int check_type); 102 | 103 | #endif /* GEOMESH_PRIV_H */ 104 | 105 | -------------------------------------------------------------------------------- /WarpLib/GeoMeshYuy2.c: -------------------------------------------------------------------------------- 1 | /*! @file GeoMeshYuy2.c 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #include 22 | 23 | #include "GeoMeshPrivate.h" 24 | #include "sse_types.h" 25 | 26 | -------------------------------------------------------------------------------- /WarpLib/GeoMeshYuy2.h: -------------------------------------------------------------------------------- 1 | /*! @file GeoMeshYuy2.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | #ifndef GEOMESH_YUY2_H 22 | #define GEOMESH_YUY2_H 23 | 24 | #include "GeoMesh.h" 25 | 26 | int geomesh_cache_init_bilinear_yuy2(void *opaque); 27 | 28 | #ifdef __cplusplus 29 | 30 | class GeoMeshYuy2 : public GeoMesh 31 | { 32 | public: 33 | 34 | GeoMeshYuy2() 35 | { 36 | } 37 | 38 | GeoMeshYuy2(int meshrows, int meshcols) 39 | : GeoMesh(meshrows, meshcols) 40 | { 41 | } 42 | 43 | virtual ~GeoMeshYuy2() 44 | { 45 | } 46 | 47 | int cache_init_bilinear(void); 48 | int apply_bilinear(unsigned char *src, unsigned char *dest, int row0, int row1); 49 | 50 | }; 51 | 52 | #endif /* __cplusplus */ 53 | 54 | #endif /* GEOMESH_YUY2_H */ 55 | 56 | -------------------------------------------------------------------------------- /WarpLib/WarpLib.h: -------------------------------------------------------------------------------- 1 | /*! @file WarpLib.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef WARPLIB_H 23 | #define WARPLIB_H 24 | 25 | #include "GeoMesh.h" 26 | 27 | #endif /* WARPLIB_H */ 28 | 29 | -------------------------------------------------------------------------------- /WarpLib/sse_types.h: -------------------------------------------------------------------------------- 1 | /*! @file sse_types.h 2 | 3 | * @brief Mesh tools 4 | * 5 | * @version 1.0.0 6 | * 7 | * (C) Copyright 2017 GoPro Inc (http://gopro.com/). 8 | * 9 | * Licensed under either: 10 | * - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0 11 | * - MIT license, http://opensource.org/licenses/MIT 12 | * at your option. 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | #ifndef SSE_TYPES_H 23 | #define SSE_TYPES_H 24 | 25 | #include "emmintrin.h" 26 | 27 | typedef union 28 | { 29 | unsigned long long ldata[2]; 30 | unsigned int idata[4]; 31 | unsigned short sdata[8]; 32 | unsigned char cdata[16]; 33 | __m128i m128; 34 | } m128i; 35 | 36 | #endif /* SSE_TYPES_H */ 37 | 38 | -------------------------------------------------------------------------------- /data/readmegfx/level1-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/readmegfx/level1-640.png -------------------------------------------------------------------------------- /data/readmegfx/level1D-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/readmegfx/level1D-640.png -------------------------------------------------------------------------------- /data/readmegfx/level2-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/readmegfx/level2-640.png -------------------------------------------------------------------------------- /data/readmegfx/level3-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/readmegfx/level3-640.png -------------------------------------------------------------------------------- /data/readmegfx/source-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/readmegfx/source-640.png -------------------------------------------------------------------------------- /data/testpatt.pgm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/data/testpatt.pgm -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | #theme: jekyll-theme-cayman 2 | remote_theme: gopro/jekyll-theme-labs 3 | -------------------------------------------------------------------------------- /docs/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/favicon.png -------------------------------------------------------------------------------- /docs/readmegfx/CF-Logo-960.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/CF-Logo-960.png -------------------------------------------------------------------------------- /docs/readmegfx/CF-Logo-OLDsm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/CF-Logo-OLDsm.png -------------------------------------------------------------------------------- /docs/readmegfx/CF-Logo-oldest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/CF-Logo-oldest.png -------------------------------------------------------------------------------- /docs/readmegfx/level1-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/level1-640.png -------------------------------------------------------------------------------- /docs/readmegfx/level1D-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/level1D-640.png -------------------------------------------------------------------------------- /docs/readmegfx/level2-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/level2-640.png -------------------------------------------------------------------------------- /docs/readmegfx/level3-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/level3-640.png -------------------------------------------------------------------------------- /docs/readmegfx/source-640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gopro/cineform-sdk/11574d0295771edccadd17af14af74a539f924c7/docs/readmegfx/source-640.png -------------------------------------------------------------------------------- /libcineformsdk.pc.cmake: -------------------------------------------------------------------------------- 1 | prefix=${CMAKE_INSTALL_PREFIX} 2 | exec_prefix=${EXEC_INSTALL_PREFIX} 3 | libdir=${LIB_INSTALL_DIR} 4 | includedir=${INCLUDE_INSTALL_DIR} 5 | 6 | Name: ${PROJECT_NAME} 7 | Description: CineForm SDK libraries 8 | URL: https://github.com/gopro/cineform-sdk 9 | Version: ${PROJECT_VERSION} 10 | Libs: -L${LIB_INSTALL_DIR} ${LIB_INSTALL_NAMES} ${ADDITIONAL_LIBS} 11 | Cflags: -I${INCLUDE_INSTALL_DIR} --------------------------------------------------------------------------------