Skip to content

Commit 25f45f8

Browse files
authored
Merge pull request #553 from ElderOrb/qcli-bugfix
Attempt to resolve first frame-related weirdness/crashes etc.
2 parents fb42f54 + 8156ca5 commit 25f45f8

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

Source/Core/CommonStats.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ CommonStats::CommonStats (const struct per_item* PerItem_, int Type_, size_t Cou
4646
additionalIntStats(nullptr),
4747
additionalStringStats(nullptr)
4848
{
49-
// Adaptation for having a graph even with 1 frame
50-
if (FrameCount<2)
51-
FrameCount=2;
5249

5350
int sizeOfLastStatsIndex = sizeof lastStatsIndexByValueType;
5451
memset(lastStatsIndexByValueType, 0, sizeOfLastStatsIndex);
@@ -193,7 +190,7 @@ CommonStats::~CommonStats()
193190
void CommonStats::processAdditionalStats(const char* key, const char* value, bool statsMapInitialized)
194191
{
195192
if(!statsMapInitialized) {
196-
auto type = StatsValueInfo::typeFromKey(key);
193+
auto type = StatsValueInfo::typeFromKey(key, value);
197194
auto stats = StatsValueInfo {
198195
lastStatsIndexByValueType[type]++, type, value
199196
};
@@ -315,7 +312,6 @@ void CommonStats::StatsFinish ()
315312
x[3][1]=durations[0]?(durations[0]/3600):1; //forcing to 1 in case duration is not available
316313
for (size_t Plot_Pos=0; Plot_Pos<CountOfItems; Plot_Pos++)
317314
y[Plot_Pos][1]= y[Plot_Pos][0];
318-
x_Current++;
319315
}
320316

321317
// Forcing max values to the last real ones, in case max values were estimated

Source/Core/CommonStats.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#define CommonStats_H
1010

1111
#include <string>
12+
#include <string.h>
1213
#include <vector>
1314
#include <map>
1415
#include <stdint.h>
1516
#include <algorithm>
17+
#include <cctype>
1618
#include <Core/Core.h>
1719

1820
using namespace std;
@@ -85,7 +87,25 @@ class CommonStats
8587
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
8688
}
8789

88-
static Type typeFromKey(const std::string& key) {
90+
static bool is_number(const std::string& s)
91+
{
92+
int dotCount = 0;
93+
if (s.empty())
94+
return false;
95+
96+
for (char c : s )
97+
{
98+
if ( !(std::isdigit(c) || c == '.' ) && dotCount > 1 )
99+
{
100+
return false;
101+
}
102+
dotCount += (c == '.');
103+
}
104+
105+
return true;
106+
}
107+
108+
static Type typeFromKey(const std::string& key, const char* value) {
89109
static const char* IntEndings[] = {
90110
"MIN",
91111
"LOW",
@@ -112,7 +132,28 @@ class CommonStats
112132
return String;
113133
}
114134

115-
return Double;
135+
// try to deduce type..
136+
if(is_number(value)) {
137+
if(strstr(value, ".") != nullptr) {
138+
try {
139+
std::stod(value);
140+
return Double;
141+
}
142+
catch(const std::exception& ex) {
143+
144+
}
145+
} else {
146+
try {
147+
std::stoi(value);
148+
return Int;
149+
}
150+
catch(const std::exception& ex) {
151+
152+
}
153+
}
154+
}
155+
156+
return String;
116157
}
117158
};
118159
typedef std::string StringStatsKey;

Source/Core/FFmpeg_Glue.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ void FFmpeg_Glue::outputdata::ApplyFilter(const AVFramePtr& sourceFrame)
465465

466466
// Pull filtered frames from the filtergraph
467467
FilteredFrame = AVFramePtr(av_frame_alloc(), FilteredFrameDeleter::free);
468-
av_frame_copy_props(FilteredFrame.get(), sourceFrame.get());
468+
469+
if(sourceFrame) {
470+
av_frame_copy_props(FilteredFrame.get(), sourceFrame.get());
471+
}
469472

470473
int GetAnswer = av_buffersink_get_frame(FilterGraph_Sink_Context, FilteredFrame.get()); //TODO: handling of multiple output per input
471474
if (GetAnswer==AVERROR(EAGAIN) || GetAnswer==AVERROR_EOF)
@@ -1319,6 +1322,13 @@ bool FFmpeg_Glue::OutputFrame(AVPacket* TempPacket, bool Decode)
13191322
{
13201323
TempPacket->data+=TempPacket->size;
13211324
TempPacket->size=0;
1325+
1326+
for (size_t OutputPos=0; OutputPos<OutputDatas.size(); OutputPos++)
1327+
if (OutputDatas[OutputPos] && OutputDatas[OutputPos]->Enabled && OutputDatas[OutputPos]->Stream==InputData->Stream) {
1328+
if(!OutputDatas[OutputPos]->Filter.empty()) // flush delayed filtered frames
1329+
OutputDatas[OutputPos]->Process(nullptr);
1330+
}
1331+
13221332
return false;
13231333
}
13241334
TempPacket->data+=Bytes;

0 commit comments

Comments
 (0)