SRS 6.0-b0 源码 + danmaku 后端(排除 objs/3rdparty/测试媒体)

This commit is contained in:
RRRosmontis
2026-08-27 21:46:20 +08:00
commit 41b5da7c7e
578 changed files with 237858 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
.PHONY: default clean
default: cpu_profiler
cpu_profiler: cpu_profiler.cc Makefile
g++ -o cpu_profiler cpu_profiler.cc -g -O0 -ansi \
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_and_profiler.a -lpthread
clean:
rm -rf cpu_profiler ./srs.prof* ./*.dSYM
+59
View File
@@ -0,0 +1,59 @@
//
// Copyright (c) 2013-2025 Winlin
//
// SPDX-License-Identifier: MIT
//
/**
@see: https://gperftools.github.io/gperftools/cpuprofile.html
config srs with gperf(to make gperftools):
./configure --with-gperf --jobs=3
set the pprof path if not set:
export PPROF_PATH=`pwd`/../../../objs/pprof
to do cpu profile:
make && rm -f ./srs.prof* && env CPUPROFILE=./srs.prof ./cpu_profiler
$PPROF_PATH --text cpu_profiler ./srs.prof*
to do cpu profile by signal:
make && rm -f ./srs.prof* && env CPUPROFILE=./srs.prof CPUPROFILESIGNAL=12 ./cpu_profiler
$PPROF_PATH --text cpu_profiler ./srs.prof*
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <gperftools/profiler.h>
void cpu_profile_imp() {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 110 * 1024 * 1024; ++j) {
}
printf("cpu profile, loop 110M\n");
printf("press CTRL+C if you want to abort the program.\n");
sleep(3);
}
}
void cpu_profile() {
cpu_profile_imp();
}
void handler(int sig) {
exit(0);
}
int main(int argc, char** argv) {
signal(SIGINT, handler);
// must start profiler manually.
ProfilerStart(NULL);
if (getenv("CPUPROFILESIGNAL")) {
printf("if specified CPUPROFILESIGNAL, use signal to active it: kill -12 %d\n", getpid());
sleep(3);
}
cpu_profile();
// not neccessary to call stop.
//ProfilerStop();
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
.PHONY: default clean
default: heap_checker
heap_checker: heap_checker.cc Makefile
g++ -o heap_checker heap_checker.cc -g -O0 -ansi \
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_and_profiler.a -lpthread
clean:
rm -rf heap_checker ./*.dSYM
+71
View File
@@ -0,0 +1,71 @@
//
// Copyright (c) 2013-2025 Winlin
//
// SPDX-License-Identifier: MIT
//
/**
@see: https://gperftools.github.io/gperftools/heap_checker.html
config srs with gperf(to make gperftools):
./configure --gperf=on --jobs=3
set the pprof path if not set:
export PPROF_PATH=`pwd`/../../../objs/pprof
to check mem leak:
make && env HEAPCHECK=normal ./heap_checker
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <gperftools/profiler.h>
void explicit_leak_imp() {
printf("func leak: do something...\n");
for (int i = 0; i < 1024; ++i) {
char* p = new char[1024];
}
printf("func leak: memory leaked\n");
}
void explicit_leak() {
explicit_leak_imp();
}
char* pglobal = NULL;
void global_leak_imp() {
printf("global leak: do something...\n");
for (int i = 0; i < 1024; ++i) {
pglobal = new char[189];
}
printf("global leak: memory leaked\n");
}
void global_leak() {
global_leak_imp();
}
bool loop = true;
void handler(int sig) {
// we must use signal to notice the main thread to exit normally.
if (sig == SIGINT) {
loop = false;
}
}
int main(int argc, char** argv) {
signal(SIGINT, handler);
global_leak();
printf("press CTRL+C if you want to abort the program.\n");
sleep(3);
if (!loop) {
return 0;
}
explicit_leak();
printf("press CTRL+C if you want to abort the program.\n");
sleep(3);
if (!loop) {
return 0;
}
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
.PHONY: default clean
default: heap_defense
heap_defense: heap_defense.cc Makefile
g++ -o heap_defense heap_defense.cc -g -O0 -ansi \
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_debug.a -lpthread
clean:
rm -rf heap_defense ./*.dSYM
+30
View File
@@ -0,0 +1,30 @@
//
// Copyright (c) 2013-2025 Winlin
//
// SPDX-License-Identifier: MIT
//
/**
@see: https://blog.csdn.net/win_lin/article/details/50461709
config srs with gperf(to make gperftools):
./configure --gperf=on --gmd=on --jobs=3
to check mem corruption:
make && env TCMALLOC_PAGE_FENCE=1 ./heap_defense
*/
#include <stdio.h>
void foo(char* buf) {
buf[16] = 0x0f;
}
void bar(char* buf) {
printf("buf[15]=%#x\n", (unsigned char)buf[15]);
}
int main(int argc, char** argv) {
char* buf = new char[16];
foo(buf);
bar(buf);
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
.PHONY: default clean
default: heap_profiler
heap_profiler: heap_profiler.cc Makefile
g++ -o heap_profiler heap_profiler.cc -g -O0 -ansi \
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_and_profiler.a -lpthread
clean:
rm -f heap_profiler srs.*.heap ./*.dSYM
+48
View File
@@ -0,0 +1,48 @@
//
// Copyright (c) 2013-2025 Winlin
//
// SPDX-License-Identifier: MIT
//
/**
@see: https://gperftools.github.io/gperftools/heapprofile.html
config srs with gperf(to make gperftools):
./configure --with-gperf --jobs=3
set the pprof path if not set:
export PPROF_PATH=`pwd`/../../../objs/pprof
to do mem profile:
make && rm -f srs.*.heap && env HEAPPROFILE=./srs ./heap_profiler
$PPROF_PATH --text heap_profiler ./*.heap
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <gperftools/heap-profiler.h>
void memory_alloc_profile_imp() {
for (int i = 0; i < 2; ++i) {
char* p = new char[110 * 1024 * 1024];
for (int j = 0; j < 110 * 1024 * 1024; ++j) {
p[j] = j;
}
printf("mem profile, increase 110MB\n");
printf("press CTRL+C if you want to abort the program.\n");
sleep(5);
}
}
void memory_alloc_profile() {
memory_alloc_profile_imp();
}
int main(int argc, char** argv) {
// must start profiler manually.
HeapProfilerStart(NULL);
memory_alloc_profile();
// not neccessary to call stop.
//HeapProfilerStop();
return 0;
}