8000 Merge pull request #16 from MarshalX/main · MarshalX/python-webrtc@b331293 · GitHub
[go: up one dir, main page]

Skip to content

Commit b331293

Browse files
authored
Merge pull request #16 from MarshalX/main
0.0.7 dev
2 parents 5ca9dd4 + 3277ff8 commit b331293

File tree

13 files changed

+157
-18
lines changed

13 files changed

+157
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project(python_webrtc
77
LANGUAGES C CXX
88
DESCRIPTION "a Python extension that provides bindings to WebRTC"
99
HOMEPAGE_URL "https://github.com/MarshalX/python-webrtc"
10-
VERSION "0.0.0.6"
10+
VERSION "0.0.0.7"
1111
)
1212

1313
include(ExternalProject)
@@ -169,12 +169,6 @@ else()
169169
use_glib=false
170170
rtc_build_tools=false
171171
)
172-
173-
if ("$ENV{TARGET_ARCH}" STREQUAL "ia32")
174-
list(APPEND GN_GEN_ARGS
175-
target_arch=ia32
176-
)
177-
endif()
178172
endif()
179173

180174
if (WIN32)

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TODO (MarshalX) make it more pretty
2+
PATH_TO_WRTC_SO = ../../build/lib.macosx-12.1-arm64-3.10/wrtc.cpython-310-darwin.so
3+
PATH_TO_PY_MODULES = ./python-webrtc/python
4+
5+
RUN_TESTS = pytest
6+
RUN_TESTS_OPTS ?= -vv -W ignore:::wrtc -W ignore:::pkg_resources
7+
TESTS_DIR = tests
8+
9+
export PATH_TO_LIB=${PATH_TO_WRTC_SO}
10+
export PYTHONPATH=${PATH_TO_PY_MODULES}
11+
12+
test:
13+
@${RUN_TESTS} ${TESTS_DIR} ${RUN_TESTS_OPTS} $(O)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
## Python WebRTC
2222

