UVCClass Class
UVCClass Class
Description
A class used for using USB webcams (USB Video Class) with Ameba.
Syntax
class UVCClass
Members
Public Constructors | |
The public constructor should not be used as this class is intended to be a singleton class. Access member functions using the object instance named UVC. |
Public Methods | |
UVCClass::begin | Initialize and start UVC |
UVCClass::end | Deinitialize and stop UVC |
UVCClass::avaliable | Check if UVC is ready |
UVCClass::status | Check if UVC is currently streaming |
UVCClass::turnOn | Enable streaming |
UVCClass::turnOff | Disable streaming |
UVCClass::getJPEG | Get a JPEG image |
UVCClass::begin
Description
Initialize and start UVC.
Syntax
void begin(int frame_type, int width, int height, int frame_rate, int compression_ratio, int app_type);
void begin(void);
Parameters
frame_type: UVC_MJPEG or UVC_H264
width: frame width
height: frame height
frame_rate: video stream frame rate
compression_ratio: video compression ratio
app_type: RTSP_STREAMING or JPEG_CAPTURE
Returns
The function returns nothing.
Example Code
Example: uvc_jpeg_capture
/* * This sketch shows how to take jpeg capture from UVC and send out to the remote server * * You need to fill in remote server's address and port. * Ex. If the remote server is a Linux system, then you can use Netcat tool to capture the jpeg file: * NC -l 5001 > my_jpeg_file.jpeg * */ #include "WiFi.h" #include "UVC.h" char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "password"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status unsigned char jpegbuf[40 * 1024]; WiFiClient client; char serverIP[] = "192.168.1.65"; // The remote server IP to receive jpeg file int serverPort = 5001; // the remote server port int chunkSize = 1460; // If MTU=1500, then data payload = 1500 - IPv4 header(20) - TCP header(20) = 1460 void setup() { // attempt to connect to Wifi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, pass); if (status == WL_CONNECTED) { break; } // wait 1 seconds for retry delay(1000); } Serial.print("You're connected to the network"); UVC.begin(UVC_MJPEG, 640, 480, 30, 0, JPEG_CAPTURE); // wait until UVC is ready for streaming while (!UVC.available()) { delay(100); } delay(1000); Serial.println("UVC is ready"); } void loop() { int i; int len = UVC.getJPEG(jpegbuf); if (len > 0) { if (client.connect(serverIP, serverPort)) { for (i = 0; i < len; i += chunkSize) { if (i+chunkSize <= len) { client.write(jpegbuf+i, chunkSize); } else { client.write(jpegbuf+i, len - i); } } client.stop(); Serial.println("Send out file"); } else { Serial.println("Fail to connect"); } } else { Serial.println("Fail to get jpeg"); } delay(1000); }
Notes and Warnings
Calling this function with no parameters uses the defaults of (UVC_MJPEG, 320, 240, 30, 0, RTSP_STREAMING).
UVCClass::end
Description
Deinitialize and stop UVC.
Syntax
void end(void);
Parameters
The function requires no input parameter.
Returns
The function returns nothing.
Example Code
NA
Notes and Warnings
NA
UVCClass::avaliable
Description
Check if UVC is ready.
Syntax
int avaliable(void);
Parameters
The function requires no input parameter.
Returns
True: if UVC is ready
Example Code
Example: uvc_basic
/* This sketch demonstrate how to streaming video of usb camera. Ameba receive video data from usb port and streaming out on wifi with rtsp protocol. User can receive ths streaming data on PC or laptop with rtsp player. In this sketch you need: Ameba x 1 usb camera x 1 OTG wire x 1 (with extra power line on OTG if needed) At first Ameba connect to AP. Then Ameba open UVC service. After UVC service is enabled, user can use rtsp player and open streaming with address: rtsp://192.168.1.123/test.sdp (NOTE: the IP address depends on Ameba's IP") */ #include "WiFi.h" #include "UVC.h" char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { // attempt to connect to Wifi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, pass); if (status == WL_CONNECTED) { break; } // wait 10 seconds for connection: delay(10000); } Serial.print("You're connected to the network"); // Default setting is motion jpeg with 320x240 resolution and frame rate is 30fps UVC.begin(); // Try below setting if you want better resolution //UVC.begin(UVC_MJPEG, 640, 480, 30, 0); // wait until UVC is ready for streaming while (!UVC.available()) { delay(100); } Serial.println("UVC is ready"); Serial.println("Open your rtsp player with this address:"); Serial.print("\trtsp://"); Serial.print(WiFi.localIP()); Serial.println("/test.sdp"); } void loop() { delay(10000); }
Notes and Warnings
NA
UVCClass::status
Description
Check if UVC is currently streaming.
Syntax
int status(void);
Parameters
The function requires no input parameter.
Returns
True if UVC is streaming.
Example Code
NA
Notes and Warnings
NA
UVCClass::turnOn
Description
Enable UVC streaming.
Syntax
int turnOn(void);
Parameters
The function requires no input parameter.
Returns
0 if success
Example Code
NA
Notes and Warnings
NA
UVCClass::turnOff
Description
Disable UVC streaming.
Syntax
void turnOff(void);
Parameters
The function requires no input parameter.
Returns
The function returns nothing.
Example Code
NA
Notes and Warnings
NA
UVCClass::getJPEG
Description
Get a JPEG image.
Syntax
int getJPEG(unsigned char* buf);
Parameters
buf: pointer to buffer to store the image
Returns
The function returns the JPEG size.
Example Code
Example: uvc_jpeg_capture
Details of the code can be found in the previous section of UVCClass::begin.
Notes and Warnings
NA