Skip to content

Commit e0c6150

Browse files
committed
New VideoToolbox rgb packet processor
Mac OS X >= 10.8 has hardware accelerated jpeg decoding (a bit hidden)
1 parent 60fde3f commit e0c6150

File tree

7 files changed

+291
-19
lines changed

7 files changed

+291
-19
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,16 @@ Use your favorite package managers (brew, ports, etc.)
144144

145145
1. ``cd`` into a directory where you want to keep libfreenect2 stuff in
146146
1. Make sure these build tools are available: wget, git, cmake, pkg-config, automake, autoconf, libtool. Xcode may provide some of them. Install the rest via package managers.
147-
1. Install dependencies: TurboJPEG, GLFW.
147+
1. Install dependencies: GLFW.
148148

149149
```
150150
brew update
151-
brew tap homebrew/science
152-
brew install jpeg-turbo
153151
brew tap homebrew/versions
154152
brew install glfw3
155153
```
156154

157155
Do not install libusb via package managers for libfreenect2. libfreenect2 includes an unreleased local version of libusb with USB3 specific patches. libfreenect2's libusb should still work fine in presence of a global version libusb.
158156

159-
It is not recommended to build TurboJPEG from source, which produces corrupted results on Mac OSX according to reports. Install TurboJPEG binary only from package managers.
160-
161157
1. Download the libfreenect2 repository
162158

