-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Added events from mediaStream to ErizoJS #1194
Added events from mediaStream to ErizoJS #1194
Conversation
erizoAPI/MediaStream.h
Outdated
static Nan::Persistent<v8::Function> constructor; | ||
|
||
static NAUV_WORK_CB(statsCallback); | ||
virtual void notifyStats(const std::string& message); | ||
|
||
static NAUV_WORK_CB(eventCallback); | ||
virtual void notifyMediaStreamEvent(const std::string& message = "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be (type, message)
instead of (message, stream_id)
?
erizo/src/erizo/WebRtcConnection.cpp
Outdated
@@ -540,6 +536,15 @@ void WebRtcConnection::onTransportData(std::shared_ptr<DataPacket> packet, Trans | |||
} | |||
} | |||
|
|||
void WebRtcConnection::maybeNotifyWebRtcConnectionEvent(const WebRTCEvent& event, const std::string& message, | |||
const std::string& stream_id) { | |||
boost::mutex::scoped_lock lock(eventlistener_mutex_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 to this mutex
erizoAPI/MediaStream.cc
Outdated
uv_close(reinterpret_cast<uv_handle_t*>(async_stats_), destroyAsyncStats); | ||
} | ||
async_stats_ = nullptr; | ||
if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(async_event_))) { | ||
ELOG_DEBUG("%s, message: Closing MediaStreamEvent handle", toLog()); | ||
uv_close(reinterpret_cast<uv_handle_t*>(async_event_), destroyAsyncStats); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should call another function to destroy the async_event_ handle.
erizoAPI/MediaStream.h
Outdated
@@ -48,10 +49,13 @@ class MediaStream : public MediaSink, public erizo::MediaStreamStatsListener { | |||
void close(); | |||
std::string toLog(); | |||
|
|||
Nan::Callback *statsCallback_; | |||
Nan::Callback *eventCallback_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: event_callback_
erizoAPI/MediaStream.h
Outdated
Nan::Callback *statsCallback_; | ||
Nan::Callback *eventCallback_; | ||
uv_async_t *async_event_; | ||
bool hasEventCallback_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: has_event_callback_
erizoAPI/MediaStream.h
Outdated
uv_async_t *async_stats_; | ||
bool hasCallback_; | ||
bool hasStatsCallback_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: has_stats_callback_
erizo/src/erizo/WebRtcConnection.h
Outdated
@@ -182,7 +181,8 @@ class WebRtcConnection: public TransportListener, public LogContext, | |||
std::shared_ptr<Stats> stats_; | |||
WebRTCEvent global_state_; | |||
|
|||
boost::mutex updateStateMutex_; // , slideShowMutex_; | |||
boost::mutex update_state_mutex_; | |||
boost::mutex eventlistener_mutex_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: event_listener_mutex_
?
erizo/src/erizo/MediaStream.h
Outdated
@@ -148,6 +162,8 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink, | |||
// parses incoming payload type, replaces occurence in buf | |||
|
|||
private: | |||
boost::mutex eventlistener_mutex_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: event_listener_mutex_
?
erizo/src/erizo/MediaStream.h
Outdated
@@ -148,6 +162,8 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink, | |||
// parses incoming payload type, replaces occurence in buf | |||
|
|||
private: | |||
boost::mutex eventlistener_mutex_; | |||
MediaStreamEventListener* mediastream_event_listener_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: media_stream_event_listener_
?
erizoAPI/MediaStream.cc
Outdated
NAUV_WORK_CB(MediaStream::statsCallback) { | ||
Nan::HandleScope scope; | ||
MediaStream* obj = reinterpret_cast<MediaStream*>(async->data); | ||
if (!obj || !obj->me) { | ||
return; | ||
} | ||
boost::mutex::scoped_lock lock(obj->mutex); | ||
if (obj->hasCallback_) { | ||
if (obj->hasStatsCallback_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now think we should block any access to hasStatsCallback_ and statsCallback_ with a mutex too, since they can be accessed from multiple threads (e.g. MediaStream::close, MediaStream::notifyMediaStreamEvent, and MediaStream::statsCallback). And the same happens to the rest of callbacks. We can do it in a separate PR though, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
This PR implements an event channel from MediaStream in erizo to ErizoJS.
As an added bonus, this PR also adds locks protecting the event listeners in both
WebRtcConnection
andStats
,[] It needs and includes Unit Tests
Changes in Client or Server public APIs
[] It includes documentation for these changes in
/doc
.