Fix curl cameras. PrimeCapture and PreCapture and PostCapture need to return 1. Also need to populate the packet and video stream.

This commit is contained in:
Isaac Connor 2021-10-07 12:35:56 -04:00
parent 505f3d1b32
commit 2dfbc013cb
1 changed files with 131 additions and 95 deletions

View File

@ -73,11 +73,28 @@ void bind_libcurl_symbols() {
*(void**) (&curl_easy_cleanup_f) = dlsym(curl_lib, "curl_easy_cleanup");
}
cURLCamera::cURLCamera( const Monitor* monitor, const std::string &p_path, const std::string &p_user, const std::string &p_pass, unsigned int p_width, unsigned int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio ) :
cURLCamera::cURLCamera(
const Monitor* monitor,
const std::string &p_path,
const std::string &p_user,
const std::string &p_pass,
unsigned int p_width,
unsigned int p_height,
int p_colours,
int p_brightness,
int p_contrast,
int p_hue,
int p_colour,
bool p_capture,
bool p_record_audio) :
Camera(monitor, CURL_SRC, p_width, p_height, p_colours, ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours), p_brightness, p_contrast, p_hue, p_colour, p_capture, p_record_audio),
mPath( p_path ), mUser( p_user ), mPass ( p_pass ), bTerminate( false ), bReset( false ), mode ( MODE_UNSET )
mPath(p_path),
mUser(p_user),
mPass(p_pass),
bTerminate(false),
bReset(false),
mode(MODE_UNSET)
{
if (capture) {
Initialise();
}
@ -85,7 +102,6 @@ cURLCamera::cURLCamera( const Monitor* monitor, const std::string &p_path, const
cURLCamera::~cURLCamera() {
if (capture) {
Terminate();
}
}
@ -156,13 +172,14 @@ void cURLCamera::Terminate() {
}
int cURLCamera::PrimeCapture() {
getVideoStream();
//Info( "Priming capture from %s", mPath.c_str() );
return 0;
return 1;
}
int cURLCamera::PreCapture() {
// Nothing to do here
return( 0 );
return 1;
}
int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
@ -179,7 +196,6 @@ int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
lock();
while (!frameComplete) {
/* If the work thread did a reset, reset our local variables */
if (bReset) {
SubHeadersParsingComplete = false;
@ -244,7 +260,11 @@ int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
}
/* Check if the crlf is \n\n or \r\n\r\n (marks end of headers, this is the last header) */
if( (crlf_size == 2 && memcmp(((const char*)databuffer.head())+crlf_start,"\n\n",2) == 0) || (crlf_size == 4 && memcmp(((const char*)databuffer.head())+crlf_start,"\r\n\r\n",4) == 0) ) {
if (
(crlf_size == 2 && memcmp(((const char*)databuffer.head())+crlf_start,"\n\n",2) == 0)
||
(crlf_size == 4 && memcmp(((const char*)databuffer.head())+crlf_start,"\r\n\r\n",4) == 0)
) {
/* This is the last header */
SubHeadersParsingComplete = true;
}
@ -297,6 +317,14 @@ int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
need_more_data = true;
} else {
/* All good. decode the image */
if (!zm_packet->image) {
Debug(4, "Allocating image");
zm_packet->image = new Image(width, height, colours, subpixelorder);
}
zm_packet->keyframe = 1;
zm_packet->codec_type = AVMEDIA_TYPE_VIDEO;
zm_packet->packet.stream_index = mVideoStreamId;
zm_packet->stream = mVideoStream;
zm_packet->image->DecodeJpeg(databuffer.extract(frame_content_length), frame_content_length, colours, subpixelorder);
frameComplete = true;
}
@ -317,6 +345,14 @@ int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
if (!single_offsets.empty()) {
if ((single_offsets.front() > 0) && (databuffer.size() >= single_offsets.front())) {
/* Extract frame */
if (!zm_packet->image) {
Debug(4, "Allocating image");
zm_packet->image = new Image(width, height, colours, subpixelorder);
}
zm_packet->keyframe = 1;
zm_packet->codec_type = AVMEDIA_TYPE_VIDEO;
zm_packet->packet.stream_index = mVideoStreamId;
zm_packet->stream = mVideoStream;
zm_packet->image->DecodeJpeg(databuffer.extract(single_offsets.front()), single_offsets.front(), colours, subpixelorder);
single_offsets.pop_front();
frameComplete = true;
@ -353,7 +389,7 @@ int cURLCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
int cURLCamera::PostCapture() {
// Nothing to do here
return( 0 );
return 1;
}
size_t cURLCamera::data_callback(void *buffer, size_t size, size_t nmemb, void *userdata) {