Webcam Server.
Dependencies: uvchost FatFileSystem mbed HTTPServer NetServicesMin
WebcamHandler.h@1:7a4f2c038803, 2012-08-14 (annotated)
- Committer:
- va009039
- Date:
- Tue Aug 14 03:42:12 2012 +0000
- Revision:
- 1:7a4f2c038803
- Parent:
- 0:2b4ea8a138e5
supported LogitechC270 and Safari
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:2b4ea8a138e5 | 1 | |
va009039 | 0:2b4ea8a138e5 | 2 | /* |
va009039 | 0:2b4ea8a138e5 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
va009039 | 0:2b4ea8a138e5 | 4 | |
va009039 | 0:2b4ea8a138e5 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
va009039 | 0:2b4ea8a138e5 | 6 | of this software and associated documentation files (the "Software"), to deal |
va009039 | 0:2b4ea8a138e5 | 7 | in the Software without restriction, including without limitation the rights |
va009039 | 0:2b4ea8a138e5 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
va009039 | 0:2b4ea8a138e5 | 9 | copies of the Software, and to permit persons to whom the Software is |
va009039 | 0:2b4ea8a138e5 | 10 | furnished to do so, subject to the following conditions: |
va009039 | 0:2b4ea8a138e5 | 11 | |
va009039 | 0:2b4ea8a138e5 | 12 | The above copyright notice and this permission notice shall be included in |
va009039 | 0:2b4ea8a138e5 | 13 | all copies or substantial portions of the Software. |
va009039 | 0:2b4ea8a138e5 | 14 | |
va009039 | 0:2b4ea8a138e5 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
va009039 | 0:2b4ea8a138e5 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
va009039 | 0:2b4ea8a138e5 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
va009039 | 0:2b4ea8a138e5 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
va009039 | 0:2b4ea8a138e5 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
va009039 | 0:2b4ea8a138e5 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
va009039 | 0:2b4ea8a138e5 | 21 | THE SOFTWARE. |
va009039 | 0:2b4ea8a138e5 | 22 | */ |
va009039 | 0:2b4ea8a138e5 | 23 | |
va009039 | 0:2b4ea8a138e5 | 24 | #ifndef WEBCAM_HANDLER_H |
va009039 | 0:2b4ea8a138e5 | 25 | #define WEBCAM_HANDLER_H |
va009039 | 0:2b4ea8a138e5 | 26 | |
va009039 | 0:2b4ea8a138e5 | 27 | #include "../HTTPRequestHandler.h" |
va009039 | 0:2b4ea8a138e5 | 28 | #include "mbed.h" |
va009039 | 0:2b4ea8a138e5 | 29 | |
va009039 | 0:2b4ea8a138e5 | 30 | struct stimage { |
va009039 | 1:7a4f2c038803 | 31 | uint8_t* buf; |
va009039 | 0:2b4ea8a138e5 | 32 | int len; |
va009039 | 0:2b4ea8a138e5 | 33 | }; |
va009039 | 0:2b4ea8a138e5 | 34 | |
va009039 | 0:2b4ea8a138e5 | 35 | class WebcamHandler : public HTTPRequestHandler |
va009039 | 0:2b4ea8a138e5 | 36 | { |
va009039 | 0:2b4ea8a138e5 | 37 | public: |
va009039 | 0:2b4ea8a138e5 | 38 | WebcamHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket); |
va009039 | 0:2b4ea8a138e5 | 39 | virtual ~WebcamHandler(){} |
va009039 | 1:7a4f2c038803 | 40 | static void setImage(uint8_t* buf, int len, int cam = 0); |
va009039 | 0:2b4ea8a138e5 | 41 | static bool busy() { return m_busy; } |
va009039 | 0:2b4ea8a138e5 | 42 | //protected: |
va009039 | 0:2b4ea8a138e5 | 43 | static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new WebcamHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one |
va009039 | 0:2b4ea8a138e5 | 44 | |
va009039 | 0:2b4ea8a138e5 | 45 | virtual void doGet(); |
va009039 | 0:2b4ea8a138e5 | 46 | virtual void doPost(){} |
va009039 | 0:2b4ea8a138e5 | 47 | virtual void doHead(){} |
va009039 | 0:2b4ea8a138e5 | 48 | |
va009039 | 0:2b4ea8a138e5 | 49 | virtual void onReadable(){} //Data has been read |
va009039 | 0:2b4ea8a138e5 | 50 | virtual void onWriteable(); //Data has been written & buf is free |
va009039 | 0:2b4ea8a138e5 | 51 | virtual void onClose(); //Connection is closing |
va009039 | 0:2b4ea8a138e5 | 52 | |
va009039 | 0:2b4ea8a138e5 | 53 | private: |
va009039 | 0:2b4ea8a138e5 | 54 | int m_pos; |
va009039 | 0:2b4ea8a138e5 | 55 | char* m_buf; |
va009039 | 0:2b4ea8a138e5 | 56 | int m_buf_len; |
va009039 | 0:2b4ea8a138e5 | 57 | static struct stimage m_image[2]; |
va009039 | 0:2b4ea8a138e5 | 58 | static bool m_busy; |
va009039 | 0:2b4ea8a138e5 | 59 | static char* m_image_buf; |
va009039 | 0:2b4ea8a138e5 | 60 | static int m_image_buf_len; |
va009039 | 0:2b4ea8a138e5 | 61 | }; |
va009039 | 0:2b4ea8a138e5 | 62 | |
va009039 | 0:2b4ea8a138e5 | 63 | #endif |