Wednesday 15 February 2012

c++ - Use of QAbstractVideoSurface -



c++ - Use of QAbstractVideoSurface -

i want create app videoconferencing qt. new in this. i'd appreciate if has illustration of it.

now, trying display photographic camera image on screen using subclass of qabstractvideosurface. has thought how it?

the qabstractvideosurface interface between producer , consumer of video frames. have 2 functions implement begin with:

supportedpixelformats producer can select appropriate format qvideoframe present more generic wording show\display frame

lets want utilize classic qwidget display. in case, may take utilize qimage draw on widget.

first qt guaranteed paint qimage rgb24 (or bgr24) on platforms.

qlist<qvideoframe::pixelformat> labelbasedvideosurface::supportedpixelformats( qabstractvideobuffer::handletype handletype) const { if (handletype == qabstractvideobuffer::nohandle) { homecoming qlist<qvideoframe::pixelformat>() << qvideoframe::format_rgb24; } else { homecoming qlist<qvideoframe::pixelformat>(); } }

now nowadays qvideoframe, map info qimage, , paint qimage widget. simplicity utilize qlabel, access straight (no signal no slot).

bool labelbasedvideosurface::present(const qvideoframe &frame) { if (notmyformat(frame.pixelformat())) { seterror(incorrectformaterror); homecoming false; } else { qvideoframe frametodraw(frame); if(!frametodraw.map(qabstractvideobuffer::readonly)) { seterror(resourceerror); homecoming false; } //this shallow operation. refer frame buffer qimage image( frametodraw.bits(), frametodraw.width(), frametodraw.height(), frametodraw.bytesperline(), qimage::format_rgb444); mylabel->resize(image.size()); //qpixmap::fromimage create new buffer pixmap mylabel->setpixmap(qpixmap::fromimage(image)); //we can release info frametodraw.unmap(); mylabel->update(); homecoming true; } }

this illustration not optimal.

it doesnt take cash on fact qvideoframe might stored in video memory, because drawing using pixmap. the conversion image pixmap unnecessary hit.

you can write own widget, , implement paintevent improve performance. also, have several design liberties on how present() behave. instance :

whether non blocking surface, ie frame shown when nowadays finishes. above mean using mylabel->repaint() instead of mylabel->update() what happens when cannot finish presentation. may want draw blank frame rather returning error may stop music.

c++ qt videochat

No comments:

Post a Comment