Merge branch 'master' into release_0_8_9
[gnash.git] / cygnal / libnet / statistics.cpp
blob696b57cf4c3ef66660b6d713dc31f12f20f36d59
1 // statistics.cpp: Network performance stats for Cygnal, for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
5 //
6 // This program 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 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program 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 this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <boost/thread/mutex.hpp>
22 #include <string>
23 #include <list>
24 #include <iostream>
26 #include "log.h"
27 #include "netstats.h"
28 #include "statistics.h"
31 static boost::mutex io_mutex;
33 // The string versions of the codec, used for debugging. If you add
34 // another enum type to codec_e, you have to add the string
35 // representation here or you'll get the wrong output.
36 const char *codec_names[] = {
37 "NO_CODEC",
38 "Ogg",
39 "Theora",
40 "Dirac",
41 "Snow",
42 "MP3",
43 "MPEG4",
44 "H264",
45 "H263",
46 "FLV",
47 "VP6",
48 "VP7"
51 // The string versions of the file type, used for debugging. If you add
52 // another enum type to filetypes_e, you have to add the string
53 // representation here or you'll get the wrong output.
54 const char *filetype_names[] = {
55 "NO_FILETYPE",
56 "HTTP",
57 "RTMP",
58 "RTMPT",
59 "RTMPTS",
60 "SWF",
61 "SWF5",
62 "SWF6",
63 "SWF7",
64 "SWF8",
65 "SWF9",
66 "AUDIO",
67 "VIDEO"
70 namespace gnash
73 Statistics::Statistics() {
76 Statistics::~Statistics() {
77 dump();
80 float
81 Statistics::getFPS() {
82 return 0.0; // TODO: FIXME !
85 int
86 Statistics::getBitRate() {
88 return (getStartTime() - getStopTime()).seconds() / getBytes();
91 int
92 Statistics::addStats() {
93 NetStats *st = new NetStats;
95 st->setStartTime(getStartTime());
96 st->setStopTime(getStopTime());
97 st->setBytes(getBytes());
98 st->setFileType(getFileType());
100 boost::mutex::scoped_lock lock(io_mutex);
101 _netstats.push_back(st);
103 return _netstats.size();
106 void
107 Statistics::dump() {
108 boost::mutex::scoped_lock lock(io_mutex);
109 std::list<NetStats *>::iterator it;
111 for (it = _netstats.begin(); it != _netstats.end(); it++) {
112 NetStats *stats = (*it);
113 if (stats->getFileType() <= VIDEO) {
114 log_debug (_("Stream type is: %s"), filetype_names[stats->getFileType()]);
116 // if (((stats->getFileType() == VIDEO) || (stats->getFileType() == AUDIO)) &&
117 // stats->getCodec() <= VP7) {
118 // log_debug (_("Stream codec is: %s"), codec_names[stats->getCodec()]);
119 // }
120 log_debug (_("%d bytes were transfered in %s seconds"),
121 stats->getBytes(),
122 to_simple_string(stats->getTimeSpan()).c_str());
126 } // end of gnash namespace
128 // local Variables:
129 // mode: C++
130 // indent-tabs-mode: t
131 // End: