Skip to content

Commit 35027b7

Browse files
committed
Fix 2gb report xml limit on Windows
Windows std::stringstream maximum size is INT_MAX Signed-off-by: Maxime Gervais <[email protected]>
1 parent 692df18 commit 35027b7

File tree

3 files changed

+63
-59
lines changed

3 files changed

+63
-59
lines changed

Source/Core/AudioStats.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,28 @@ void AudioStats::TimeStampFromFrame (const QAVFrame& frame, size_t FramePos)
304304

305305
std::string AudioStats::StatsToXML (const activefilters& filters)
306306
{
307-
std::stringstream Data;
307+
std::string Data;
308308

309309
// Per frame (note: the XML header and footer are not created here)
310310
for (size_t x_Pos=0; x_Pos<x_Current; ++x_Pos)
311311
{
312+
std::stringstream Frame;
312313
std::stringstream pkt_pts_time; pkt_pts_time<<std::fixed<<std::setprecision(7)<<(x[1][x_Pos]+FirstTimeStamp);
313314
std::stringstream pkt_duration_time; pkt_duration_time<<std::fixed<<std::setprecision(7)<<durations[x_Pos];
314315
std::stringstream key_frame; key_frame<< (key_frames[x_Pos]? '1' : '0');
315316

316-
Data<<" <frame media_type=\"audio\"";
317-
Data << " stream_index=\"" << streamIndex << "\"";
317+
Frame<<" <frame media_type=\"audio\"";
318+
Frame << " stream_index=\"" << streamIndex << "\"";
318319

319-
Data<<" key_frame=\"" << key_frame.str() << "\"";
320-
Data << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
321-
Data<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
320+
Frame<<" key_frame=\"" << key_frame.str() << "\"";
321+
Frame << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
322+
Frame<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
322323
if (pkt_duration_time)
323-
Data<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
324-
Data << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
325-
Data << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
324+
Frame<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
325+
Frame << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
326+
Frame << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
326327

327-
Data << ">\n";
328+
Frame << ">\n";
328329

329330
for (size_t Plot_Pos=0; Plot_Pos<Item_AudioMax; Plot_Pos++)
330331
{
@@ -338,13 +339,14 @@ std::string AudioStats::StatsToXML (const activefilters& filters)
338339
const std::string& key = PerItem[Plot_Pos].FFmpeg_Name;
339340
auto value = std::to_string(y[Plot_Pos][x_Pos]);
340341

341-
Data<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
342+
Frame<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
342343
}
343344

344-
writeAdditionalStats(Data, x_Pos);
345+
writeAdditionalStats(Frame, x_Pos);
345346

346-
Data<<" </frame>\n";
347+
Frame<<" </frame>\n";
348+
Data+=Frame.str();
347349
}
348350

349-
return Data.str();
351+
return Data;
350352
}

Source/Core/FileInformation.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,19 +1256,21 @@ void FileInformation::startExport(const QString &exportFileName)
12561256
//---------------------------------------------------------------------------
12571257
void FileInformation::Export_XmlGz (const QString &ExportFileName, const activefilters& filters)
12581258
{
1259-
std::stringstream Data;
1259+
std::string Data;
12601260

12611261
// Header
1262-
Data<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1263-
Data<<"<!-- Created by QCTools " << Version << " -->\n";
1264-
Data<<"<ffprobe:ffprobe xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'>\n";
1265-
Data<<" <program_version version=\"" << FFmpeg_Version() << "\" copyright=\"Copyright (c) 2007-" << FFmpeg_Year() << " the FFmpeg developers\" build_date=\"" __DATE__ "\" build_time=\"" __TIME__ "\" compiler_ident=\"" << FFmpeg_Compiler() << "\" configuration=\"" << FFmpeg_Configuration() << "\"/>\n";
1266-
Data<<"\n";
1267-
Data<<" <library_versions>\n";
1268-
Data<<FFmpeg_LibsVersion();
1269-
Data<<" </library_versions>\n";
1270-
1271-
Data<<" <frames>\n";
1262+
std::stringstream Header;
1263+
Header<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1264+
Header<<"<!-- Created by QCTools " << Version << " -->\n";
1265+
Header<<"<ffprobe:ffprobe xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'>\n";
1266+
Header<<" <program_version version=\"" << FFmpeg_Version() << "\" copyright=\"Copyright (c) 2007-" << FFmpeg_Year() << " the FFmpeg developers\" build_date=\"" __DATE__ "\" build_time=\"" __TIME__ "\" compiler_ident=\"" << FFmpeg_Compiler() << "\" configuration=\"" << FFmpeg_Configuration() << "\"/>\n";
1267+
Header<<"\n";
1268+
Header<<" <library_versions>\n";
1269+
Header<<FFmpeg_LibsVersion();
1270+
Header<<" </library_versions>\n";
1271+
1272+
Header<<" <frames>\n";
1273+
Data+=Header.str();
12721274

12731275
// From stats
12741276
for (size_t Pos=0; Pos<Stats.size(); Pos++)
@@ -1281,12 +1283,13 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
12811283
videoStats->setWidth(m_mediaParser->availableVideoStreams()[0].stream()->codecpar->width);
12821284
videoStats->setHeight(m_mediaParser->availableVideoStreams()[0].stream()->codecpar->height);
12831285
}
1284-
Data<<Stats[Pos]->StatsToXML(filters);
1286+
Data+=Stats[Pos]->StatsToXML(filters);
12851287
}
12861288
}
12871289

