| 1 |
#include "StreamInfoPriv.h" |
| 2 |
#include "utils.h" |
| 3 |
#include <stdio.h> |
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
AVM_BEGIN_NAMESPACE; |
| 7 |
|
| 8 |
StreamInfo::StreamInfoPriv::StreamInfoPriv() |
| 9 |
{ |
| 10 |
memset(this, 0, sizeof(*this)); |
| 11 |
} |
| 12 |
|
| 13 |
StreamInfo::StreamInfo() : m_p(new StreamInfoPriv) |
| 14 |
{ |
| 15 |
// FIXME - check other returning values or rewrite this class |
| 16 |
m_p->m_dLengthTime = 0.; |
| 17 |
m_p->m_Type = Video; |
| 18 |
} |
| 19 |
|
| 20 |
StreamInfo::StreamInfo(const StreamInfo& si) : m_p(new StreamInfoPriv) |
| 21 |
{ |
| 22 |
*m_p = *si.m_p; |
| 23 |
} |
| 24 |
|
| 25 |
StreamInfo::~StreamInfo() |
| 26 |
{ |
| 27 |
delete m_p; |
| 28 |
} |
| 29 |
|
| 30 |
StreamInfo::Type StreamInfo::GetType() const |
| 31 |
{ |
| 32 |
return m_p->m_Type; |
| 33 |
} |
| 34 |
|
| 35 |
uint_t StreamInfo::GetFormat() const |
| 36 |
{ |
| 37 |
return m_p->m_uiFormat; |
| 38 |
} |
| 39 |
|
| 40 |
const char* StreamInfo::GetFormatName() const |
| 41 |
{ |
| 42 |
return (m_p->m_Type == Audio) ? |
| 43 |
avm_wave_format_name((short)m_p->m_uiFormat) : avm_fcc_name(m_p->m_uiFormat); |
| 44 |
} |
| 45 |
|
| 46 |
double StreamInfo::GetBps() const |
| 47 |
{ |
| 48 |
return (m_p->m_dLengthTime && m_p->m_dLengthTime < 0x7fffffff && GetStreamSize() > 0) |
| 49 |
? (double) GetStreamSize() / m_p->m_dLengthTime : (double) m_p->m_uiBps; |
| 50 |
} |
| 51 |
|
| 52 |
double StreamInfo::GetFps() const |
| 53 |
{ |
| 54 |
return (m_p->m_dLengthTime) ? GetStreamFrames() / m_p->m_dLengthTime : 0.; |
| 55 |
} |
| 56 |
|
| 57 |
double StreamInfo::GetLengthTime() const |
| 58 |
{ |
| 59 |
return m_p->m_dLengthTime; |
| 60 |
} |
| 61 |
|
| 62 |
int64_t StreamInfo::GetStreamSize() const |
| 63 |
{ |
| 64 |
return m_p->m_uiKfFramesSize + m_p->m_uiFramesSize; |
| 65 |
} |
| 66 |
|
| 67 |
uint_t StreamInfo::GetStreamFrames() const |
| 68 |
{ |
| 69 |
return m_p->m_uiKfFrames + m_p->m_uiFrames; |
| 70 |
} |
| 71 |
|
| 72 |
size_t StreamInfo::GetMaxKfFrameSize() const |
| 73 |
{ |
| 74 |
return m_p->m_uiMaxKfFrameSize; |
| 75 |
} |
| 76 |
|
| 77 |
size_t StreamInfo::GetMinKfFrameSize() const |
| 78 |
{ |
| 79 |
return m_p->m_uiMinKfFrameSize; |
| 80 |
} |
| 81 |
|
| 82 |
size_t StreamInfo::GetAvgKfFrameSize() const |
| 83 |
{ |
| 84 |
return (m_p->m_uiKfFrames > 0) ? (m_p->m_uiKfFramesSize / m_p->m_uiKfFrames) : 0; |
| 85 |
} |
| 86 |
|
| 87 |
int64_t StreamInfo::GetKfFramesSize() const |
| 88 |
{ |
| 89 |
return m_p->m_uiKfFramesSize; |
| 90 |
} |
| 91 |
|
| 92 |
uint_t StreamInfo::GetKfFrames() const |
| 93 |
{ |
| 94 |
return m_p->m_uiKfFrames; |
| 95 |
} |
| 96 |
|
| 97 |
size_t StreamInfo::GetMaxFrameSize() const |
| 98 |
{ |
| 99 |
return m_p->m_uiMaxFrameSize; |
| 100 |
} |
| 101 |
|
| 102 |
size_t StreamInfo::GetMinFrameSize() const |
| 103 |
{ |
| 104 |
return m_p->m_uiMinFrameSize; |
| 105 |
} |
| 106 |
|
| 107 |
size_t StreamInfo::GetAvgFrameSize() const |
| 108 |
{ |
| 109 |
return (m_p->m_uiFrames > 0) ? (m_p->m_uiFramesSize / m_p->m_uiFrames) : 0; |
| 110 |
} |
| 111 |
|
| 112 |
int64_t StreamInfo::GetFramesSize() const |
| 113 |
{ |
| 114 |
return m_p->m_uiFramesSize; |
| 115 |
} |
| 116 |
|
| 117 |
uint_t StreamInfo::GetFrames() const |
| 118 |
{ |
| 119 |
return m_p->m_uiFrames; |
| 120 |
} |
| 121 |
|
| 122 |
size_t StreamInfo::GetSampleSize() const |
| 123 |
{ |
| 124 |
return m_p->m_iSampleSize; |
| 125 |
} |
| 126 |
|
| 127 |
int StreamInfo::GetQuality() const |
| 128 |
{ |
| 129 |
return m_p->m_iQuality; |
| 130 |
} |
| 131 |
|
| 132 |
int StreamInfo::GetVideoWidth() const |
| 133 |
{ |
| 134 |
return (m_p->m_Type == Video) ? m_p->vid.m_iWidth : -1; |
| 135 |
} |
| 136 |
|
| 137 |
int StreamInfo::GetVideoHeight() const |
| 138 |
{ |
| 139 |
return (m_p->m_Type == Video) ? m_p->vid.m_iHeight : -1; |
| 140 |
} |
| 141 |
|
| 142 |
float StreamInfo::GetAspectRatio() const |
| 143 |
{ |
| 144 |
return (m_p->m_Type == Video) ? m_p->vid.m_fAspect : -1; |
| 145 |
} |
| 146 |
|
| 147 |
int StreamInfo::GetAudioChannels() const |
| 148 |
{ |
| 149 |
return (m_p->m_Type == Audio) ? m_p->aud.m_iChannels : -1; |
| 150 |
} |
| 151 |
|
| 152 |
int StreamInfo::GetAudioSamplesPerSec() const |
| 153 |
{ |
| 154 |
return (m_p->m_Type == Audio) ? m_p->aud.m_iSamplesPerSec : -1; |
| 155 |
} |
| 156 |
|
| 157 |
int StreamInfo::GetAudioBitsPerSample() const |
| 158 |
{ |
| 159 |
return (m_p->m_Type == Audio) ? m_p->aud.m_iBitsPerSample : -1; |
| 160 |
} |
| 161 |
|
| 162 |
avm::string StreamInfo::GetString() const |
| 163 |
{ |
| 164 |
double keyproc = 0., delproc = 0.; |
| 165 |
double skeyproc = 0., sdelproc = 0.; |
| 166 |
char buffer[2048]; |
| 167 |
|
| 168 |
if (GetStreamFrames() > 0) |
| 169 |
{ |
| 170 |
keyproc = GetKfFrames()/(double)GetStreamFrames() * 100.; |
| 171 |
delproc = 100. - keyproc; |
| 172 |
skeyproc = (GetStreamSize() > 0) ? (double)GetKfFramesSize()/(double)GetStreamSize() : 0.; |
| 173 |
skeyproc *= 100.; |
| 174 |
sdelproc = 100. - skeyproc; |
| 175 |
} |
| 176 |
|
| 177 |
int i = 0; |
| 178 |
if (m_p->m_Type == Audio) |
| 179 |
{ |
| 180 |
i = sprintf(buffer, " AudioInfo - %s (0x%x) %dHz %db Channels: %d Sample Size: %" PRIsz "\n", |
| 181 |
avm_wave_format_name((short)GetFormat()), GetFormat(), |
| 182 |
GetAudioSamplesPerSec(), |
| 183 |
GetAudioBitsPerSample(), GetAudioChannels(), |
| 184 |
GetSampleSize()); |
| 185 |
} |
| 186 |
else if (m_p->m_Type == Video) |
| 187 |
{ |
| 188 |
char b[4]; |
| 189 |
avm_set_le32(b, GetFormat()); |
| 190 |
i = sprintf(buffer, " VideoInfo - %.4s (0x%x) %dx%d Fps: %.3f Quality: %d\n", |
| 191 |
b, GetFormat(), GetVideoWidth(), GetVideoHeight(), GetFps(), |
| 192 |
GetQuality()); |
| 193 |
} |
| 194 |
|
| 195 |
char tlen[30]; |
| 196 |
sprintf(tlen, "%.2f", GetLengthTime()); |
| 197 |
if (GetLengthTime() >= 0x7fffffff) |
| 198 |
strcpy(tlen, "Live"); |
| 199 |
|
| 200 |
i += sprintf(buffer + i, " Time length: %s Size: %.0f bytes (%.2fKB)\n" |
| 201 |
" Chunks: %d Bps: %.2f kbps (%.2fKB/s)\n", |
| 202 |
tlen, (double)GetStreamSize(), (double)GetStreamSize() / 1024., |
| 203 |
GetStreamFrames(), GetBps() * 8 / 1000, GetBps() / 1024.); |
| 204 |
|
| 205 |
if (m_p->m_Type == Video) |
| 206 |
{ |
| 207 |
if (GetMinKfFrameSize() != ~0U || GetMinFrameSize() != ~0U) |
| 208 |
|
| 209 |
i += sprintf(buffer + i, |
| 210 |
" Key frames/size %.2f%% (%.2f%%) delta frames/size %.2f%%\n" |
| 211 |
" Min/avg/max/total key frame size: %" PRIsz "/%" PRIsz "/%" PRIsz " (%.2fKB) in %d frames\n" |
| 212 |
" Min/avg/max/total delta frame size: %" PRIsz "/%" PRIsz "/%" PRIsz "(%.2fKB) in %d frames\n", |
| 213 |
|
| 214 |
keyproc, skeyproc, sdelproc, |
| 215 |
|
| 216 |
GetMinKfFrameSize(), GetAvgKfFrameSize(), GetMaxKfFrameSize(), |
| 217 |
(double)GetKfFramesSize() / 1024., GetKfFrames(), |
| 218 |
|
| 219 |
GetMinFrameSize(), GetAvgFrameSize(), GetMaxFrameSize(), |
| 220 |
(double)GetFramesSize() / 1024., GetFrames()); |
| 221 |
} |
| 222 |
else if (m_p->m_Type == Audio) |
| 223 |
{ |
| 224 |
if (GetMinKfFrameSize() != ~0U || GetMinFrameSize() != ~0U) |
| 225 |
i += sprintf(buffer + i, |
| 226 |
" Min/avg/max/total chunk size: %" PRIsz "/%" PRIsz "/%" PRIsz " (%.2fKB) in %d frames\n", |
| 227 |
GetMinKfFrameSize(), GetAvgKfFrameSize(), GetMaxKfFrameSize(), |
| 228 |
(double)GetKfFramesSize() / 1024., GetKfFrames()); |
| 229 |
} |
| 230 |
|
| 231 |
return avm::string(buffer); |
| 232 |
} |
| 233 |
|
| 234 |
AVM_END_NAMESPACE; |