Skip to content
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

Merged
merged 5 commits into from
Apr 12, 2018

Conversation

lodoyun
Copy link
Contributor

@lodoyun lodoyun commented Apr 11, 2018

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 and Stats,

[] It needs and includes Unit Tests

Changes in Client or Server public APIs

[] It includes documentation for these changes in /doc.

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 = "",
Copy link
Contributor

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)?

@@ -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_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 to this mutex

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);
Copy link
Contributor

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.

@@ -48,10 +49,13 @@ class MediaStream : public MediaSink, public erizo::MediaStreamStatsListener {
void close();
std::string toLog();

Nan::Callback *statsCallback_;
Nan::Callback *eventCallback_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: event_callback_

Nan::Callback *statsCallback_;
Nan::Callback *eventCallback_;
uv_async_t *async_event_;
bool hasEventCallback_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: has_event_callback_

uv_async_t *async_stats_;
bool hasCallback_;
bool hasStatsCallback_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: has_stats_callback_

@@ -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_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: event_listener_mutex_?

@@ -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_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: event_listener_mutex_?

@@ -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_;
Copy link
Contributor

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_ ?

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_) {
Copy link
Contributor

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?

Copy link
Contributor

@jcague jcague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lodoyun lodoyun merged commit 4e864f4 into lynckia:master Apr 12, 2018
@lodoyun lodoyun deleted the add/MediaStreamEventsToErizoJS branch September 20, 2018 07:33
Arri98 pushed a commit to Arri98/licode that referenced this pull request Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants