[gephex-devel] gephex--main--0.4--patch-1876
gephex at sonnenland.kexbox.org
gephex at sonnenland.kexbox.org
Thu Apr 7 13:03:55 CEST 2005
Archive: gephex at gephex.org--2004
New revision: gephex--main--0.4--patch-1876
--
Revision: gephex--main--0.4--patch-1876
Archive: gephex at gephex.org--2004
Creator: The Gephex Source Archive <gephex at gephex.org>
Date: Thu Apr 7 13:01:41 CEST 2005
Standard-date: 2005-04-07 11:01:41 GMT
Modified-files: modules/src/ffmpegoutmodule/ffmpegoutmodule.cpp
modules/src/ffmpegoutmodule/ffmpegwriter.cpp
modules/src/ffmpegoutmodule/ffmpegwriter.h
New-patches: gephex at gephex.org--2004/gephex--main--0.4--patch-1876
martin at gephex.org--2004/gephex--ffmpegout--0.4--patch-4
martin at gephex.org--2004/gephex--ffmpegout--0.4--patch-5
Summary: [MERGE-REQUEST] bugfix #94
Keywords:
Patches applied:
* martin at gephex.org--2004/gephex--ffmpegout--0.4--patch-4
tag of gephex at gephex.org--2004/gephex--main--0.4--patch-1874
* martin at gephex.org--2004/gephex--ffmpegout--0.4--patch-5
ffmpegoutput errorhandling + bugfix for #94
* added files
{arch}/gephex/gephex--ffmpegout/gephex--ffmpegout--0.4/martin at gephex.org--2004/patch-log/patch-4
{arch}/gephex/gephex--ffmpegout/gephex--ffmpegout--0.4/martin at gephex.org--2004/patch-log/patch-5
{arch}/gephex/gephex--main/gephex--main--0.4/gephex at gephex.org--2004/patch-log/patch-1876
* modified files
--- orig/modules/src/ffmpegoutmodule/ffmpegoutmodule.cpp
+++ mod/modules/src/ffmpegoutmodule/ffmpegoutmodule.cpp
@@ -29,8 +29,9 @@
#include <string>
#include <vector>
#include <sstream>
-
-#include "basic_types.h"
+#include <stdexcept>
+
+#include "basic_types.h"
static logT s_log;
@@ -44,7 +45,7 @@
~_MyInstance()
{
- if (ffmpegWriter) delete ffmpegWriter;
+ delete ffmpegWriter;
framebuffer_deleteInstance(scaledFb);
}
@@ -89,16 +90,6 @@
const std::string filename(inst->in_filename->text);
const std::string encoding(inst->in_encoding->text);
- if (filename == "null")
- {
- if (my.ffmpegWriter != 0)
- {
- delete my.ffmpegWriter;
- my.ffmpegWriter = 0;
- }
- return;
- }
-
// change size to valid one
const size_t xsize = xsize_pre - xsize_pre % 4;
const size_t ysize = ysize_pre - ysize_pre % 4;
@@ -106,43 +97,69 @@
// yuv4mpeg2 spec or ffpmeg
assert(xsize%4==0);
assert(ysize%4==0);
-
-
- if (my.ffmpegWriter == 0)
- my.ffmpegWriter=new FFMpegWriter(filename,xsize,ysize,encoding);
-
- if (my.ffmpegWriter->getFilename() != filename ||
- my.ffmpegWriter->getXres() != xsize ||
- my.ffmpegWriter->getYres() != ysize ||
- my.ffmpegWriter->getEncoding() != encoding)
+
+ if (filename == "null")
{
- delete my.ffmpegWriter;
-
- my.ffmpegWriter=new FFMpegWriter(filename,xsize,ysize,encoding);
+ delete my.ffmpegWriter;
+ my.ffmpegWriter = 0;
+ return;
}
-
- // the framebuffer
- uint32_t* fb;
- if (inst->in_in->xsize != my.ffmpegWriter->getXres() ||
- inst->in_in->ysize != my.ffmpegWriter->getYres())
+ try
{
- FrameBufferAttributes in_attr;
- framebuffer_getAttributes(inst->in_in, &in_attr);
- in_attr.xsize=my.ffmpegWriter->getXres();
- in_attr.ysize=my.ffmpegWriter->getYres();
- framebuffer_convertType(my.scaledFb, inst->in_in , &in_attr);
+ if (my.ffmpegWriter == 0)
+ my.ffmpegWriter=new FFMpegWriter(filename,xsize,ysize,encoding);
- // use the scaled one
- fb=my.scaledFb->framebuffer;
+ assert(my.ffmpegWriter != 0);
+
+ if (my.ffmpegWriter->getFilename() != filename ||
+ my.ffmpegWriter->getXres() != xsize ||
+ my.ffmpegWriter->getYres() != ysize ||
+ my.ffmpegWriter->getEncoding() != encoding)
+ {
+ delete my.ffmpegWriter;
+ my.ffmpegWriter=new FFMpegWriter(filename,xsize,ysize,encoding);
+ }
+
+ assert(my.ffmpegWriter != 0);
}
- else
+ catch(std::runtime_error& e)
{
- // use the original
- fb=inst->in_in->framebuffer;
+ my.ffmpegWriter=0;
+ s_log( 0, e.what() );
}
- my.ffmpegWriter->writeFrame(fb);
+ if ( my.ffmpegWriter != 0 )
+ {
+ // the framebuffer
+ uint32_t* fb;
+
+ if (inst->in_in->xsize != my.ffmpegWriter->getXres() ||
+ inst->in_in->ysize != my.ffmpegWriter->getYres())
+ {
+ FrameBufferAttributes in_attr;
+ framebuffer_getAttributes(inst->in_in, &in_attr);
+ in_attr.xsize=my.ffmpegWriter->getXres();
+ in_attr.ysize=my.ffmpegWriter->getYres();
+ framebuffer_convertType(my.scaledFb, inst->in_in , &in_attr);
+
+ // use the scaled one
+ fb=my.scaledFb->framebuffer;
+ }
+ else
+ {
+ // use the original
+ fb=inst->in_in->framebuffer;
+ }
+ try
+ {
+ my.ffmpegWriter->writeFrame(fb);
+ }
+ catch(std::runtime_error& e)
+ {
+ s_log(0,e.what());
+ }
+ }
}
--- orig/modules/src/ffmpegoutmodule/ffmpegwriter.cpp
+++ mod/modules/src/ffmpegoutmodule/ffmpegwriter.cpp
@@ -21,21 +21,17 @@
#include "ffmpegwriter.h"
#include <iostream>
#include <string>
+#include <stdexcept>
+
FFMpegWriter::FFMpegWriter(const std::string &filename, int xres, int yres,
std::string encoding)
+ : outfile(filename), encstr(encoding), x_res(xres), y_res(yres)
{
std::cout << "creating new ffmpeg writer " << filename << " "
<< xres << "x" << yres
<< ", encoding: " << encoding << std::endl;
- outfile = filename;
-
- encstr = encoding;
-
- x_res = xres;
- y_res = yres;
-
av_register_all();
initEncoderMap();
@@ -81,30 +77,28 @@
return encstr;
}
-int FFMpegWriter::initEncoderMap()
-{
- /*
- * Had to add the template qualifiers <int, const char*>, because
- * otherwise vs6 does not compile...
- * georg
- */
- encmap["DIVX High"] = std::make_pair<int, const char*>(800000, "avi" );
- encmap["DIVX Low"] = std::make_pair<int, const char*>(200000, "avi" );
- encmap["MPEG2 High"] = std::make_pair<int, const char*>(800000, "mpeg");
- encmap["MPEG2 Low"] = std::make_pair<int, const char*>(200000, "mpeg");
- encmap["RM High"] = std::make_pair<int, const char*>(800000, "rm" );
- encmap["RM Low"] = std::make_pair<int, const char*>(200000, "rm" );
- encmap["MOV High"] = std::make_pair<int, const char*>(800000, "mov" );
- encmap["MOV Low"] = std::make_pair<int, const char*>(200000, "mov" );
-
- return 0;
+void FFMpegWriter::initEncoderMap()
+{
+ encmap["DIVX High"] = std::make_pair(800000, std::string("avi") );
+ encmap["DIVX Low"] = std::make_pair(200000, std::string("avi") );
+ encmap["MPEG2 High"] = std::make_pair(800000, std::string("mpeg"));
+ encmap["MPEG2 Low"] = std::make_pair(200000, std::string("mpeg"));
+ encmap["RM High"] = std::make_pair(800000, std::string("rm"));
+ encmap["RM Low"] = std::make_pair(200000, std::string("rm"));
+ encmap["MOV High"] = std::make_pair(800000, std::string("mov"));
+ encmap["MOV Low"] = std::make_pair(200000, std::string("mov"));
}
-int FFMpegWriter::initEncoder()
+void FFMpegWriter::initEncoder()
{
- fmt = guess_format(encmap.find(encstr)->second.second.c_str(), NULL, NULL);
- bps = encmap.find(encstr)->second.first;
+ encmap_t::const_iterator enc = encmap.find(encstr);
+
+ if ( enc == encmap.end() )
+ throw std::runtime_error( "unkown encoder format" );
+
+ fmt = guess_format( enc->second.second.c_str(), NULL, NULL);
+ bps = enc->second.first;
// use mpeg if unable to guess
if (fmt == NULL)
@@ -117,8 +111,7 @@
// mpeg not available
if (fmt == NULL)
{
- std::cout << "error initializing mpeg encoder!" << std::endl;
- return -1;
+ std::runtime_error("error initializing mpeg encoder!");
}
else
{
@@ -132,17 +125,14 @@
oc = av_alloc_format_context();
if (oc == NULL)
{
- std::cout << "ffmpeg: memory error allocating format context" << std::endl;
- return -2;
+ throw std::runtime_error("ffmpeg: memory error allocating format context");
}
// set output format
oc->oformat = fmt;
-
- return 0;
}
-int FFMpegWriter::initStream()
+void FFMpegWriter::initStream()
{
// create the video stream
@@ -162,15 +152,12 @@
{
if (url_fopen(&oc->pb, outfile.c_str(), URL_WRONLY) < 0)
{
- std::cout << "Could not open outfile" << std::endl;
- return -1;
+ std::runtime_error("Could not open outfile");
}
}
// write file header if needed
av_write_header(oc);
-
- return 0;
}
void FFMpegWriter::cleanup()
--- orig/modules/src/ffmpegoutmodule/ffmpegwriter.h
+++ mod/modules/src/ffmpegoutmodule/ffmpegwriter.h
@@ -44,9 +44,9 @@
private:
- int initEncoder();
- int initEncoderMap();
- int initStream();
+ void initEncoder();
+ void initEncoderMap();
+ void initStream();
void cleanup();
void open_video(AVFormatContext *oc, AVStream *st);
@@ -61,7 +61,8 @@
int x_res, y_res;
unsigned int bps;
- std::map<std::string, std::pair<int, std::string> > encmap;
+ typedef std::map<std::string, std::pair<int, std::string> > encmap_t;
+ encmap_t encmap;
uint8_t *video_outbuf;
int video_outbuf_size;
More information about the gephex-devel
mailing list