2 Copyright 2004-2005 Chris Tallon, 2009 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "videovpeogl.h"
23 #include "mtdraspberry.h"
25 #include "osdopengl.h"
30 //A lot of parts of this file are heavily inspired by xbmc omx implementations
32 VideoVPEOGL::VideoVPEOGL()
40 cur_input_buf_omx=NULL;
44 VideoVPEOGL::~VideoVPEOGL()
49 int VideoVPEOGL::init(UCHAR tformat)
51 if (initted) return 0;
54 // if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
56 if (!setFormat(tformat)) { shutdown(); return 0; }
57 if (!setConnection(COMPOSITERGB)) { shutdown(); return 0; }
58 if (!setAspectRatio(ASPECT4X3)) { shutdown(); return 0; }
59 if (!setMode(NORMAL)) { shutdown(); return 0; }
60 if (!setSource()) { shutdown(); return 0; }
61 if (!attachFrameBuffer()) { shutdown(); return 0; }
65 /* if (format == PAL) setLetterboxBorder("38");
66 else setLetterboxBorder("31");*/
77 int VideoVPEOGL::initUsingOSDObjects()
79 EGLDisplay i_egl_display;
80 EGLSurface i_egl_surface;
81 EGLContext i_egl_context;
82 OsdOpenGL *osd=(OsdOpenGL*)osd->getInstance();
83 osd->getEGLObjs(&i_egl_display,&i_egl_surface,&i_egl_context);
85 egl_display=i_egl_display;
86 egl_surface=i_egl_surface;
87 egl_context=i_egl_context;
90 #ifdef VPE_OMX_SUPPORT
91 // we are called before the audio
94 if (error!=OMX_ErrorNone) {
95 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX failed %x", error);
99 //our callbacks move to play?
109 #ifdef VPE_OMX_SUPPORT
111 OMX_ERRORTYPE VideoVPEOGL::EventHandler_OMX(OMX_IN OMX_HANDLETYPE handle,OMX_IN OMX_PTR appdata,
112 OMX_IN OMX_EVENTTYPE event_type,OMX_IN OMX_U32 data1,
113 OMX_IN OMX_U32 data2,OMX_IN OMX_PTR event_data) {
115 Log::getInstance()->log("Video", Log::NOTICE, "eventHandler %x %x %x %x %x",handle,event_type,data1,data2,event_data);
117 /* switch (event_type) {
118 case OMX_EventCmdComplete: {
123 return OMX_ErrorNone;
127 OMX_ERRORTYPE VideoVPEOGL::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){
129 Log::getInstance()->log("Video", Log::NOTICE, "EmptyBufferDone");
130 return OMX_ErrorNone;
134 OMX_ERRORTYPE VideoVPEOGL::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
135 Log::getInstance()->log("Video", Log::NOTICE, "FillBufferDone");
136 return OMX_ErrorNone;
141 int VideoVPEOGL::shutdown()
143 if (!initted) return 0;
146 #ifdef VPE_OMX_SUPPORT
147 DeAllocateCodecsOMX();
150 eglDestroyContext(egl_display,egl_context);
158 int VideoVPEOGL::setTVsize(UCHAR ttvsize)
162 // Override the aspect ratio usage, temporarily use to set the video chip mode
163 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
165 if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
166 if (!setSource()) { shutdown(); return 0; }
167 if (!attachFrameBuffer()) { shutdown(); return 0; }
169 // Reopening the fd causes the scart aspect line to go back to 4:3
170 // Set this again to the same as the tv screen size
171 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
173 // mode == LETTERBOX is invalid if the TV is widescreen
174 if (tvsize == ASPECT16X9) setMode(NORMAL);
179 int VideoVPEOGL::setDefaultAspect()
181 return setAspectRatio(tvsize);
186 int VideoVPEOGL::setFormat(UCHAR tformat)
188 if (!initted) return 0;
189 if ((tformat != PAL) && (tformat != NTSC)) return 0;
192 // if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
208 int VideoVPEOGL::setConnection(UCHAR tconnection)
210 if (!initted) return 0;
211 if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
212 connection = tconnection;
214 // if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
218 int VideoVPEOGL::setAspectRatio(UCHAR taspectRatio)
220 if (!initted) return 0;
221 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
222 aspectRatio = taspectRatio;
224 Log::getInstance()->log("Video", Log::DEBUG, "Setting aspect to %i", aspectRatio);
226 // if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
230 int VideoVPEOGL::setMode(UCHAR tmode)
232 if (!initted) return 0;
234 if ((tmode == LETTERBOX) && (tvsize == ASPECT16X9)) return 0; // invalid mode
236 if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
237 && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
240 // if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
244 int VideoVPEOGL::signalOff()
246 // if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
250 int VideoVPEOGL::signalOn()
252 // if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
256 int VideoVPEOGL::setSource()
258 if (!initted) return 0;
260 // What does this do...
261 // if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
265 int VideoVPEOGL::setPosition(int x, int y)
267 if (!initted) return 0;
269 // vid_pos_regs_t pos_d;
273 /* vid_pos_regs_t pos_d;
275 memset(&pos_d, 0, sizeof(pos_d));
300 pos_d.y = 100; // Top left X
301 pos_d.x = 50; // Top left Y
309 // if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
313 int VideoVPEOGL::sync()
315 if (!initted) return 0;
317 // if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
324 int VideoVPEOGL::play()
326 if (!initted) return 0;
327 #ifdef VPE_OMX_SUPPORT
328 if (AllocateCodecsOMX()) {
331 // Otherwise fall back to ffmpeg
335 // if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
339 #ifdef VPE_OMX_SUPPORT
340 int VideoVPEOGL::AllocateCodecsOMX()
343 static OMX_CALLBACKTYPE callbacks= {&EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
345 Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX");
346 //Clock, move later to audio
348 error=OMX_GetHandle(&omx_clock,VPE_OMX_CLOCK,NULL,&callbacks);
351 if (error!=OMX_ErrorNone){
352 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX clock failed %x", error);
353 DeAllocateCodecsOMX();
359 OMX_PORT_PARAM_TYPE p_param;
360 p_param.nSize=sizeof(p_param);
361 p_param.nVersion.nVersion=OMX_VERSION;
362 error=OMX_GetParameter(omx_clock,OMX_IndexParamOtherInit,&p_param);
363 if (error!=OMX_ErrorNone){
364 Log::getInstance()->log("Video", Log::DEBUG, "Init clock OMX_GetParameter failed %x", error);
365 DeAllocateCodecsOMX();
368 omx_clock_output_port=p_param.nStartPortNumber+1;
371 OMX_TIME_CONFIG_CLOCKSTATETYPE clock_conf;
372 clock_conf.nSize=sizeof(clock_conf);
373 clock_conf.nVersion.nVersion=OMX_VERSION;
374 clock_conf.eState=OMX_TIME_ClockStateWaitingForStartTime;
375 clock_conf.nStartTime=0;
376 clock_conf.nOffset=0;
377 clock_conf.nWaitMask=OMX_CLOCKPORT0;
378 error=OMX_SetParameter(omx_clock,OMX_IndexConfigTimeClockState,&clock_conf);
379 if (error!=OMX_ErrorNone){
380 Log::getInstance()->log("Video", Log::DEBUG, "Clock IndexConfigTimeClockState failed %x", error);
386 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_H264_DECODER,NULL,&callbacks);
388 error=OMX_GetHandle(&omx_vid_dec,VPE_OMX_MPEG2_DECODER,NULL,&callbacks);
391 if (error!=OMX_ErrorNone){
392 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video decoder failed %x", error);
393 DeAllocateCodecsOMX();
397 p_param.nSize=sizeof(p_param);
398 p_param.nVersion.nVersion=OMX_VERSION;
399 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoInit,&p_param);
400 if (error!=OMX_ErrorNone){
401 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_GetParameter failed %x", error);
402 DeAllocateCodecsOMX();
405 omx_codec_input_port=p_param.nStartPortNumber;
406 omx_codec_output_port=p_param.nStartPortNumber+1;
409 error=OMX_GetHandle(&omx_vid_sched,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
410 if (error!=OMX_ErrorNone){
411 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler failed %x", error);
412 DeAllocateCodecsOMX();
418 error=OMX_GetParameter(omx_vid_sched,OMX_IndexParamVideoInit,&p_param);
419 if (error!=OMX_ErrorNone){
420 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video scheduler OMX_GetParameter failed %x", error);
421 DeAllocateCodecsOMX();
424 omx_shed_input_port=p_param.nStartPortNumber;
425 omx_shed_output_port=p_param.nStartPortNumber+1;
426 omx_shed_clock_port=p_param.nStartPortNumber+2;
429 error=OMX_GetHandle(&omx_vid_rend,VPE_OMX_VIDEO_SCHED,NULL,&callbacks);
430 if (error!=OMX_ErrorNone){
431 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend failed %x", error);
432 DeAllocateCodecsOMX();
436 error=OMX_GetParameter(omx_vid_rend,OMX_IndexParamVideoInit,&p_param);
437 if (error!=OMX_ErrorNone){
438 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX video rend OMX_GetParameter failed %x", error);
439 DeAllocateCodecsOMX();
442 omx_rend_input_port=p_param.nStartPortNumber;
443 omx_rend_output_port=p_param.nStartPortNumber+1;
447 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,omx_vid_sched,omx_shed_clock_port);
448 if (error!=OMX_ErrorNone){
449 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel clock to sched failed %x %d %d", error,omx_clock_output_port,omx_shed_clock_port);
450 DeAllocateCodecsOMX();
455 error=OMX_SendCommand(omx_clock,OMX_CommandStateSet,OMX_StateExecuting,0);
456 if (error!=OMX_ErrorNone){
457 Log::getInstance()->log("Video", Log::DEBUG, "clock Send Command to OMX State Executing %x", error);
474 OMX_VIDEO_PARAM_PORTFORMATTYPE ft_type;
475 ft_type.nSize=sizeof(ft_type);
476 ft_type.nVersion.nVersion=OMX_VERSION;
478 ft_type.nPortIndex=omx_codec_input_port;
480 ft_type.eCompressionFormat=OMX_VIDEO_CodingAVC;
482 ft_type.eCompressionFormat=OMX_VIDEO_CodingMPEG2;
486 error=OMX_SendCommand(omx_vid_dec,OMX_CommandStateSet,OMX_StateIdle,0);
487 if (error!=OMX_ErrorNone){
488 Log::getInstance()->log("Video", Log::DEBUG, "vid_dec Send Command to OMX State Idle %x", error);
492 Demuxer* demux=Demuxer::getInstance();
494 ft_type.xFramerate=demux->getFrameRate()*(1<<16);
495 error=OMX_SetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
496 if (error!=OMX_ErrorNone){
497 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX_IndexParamVideoPortFormat failed %x", error);
501 OMX_NALSTREAMFORMATTYPE nalu_type;
502 nalu_type.nSize=sizeof(nalu_type);
503 nalu_type.nVersion.nVersion=OMX_VERSION;
504 nalu_type.nPortIndex=omx_input_port;
506 error=OMX_GetParameter(omx_vid_dec,(OMX_INDEXTYPE)OMX_IndexParamNalStreamFormatSupported, &nalu_type);
508 if (error!=OMX_ErrorNone) {
509 Log::getInstance()->log("Video", Log::DEBUG, "Getting Nalutypes failed %x", error);
511 Log::getInstance()->log("Video", Log::DEBUG, "Nalutypes %x", nalu_type.eNaluFormat);
512 omx_nalu_format=nalu_type.eNaluFormat;
517 if (!PrepareInputBufsOMX()) {
522 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,omx_vid_sched,omx_shed_input_port);
523 if (error!=OMX_ErrorNone){
524 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel dec to sched failed %x", error);
525 DeAllocateCodecsOMX();
531 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,omx_vid_rend,omx_rend_input_port);
532 if (error!=OMX_ErrorNone){
533 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel sched to rend failed %x", error);
534 DeAllocateCodecsOMX();
544 error=OMX_SendCommand(omx_vid_sched,OMX_CommandStateSet,OMX_StateIdle,0);
545 if (error!=OMX_ErrorNone){
546 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend Send Command to OMX State Idle %x", error);
550 error=OMX_SendCommand(omx_vid_rend,OMX_CommandStateSet,OMX_StateIdle,0);
551 if (error!=OMX_ErrorNone){
552 Log::getInstance()->log("Video", Log::DEBUG, "vid_rend Send Command to OMX State Idle %x", error);
559 /* Code for querying supported formats well it says everything is supported ?
562 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamVideoPortFormat,&ft_type);
563 if (error!=OMX_ErrorNone && error != OMX_ErrorNoMore) {
564 Log::getInstance()->log("Video", Log::DEBUG, "Init OMX h264 decoder OMX_SetParameter failed %x", error);
567 Log::getInstance()->log("Video", Log::DEBUG, "OMX format found %x", ft_type.eCompressionFormat);
571 }while (error==OMX_ErrorNone);*/
579 int getHorizontalSize() { return horizontal_size; }
580 int getVerticalSize() { return vertical_size; }
581 int getAspectRatio() { return aspect_ratio; }
582 int getFrameRate() { return frame_rate; }
602 int VideoVPEOGL::PrepareInputBufsOMX()
605 OMX_PARAM_PORTDEFINITIONTYPE port_def_type;
606 port_def_type.nSize=sizeof(port_def_type);
607 port_def_type.nVersion.nVersion=OMX_VERSION;
608 port_def_type.nPortIndex=omx_codec_input_port;
610 error=OMX_GetParameter(omx_vid_dec,OMX_IndexParamPortDefinition, &port_def_type);
612 if (error!=OMX_ErrorNone){
613 Log::getInstance()->log("Video", Log::DEBUG, "Get OMX OMX_IndexParamPortDefinition failed %x", error);
615 input_bufs_omx_mutex.Lock();
616 for (unsigned int i=0; i< port_def_type.nBufferCountMin;i++) {
618 unsigned char* new_buffer_data=(unsigned char*)malloc(port_def_type.nBufferSize);
619 OMX_BUFFERHEADERTYPE *buf_head=NULL;
620 error=OMX_UseBuffer(omx_vid_dec,&buf_head,omx_codec_input_port,NULL,port_def_type.nBufferSize,new_buffer_data);
621 if (error!=OMX_ErrorNone){
622 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_UseBuffer failed %x", error);
623 input_bufs_omx_mutex.Unlock();
626 input_bufs_omx_all.push_back(buf_head);
627 input_bufs_omx_free.push_back(buf_head);
629 input_bufs_omx_mutex.Unlock();
630 omx_first_frame=true;
633 cur_input_buf_omx=NULL;
638 int VideoVPEOGL::DestroyInputBufsOMX()
642 cur_input_buf_omx=NULL;
643 input_bufs_omx_mutex.Lock();
644 for (int i=0; i< input_bufs_omx_all.size();i++) {
645 free(input_bufs_omx_all[i]->pBuffer);
646 input_bufs_omx_all[i]->pBuffer=NULL;
647 error=OMX_FreeBuffer(omx_vid_dec,omx_codec_input_port,input_bufs_omx_all[i]);
648 if (error!=OMX_ErrorNone){
649 Log::getInstance()->log("Video", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);
650 input_bufs_omx_mutex.Unlock();
654 input_bufs_omx_all.clear();
655 input_bufs_omx_free.clear();
656 input_bufs_omx_mutex.Unlock();
663 int VideoVPEOGL::DeAllocateCodecsOMX()
667 DestroyInputBufsOMX();
670 error=OMX_SetupTunnel(omx_vid_rend,omx_rend_input_port,NULL,NULL);
671 if (error!=OMX_ErrorNone){
672 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
675 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_output_port,NULL,NULL);
676 if (error!=OMX_ErrorNone){
677 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
680 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_input_port,NULL,NULL);
681 if (error!=OMX_ErrorNone){
682 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
685 error=OMX_SetupTunnel(omx_vid_sched,omx_shed_clock_port,NULL,NULL);
686 if (error!=OMX_ErrorNone){
687 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
691 error=OMX_SetupTunnel(omx_clock,omx_clock_output_port,NULL,NULL);
692 if (error!=OMX_ErrorNone){
693 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
697 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_output_port,NULL,NULL);
698 if (error!=OMX_ErrorNone){
699 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
702 error=OMX_SetupTunnel(omx_vid_dec,omx_codec_input_port,NULL,NULL);
703 if (error!=OMX_ErrorNone){
704 Log::getInstance()->log("Video", Log::DEBUG, "OMX_Setup tunnel teardown failed %x", error);
710 error=OMX_FreeHandle(omx_vid_dec);
711 error=OMX_FreeHandle(omx_vid_sched);
712 error=OMX_FreeHandle(omx_vid_rend);
713 error=OMX_FreeHandle(omx_clock);
715 if (error!=OMX_ErrorNone) {
716 Log::getInstance()->log("Video", Log::DEBUG, "FreeHandle failed %d", error);
725 int VideoVPEOGL::stop()
727 if (!initted) return 0;
729 #ifdef VPE_OMX_SUPPORT
730 //Check if ffmpeg mode
731 DeAllocateCodecsOMX();
736 // if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
740 int VideoVPEOGL::reset()
742 if (!initted) return 0;
744 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
748 int VideoVPEOGL::pause()
750 if (!initted) return 0;
752 // if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
756 int VideoVPEOGL::unPause() // FIXME get rid - same as play!!
758 if (!initted) return 0;
759 // if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
763 int VideoVPEOGL::fastForward()
765 if (!initted) return 0;
767 // if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
771 int VideoVPEOGL::unFastForward()
773 if (!initted) return 0;
775 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
777 //// if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
781 int VideoVPEOGL::attachFrameBuffer()
783 if (!initted) return 0;
785 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
789 int VideoVPEOGL::blank(void)
791 // if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
792 // if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
796 ULLONG VideoVPEOGL::getCurrentTimestamp()
798 /* sync_data_t timestamps;
799 if (ioctl(fdVideo, AV_GET_VID_TIMESTAMPS, ×tamps) == 0)
801 // FIXME are these the right way around?
803 timestamps.stc = (timestamps.stc >> 31 ) | (timestamps.stc & 1);
804 timestamps.pts = (timestamps.pts >> 31 ) | (timestamps.pts & 1);
806 return timestamps.stc;
815 ULONG VideoVPEOGL::timecodeToFrameNumber(ULLONG timecode)
817 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
818 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
822 int VideoVPEOGL::test()
827 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
834 int VideoVPEOGL::test2()
840 void VideoVPEOGL::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos)
842 mediapacket = mplist.front();
845 UINT VideoVPEOGL::DeliverMediaSample(UCHAR* buffer, UINT *samplepos)
847 DeliverMediaPacket(mediapacket, buffer, samplepos);
848 if (*samplepos == mediapacket.length) {
856 UINT VideoVPEOGL::DeliverMediaPacket(MediaPacket packet,
861 /*First Check, if we have an audio sample*/
863 if (packet.type == MPTYPE_VIDEO_H264)
871 //Later add fail back code for ffmpeg
873 *samplepos+=packet.length;
874 return packet.length;
877 #ifdef VPE_OMX_SUPPORT
878 if (!omx_running) return 0; // if we are not runnig do not do this
881 /*First Check, if we have an audio sample*/
885 return 0; //Not in iframe mode!
891 if (packet.disconti) {
893 if (cur_input_buf_omx) {
894 OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
895 if (error!=OMX_ErrorNone){
896 Log::getInstance()->log("Video", Log::DEBUG, "OMX_EmptyThisBuffer failed %x", error);
898 cur_input_buf_omx=NULL;
902 /*Inspect PES-Header */
907 if (*samplepos==0) {//stripheader
908 headerstrip=buffer[packet.pos_buffer+8]+9/*is this right*/;
909 *samplepos+=headerstrip;
910 if ( packet.synched ) {
911 if (cur_input_buf_omx) {
912 OMX_ERRORTYPE error=OMX_EmptyThisBuffer(omx_vid_dec,cur_input_buf_omx);
914 cur_input_buf_omx=NULL;//write out old data
916 // reftime1=packet.presentation_time;
917 // reftime2=reftime1+1;
920 if (!firstsynched) {//
921 *samplepos=packet.length;//if we have not processed at least one
922 return packet.length;//synched packet ignore it!
927 if (!cur_input_buf_omx) {
928 input_bufs_omx_mutex.Lock();
929 if (input_bufs_omx_free.size()==0) {
930 input_bufs_omx_mutex.Unlock();
931 return 0; // we do not have a free media sample
934 cur_input_buf_omx=input_bufs_omx_free.front();
935 cur_input_buf_omx->nFilledLen=0;
936 cur_input_buf_omx->nOffset=0;
937 input_bufs_omx_free.pop_front();
938 input_bufs_omx_mutex.Unlock();
945 if (cur_input_buf_omx->nFilledLen==0) {//will only be changed on first packet
946 /*if (packet.disconti) {
947 ms->SetDiscontinuity(TRUE);
949 ms->SetDiscontinuity(FALSE);
951 //if (packet.synched) {
954 //lastreftimePTS=packet.pts;
955 if (omx_first_frame) { // TODO time
956 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_STARTTIME;
962 cur_input_buf_omx->nFlags=OMX_BUFFERFLAG_TIME_UNKNOWN;
965 // ms->SetSyncPoint(TRUE);
969 unsigned int haveToCopy=packet.length-*samplepos;
971 if (haveToCopy> (cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen)) {
972 cur_input_buf_omx->pBuffer=(OMX_U8*)realloc(cur_input_buf_omx->pBuffer,cur_input_buf_omx->nFilledLen+haveToCopy);
973 cur_input_buf_omx->nAllocLen=cur_input_buf_omx->nFilledLen+haveToCopy;
975 memcpy(cur_input_buf_omx->pBuffer,buffer+packet.pos_buffer+*samplepos,haveToCopy);
976 cur_input_buf_omx->nFilledLen=cur_input_buf_omx->nFilledLen+haveToCopy;
980 *samplepos+=haveToCopy;
982 return haveToCopy+headerstrip;
986 *samplepos+=packet.length; //yet not implemented//bad idea
987 return packet.length;
996 void VideoVPEOGL::ResetTimeOffsets()
1000 bool VideoVPEOGL::displayIFrame(const UCHAR* buffer, UINT length)
1002 //write(fdVideo, buffer, length);
1003 if (!iframemode) EnterIframePlayback();
1004 // WriteOutTS(buffer,length, h264?MPTYPE_VIDEO_H264 :MPTYPE_VIDEO_MPEG2 );
1010 int VideoVPEOGL::EnterIframePlayback()