10000 0.0.6 dev by MarshalX · Pull Request #11 · MarshalX/python-webrtc · GitHub
[go: up one dir, main page]

Skip to content

0.0.6 dev #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add bind of RTCError, SdpParseError and common exceptions;
add onFailure callbacks for async methods;
fix segfault in close method of peer connection;
update stub;
bump dev version.
  • Loading branch information
MarshalX committed Feb 10, 2022
commit 899694dc93d1481fb6ffc279132fc0161a109c2a
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ include(ExternalProject)

project(python_webrtc
LANGUAGES C CXX
DESCRIPTION "a Python Extension that provides bindings to WebRTC"
DESCRIPTION "a Python extension that provides bindings to WebRTC"
HOMEPAGE_URL "https://github.com/MarshalX/python-webrtc"
VERSION "0.0.0.5"
VERSION "0.0.0.6"
)

include(ExternalProject)
Expand Down
28 changes: 24 additions & 4 deletions docs/links/wrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import typing

__all__ = [
"CallbackPythonWebRTCException",
"MediaStream",
"MediaStreamSourceState",
"MediaStreamTrack",
"MediaStreamTrackState",
"PeerConnectionFactory",
"PythonWebRTCException",
"PythonWebRTCExceptionBase",
"RTCAudioSource",
"RTCCallbackException",
"RTCException",
"RTCIceConnectionState",
"RTCIceGatheringState",
"RTCOnDataEvent",
Expand All @@ -18,6 +23,7 @@
"RTCSdpType",
"RTCSessionDescription",
"RTCSessionDescriptionInit",
"SdpParseException",
"answer",
"checking",
"closed",
Expand All @@ -42,6 +48,9 @@
]


class CallbackPythonWebRTCException():
def what(self) -> str: ...
pass
class MediaStream():
def addTrack(self, arg0: MediaStreamTrack) -> None: ...
def clone(self) -> MediaStream: ...
Expand Down Expand Up @@ -170,11 +179,20 @@ def getOrCreateDefault() -> PeerConnectionFactory: ...
@staticmethod
def release() -> None: ...
pass
class PythonWebRTCExceptionBase(Exception, BaseException):
pass
class PythonWebRTCException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
class RTCAudioSource():
def __init__(self) -> None: ...
def createTrack(self) -> MediaStreamTrack: ...
def onData(self, arg0: RTCOnDataEvent) -> None: ...
pass
class RTCCallbackException():
def what(self) -> str: ...
pass
class RTCException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
class RTCIceConnectionState():
"""
Members:
Expand Down Expand Up @@ -306,10 +324,10 @@ def __init__(self) -> None: ...
@staticmethod
def addTrack(*args, **kwargs) -> typing.Any: ...
def close(self) -> None: ...
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None]) -> None: ...
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: RTCSessionDescription) -> None: ...
def createAnswer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
def createOffer(self, arg0: typing.Callable[[RTCSessionDescription], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None]) -> None: ...
def setLocalDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
def setRemoteDescription(self, arg0: typing.Callable[[], None], arg1: typing.Callable[[CallbackPythonWebRTCException], None], arg2: RTCSessionDescription) -> None: ...
pass
class RTCPeerConnectionState():
"""
Expand Down Expand Up @@ -430,6 +448,8 @@ def type(self) -> RTCSdpType:
def type(self, arg0: RTCSdpType) -> None:
pass
pass
class SdpParseException(PythonWebRTCExceptionBase, Exception, BaseException):
pass
def getUserMedia() -> MediaStream:
pass
def ping() -> None:
Expand Down
53 changes: 53 additions & 0 deletions python-webrtc/cpp/src/exceptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE.md file in the root of the project.
//

#include "exceptions.h"

