2011-09-15 16:42:52 +03:00
|
|
|
#include "avsnoop.hpp"
|
|
|
|
#include "misc.hpp"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
std::list<av_snooper*>* snoopers;
|
|
|
|
std::list<av_snooper::dump_notification*> notifiers;
|
|
|
|
std::string s_gamename;
|
|
|
|
std::string s_rerecords;
|
|
|
|
double s_gametime;
|
|
|
|
std::list<std::pair<std::string, std::string>> s_authors;
|
|
|
|
bool gameinfo_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_snooper::av_snooper() throw(std::bad_alloc)
|
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
snoopers = new std::list<av_snooper*>();
|
|
|
|
snoopers->push_back(this);
|
|
|
|
for(auto i = notifiers.begin(); i != notifiers.end(); i++)
|
|
|
|
(*i)->dump_starting();
|
|
|
|
}
|
|
|
|
|
|
|
|
av_snooper::~av_snooper() throw()
|
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
return;
|
|
|
|
for(auto i = snoopers->begin(); i != snoopers->end(); i++)
|
|
|
|
if(*i == this) {
|
|
|
|
snoopers->erase(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(auto i = notifiers.begin(); i != notifiers.end(); i++)
|
|
|
|
(*i)->dump_ending();
|
|
|
|
}
|
|
|
|
|
2011-09-17 01:05:41 +03:00
|
|
|
void av_snooper::frame(struct lcscreen& _frame, uint32_t fps_n, uint32_t fps_d, bool dummy) throw(std::bad_alloc)
|
2011-09-15 16:42:52 +03:00
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
return;
|
|
|
|
for(auto i = snoopers->begin(); i != snoopers->end(); i++)
|
|
|
|
try {
|
2011-09-17 00:06:20 +03:00
|
|
|
(*i)->frame(_frame, fps_n, fps_d);
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(std::bad_alloc& e) {
|
2011-09-17 00:06:20 +03:00
|
|
|
throw;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(std::exception& e) {
|
|
|
|
try {
|
2011-09-17 09:55:35 +03:00
|
|
|
messages << "Error dumping frame: " << e.what() << std::endl;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-17 01:05:41 +03:00
|
|
|
void av_snooper::sample(short l, short r, bool dummy) throw(std::bad_alloc)
|
2011-09-15 16:42:52 +03:00
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
return;
|
|
|
|
for(auto i = snoopers->begin(); i != snoopers->end(); i++)
|
|
|
|
try {
|
|
|
|
(*i)->sample(l, r);
|
|
|
|
} catch(std::bad_alloc& e) {
|
2011-09-17 00:06:20 +03:00
|
|
|
throw;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(std::exception& e) {
|
|
|
|
try {
|
2011-09-17 09:55:35 +03:00
|
|
|
messages << "Error dumping sample: " << e.what() << std::endl;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-17 01:05:41 +03:00
|
|
|
void av_snooper::end(bool dummy) throw(std::bad_alloc)
|
2011-09-15 16:42:52 +03:00
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
return;
|
|
|
|
for(auto i = snoopers->begin(); i != snoopers->end(); i++)
|
|
|
|
try {
|
|
|
|
(*i)->end();
|
|
|
|
} catch(std::bad_alloc& e) {
|
2011-09-17 00:06:20 +03:00
|
|
|
throw;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(std::exception& e) {
|
|
|
|
try {
|
2011-09-17 09:55:35 +03:00
|
|
|
messages << "Error ending dump: " << e.what() << std::endl;
|
2011-09-15 16:42:52 +03:00
|
|
|
} catch(...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::gameinfo(const std::string& gamename, const std::list<std::pair<std::string, std::string>>&
|
2011-09-17 01:05:41 +03:00
|
|
|
authors, double gametime, const std::string& rerecords, bool dummy) throw(std::bad_alloc)
|
2011-09-15 16:42:52 +03:00
|
|
|
{
|
|
|
|
if(!snoopers)
|
|
|
|
return;
|
|
|
|
s_gamename = gamename;
|
|
|
|
s_authors = authors;
|
|
|
|
s_gametime = gametime;
|
|
|
|
s_rerecords = rerecords;
|
|
|
|
gameinfo_set = true;
|
|
|
|
for(auto i = snoopers->begin(); i != snoopers->end(); i++)
|
|
|
|
(*i)->send_gameinfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::send_gameinfo() throw()
|
|
|
|
{
|
|
|
|
if(gameinfo_set)
|
|
|
|
try {
|
|
|
|
gameinfo(s_gamename, s_authors, s_gametime, s_rerecords);
|
|
|
|
} catch(...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool av_snooper::dump_in_progress() throw()
|
|
|
|
{
|
|
|
|
return (snoopers && !snoopers->empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
av_snooper::dump_notification::~dump_notification() throw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::dump_notification::dump_starting() throw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::dump_notification::dump_ending() throw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::add_dump_notifier(av_snooper::dump_notification& notifier) throw(std::bad_alloc)
|
|
|
|
{
|
|
|
|
notifiers.push_back(¬ifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_snooper::remove_dump_notifier(av_snooper::dump_notification& notifier) throw()
|
|
|
|
{
|
|
|
|
for(auto i = notifiers.begin(); i != notifiers.end(); i++)
|
|
|
|
if(*i == ¬ifier) {
|
|
|
|
notifiers.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|