Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 2af680b

Browse files
authored
Add debug environment for analytics (#925)
* Add debug environment variables for analytics
1 parent 43f2caf commit 2af680b

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

source/agent/analytics/videoGstPipeline/GstInternalIn.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#include <gst/gst.h>
77
#include <stdio.h>
88

9+
static void dump(void* index, uint8_t* buf, int len)
10+
{
11+
char dumpFileName[128];
12+
13+
snprintf(dumpFileName, 128, "/tmp/analyticsIn-%p", index);
14+
FILE* bsDumpfp = fopen(dumpFileName, "ab");
15+
if (bsDumpfp) {
16+
fwrite(buf, 1, len, bsDumpfp);
17+
fclose(bsDumpfp);
18+
}
19+
}
920

1021
DEFINE_LOGGER(GstInternalIn, "GstInternalIn");
1122
GstInternalIn::GstInternalIn(GstAppSrc *data, unsigned int minPort, unsigned int maxPort)
@@ -20,7 +31,12 @@ GstInternalIn::GstInternalIn(GstAppSrc *data, unsigned int minPort, unsigned int
2031
appsrc = data;
2132
m_needKeyFrame = true;
2233
m_start = false;
23-
34+
m_dumpIn = false;
35+
char* pIn = std::getenv("DUMP_ANALYTICS_IN");
36+
if(pIn != NULL) {
37+
ELOG_INFO("Dump analytics in stream");
38+
m_dumpIn = true;
39+
}
2440
}
2541

2642
GstInternalIn::~GstInternalIn()
@@ -49,8 +65,6 @@ void GstInternalIn::onTransportData(char* buf, int len)
4965
{
5066
if(!m_start) {
5167
ELOG_INFO("Not start yet, stop pushing data to appsrc\n");
52-
pthread_t tid;
53-
tid = pthread_self();
5468
return;
5569
}
5670

@@ -88,6 +102,10 @@ void GstInternalIn::onTransportData(char* buf, int len)
88102
memcpy(map.data, frame, headerLength);
89103
memcpy(map.data + headerLength, frame->payload, payloadLength);
90104

105+
if(m_dumpIn) {
106+
dump(this, map.data, map.size);
107+
}
108+
91109
gst_buffer_unmap(buffer, &map);
92110
g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret);
93111

source/agent/analytics/videoGstPipeline/GstInternalIn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class GstInternalIn : public owt_base::RawTransportListener{
3333
private:
3434
bool m_start;
3535
bool m_needKeyFrame;
36+
bool m_dumpIn;
3637
GstAppSrc *appsrc;
3738
boost::shared_ptr<owt_base::RawTransportInterface> m_transport;
3839
};

source/agent/analytics/videoGstPipeline/VideoGstAnalyzer.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,31 @@ inline bool isVp8KeyFrame(uint8_t *data, size_t len)
6767
return (key_frame == 0);
6868
}
6969

70+
static void dump(void* index, uint8_t* buf, int len)
71+
{
72+
char dumpFileName[128];
73+
74+
snprintf(dumpFileName, 128, "/tmp/analyticsOut-%p", index);
75+
FILE* bsDumpfp = fopen(dumpFileName, "ab");
76+
if (bsDumpfp) {
77+
fwrite(buf, 1, len, bsDumpfp);
78+
fclose(bsDumpfp);
79+
}
80+
}
81+
7082
VideoGstAnalyzer::VideoGstAnalyzer() {
7183
ELOG_INFO("Init");
7284
sourceid = 0;
7385
sink = NULL;
7486
encoder_pad = NULL;
7587
addlistener = false;
7688
m_frameCount = 0;
89+
m_dumpOut = false;
90+
char* pOut = std::getenv("DUMP_ANALYTICS_OUT");
91+
if(pOut != NULL) {
92+
ELOG_INFO("Dump analytics Out stream");
93+
m_dumpOut = true;
94+
}
7795
}
7896

7997
VideoGstAnalyzer::~VideoGstAnalyzer() {
@@ -100,7 +118,6 @@ gboolean VideoGstAnalyzer::StreamEventCallBack(GstBus *bus, GstMessage *message,
100118
g_error_free(err);
101119
g_free(debug);
102120
g_main_loop_quit(pStreamObj->loop);
103-
104121
break;
105122
}
106123
case GST_MESSAGE_EOS:
@@ -238,6 +255,9 @@ void VideoGstAnalyzer::new_sample_from_sink (GstElement * source, gpointer data)
238255
outFrame.payload = map.data;
239256

240257
pStreamObj->m_gstinternalout->onFrame(outFrame);
258+
if(pStreamObj->m_dumpOut) {
259+
dump(pStreamObj, map.data, map.size);
260+
}
241261

242262
gst_buffer_unmap(buffer, &map);
243263
gst_sample_unref(sample);

source/agent/analytics/videoGstPipeline/VideoGstAnalyzer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class VideoGstAnalyzer{
8686
int framerate,bitrate;
8787
int kfi; //keyFrameInterval
8888
bool addlistener;
89+
bool m_dumpOut;
8990
};
9091

9192
}

0 commit comments

Comments
 (0)