namespace python_webrtc {

const char *CallbackPythonWebRTCException::what() const noexcept {
return _msg.c_str();
}

[[nodiscard]] const char *PythonWebRTCException::what() const noexcept {
return _msg.c_str();
}

void Exceptions::Init(pybind11::module &m) {
pybind11::class_<CallbackPythonWebRTCException>(m, "CallbackPythonWebRTCException")
.def("what", &CallbackPythonWebRTCException::what);
pybind11::class_<RTCCallbackException>(m, "RTCCallbackException")
.def("what", &RTCCallbackException::what);

static pybind11::exception<PythonWebRTCException> baseExc(m, "PythonWebRTCExceptionBase");

pybind11::register_exception<PythonWebRTCException>(m, "PythonWebRTCException", baseExc);
pybind11::register_exception<RTCException>(m, "RTCException", baseExc);
pybind11::register_exception<SdpParseException>(m, "SdpParseException", baseExc);
}

RTCException wrapRTCError(const webrtc::RTCError &error) {
std::string msg;
return RTCException(msg + "[" + ToString(error.type()) + "] " + error.message());
}

RTCCallbackException wrapRTCErrorForCallback(const webrtc::RTCError &error) {
std::string msg;
return RTCCallbackException(msg + "[" + ToString(error.type()) + "] " + error.message());
}

SdpParseException wrapSdpParseError(const webrtc::SdpParseError &error) {
std::string msg;

if (error.line.empty()) {
return SdpParseException(msg + error.description);
} else {
return SdpParseException(msg + "Line: " + error.line + ". " + error.description);
}
}

} // namespace python_webrtc
60 changes: 60 additions & 0 deletions python-webrtc/cpp/src/exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright 2022 Il`ya (Marshal) <https://github.com/MarshalX>. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE.md file in the root of the project.
//

#pragma once

#include <pybind11/pybind11.h>

#include <api/rtc_error.h>
#include <api/jsep.h>

namespace python_webrtc {

class CallbackPythonWebRTCException {
public:
explicit CallbackPythonWebRTCException(std::string msg) : _msg(std::move(msg)) {}

[[nodiscard]] const char *what() const noexcept;

private:
std::string _msg;
};

class PythonWebRTCException : public std::exception {
public:
explicit PythonWebRTCException(std::string msg) : _msg(std::move(msg)) {}

[[nodiscard]] const char *what() const noexcept override;

private:
std::string _msg;
};

class RTCException : public PythonWebRTCException {
using PythonWebRTCException::PythonWebRTCException;
};

class SdpParseException : public PythonWebRTCException {
using PythonWebRTCException::PythonWebRTCException;
};

class RTCCallbackException : public CallbackPythonWebRTCException {
using CallbackPythonWebRTCException::CallbackPythonWebRTCException;
};

RTCException wrapRTCError(const webrtc::RTCError &error);

SdpParseException wrapSdpParseError(const webrtc::SdpParseError &error);

RTCCallbackException wrapRTCErrorForCallback(const webrtc::RTCError &error);

class Exceptions {
public:
static void Init(pybind11::module &m);
};

} // namespace python_webrtc
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@

namespace python_webrtc {

CreateSessionDescriptionObserver::CreateSessionDescriptionObserver(
RTCPeerConnection *peer_connection, std::function<void(RTCSessionDescription)> &on_success) {
_on_success = on_success;
_peer_connection = peer_connection;
}

void CreateSessionDescriptionObserver::OnSuccess(webrtc::SessionDescriptionInterface *description) {
// TODO
// ref: https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription/RTCSessionDescription
// Note: This is no longer necessary, however; RTCPeerConnection.setLocalDescription()
// and other methods which take SDP as input now directly accept an object conforming to the
// RTCSessionDescriptionInit dictionary, so you don't have to instantiate an RTCSessionDescription yourself.

_peer_connection->SaveLastSdp(RTCSessionDescriptionInit::Wrap(description));
_on_success(RTCSessionDescription::Wrap(description));
_peerConnection->SaveLastSdp(RTCSessionDescriptionInit::Wrap(description));
_onSuccess(RTCSessionDescription::Wrap(description));
delete description;
}

void CreateSessionDescriptionObserver::OnFailure(webrtc::RTCError) {
// TODO call onFail
void CreateSessionDescriptionObserver::OnFailure(webrtc::RTCError error) {
_onFailure(wrapRTCErrorForCallback(error));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ namespace python_webrtc {

class CreateSessionDescriptionObserver : public webrtc::CreateSessionDescriptionObserver {
public:
explicit CreateSessionDescriptionObserver(RTCPeerConnection *peer_connection,
std::function<void(RTCSessionDescription)> &on_success);
CreateSessionDescriptionObserver(RTCPeerConnection *peerConnection,
std::function<void(RTCSessionDescription)> &onSuccess,
std::function<void(CallbackPythonWebRTCException)> &onFailure) :
_peerConnection(peerConnection), _onSuccess(onSuccess), _onFailure(onFailure) {}

void OnSuccess(webrtc::SessionDescriptionInterface *) override;

void OnFailure(webrtc::RTCError) override;

private:
RTCPeerConnection *_peer_connection;
std::function<void(RTCSessionDescription)> _on_success = nullptr;
std::function<void(std::string)> _on_error = nullptr;
RTCPeerConnection *_peerConnection;
std::function<void(RTCSessionDescription)> _onSuccess = nullptr;
std::function<void(CallbackPythonWebRTCException)> _onFailure = nullptr;
};

} // namespace python_webrtc
Loading
0