YUVinYUVoverlay.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: YUVinYUVoverlay.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "YUVinYUVoverlay.hpp" 00045 #include "UncompressedVideoFrame.hpp" 00046 00047 00048 YUVinYUVoverlay::YUVinYUVoverlay(VideoESInfo* esi, YUVStreamIO *watermarkStream, int x, int y, bool loopWatermark) { 00049 00050 es = esi; 00051 waterStream = watermarkStream; 00052 posX = x; 00053 posY = y; 00054 this->loopWatermark = loopWatermark; 00055 waterFrame = NULL; 00056 numFrames = 0; 00057 lastAU.payload = NULL; 00058 strcpy(name,"YUVinYUVoverlay"); 00059 } 00060 00061 00062 YUVinYUVoverlay::~YUVinYUVoverlay() { 00063 delete waterStream; 00064 if (waterFrame) { 00065 waterFrame->unsetAU(); 00066 delete waterFrame; 00067 } 00068 } 00069 00070 00071 void YUVinYUVoverlay::initialize() { 00072 } 00073 00074 void YUVinYUVoverlay::setESInfo(ESInfo * esi) { 00075 es = (VideoESInfo*)esi; 00076 } 00077 00078 ESInfo *YUVinYUVoverlay::getESInfo() { 00079 return es; 00080 } 00081 00082 00083 /***************************************************************/ 00084 list < Frame * > YUVinYUVoverlay::adapt(Frame * frm) { 00085 list < Frame * >tmp; 00086 u32 thisCTS; 00087 int thisSec; 00088 int inW,inH,waterW,waterH; 00089 u8 *inPay, *waterPay; 00090 UncompressedVideoFrame *inFrame = (UncompressedVideoFrame*)frm; 00091 00092 //call open on first frame 00093 if (numFrames == 0) 00094 if (!waterStream->open()) { 00095 dprintf_err("YUVinYUVoverlay: FATAL: not writing, since another IO class is accessing file %s\n",waterStream->getURL()); 00096 //standard forwarding adaptor behaviour 00097 tmp.push_front(frm); 00098 return tmp; 00099 } 00100 00101 thisCTS = inFrame->getAU()->cts; 00102 thisSec = (int)floor((double)thisCTS / es->getMediaTimeScale()); 00103 dprintf_full("YUVinYUVoverlay::adapt frame %i CTS %i, VOP increment %i\n", numFrames, thisCTS,es->getVOPTimeIncrement()); 00104 00105 //FIXME: assert(isVideoFrame) 00106 00107 waterFrame = (UncompressedVideoFrame*)waterStream->getFrame(); 00108 00109 if (!waterFrame && loopWatermark) { 00110 //loop & reget first frame 00111 // waterStream->setToFrameNumber(0); 00112 waterStream->close(); 00113 waterStream->open(); 00114 waterFrame = (UncompressedVideoFrame*)waterStream->getFrame(); 00115 assert(waterFrame); 00116 } 00117 00118 if (waterFrame) { 00119 inW = inFrame->getWidth(); 00120 inH = inFrame->getHeight(); 00121 waterW = waterFrame->getWidth(); 00122 waterH = waterFrame->getHeight(); 00123 int inCromU = inW*inH; 00124 int waterCromU = waterW*waterH; 00125 int inCromV = inCromU + (inW*inH)/4; 00126 int waterCromV = waterCromU + (waterW*waterH)/4; 00127 00128 inPay = inFrame->getAU()->payload; 00129 waterPay = waterFrame->getAU()->payload; 00130 for (int i=0; i < waterW; i++) 00131 for (int j=0; j < waterH; j++) 00132 memcpy(&inPay[(posY+j)*inW+posX], &waterPay[j*waterW], waterW); 00133 00134 for (int i=0; i < waterW/2; i++) 00135 for (int j=0; j < waterH/2; j++) { 00136 memcpy(&inPay[posX/2+inCromU+(posY/2+j)*(inW/2)], &waterPay[waterCromU+j*(waterW/2)], waterW/2); 00137 memcpy(&inPay[posX/2+inCromV+(posY/2+j)*(inW/2)], &waterPay[waterCromV+j*(waterW/2)], waterW/2); 00138 } 00139 } 00140 00141 //standard forwarding adaptor behaviour 00142 tmp.push_front(frm); 00143 return tmp; 00144 }