12881290
// Footer
1289-
Data<<" </frames>";
1291+
std::stringstream Footer;
1292+
Footer<<" </frames>";
12901293

12911294
QString streamsAndFormats;
12921295
QXmlStreamWriter writer(&streamsAndFormats);
@@ -1305,9 +1308,10 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
13051308
splitted[i] = QString(qAbs(writer.autoFormattingIndent()), writer.autoFormattingIndent() > 0 ? ' ' : '\t') + splitted[i];
13061309
streamsAndFormats = splitted.join("\n");
13071310

1308-
Data<<streamsAndFormats.toStdString() << "\n\n";
1311+
Footer<<streamsAndFormats.toStdString() << "\n\n";
13091312

1310-
Data<<"</ffprobe:ffprobe>";
1313+
Footer<<"</ffprobe:ffprobe>";
1314+
Data+=Footer.str();
13111315

13121316
SharedFile file;
13131317
QString name;
@@ -1323,23 +1327,21 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
13231327
name = info.fileName();
13241328
}
13251329

1326-
std::string DataS=Data.str();
13271330
uLongf Buffer_Size=65536;
1328-
13291331
if(file->open(QIODevice::ReadWrite))
13301332
{
1331-
if (name.endsWith(".qctools.xml"))
1333+
if (name.endsWith(".xml"))
13321334
{
1333-
auto bytesLeft = Data.str().size();
1334-
auto writePtr = DataS.c_str();
1335+
auto bytesLeft = Data.size();
1336+
auto writePtr = Data.c_str();
13351337
auto totalBytesWritten = 0;
13361338

13371339
while (bytesLeft) {
13381340
auto bytesToWrite = std::min(size_t(Buffer_Size), bytesLeft);
13391341
auto bytesWritten = file->write(writePtr, bytesToWrite);
13401342
totalBytesWritten += bytesWritten;
13411343

1342-
Q_EMIT statsFileGenerationProgress(totalBytesWritten, DataS.size());
1344+
Q_EMIT statsFileGenerationProgress(totalBytesWritten, Data.size());
13431345

13441346
writePtr += bytesToWrite;
13451347
bytesLeft -= bytesWritten;
@@ -1348,14 +1350,12 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
13481350
break;
13491351
}
13501352
}
1351-
else if (name.endsWith(".xml"))
1353+
else
13521354
{
1353-
file->write(DataS.c_str(), DataS.length());
1354-
} else {
13551355
char* Buffer=new char[Buffer_Size];
13561356
z_stream strm;
1357-
strm.next_in = (Bytef *) DataS.c_str();
1358-
strm.avail_in = DataS.size() ;
1357+
strm.next_in = (Bytef *) Data.c_str();
1358+
strm.avail_in = Data.size() ;
13591359
strm.total_out = 0;
13601360
strm.zalloc = Z_NULL;
13611361
strm.zfree = Z_NULL;
@@ -1369,7 +1369,7 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
13691369
break;
13701370
file->write(Buffer, Buffer_Size-strm.avail_out);
13711371

1372-
Q_EMIT statsFileGenerationProgress((char*) strm.next_in - DataS.c_str(), DataS.size());
1372+
Q_EMIT statsFileGenerationProgress((char*) strm.next_in - Data.c_str(), Data.size());
13731373
}
13741374
while (strm.avail_out == 0);
13751375
deflateEnd (&strm);

Source/Core/VideoStats.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -439,31 +439,32 @@ void VideoStats::setHeight(int height)
439439
//---------------------------------------------------------------------------
440440
std::string VideoStats::StatsToXML (const activefilters& filters)
441441
{
442-
std::stringstream Data;
442+
std::string Data;
443443

444444
// Per frame (note: the XML header and footer are not created here)
445445
std::stringstream widthStream; widthStream<<width; // Note: we use the same value for all frame, we should later use the right value per frame
446446
std::stringstream heightStream; heightStream<<height; // Note: we use the same value for all frame, we should later use the right value per frame
447447
for (size_t x_Pos=0; x_Pos<x_Current; ++x_Pos)
448448
{
449+
std::stringstream Frame;
449450
std::stringstream pkt_pts_time; pkt_pts_time<<std::fixed<<std::setprecision(7)<<(x[1][x_Pos]+FirstTimeStamp);
450451
std::stringstream pkt_duration_time; pkt_duration_time<<std::fixed<<std::setprecision(7)<<durations[x_Pos];
451452
std::stringstream key_frame; key_frame<<key_frames[x_Pos]?'1':'0';
452-
Data<<" <frame media_type=\"video\"";
453-
Data << " stream_index=\"" << streamIndex << "\"";
453+
Frame<<" <frame media_type=\"video\"";
454+
Frame << " stream_index=\"" << streamIndex << "\"";
454455

455-
Data<<" key_frame=\"" << key_frame.str() << "\"";
456-
Data << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
457-
Data<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
456+
Frame<<" key_frame=\"" << key_frame.str() << "\"";
457+
Frame << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
458+
Frame<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
458459
if (pkt_duration_time)
459-
Data<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
460-
Data << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
461-
Data << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
462-
Data<<" width=\"" << widthStream.str() << "\" height=\"" << heightStream.str() <<"\"";
463-
Data << " pix_fmt=\"" << av_get_pix_fmt_name((AVPixelFormat) pix_fmt[x_Pos]) << "\"";
464-
Data << " pict_type=\"" << pict_type_char[x_Pos] << "\"";
460+
Frame<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
461+
Frame << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
462+
Frame << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
463+
Frame<<" width=\"" << widthStream.str() << "\" height=\"" << heightStream.str() <<"\"";
464+
Frame << " pix_fmt=\"" << av_get_pix_fmt_name((AVPixelFormat) pix_fmt[x_Pos]) << "\"";
465+
Frame << " pict_type=\"" << pict_type_char[x_Pos] << "\"";
465466

466-
Data << ">\n";
467+
Frame << ">\n";
467468

468469
for (size_t Plot_Pos=0; Plot_Pos<Item_VideoMax; Plot_Pos++)
469470
{
@@ -493,16 +494,17 @@ std::string VideoStats::StatsToXML (const activefilters& filters)
493494
value = std::to_string(y[Plot_Pos][x_Pos]);
494495
}
495496

496-
Data<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
497+
Frame<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
497498
}
498499

499-
writeAdditionalStats(Data, x_Pos);
500+
writeAdditionalStats(Frame, x_Pos);
500501

501502
if(comments[x_Pos])
502-
Data<<" <tag key=\"qctools.comment\" value=\"" << comments[x_Pos] << "\"/>\n";
503+
Frame<<" <tag key=\"qctools.comment\" value=\"" << comments[x_Pos] << "\"/>\n";
503504

504-
Data<<" </frame>\n";
505+
Frame<<" </frame>\n";
506+
Data+=Frame.str();
505507
}
506508

507-
return Data.str();
509+
return Data;
508510
}

0 commit comments

Comments
 (0)