bool KTPackageHandler::makePackage(const QString &projectPath, const QString &packagePath)
{
	if ( !QFile::exists(projectPath))
	{
		qWarning("Project not saved!");
		
		return false;
	}
	
	QFileInfo packageInfo(packagePath);
	
	QuaZip zip(packagePath);
	if(!zip.open(QuaZip::mdCreate))
	{
		dError() << "Error while create package: " << zip.getZipError();
		return false;
	}
	
	if ( ! compress(&zip, projectPath ))
	{
		dError() << "Error while compress project" << zip.getZipError();
		return false;
	}
	
	zip.close();
	if(zip.getZipError() != 0)
	{
		dError() << "Error: " << zip.getZipError();
		return false;
	}
	
	return true;
}
bool FFMpegManager::openVideo(AVFormatContext *oc, AVStream *st)
{
	AVCodec *codec;
	AVCodecContext *c;
#if LIBAVCODEC_BUILD <= 4743
	c = &st->codec;
#else
	c = st->codec;
#endif
	/* find the video encoder */
	
	codec = avcodec_find_encoder(c->codec_id);
	
	if (!codec)
	{
		dError() << "codec not found";
		return false;
	}

	/* open the codec */
	if (avcodec_open(c, codec) < 0)
	{
		dError() << "could not open codec";
		return false;
	}

	videOutbuf = 0;
	if (!(oc->oformat->flags & AVFMT_RAWPICTURE))
	{
		/* allocate output buffer */
		/* XXX: API change will be done */
		videOutbufSize = 200000;
// 		videOutbuf = (uint8_t *) malloc(videOutbufSize);
		videOutbuf = (uint8_t *) av_malloc(videOutbufSize);
	}

	/* allocate the encoded raw m_picture */
	m_picture = allocPicture(c->pix_fmt, c->width, c->height);
	if (!m_picture) 
	{
		dError() << "Could not allocate m_picture";
		return false;
	}
	
	m_tmpPicture = 0;
	if (c->pix_fmt != PIX_FMT_YUV420P) 
	{
		m_tmpPicture = allocPicture(PIX_FMT_YUV420P, c->width, c->height);
		if (!m_tmpPicture)
		{
			dError() << "Could not allocate temporary picture";
			return false;
		}
	}
	
	return true;
}
Esempio n. 3
0
@@@ this file should not be compiled any more @@@

#include <string.h>
#include <errno.h>
#include "stack.h"
#include "ode/error.h"
#include "ode/config.h"

//****************************************************************************
// unix version that uses mmap(). some systems have anonymous mmaps and some
// need to mmap /dev/zero.

#ifndef WIN32

#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


