sphere_mixed.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000 Brian Gerkey et al.
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  */
21 
22 #include <stdint.h>
23 
24 #include <libplayercore/playercore.h>
25 
26 #include "v4lcapture.h"
27 
28 #define PLAYER_CAMERA_FORMAT_RGB 6
29 #define PLAYER_CAMERA_FORMAT_YUV420P 7
30 
32 // The class for the driver
34 {
35  public:
36 
37  // Constructor; need that
38  SphereDriver(ConfigFile* cf, int section);
39 
40  // Must implement the following methods.
41  int MainSetup();
42  void MainQuit();
43  // Main function for device thread.
44  virtual void Main();
45 
46  // This method will be invoked on each incoming message
47  virtual int ProcessMessage(QueuePointer & resp_queue,
48  player_msghdr * hdr,
49  void * data);
50  //void ProcessConfig();
51  void ProcessCommand(player_msghdr_t* hdr, player_ptz_cmd_t &data);
52  void RefreshData();
53 
54  private:
55 
56  void YUV422toRGB(uint8_t* argInputData, uint8_t* argOutputData);
57 
58  inline double LimitPan(double argP)
59  {return (argP < mPanMin) ? mPanMin : ((argP > mPanMax) ? mPanMax : argP);};
60  inline double LimitTilt(double argT)
61  {return (argT < mTiltMin) ? mTiltMin : ((argT > mTiltMax) ? mTiltMax : argT);};
62 
63  // Camera interface
64  player_devaddr_t mCameraAddr;
65  player_camera_data_t mCameraData;
66  // PTZ interface
67  player_devaddr_t mPtzAddr;
68  player_ptz_data_t mPtzData;
69  player_ptz_cmd_t mPtzCmd;
70 
71  int32_t mSleep;
72  int32_t mFrameRate;
73  int32_t mShutterSpeed;
74  int32_t mCompressionPreference;
75  int32_t mAutomaticGain;
76  int32_t mSharpness;
77  int32_t mBacklight;
78  int32_t mFlicker;
79  int32_t mNoiseReduction;
80  int32_t mDumpSettings;
81  int32_t mDebug;
82  const char *mAutomaticWb;
83 
84  double mPanMin;
85  double mPanMax;
86  double mTiltMin;
87  double mTiltMax;
88 
89  // Video device
90  const char *mDevice;
91  // Input source
92  int32_t mSource;
93 
94  // Camera palette
95  const char *mPalette;
96  // Frame grabber interface
97  FRAMEGRABBER* mFg;
98 
99  // The current image (local copy)
100  FRAME* mFrame;
101  FRAME* mRGBFrame;
102  int32_t mFrameNumber;
103 
104  // Image dimensions
105  int32_t mWidth, mHeight;
106  // Pixel depth
107  int32_t mDepth;
108 
109  // Write frames to disk?
110  int32_t mSave;
111 
112 };
T min(T a, T b)
Return the minimum of a, b.
Definition: utility.h:91
virtual void Publish(player_devaddr_t addr, QueuePointer &queue, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true)
Publish a message via one of this driver's interfaces.
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
int AddInterface(player_devaddr_t addr)
Add an interface.
Generic message header.
Definition: player.h:162
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:658
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition: player.h:166
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:75
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
virtual void Main(void)=0
Main method for driver thread.
int ReadInt(int section, const char *name, int value)
Read an integer value.
void ProcessMessages(void)
Process pending messages.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
Definition: sphere_mixed.h:34
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
void YUV422toRGB(uint8_t *argInputData, uint8_t *argOutputData)
Conversion of YUV422 pixel data into RGB ( CCIR 601 )
Definition: sphere_mixed.cc:671
void MainQuit()
Cleanup method for driver thread (called when main exits)
Definition: sphere_mixed.cc:362
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
Definition: sphere_mixed.cc:405
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
Class for loading configuration file information.
Definition: configfile.h:197
int ReadTupleInt(int section, const char *name, int index, int value)
Read an integer from a tuple field.
A device address.
Definition: player.h:146
An autopointer for the message queue.
Definition: message.h:74
Definition: v4lcapture.h:100
Definition: v4lframe.h:64
void SetError(int code)
Set/reset error code.
Definition: driver.h:145
#define PLAYER_ERROR1(msg, a)
Definition: error.h:82
#define PLAYER_ERROR(msg)
Definition: error.h:81
player_devaddr_t device_addr
Default device address (single-interface drivers)
Definition: driver.h:269
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
int MainSetup()
Sets up the resources needed by the driver thread.
Definition: sphere_mixed.cc:276
uint32_t size
Size in bytes of the payload to follow.
Definition: player.h:174
SphereDriver(ConfigFile *cf, int section)
Definition: sphere_mixed.cc:200
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
Base class for all drivers.
Definition: driver.h:109
virtual void Main()
Main method for driver thread.
Definition: sphere_mixed.cc:382
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:104