163159
```

examples/protonect/CMakeLists.txt

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)
4747
# dependencies
4848
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
4949
FIND_PACKAGE(LibUSB REQUIRED)
50-
FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
5150

5251
# Add includes
5352
INCLUDE_DIRECTORIES(
5453
"${MY_DIR}/include"
5554
${LIBFREENECT2_THREADING_INCLUDE_DIR}
5655
${LibUSB_INCLUDE_DIRS}
57-
${TurboJPEG_INCLUDE_DIRS}
5856
)
5957

6058
LINK_DIRECTORIES(${LibUSB_LIBRARY_DIRS})
@@ -94,7 +92,6 @@ SET(SOURCES
9492
src/packet_pipeline.cpp
9593
src/rgb_packet_stream_parser.cpp
9694
src/rgb_packet_processor.cpp
97-
src/turbo_jpeg_rgb_packet_processor.cpp
9895
src/depth_packet_stream_parser.cpp
9996
src/depth_packet_processor.cpp
10097
src/cpu_depth_packet_processor.cpp
@@ -110,7 +107,6 @@ SET(SOURCES
110107

111108
SET(LIBRARIES
112109
${LibUSB_LIBRARIES}
113-
${TurboJPEG_LIBRARIES}
114110
${LIBFREENECT2_THREADING_LIBRARIES}
115111
)
116112

@@ -169,6 +165,49 @@ IF(ENABLE_OPENCL)
169165
ENDIF(OPENCL_FOUND)
170166
ENDIF(ENABLE_OPENCL)
171167

168+
IF(APPLE)
169+
FIND_LIBRARY(VIDEOTOOLBOX_LIBRARY VideoToolbox)
170+
171+
IF(VIDEOTOOLBOX_LIBRARY)
172+
SET(LIBFREENECT2_WITH_VT_SUPPORT 1)
173+
174+
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation REQUIRED)
175+
FIND_LIBRARY(COREMEDIA_LIBRARY CoreMedia REQUIRED)
176+
FIND_LIBRARY(COREVIDEO_LIBRARY CoreVideo REQUIRED)
177+
178+
LIST(APPEND SOURCES
179+
src/vt_rgb_packet_processor.cpp
180+
)
181+
182+
LIST(APPEND LIBRARIES
183+
${VIDEOTOOLBOX_LIBRARY}
184+
${COREFOUNDATION_LIBRARY}
185+
${COREMEDIA_LIBRARY}
186+
${COREVIDEO_LIBRARY}
187+
)
188+
ENDIF(VIDEOTOOLBOX_LIBRARY)
189+
ENDIF(APPLE)
190+
191+
IF(LIBFREENECT2_WITH_VT_SUPPORT)
192+
FIND_PACKAGE(TurboJPEG)
193+
ELSE()
194+
FIND_PACKAGE(TurboJPEG REQUIRED)
195+
ENDIF()
196+
197+
IF(TurboJPEG_FOUND)
198+
SET(LIBFREENECT2_WITH_TURBOJPEG_SUPPORT 1)
199+
200+
INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS})
201+
202+
LIST(APPEND SOURCES
203+
src/turbo_jpeg_rgb_packet_processor.cpp
204+
)
205+
206+
LIST(APPEND LIBRARIES
207+
${TurboJPEG_LIBRARIES}
208+
)
209+
ENDIF()
210+
172211
SET(CMAKE_INSTALL_RPATH ${LibUSB_LIBDIR})
173212

174213
CONFIGURE_FILE("${MY_DIR}/include/libfreenect2/config.h.in" "${MY_DIR}/include/libfreenect2/config.h" @ONLY)

examples/protonect/include/libfreenect2/config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343

4444
#cmakedefine LIBFREENECT2_WITH_OPENCL_SUPPORT
4545

46+
#cmakedefine LIBFREENECT2_WITH_VT_SUPPORT
47+
48+
#cmakedefine LIBFREENECT2_WITH_TURBOJPEG_SUPPORT
49+
4650
#cmakedefine LIBFREENECT2_THREADING_STDLIB
4751

4852
#cmakedefine LIBFREENECT2_THREADING_TINYTHREAD

examples/protonect/include/libfreenect2/frame_listener.hpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,30 @@ class LIBFREENECT2_API Frame
4949
size_t width, height, bytes_per_pixel;
5050
unsigned char* data;
5151

52-
Frame(size_t width, size_t height, size_t bytes_per_pixel) :
52+
Frame(size_t width, size_t height, size_t bytes_per_pixel, unsigned char* _data = NULL) :
5353
width(width),
5454
height(height),
55-
bytes_per_pixel(bytes_per_pixel)
55+
bytes_per_pixel(bytes_per_pixel),
56+
rawdata(NULL),
57+
data(_data)
5658
{
57-
const size_t alignment = 64;
58-
size_t space = width * height * bytes_per_pixel + alignment;
59-
rawdata = new unsigned char[space];
60-
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
61-
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
62-
data = reinterpret_cast<unsigned char *>(aligned);
59+
if (data == NULL)
60+
{
61+
const size_t alignment = 64;
62+
size_t space = width * height * bytes_per_pixel + alignment;
63+
rawdata = new unsigned char[space];
64+
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
65+
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
66+
data = reinterpret_cast<unsigned char *>(aligned);
67+
}
6368
}
6469

65-
~Frame()
70+
virtual ~Frame()
6671
{
67-
delete[] rawdata;
72+
if (rawdata)
73+
{
74+
delete[] rawdata;
75+
}
6876
}
6977

7078
protected:

examples/protonect/include/libfreenect2/rgb_packet_processor.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LIBFREENECT2_API DumpRgbPacketProcessor : public RgbPacketProcessor
6868
virtual void process(const libfreenect2::RgbPacket &packet);
6969
};
7070

71+
#ifdef LIBFREENECT2_WITH_TURBOJPEG_SUPPORT
7172
class TurboJpegRgbPacketProcessorImpl;
7273

7374
class LIBFREENECT2_API TurboJpegRgbPacketProcessor : public RgbPacketProcessor
@@ -80,6 +81,22 @@ class LIBFREENECT2_API TurboJpegRgbPacketProcessor : public RgbPacketProcessor
8081
private:
8182
TurboJpegRgbPacketProcessorImpl *impl_;
8283
};
84+
#endif
85+
86+
#ifdef LIBFREENECT2_WITH_VT_SUPPORT
87+
class VTRgbPacketProcessorImpl;
88+
89+
class LIBFREENECT2_API VTRgbPacketProcessor : public RgbPacketProcessor
90+
{
91+
public:
92+
VTRgbPacketProcessor();
93+
virtual ~VTRgbPacketProcessor();
94+
protected:
95+
virtual void process(const libfreenect2::RgbPacket &packet);
96+
private:
97+
VTRgbPacketProcessorImpl *impl_;
98+
};
99+
#endif
83100

84101
} /* namespace libfreenect2 */
85102
#endif /* RGB_PACKET_PROCESSOR_H_ */

examples/protonect/src/packet_pipeline.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ void BasePacketPipeline::initialize()
3939
rgb_parser_ = new RgbPacketStreamParser();
4040
depth_parser_ = new DepthPacketStreamParser();
4141

42+
#ifdef LIBFREENECT2_WITH_VT_SUPPORT
43+
rgb_processor_ = new VTRgbPacketProcessor();
44+
#else
4245
rgb_processor_ = new TurboJpegRgbPacketProcessor();
46+
#endif
47+
4348
depth_processor_ = createDepthPacketProcessor();
4449

4550
async_rgb_processor_ = new AsyncPacketProcessor<RgbPacket>(rgb_processor_);

0 commit comments

Comments
 (0)