diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 7ffaecca3..bfb283d99 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -362,7 +362,7 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr vframe) ToxYUVFrame frame = vframe->toToxYUVFrame(); - if(frame.width == 0 || frame.height == 0) + if(!frame) { return; } diff --git a/src/video/videoframe.cpp b/src/video/videoframe.cpp index 658b41225..fcacc1bb3 100644 --- a/src/video/videoframe.cpp +++ b/src/video/videoframe.cpp @@ -356,7 +356,6 @@ QImage VideoFrame::toQImage(QSize frameSize) * * @param frameSize the given frame size of ToxAVFrame to generate. Defaults to source frame size * if frameSize is invalid. - * to source frame size. * @return a ToxAVFrame structure that represents this VideoFrame, sharing it's buffers or an * empty structure if this VideoFrame is no longer valid. */ @@ -784,4 +783,24 @@ T VideoFrame::toGenericObject(const QSize& dimensions, const int pixelFormat, co template QImage VideoFrame::toGenericObject(const QSize& dimensions, const int pixelFormat, const bool requireAligned, const std::function objectConstructor, const QImage& nullObject); template ToxYUVFrame VideoFrame::toGenericObject(const QSize& dimensions, const int pixelFormat, const bool requireAligned, - const std::function objectConstructor, const ToxYUVFrame& nullObject); +const std::function objectConstructor, const ToxYUVFrame& nullObject); + +/** + * @brief Returns whether the given ToxYUVFrame represents a valid frame or not. + * + * Valid frames are frames in which both width and height are greater than zero. + * + * @return true if the frame is valid, false otherwise. + */ +bool ToxYUVFrame::isValid() const +{ + return width > 0 && height > 0; +} + +/** + * @brief Checks if the given ToxYUVFrame is valid or not, delegates to isValid(). + */ +ToxYUVFrame::operator bool() const +{ + return isValid(); +} diff --git a/src/video/videoframe.h b/src/video/videoframe.h index 4d7cb5f7b..dcf8e7dfa 100644 --- a/src/video/videoframe.h +++ b/src/video/videoframe.h @@ -39,6 +39,9 @@ extern "C"{ struct ToxYUVFrame { public: + bool isValid() const; + explicit operator bool() const; + const std::uint16_t width; const std::uint16_t height; diff --git a/src/video/videosource.h b/src/video/videosource.h index ca053ba64..66c242574 100644 --- a/src/video/videosource.h +++ b/src/video/videosource.h @@ -44,7 +44,7 @@ public: /** * @brief If subscribe sucessfully opens the source, it will start emitting frameAvailable signals. */ - virtual bool subscribe() = 0; + virtual bool subscribe() = 0; /** * @brief Stop emitting frameAvailable signals, and free associated resources if necessary. */