From c5ca59ed8d7d94229f3e47dd0afdb842e6d4a925 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sun, 27 Jul 2014 20:14:14 +0200 Subject: [PATCH] Commit towards hardware accelarated jpegs, does not work, crashes and freezes, use only for bug hunting --- GNUmakefile | 4 ++-- defines.h | 2 ++ osdopenvg.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ osdopenvg.h | 14 ++++++++++++-- osdvector.cc | 19 +++++++++++++++++++ osdvector.h | 8 ++++++++ videoomx.h | 1 + 7 files changed, 97 insertions(+), 4 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 435d644..d0c518e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -63,7 +63,7 @@ $(info Raspberry pi flags) LDFLAGS = -Wall -Wl,--format=binary -Wl,other/vdrhires.jpg -Wl,other/wallpaper720p.jpg -Wl,--format=default LIBS = -L/opt/vc/lib -lpthread -lrt -lEGL -lOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o wjpegsimple.o remotelinux.o +OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o imageomx.o wjpegsimple.o remotelinux.o LIBS+= -lfreetype -lMagick++ CROSSLIBS = INCLUDES = -DVOMP_PLATTFORM_RASPBERRY -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/usr/include/freetype2 -I/usr/include/ImageMagick @@ -77,7 +77,7 @@ $(info Raspberry pi flags cross compiler) LDFLAGS = -Wall -Wl,--format=binary -Wl,other/vdrhires.jpg -Wl,other/wallpaper720p.jpg -Wl,--format=default -Wl,--verbose -Xlinker --rpath-link=rpi-root/usr/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/lib/arm-linux-gnueabihf -Xlinker --rpath-link=rpi-root/opt/vc/lib LIBS = -Lrpi-root/opt/vc/lib -Lrpi-root/lib -Lrpi-root/usr/lib -Lrpi-root/lib/arm-linux-gnueabihf -Lrpi-root/usr/lib/arm-linux-gnueabihf -Lrpi-root/usr/local/lib -lpthread -lrt -lEGL -lOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -ldl -lfontconfig -OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o wjpegsimple.o remotelinux.o +OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o imageomx.o wjpegsimple.o remotelinux.o LIBS+= -lfreetype -lMagick++ CROSSLIBS = INCLUDES = -DVOMP_PLATTFORM_RASPBERRY -Irpi-root/opt/vc/include -Irpi-root/opt/vc/include/interface/vcos/pthreads -Irpi-root/usr/include -Irpi-root/usr/include/freetype2 -Irpi-root/usr/include/ImageMagick diff --git a/defines.h b/defines.h index 8b62f5d..14d0e4c 100644 --- a/defines.h +++ b/defines.h @@ -111,6 +111,8 @@ long long getTimeMS(); #define VPE_OMX_CLOCK "OMX.broadcom.clock" #define VPE_OMX_AUDIO_DECODER "OMX.broadcom.audio_decode" #define VPE_OMX_AUDIO_REND "OMX.broadcom.audio_render" + #define VPE_OMX_IMAGE_DECODER "OMX.broadcom.image_decode" + #define VPE_OMX_EGL_REND "OMX.broadcom.egl_render" //#define VPE_LIBAV_SUPPORT // #define VPE_LIBAV_MPEG2_TRANSCODING diff --git a/osdopenvg.cc b/osdopenvg.cc index 12a0e6d..ece11cd 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -301,6 +301,11 @@ int OsdOpenVG::init(void* device) taskmutex.Unlock(); vgmutex.Unlock(); +#ifdef PICTURE_DECODER_OMX + imageomx=new ImageOMX(&reader); + reader.addDecoder(imageomx); +#endif + return 1; } @@ -397,6 +402,11 @@ void OsdOpenVG::purgeAllReferences() int OsdOpenVG::shutdown() { reader.shutdown(); +#ifdef PICTURE_DECODER_OMX + if (imageomx) reader.removeDecoder(imageomx); + imageomx=NULL; +#endif + if (!initted) return 0; initted = 0; @@ -1107,6 +1117,35 @@ unsigned int OsdOpenVG::handleTask(OpenVGCommand& command) delete info; } break; + case OVGcreateEGLImage: { + PictureInfo *info = (PictureInfo*) command.data; + VGImage handle; + //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateImageMemory"); + handle=vgCreateImage(VG_sXBGR_8888,info->width,info->height,VG_IMAGE_QUALITY_BETTER); + + info->handle = handle; + info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, (EGLClientBuffer)handle, NULL); + if (info->reference) return true; + else return false; + + } break; + + case OVGreadyEGLImage: { + PictureInfo *info = (PictureInfo*) command.data; + eglDestroyImageKHR(egl_display,info->reference); + + Message* m = new Message(); + m->message=Message::NEW_PICTURE; + m->from=this; + m->to=Command::getInstance(); + m->parameter = info->handle; + m->tag = info->lindex; + Command::getInstance()->postMessageFromOuterSpace(m); // inform command about new picture + + delete info; + } break; + + case OVGcreateColorRef :{ VGPaint handle; @@ -1323,6 +1362,10 @@ void OsdOpenVG::createPicture(struct PictureInfo& pict_inf) comm.task = OVGcreateImageMemory; comm.data = new PictureInfo(pict_inf); putOpenVGCommand(comm,false); + } else if (pict_inf.type == PictureInfo::EGLImage) { + comm.task = OVGreadyEGLImage; + comm.data = new PictureInfo(pict_inf); + putOpenVGCommand(comm,false); } else { // unsupported pict_inf.decoder->freeReference(pict_inf.reference); @@ -1331,6 +1374,16 @@ void OsdOpenVG::createPicture(struct PictureInfo& pict_inf) } } +bool OsdOpenVG::getEGLPicture(struct OsdVector::PictureInfo & info , EGLDisplay * display) +{ + struct OpenVGCommand comm; + info.type = PictureInfo::EGLImage; + comm.task = OVGcreateEGLImage; + comm.data = &info; + *display = egl_display; + return putOpenVGCommand(comm,true); +} + ImageIndex OsdOpenVG::createMonoBitmap(void *base,int width,int height) diff --git a/osdopenvg.h b/osdopenvg.h index afcaebc..ff657f3 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -37,6 +37,9 @@ #include "threadp.h" #include "mutex.h" #include "videoomx.h" +#ifdef PICTURE_DECODER_OMX +#include "imageomx.h" +#endif #include @@ -52,7 +55,9 @@ enum OpenVGTask { OVGimageUploadLine, OVGcreateImageFile, OVGreplacefont, - OVGcreateImageMemory + OVGcreateImageMemory, + OVGcreateEGLImage, + OVGreadyEGLImage }; struct OpenVGCommand @@ -70,7 +75,7 @@ struct OpenVGResponse{ }; -class OsdOpenVG : public OsdVector, public Thread_TYPE +class OsdOpenVG : public OsdVector, public Thread_TYPE, public EGLPictureCreator { public: OsdOpenVG(); @@ -93,6 +98,8 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE virtual float getPixelAspect() {return aspect_correction;}; + bool getEGLPicture(struct OsdVector::PictureInfo & info, EGLDisplay * display); + protected: @@ -175,6 +182,9 @@ protected: float aspect_correction; bool freetype_inited; +#ifdef PICTURE_DECODER_OMX + ImageOMX *imageomx; +#endif }; diff --git a/osdvector.cc b/osdvector.cc index 1b1bd76..bacb245 100644 --- a/osdvector.cc +++ b/osdvector.cc @@ -647,10 +647,29 @@ void OsdVector::PictureReader::shutdown() void OsdVector::PictureReader::addDecoder(PictureDecoder* decoder) { decoders_lock.Lock(); + decoder->init(); decoders.push_front(decoder); decoders_lock.Unlock(); } +void OsdVector::PictureReader::removeDecoder(PictureDecoder* decoder) +{ + decoders_lock.Lock(); + std::list::iterator itty=decoders.begin(); + while (itty!=decoders.end()) { + if ((*itty) == decoder) + { + decoders.erase(itty); + break; + } + itty++; + } + Log::getInstance()->log("OsdVector", Log::DEBUG, "removeDecoder"); + decoder->shutdown(); + delete decoder; + decoders_lock.Unlock(); +} + void OsdVector::PictureReader::threadMethod() { OsdVector *osdvector = dynamic_cast(Osd::getInstance()); diff --git a/osdvector.h b/osdvector.h index 57d449b..a91d63c 100644 --- a/osdvector.h +++ b/osdvector.h @@ -258,7 +258,10 @@ class OsdVector : public Osd ULONG width; ULONG height; LoadIndex lindex; + union { const void * image; + unsigned int handle; + }; void *reference; PictureDecoder* decoder; }; @@ -270,6 +273,7 @@ class OsdVector : public Osd { public: PictureDecoder(PictureReader * treader) {reader=treader;}; + virtual ~PictureDecoder() {}; // its is always guaranted, that after getDecodedPicture a call to decodePicture follows, if the return value was true; virtual bool decodePicture(LoadIndex index, unsigned char * buffer, unsigned int length)=0; @@ -277,6 +281,9 @@ class OsdVector : public Osd virtual bool getDecodedPicture(struct PictureInfo& pict_inf)=0; virtual void freeReference(void * ref)=0; + virtual void init() {}; + virtual void shutdown() {}; + protected: PictureReader * reader; }; @@ -288,6 +295,7 @@ class OsdVector : public Osd void init(); void addDecoder(PictureDecoder*); + void removeDecoder(PictureDecoder*); void shutdown(); diff --git a/videoomx.h b/videoomx.h index 66a901c..6791430 100644 --- a/videoomx.h +++ b/videoomx.h @@ -65,6 +65,7 @@ class AudioVPE; class VideoOMX : public Video { friend class AudioOMX; + friend class ImageOMX; public: VideoOMX(); virtual ~VideoOMX(); -- 2.39.2