Skip to content

Commit

Permalink
Merge pull request #507 from xlz/preemptive-api-expansion
Browse files Browse the repository at this point in the history
Preemptive API expansion
  • Loading branch information
floe committed Dec 17, 2015
2 parents 7fa5b68 + 625a9e9 commit 7867c9e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
17 changes: 14 additions & 3 deletions include/libfreenect2/frame_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,34 @@ namespace libfreenect2
class LIBFREENECT2_API Frame
{
public:
/** Available types of frames and their pixel format. */
/** Available types of frames. */
enum Type
{
Color = 1, ///< 1920x1080 32-bit BGRX.
Ir = 2, ///< 512x424 float. Range is [0.0, 65535.0].
Depth = 4 ///< 512x424 float, unit: millimeter. Non-positive, NaN, and infinity are invalid or missing data.
};

uint32_t timestamp; ///< Unit: roughly or exactly 0.1 millisecond
uint32_t sequence; ///< Increasing frame sequence number
/** (Proposed for 0.2) Pixel format. */
enum Format
{
BGRX,
RGBX,
Gray,
Float
};

size_t width; ///< Length of a line (in pixels).
size_t height; ///< Number of lines in the frame.
size_t bytes_per_pixel; ///< Number of bytes in a pixel.
unsigned char* data; ///< Data of the frame (aligned). @see See Frame::Type for pixel format.
uint32_t timestamp; ///< Unit: roughly or exactly 0.1 millisecond
uint32_t sequence; ///< Increasing frame sequence number
float exposure; ///< From 0.5 (very bright) to ~60.0 (fully covered)
float gain; ///< From 1.0 (bright) to 1.5 (covered)
float gamma; ///< From 1.0 (bright) to 6.4 (covered)
uint32_t status; ///< Reserved. To be defined in 0.2.
Format format; ///< Reserved. To be defined in 0.2.

/** Construct a new frame.
* @param width Width in pixel
Expand Down
18 changes: 13 additions & 5 deletions include/libfreenect2/libfreenect2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,22 @@ class LIBFREENECT2_API Freenect2Device
* All above configuration must only be called before start() or after stop().
*
* FrameListener will receive frames when the device is running.
*
* @return Undefined. To be defined in 0.2.
*/
virtual void start() = 0;
virtual bool start() = 0;

/** Stop data processing. */
virtual void stop() = 0;
/** Stop data processing.
*
* @return Undefined. To be defined in 0.2.
*/
virtual bool stop() = 0;

/** Shut down the device. */
virtual void close() = 0;
/** Shut down the device.
*
* @return Undefined. To be defined in 0.2.
*/
virtual bool close() = 0;
};

class Freenect2Impl;
Expand Down
21 changes: 12 additions & 9 deletions src/libfreenect2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class Freenect2DeviceImpl : public Freenect2Device

virtual void setColorFrameListener(libfreenect2::FrameListener* rgb_frame_listener);
virtual void setIrAndDepthFrameListener(libfreenect2::FrameListener* ir_frame_listener);
virtual void start();
virtual void stop();
virtual void close();
virtual bool start();
virtual bool stop();
virtual bool close();
};

struct PrintBusAndDevice
Expand Down Expand Up @@ -671,10 +671,10 @@ bool Freenect2DeviceImpl::open()
return true;
}

void Freenect2DeviceImpl::start()
bool Freenect2DeviceImpl::start()
{
LOG_INFO << "starting...";
if(state_ != Open) return;
if(state_ != Open) return false;

CommandTransaction::Result serial_result, firmware_result, result;

Expand Down Expand Up @@ -801,16 +801,17 @@ void Freenect2DeviceImpl::start()

state_ = Streaming;
LOG_INFO << "started";
return true;
}

void Freenect2DeviceImpl::stop()
bool Freenect2DeviceImpl::stop()
{
LOG_INFO << "stopping...";

if(state_ != Streaming)
{
LOG_INFO << "already stopped, doing nothing";
return;
return false;
}

LOG_INFO << "disabling usb transfer submission...";
Expand All @@ -837,16 +838,17 @@ void Freenect2DeviceImpl::stop()

state_ = Open;
LOG_INFO << "stopped";
return true;
}

void Freenect2DeviceImpl::close()
bool Freenect2DeviceImpl::close()
{
LOG_INFO << "closing...";

if(state_ == Closed)
{
LOG_INFO << "already closed, doing nothing";
return;
return true;
}

if(state_ == Streaming)
Expand Down Expand Up @@ -885,6 +887,7 @@ void Freenect2DeviceImpl::close()

state_ = Closed;
LOG_INFO << "closed";
return true;
}

PacketPipeline *createDefaultPacketPipeline()
Expand Down

0 comments on commit 7867c9e

Please sign in to comment.