diff --git a/MediaImpl.cpp b/MediaImpl.cpp index e2d3dcc..1793a5a 100644 --- a/MediaImpl.cpp +++ b/MediaImpl.cpp @@ -44,12 +44,12 @@ bool MediaImpl::hasVideoSupport() int MediaImpl::getWidth() const { - return _width; + return _padHandlerData.width; } int MediaImpl::getHeight() const { - return _height; + return _padHandlerData.height; } const uchar* MediaImpl::getBits() const @@ -665,6 +665,9 @@ void MediaImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, MediaImpl:: else if (g_str_has_prefix (newPadType, "video/x-raw")) { sinkPad = gst_element_get_static_pad (data->videoToConnect, "sink"); + gst_structure_get_int(newPadStruct, "width", &data->width); + gst_structure_get_int(newPadStruct, "height", &data->height); + isAudio = false; } else diff --git a/MediaImpl.h b/MediaImpl.h index f35336f..7470bf0 100644 --- a/MediaImpl.h +++ b/MediaImpl.h @@ -55,6 +55,8 @@ public: int getHeight() const; const uchar* getBits() const; + bool isReady() const { return _padHandlerData.isConnected(); } + /// Returns true if the image has changed. bool runVideo(); // void runAudio(); @@ -90,10 +92,13 @@ public: GstElement* videoSink; bool audioIsConnected; bool videoIsConnected; + int width; + int height; GstPadHandlerData() : audioToConnect(NULL), videoToConnect(NULL), videoSink(NULL), - audioIsConnected(false), videoIsConnected(false) + audioIsConnected(false), videoIsConnected(false), + width(-1), height(-1) {} bool isConnected() const { diff --git a/Paint.cpp b/Paint.cpp index eeb7682..337e8f8 100644 --- a/Paint.cpp +++ b/Paint.cpp @@ -73,11 +73,15 @@ void Media::build() int Media::getWidth() const { + // Wait for impl to be ready. + while (!this->impl_->isReady()); return this->impl_->getWidth(); } int Media::getHeight() const { + // Wait for impl to be ready. + while (!this->impl_->isReady()); return this->impl_->getHeight(); }