// Loop and grab mjpeg stream
while(true)
{
int retval;
retval = recv(hSocket, tempBuffer, sizeof(tempBuffer)-1, 0);
if (retval==0)
{
break; // Connection has been closed
}
elseif (retval==SOCKET_ERROR)
{
throw HRException("socket error while receiving.");
}
else
{
//***************************************************
//
// This is where we receive the incoming data stream
//
//***************************************************
// retval is number of bytes read
// Terminate buffer with zero
tempBuffer[retval] = 0;
INCOMING_STREAM=tempBuffer;
}
}
The ip camera server returns the headers followed by jpeg data between --myboundary tags like so
My question is what would be the best solution to achieve this data extraction process in c++, string function? Any coding examples help/advice would be greatly appreciated.
My question is what would be the best solution to achieve this data extraction process in c++, string function? Any coding examples help/advice would be greatly appreciated.
First, I think you may want to consider a Regular Expression libraries (someone told me Boost::RegEx) to help you extract those <<jpeg image data> using --myboundary as the boundary marker to indicate each jpeg image data.
Second, it seems to be using HTTP so for binary stream data, they maybe using Base64 encoding so you may need to find a Base64 library for decoding to get the plain raw bytes.
Third, after getting the plain raw bytes representing the jpeg image data, you may want to use a jpeg library to read/write or analyze that jpeg image. http://en.wikipedia.org/wiki/Libjpeg is one jpeg library.