2

The webrtc repository has an internal sample application, named sample_test_webrtc (the folder's name where it's implementation resides). I built it using gn and ninja and it works.

Then I took that code separately, statically linked it with libwebrtc.a that I generated using the command below:

./buildtools/linux64/gn gen out/Default --target_cpu=x64 --target_os="linux" --host_os="linux" --host_cpu="x64" --args="is_debug=false rtc_include_tests=false libyuv_include_tests=false rtc_build_examples=false 
is_component_build=false use_rtti=true use_custom_libcxx=false rtc_enable_protobuf=false clang_use_chrome_plugins=false rtc_ios_macos_use_opengl_rendering=false rtc_libvpx_build_vp9=false archive_seed_corpus=false 
toolkit_views=false enable_iterator_debugging=false enable_libaom=false rtc_build_tools=false" --complete_static_lib

In order to separately compile and link this sample program with the such generated library, I used the following makefile:

CC = clang++
CFLAGS = -Wall -g -DWEBRTC_POSIX -std=c++17 -stdlib=libstdc++

SRC_DIR = $(PWD)
SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/*/*.cpp) 

OBJ_DIR = $(PWD)/Obj
OBJ_FILES = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES)) 
ADDITIONAL_OBJ_FILES = $(PWD)/Deps/*.o

INCLUDES_PATH = -I. -I/home/stefan/webrtc-l4s/webrtc_native/m104/src -I../../third_party/webrtc/buildtools/third_party -I../../third_party/webrtc/third_party/abseil-cpp/ 
LIBRARIES_PATH = -L../../third_party/webrtc/buildtools/third_party -L/home/stefan/webrtc-l4s/webrtc_native/m104/src/out/Default2/obj
#use portable -pthread instead of classic -lpthread
LIBS = -pthread -ldl -lX11 -L. -lwebrtc  

BIN_DIR = $(PWD)/Bin
TARGET_BINARY = $(BIN_DIR)/demoWebrtc.bin

all: $(TARGET_BINARY)
    @echo "[Build log] Target binary successfully built!"

$(TARGET_BINARY): $(OBJ_FILES)
    @echo "[Build log] Linking..." 
    @echo $(ADDITIONAL_OBJ_FILES)
    $(CC) $(LIBRARIES_PATH) -o $@ $^ $(LIBS)
    @echo "[Build log] Program linked!" 

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
    @echo "[Build log] Compiling..."
    $(CC) $(CFLAGS) $(INCLUDES_PATH) -c $< -o $@
    @echo "[Build log] File" $< "compiled!"  

clean:
    rm -rf $(OBJ_DIR)/*.o
    rm -rf $(BIN_DIR)/*.bin

That said, my program is successfully compiled and linked, with the executable demoWebrtc.bin being generated. Nonetheless, when I run it, it fails with the following error:

demoWebrtc.bin: ../nptl/pthread_mutex_lock.c:81: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed.
Aborted (core dumped)

I examined the error and it indicates a thread aims to acquire again a mutex it already had locked, in method bool SequenceCheckerImpl::IsCurrent() const from src/rtc_base/synchronization/sequence_checker_internal.cc file, that can be found in webrtc's repository: https://webrtc.googlesource.com/src/+/refs/heads/main/rtc_base/synchronization/sequence_checker_internal.cc. However, I am 100% sure the problem is not the webrtc implementation. As I use the same test application (same source code), I am also quite sure it is not the problem with the code using the library.

The code for sample_test_webrtc can also be found in another repository: https://github.com/MemeTao/webrtc-native-examples/tree/master/src/video-channel. But, in my case, it was included in the webrtc repository I pulled.

My question is: why does not this error occur in the first case, when I built the program using gn and ninja, that works smoothly? Or what I miss in my second case, thus leading to the mutex error?

Later edit: since it is a threading issue, I found this topic WebRTC Peer to Peer Connection. I applied the proposed solution, but it did not solve my issue.

1
  • Please extract a minimal reproducible example, I'm sure it would answer your questions on the way. That said, if a mutex is already owned by a thread, you could look through the stack trace to find out where it is already locked. Commented Jan 16, 2024 at 11:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.