From 01834d4ddc5f53f7847c91fc5e954b1a94d393e6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 9 May 2021 07:35:47 -0400 Subject: [PATCH] finish converting Capture to std::shared_ptr --- src/zm_curl_camera.cpp | 14 +++++++------- src/zm_curl_camera.h | 2 +- src/zm_libvlc_camera.cpp | 8 ++++---- src/zm_libvlc_camera.h | 2 +- src/zm_libvnc_camera.cpp | 16 ++++++++-------- src/zm_libvnc_camera.h | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/zm_curl_camera.cpp b/src/zm_curl_camera.cpp index a107d78eb..4c9f7c737 100644 --- a/src/zm_curl_camera.cpp +++ b/src/zm_curl_camera.cpp @@ -165,7 +165,7 @@ int cURLCamera::PreCapture() { return( 0 ); } -int cURLCamera::Capture( ZMPacket &zm_packet ) { +int cURLCamera::Capture(std::shared_ptr &zm_packet) { bool frameComplete = false; /* MODE_STREAM specific variables */ @@ -297,27 +297,27 @@ int cURLCamera::Capture( ZMPacket &zm_packet ) { need_more_data = true; } else { /* All good. decode the image */ - zm_packet.image->DecodeJpeg(databuffer.extract(frame_content_length), frame_content_length, colours, subpixelorder); + zm_packet->image->DecodeJpeg(databuffer.extract(frame_content_length), frame_content_length, colours, subpixelorder); frameComplete = true; } } /* Attempt to get more data */ - if(need_more_data) { + if (need_more_data) { nRet = pthread_cond_wait(&data_available_cond,&shareddata_mutex); - if(nRet != 0) { + if (nRet != 0) { Error("Failed waiting for available data condition variable: %s",strerror(nRet)); return -1; } need_more_data = false; } - } else if(mode == MODE_SINGLE) { + } else if (mode == MODE_SINGLE) { /* Check if we have anything */ if (!single_offsets.empty()) { - if( (single_offsets.front() > 0) && (databuffer.size() >= single_offsets.front()) ) { + if ((single_offsets.front() > 0) && (databuffer.size() >= single_offsets.front())) { /* Extract frame */ - zm_packet.image->DecodeJpeg(databuffer.extract(single_offsets.front()), single_offsets.front(), colours, subpixelorder); + zm_packet->image->DecodeJpeg(databuffer.extract(single_offsets.front()), single_offsets.front(), colours, subpixelorder); single_offsets.pop_front(); frameComplete = true; } else { diff --git a/src/zm_curl_camera.h b/src/zm_curl_camera.h index bd2266d5f..302d8f877 100644 --- a/src/zm_curl_camera.h +++ b/src/zm_curl_camera.h @@ -88,7 +88,7 @@ public: int PrimeCapture() override; int PreCapture() override; - int Capture(ZMPacket &p)override; + int Capture(std::shared_ptr &p)override; int PostCapture()override ; size_t data_callback(void *buffer, size_t size, size_t nmemb, void *userdata); diff --git a/src/zm_libvlc_camera.cpp b/src/zm_libvlc_camera.cpp index 59cdc4ccf..beda38498 100644 --- a/src/zm_libvlc_camera.cpp +++ b/src/zm_libvlc_camera.cpp @@ -276,7 +276,7 @@ int LibvlcCamera::PreCapture() { } // Should not return -1 as cancels capture. Always wait for image if available. -int LibvlcCamera::Capture( ZMPacket &zm_packet ) { +int LibvlcCamera::Capture(std::shared_ptr &zm_packet) { // newImage is a mutex/condition based flag to tell us when there is an image available { std::unique_lock lck(mLibvlcData.newImageMutex); @@ -288,9 +288,9 @@ int LibvlcCamera::Capture( ZMPacket &zm_packet ) { return 0; mLibvlcData.mutex.lock(); - zm_packet.image->Assign(width, height, colours, subpixelorder, mLibvlcData.buffer, width * height * mBpp); - zm_packet.packet.stream_index = mVideoStreamId; - zm_packet.stream = mVideoStream; + zm_packet->image->Assign(width, height, colours, subpixelorder, mLibvlcData.buffer, width * height * mBpp); + zm_packet->packet.stream_index = mVideoStreamId; + zm_packet->stream = mVideoStream; mLibvlcData.mutex.unlock(); return 1; diff --git a/src/zm_libvlc_camera.h b/src/zm_libvlc_camera.h index 7d9be27c1..c516a63e0 100644 --- a/src/zm_libvlc_camera.h +++ b/src/zm_libvlc_camera.h @@ -72,7 +72,7 @@ public: int PrimeCapture() override; int PreCapture() override; - int Capture(ZMPacket &p) override; + int Capture(std::shared_ptr &p) override; int PostCapture() override; int Close() override { return 0; }; }; diff --git a/src/zm_libvnc_camera.cpp b/src/zm_libvnc_camera.cpp index faa594a7e..6fb414686 100644 --- a/src/zm_libvnc_camera.cpp +++ b/src/zm_libvnc_camera.cpp @@ -208,21 +208,21 @@ int VncCamera::PreCapture() { return res == TRUE ? 1 : -1; } -int VncCamera::Capture(ZMPacket &zm_packet) { +int VncCamera::Capture(std::shared_ptr &zm_packet) { if (!mVncData.buffer) { Debug(1, "No buffer"); return 0; } - if (!zm_packet.image) { + if (!zm_packet->image) { Debug(1, "Allocating image %dx%d %dcolours = %d", width, height, colours, colours*pixels); - zm_packet.image = new Image(width, height, colours, subpixelorder); + 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->keyframe = 1; + zm_packet->codec_type = AVMEDIA_TYPE_VIDEO; + zm_packet->packet.stream_index = mVideoStreamId; + zm_packet->stream = mVideoStream; - uint8_t *directbuffer = zm_packet.image->WriteBuffer(width, height, colours, subpixelorder); + uint8_t *directbuffer = zm_packet->image->WriteBuffer(width, height, colours, subpixelorder); Debug(1, "scale src %p, %d, dest %p %d %d %dx%d %dx%d", mVncData.buffer, mRfb->si.framebufferWidth * mRfb->si.framebufferHeight * 4, directbuffer, diff --git a/src/zm_libvnc_camera.h b/src/zm_libvnc_camera.h index caa1bb1da..20cad4f4b 100644 --- a/src/zm_libvnc_camera.h +++ b/src/zm_libvnc_camera.h @@ -53,7 +53,7 @@ public: int PreCapture() override; int PrimeCapture() override; - int Capture(ZMPacket &packet) override; + int Capture(std::shared_ptr &packet) override; int PostCapture() override; int Close() override; };