23-
> Stop making unstandard pure implementations of WebRTC and let's use the native library!
23+
> Let's use the native WebRTC with strict compatibility and fully implemented stuff!
2424
2525
This project follows the [W3C specification](https://w3c.github.io/webrtc-pc/) with some modifications and additions to make it work better with Python applications, with useful APIs like programmatic audio and video.
2626

2727
## DISCLAIMER
2828

29-
This project is still under development and isn't ready for any serious use! In the current stage it's possible to establish connection and work with audio with a large number of segfaults and sigbuses. ✨
29+
This project is still under development and isn't ready for any serious use. In the current stage, it's possible to establish connection and work with audio, but many interfaces and methods not implemented yet.
3030

3131
#### Snippet
3232

build/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
ARG MANYLINUX_ARCH
2-
# celf pathed cpython https://github.com/MarshalX/manylinux-cpython-pathes
2+
# self pathed cpython https://github.com/MarshalX/manylinux-cpython-pathes
33
FROM quay.io/pypa_patched/manylinux_2_24_$MANYLINUX_ARCH AS builder
44

55
RUN apt-get update && apt-get install -y xz-utils libxml2 wget build-essential
66

77
WORKDIR /opt
88
RUN wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-7.5.0/gcc-7.5.0.tar.gz && \
9-
tar zxf gcc-7.5.0.tar.gz
10-
WORKDIR gcc-7.5.0
11-
RUN ./contrib/download_prerequisites && \
9+
tar zxf gcc-7.5.0.tar.gz && \
10+
cd gcc-7.5.0 && \
11+
./contrib/download_prerequisites && \
1212
./configure --disable-multilib && \
1313
make -j $(nproc) && \
14-
make install
14+
make install && \
15+
cd .. && \
16+
rm -rf gcc-7.5.0 && \
17+
rm gcc-7.5.0.tar.gz

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
asyncio_mode = strict

python-webrtc/cpp/src/functions/functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace python_webrtc {
1313

1414
void Functions::Init(pybind11::module &m) {
15-
m.def("getUserMedia", &GetUserMedia, pybind11::return_value_policy::move);
15+
m.def("getUserMedia", &GetUserMedia, pybind11::return_value_policy::reference);
1616
}
1717

1818
}

python-webrtc/cpp/src/functions/get_user_media.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace python_webrtc {
1111

12-
static std::unique_ptr<MediaStream> GetUserMedia() {
12+
static MediaStream *GetUserMedia() {
1313
// TODO GetUserMediaImpl should be asynced method ?
1414
auto factory = PeerConnectionFactory::GetOrCreateDefault();
1515
auto stream = factory->factory()->CreateLocalMediaStream(rtc::CreateRandomUuid());
@@ -32,7 +32,7 @@ namespace python_webrtc {
3232
// stream->AddTrack(track);
3333
}
3434

35-
return std::make_unique<MediaStream>(factory, stream);
35+
return MediaStream::holder()->GetOrCreate(factory, stream);
3636
}
3737

3838
} // namespace python_webrtc

python-webrtc/python/webrtc/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ def _wrap_many(cls, items) -> List['WebRTCObject']:
3535

3636
def __repr__(self):
3737
return f'<webrtc.{self.__class__.__name__} object at {hex(id(self))}'
38+
39+
def __eq__(self, other):
40+
if isinstance(other, WebRTCObject):
41+
return id(self._native_obj) == id(other._native_obj)
42+
43+
return super().__eq__(other)

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
black
1+
black
2+
pytest-asyncio

tests/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style license
5+
# that can be found in the LICENSE.md file in the root of the project.
6+
#

tests/conftest.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style license
5+
# that can be found in the LICENSE.md file in the root of the project.
6+
#
7+
8+
import pytest
9+
10+
import webrtc
11+
12+
13+
# alias for rtc_peer_connection
14+
@pytest.fixture
15+
def pc(rtc_peer_connection):
16+
return rtc_peer_connection
17+
18+
19+
@pytest.fixture
20+
def rtc_peer_connection(request):
21+
pc = webrtc.RTCPeerConnection()
22+
23+
def close_pc():
24+
pc.close()
25+
26+
request.addfinalizer(close_pc)
27+
28+
return pc
29+
30+
31+
def get_stream(constraints, request):
32+
# TODO pass constraints when cpp part will be ready
33+
stream = webrtc.get_user_media()
34+
35+
def stop_tracks():
36+
for track in stream.get_tracks():
37+
track.stop()
38+
39+
request.addfinalizer(stop_tracks)
40+
41+
return stream
42+
43+
44+
@pytest.fixture
45+
def audio_stream(request):
46+
return get_stream(None, request)
47+
48+
49+
@pytest.fixture
50+
def video_stream(request):
51+
return get_stream(None, request)

tests/rtc_peer_connection/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style license
5+
# that can be found in the LICENSE.md file in the root of the project.
6+
#
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style license
5+
# that can be found in the LICENSE.md file in the root of the project.
6+
#
7+
8+
import pytest
9+
10+
import webrtc
11+
12+
13+
def test_on_closed_pc(pc, audio_stream):
14+
track, *_ = audio_stream.get_audio_tracks()
15+
pc.close()
16+
17+
with pytest.raises(webrtc.PythonWebRTCException):
18+
pc.add_track(track, audio_stream)
19+
20+
21+
def test_sender_creation(pc, audio_stream):
22+
track, *_ = audio_stream.get_audio_tracks()
23+
24+
sender = pc.add_track(track, audio_stream)
25+
26+
assert isinstance(sender, webrtc.RTCRtpSender)
27+
28+
29+
def test_adding_of_the_same_track(pc, audio_stream):
30+
track, *_ = audio_stream.get_audio_tracks()
31+
32+
pc.add_track(track, audio_stream)
33+
34+
with pytest.raises(webrtc.RTCException):
35+
pc.add_track(track, audio_stream)
36+
37+
38+
def test_sender_and_transceivers(pc, audio_stream):
39+
track, *_ = audio_stream.get_audio_tracks()
40+
41+
sender = pc.add_track(track, audio_stream)
42+
43+
assert isinstance(sender, webrtc.RTCRtpSender)
44+
45+
assert track == sender.track
46+
47+
return
48+
# when we ready in cpp
49+
transceivers = pc.get_transceivers()
50+
assert len(transceivers) == 1
51+
52+
transceiver, *_ = transceivers
53+
assert transceiver.sender == server
54+
55+
assert [sender] == pc.get_senders()
56+
57+
# assert kind and list of receivers

0 commit comments

Comments
 (0)
0