void dStack::init (int max_size)
{
  if (sizeof(long int) != sizeof(char*)) dDebug (0,"internal");
  if (max_size <= 0) dDebug (0,"Stack::init() given size <= 0");

#ifndef MMAP_ANONYMOUS
  static int dev_zero_fd = -1;	// cached file descriptor for /dev/zero
  if (dev_zero_fd < 0) dev_zero_fd = open ("/dev/zero", O_RDWR);
  if (dev_zero_fd < 0) dError (0,"can't open /dev/zero (%s)",strerror(errno));
  base = (char*) mmap (0,max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE,
		       dev_zero_fd,0);
#else
  base = (char*) mmap (0,max_size, PROT_READ | PROT_WRITE,
		       MAP_PRIVATE | MAP_ANON,0,0);
#endif

  if (int(base) == -1) dError (0,"Stack::init(), mmap() failed, "
    "max_size=%d (%s)",max_size,strerror(errno));
  size = max_size;
  pointer = base;
  frame = 0;
}
QAction *DActionManager::find(const QString &id) const
{
	QAction *action = m_actionDict[id.toLower()];
	
	if ( action == 0)
	{
		dError() << "DActionManager::find(): Returning NULL action: " << id;
	}
	
	return action;
}
Esempio n. 5
0
void dStack::init (int max_size)
{
  if (sizeof(LPVOID) != sizeof(char*)) dDebug (0,"internal");
  if (max_size <= 0) dDebug (0,"Stack::init() given size <= 0");
  base = (char*) VirtualAlloc (NULL,max_size,MEM_RESERVE,PAGE_READWRITE);
  if (base == 0) dError (0,"Stack::init(), VirtualAlloc() failed, "
    "max_size=%d",max_size);
  size = max_size;
  pointer = base;
  frame = 0;
  committed = 0;

  // get page size
  SYSTEM_INFO info;
  GetSystemInfo (&info);
  pagesize = info.dwPageSize;
}
Esempio n. 6
0
void doTest (int argc, char **argv, int n, int fatal_if_bad_n)
{
  test_num = n;
  iteration = 0;
  max_iterations = 300;
  max_error = 0;

  if (! setupTest (n)) {
    if (fatal_if_bad_n) dError (0,"bad test number");
    return;
  }

  // setup pointers to drawstuff callback functions
  dsFunctions fn;
  fn.version = DS_VERSION;
  fn.start = &start;
  fn.step = &simLoop;
  fn.command = 0;
  fn.stop = 0;
  if (cmd_path_to_textures)
    fn.path_to_textures = cmd_path_to_textures;
  else
  fn.path_to_textures = "../../drawstuff/textures";

  // run simulation
  if (cmd_graphics) {
    dsSimulationLoop (argc,argv,352,288,&fn);
  }
  else {
    for (int i=0; i < max_iterations; i++) simLoop (0);
  }
  dWorldDestroy (world);
  body[0] = 0;
  body[1] = 0;
  joint = 0;

  // print results
  printf ("test %d: ",n);
  if (max_error == dInfinity) printf ("error not computed\n");
  else {
    printf ("max scaled error = %.4e",max_error);
    if (max_error < 1) printf (" - passed\n");
    else printf (" - FAILED\n");
  }
}
bool KTPackageHandler::compress(QuaZip *zip, const QString &path)
{
	QFile inFile;
	QuaZipFile outFile(zip);
	char c;
	
	QFileInfoList files= QDir(path).entryInfoList();
	
	foreach(QFileInfo file, files)
	{
		QString filePath = path+"/"+file.fileName();
		
		
		if ( file.fileName().startsWith(".") ) continue;
		
		if ( file.isDir() )
		{
			compress(zip, file.path()+"/"+file.fileName());
			continue;
		}
		
		inFile.setFileName(filePath);
		if(!inFile.open(QIODevice::ReadOnly)) 
		{
			dError() << "Error opening file " << inFile.fileName() << " : " << inFile.errorString();
			return false;
		}
		
		if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(stripRepositoryFromPath(filePath), stripRepositoryFromPath(filePath) ))) 
		{
			return false;
		}
		while(inFile.getChar(&c) && outFile.putChar(c));
		
		if(outFile.getZipError()!=UNZ_OK)
		{
			return false;
		}
		outFile.close();
		if(outFile.getZipError()!=UNZ_OK)
		{
			return false;
		}
		inFile.close();
	}
