Skip to content

Commit c624967

Browse files
committed
Merge pull request opencv#10007 from alalek:videoio_gst_mjpeg_fix
2 parents f9ac166 + b1b2528 commit c624967

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/videoio/src/cap_gstreamer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class CvCapture_GStreamer : public CvCapture
178178
bool isPosFramesSupported;
179179
bool isPosFramesEmulated;
180180
gint64 emulatedFrameNumber;
181+
182+
bool isOutputByteBuffer;
181183
};
182184

183185
/*!
@@ -205,6 +207,8 @@ void CvCapture_GStreamer::init()
205207
isPosFramesSupported = false;
206208
isPosFramesEmulated = false;
207209
emulatedFrameNumber = -1;
210+
211+
isOutputByteBuffer = false;
208212
}
209213

210214
/*!
@@ -357,6 +361,7 @@ IplImage * CvCapture_GStreamer::retrieveFrame(int)
357361
} else if(strcasecmp(name, "image/jpeg") == 0) {
358362
depth = 1;
359363
// the correct size will be set once the first frame arrives
364+
isOutputByteBuffer = true;
360365
}
361366
#endif
362367
if (depth > 0) {
@@ -383,7 +388,8 @@ IplImage * CvCapture_GStreamer::retrieveFrame(int)
383388
gboolean success = gst_buffer_map(buffer,&info, (GstMapFlags)GST_MAP_READ);
384389

385390
// with MJPEG streams frame size can change arbitrarily
386-
if(int(info.size) != frame->imageSize) {
391+
if (isOutputByteBuffer && (size_t)info.size != (size_t)frame->imageSize)
392+
{
387393
cvReleaseImageHeader(&frame);
388394
frame = cvCreateImageHeader(cvSize(info.size, 1), IPL_DEPTH_8U, 1);
389395
}

0 commit comments

Comments
 (0)