Esempio n. 8
0
DConfig::DConfig() : QObject()
{
	DINIT;
#ifdef Q_WS_X11
	configDirectory.setPath(QDir::homePath()+"/."+QCoreApplication::applicationName ());
#elif defined(Q_WS_WIN)
	configDirectory.setPath(QDir::homePath()+"/"+QCoreApplication::applicationName ());
#elif defined(Q_WS_MAC)
	configDirectory.setPath(QDir::homePath()+"/."+QCoreApplication::applicationName ());
#endif

	if ( !configDirectory.exists() )
	{
		dDebug() << tr("%1 not exists... creating...").arg(configDirectory.path()) << endl;
		if(!configDirectory.mkdir(configDirectory.path()))
		{
			dError() << tr("I can't create %1").arg(configDirectory.path()) << endl;
		}
	}

	m_dconfig = new DConfigDocument( configDirectory.path() + "/"+QCoreApplication::applicationName().toLower()+".cfg" );
	
	init();
}
void FFMpegManager::create(const QString &filePath, int formatId, const QStringList &paths, const QSize &size, int fps)
{
#ifdef HAVE_FFMPEG
	
	AVOutputFormat *fmt = guess_format(0, filePath.toLatin1().data(), 0);
	
	if ( !fmt )
	{
		fmt = guess_format("mpeg", NULL, NULL);
	}
	
// 	AVFormatParameters params, *ap = &params;
	
	switch(formatId)
	{
		case ExportInterface::ASF:
		{
			
		}
		break;
		case ExportInterface::AVI:
		{
			fmt->video_codec = CODEC_ID_MSMPEG4V3;
// 			video_st->codec.codec_tag = 0;
		}
		break;
		case ExportInterface::MOV:
		{
			
		}
		break;
		case ExportInterface::MPEG:
		{
		}
		break;
		case ExportInterface::RM:
		{
			
		}
		break;
		case ExportInterface::SWF:
		{
			
		}
		break;
		case ExportInterface::GIF:
		{
// 			AVImageFormat *imageFormat = guess_image_format(filePath.toLatin1().data());
// 			
// 			memset(ap, 0, sizeof(*ap));
// 			ap->image_format = imageFormat;
		}
		break;
		default: break;
	}
	
	AVFormatContext *oc = av_alloc_format_context();
	if ( !oc )
	{
		dError() << "Error while export";
		return;
	}

	
	oc->oformat = fmt;
	snprintf(oc->filename, sizeof(oc->filename), "%s", filePath.toLatin1().data());
	
	AVStream *video_st = addVideoStream(oc, fmt->video_codec, size.width(), size.height(), fps);
	
	if ( !video_st )
	{
		dError() << "Can't add video stream";
		return;
	}
	
	if (av_set_parameters(oc, 0) < 0)
	{
		dError() << "Invalid output format parameters";
		return ;
	}
	
	dump_format(oc, 0, filePath.toLatin1().data(), 1);
	
	if (!openVideo(oc, video_st) )
	{
		dError() << "Can't open video";
		return;
	}
	
	if (!(fmt->flags & AVFMT_NOFILE))
	{
		if (url_fopen(&oc->pb, filePath.toLatin1().data(), URL_WRONLY) < 0) 
		{
			dError() << "Could not open " << filePath.toLatin1().data();
			return;
		}
	}
	
	av_write_header(oc);
	
	double video_pts = 0.0;
	
	foreach(QString imagePath, paths)
	{
		if (video_st)
		{
			video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
		}
		else
		{
			video_pts = 0.0;
		}
		if (!video_st || video_pts >= m_streamDuration )
		{
			break;
		}
		
		if (! writeVideoFrame(imagePath, oc, video_st, fps) )
		{
			break;
		}
	}
	
	closeVideo(oc, video_st);
	av_write_trailer(oc);
	
	for(int i = 0; i < oc->nb_streams; i++)
	{
		av_freep(&oc->streams[i]);
	}
	
	if (!(fmt->flags & AVFMT_NOFILE)) 
	{
		/* close the output file */
		url_fclose(&oc->pb);
	}
	
	av_free(oc);
#endif
}
Esempio n. 10
0
bool FFMpegManager::writeVideoFrame(const QString &imagePath, AVFormatContext *oc, AVStream *st, int fps)
{
#if LIBAVCODEC_BUILD <= 4743
	AVCodecContext *c = &st->codec;
#else
	AVCodecContext *c = st->codec;
#endif

	AVFrame *picturePtr;
	
	double nbFrames = ((int)(m_streamDuration * fps));
	if (m_frameCount >= nbFrames)
	{
        	/* no more frame to compress. The codec has a latency of a few
		frames if using B frames, so we get the last frames by
		passing a 0 m_picture */
		picturePtr = 0;
	}
	else
	{
		QImage image(imagePath);
		
		AVPicture pictTmp;
		
		avpicture_alloc(&pictTmp, PIX_FMT_RGBA32,c->width, c->height);

		memcpy(pictTmp.data[0],image.bits(),c->width*c->height*4);

		img_convert((AVPicture *)m_picture,c->pix_fmt,&pictTmp,PIX_FMT_RGBA32,c->width,c->height);
		avpicture_free(&pictTmp);

		picturePtr = m_picture;
	}

	int out_size = -1, ret = -1;
	if (oc->oformat->flags & AVFMT_RAWPICTURE)
	{
        	/* raw video case. The API will change slightly in the near
		futur for that */
		AVPacket pkt;
		av_init_packet(&pkt);
        
		pkt.flags |= PKT_FLAG_KEY;
		pkt.stream_index= st->index;
		pkt.data= (uint8_t *)picturePtr;
		pkt.size= sizeof(AVPicture);
        
		ret = av_write_frame(oc, &pkt);
	} 
	else 
	{
		/* encode the image */
		out_size = avcodec_encode_video(c, videOutbuf, videOutbufSize, picturePtr);
// 		out_size = av_write_trailer(oc);
		/* if zero size, it means the image was buffered */

		if (out_size > 0)
		{
			AVPacket pkt;
			av_init_packet(&pkt);
            
// 			pkt.pts= c->coded_frame->pts;
			pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
			
			if(c->coded_frame->key_frame)
				pkt.flags |= PKT_FLAG_KEY;
			pkt.stream_index= st->index;
			pkt.data= videOutbuf;
			pkt.size= out_size;
            
			/* write the compressed frame in the media file */
			ret = av_write_frame(oc, &pkt);
		} 
		else 
		{
			ret = 0;
		}
	}
	if (ret != 0)
	{
		dError() << "Error while writing video frame";
		return false;
	}
	m_frameCount++;
	
	return true;
}
Esempio n. 11
0
AVStream *FFMpegManager::addVideoStream(AVFormatContext *oc, int codec_id, int width, int height, int fps)
{
	AVCodecContext *c;
	AVStream *st;
	
	int w = width;
	int h = height;

	st = av_new_stream(oc, 0);
	if (!st) 
	{
		dError() << "Could not alloc stream";
		return 0;
	}

#if LIBAVCODEC_BUILD <= 4743
	c = &st->codec;
#else
	c = st->codec;
#endif

	c->codec_id = CodecID(codec_id);
	c->codec_type = CODEC_TYPE_VIDEO;

	/* put sample parameters */
	c->bit_rate = 400000;
	/* resolution must be a multiple of two */
	c->width = w;  // 520
	c->height = h; // 340

#if LIBAVCODEC_BUILD <= 4743
	/* frames per second */
	c->frame_rate = fps;
	c->frame_rate_base = 1;
#else
	c->time_base.den = fps;
	c->time_base.num = 1;
	c->gop_size = 12; /* emit one intra frame every twelve frames at most */
	c->pix_fmt = PIX_FMT_YUV420P;
#endif

	c->gop_size = 12; /* emit one intra frame every twelve frames at most */
	if (c->codec_id == CODEC_ID_MPEG2VIDEO) 
	{
		/* just for testing, we also add B frames */
		c->max_b_frames = 2;
	}
	if (c->codec_id == CODEC_ID_MPEG1VIDEO)
	{
        /* needed to avoid using macroblocks in which some coeffs overflow
		this doesnt happen with normal video, it just happens here as the
		motion of the chroma plane doesnt match the luma plane */
		c->mb_decision=2;
	}
    // some formats want stream headers to be seperate
	if(!strcmp(oc->oformat->name, "mp4") || !strcmp(oc->oformat->name, "mov") || !strcmp(oc->oformat->name, "3gp"))
	{
		c->flags |= CODEC_FLAG_GLOBAL_HEADER;
	}
	
	return st;
}
SResourcePackage::SResourcePackage() : QDomDocument()
{
	QDomElement root = createElement("Resources");
	appendChild(root);
	
	// Leemos los datos desde un archivo de indices
	QFile rscIndex(HOME+"/data/index.rsc");
	
	if( rscIndex.open( QIODevice::ReadOnly | QIODevice::Text))
	{
		QDomDocument doc;
		if ( doc.setContent( &rscIndex ) )
		{
			QDomElement docElem = doc.documentElement();
			
			QDomNode n = docElem.firstChild();
			
			QDomElement resource;
			
			while(!n.isNull())
			{
				QDomElement e = n.toElement();
				if(!e.isNull())
				{
					dDebug() << e.tagName();
					
					QString path = e.attribute("path");
						
					QString name = e.attribute("name");
						
					if( name.isEmpty() )
					{
						QFileInfo finfo(path);
						name = finfo.fileName();
					}
					
					if ( e.tagName() == "Image" )
					{
						resource = createElement("Image");
						resource.setAttribute("filename", name);
						
						addResource( resource, path );
						
						documentElement().appendChild(resource);
					}
					else if ( e.tagName() == "Svg" )
					{
						resource = createElement("Svg");
						resource.setAttribute("filename", name);
						
						addResource( resource, path );
						
						documentElement().appendChild(resource);
					}
					else if ( e.tagName() == "Sourd" )
					{
						resource = createElement("Sourd");
						resource.setAttribute("filename", name);
						
						addResource( resource, path );
						
						documentElement().appendChild(resource);
					}
					
					
				}
				n = n.nextSibling();
			}

		}
		else
		{
			dError() << "Invalid resource index file: " << rscIndex.fileName();
		}
		
		rscIndex.close();
	}
}
Esempio n. 13
0
void do_tests (int argc, char **argv)
{
  int i,j;

  // process command line arguments
  if (argc >= 2) {
    graphical_test = atoi (argv[1]);
  }

  if (graphical_test) {
    // do one test gaphically and interactively

    if (graphical_test < 1 || graphical_test >= MAX_TESTS ||
	!testslot[graphical_test].name) {
      dError (0,"invalid test number");
    }

    printf ("performing test: %s\n",testslot[graphical_test].name);

    // setup pointers to drawstuff callback functions
    dsFunctions fn;
    fn.version = DS_VERSION;
    fn.start = &start;
    fn.step = &simLoop;
    fn.command = &command;
    fn.stop = 0;
    fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH;

    dsSetSphereQuality (3);
    dsSetCapsuleQuality (8);
    dsSimulationLoop (argc,argv,1280,900,&fn);
  }
  else {
    // do all tests noninteractively

    for (i=0; i<MAX_TESTS; i++) testslot[i].number = i;

    // first put the active tests into a separate array
    int n=0;
    for (i=0; i<MAX_TESTS; i++) if (testslot[i].name) n++;
    TestSlot **ts = (TestSlot**) malloc (n * sizeof(TestSlot*));
    j = 0;
    for (i=0; i<MAX_TESTS; i++) if (testslot[i].name) ts[j++] = testslot+i;
    if (j != n) dDebug (0,"internal");

    // do two test batches. the first test batch has far fewer reps and will
    // catch problems quickly. if all tests in the first batch passes, the
    // second batch is run.

    for (i=0; i<n; i++) ts[i]->failcount = 0;
    int total_reps=0;
    for (int batch=0; batch<2; batch++) {
      int reps = (batch==0) ? TEST_REPS1 : TEST_REPS2;
      total_reps += reps;
      printf ("testing batch %d (%d reps)...\n",batch+1,reps);

      // run tests
      for (j=0; j<reps; j++) {
	for (i=0; i<n; i++) {
	  current_test = ts[i]->number;
	  if (ts[i]->test_fn() != 1) ts[i]->failcount++;
	}
      }

      // check for failures
      int total_fail_count=0;
      for (i=0; i<n; i++) total_fail_count += ts[i]->failcount;
      if (total_fail_count) break;
    }

    // print results
    for (i=0; i<n; i++) {
      printf ("%3d: %-30s: ",ts[i]->number,ts[i]->name);
      if (ts[i]->failcount) {
	printf ("FAILED (%.2f%%) at line %d\n",
		double(ts[i]->failcount)/double(total_reps)*100.0,
		ts[i]->last_failed_line);
      }
      else {
	printf ("ok\n");
      }
    }
  }
}