Skip to content

Commit

Permalink
Allow querying the state of endpoint debug features (#1546)
Browse files Browse the repository at this point in the history
* implement new rtpreceiver/sender methods in octortpreceiver/sender

* add new isFeatureEnabled method to AbstractEndpoint

* add new rest endpoint to query endpoint feature state

* add unit tests

* move isFeatureEnabled to Endpoint

* update jmt: get ep feature api tweaks
  • Loading branch information
bbaldino authored Jan 4, 2021
1 parent bc53883 commit 2f43d1b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 24 deletions.
8 changes: 0 additions & 8 deletions jvb/src/main/java/org/jitsi/videobridge/AbstractEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,6 @@ private void receiverVideoConstraintsChanged(
}
}

/**
* Enables/disables the given feature, if the endpoint implementation supports it.
*
* @param feature the feature to enable or disable.
* @param enabled the state of the feature.
*/
public abstract void setFeature(EndpointDebugFeatures feature, boolean enabled);

/**
* Whether the remote endpoint is currently sending (non-silence) audio.
*/
Expand Down
17 changes: 15 additions & 2 deletions jvb/src/main/java/org/jitsi/videobridge/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,11 @@ public JSONObject getDebugState()
}

/**
* {@inheritDoc}
* Enables/disables the given feature, if the endpoint implementation supports it.
*
* @param feature the feature to enable or disable.
* @param enabled the state of the feature.
*/
@Override
public void setFeature(EndpointDebugFeatures feature, boolean enabled) {

switch (feature)
Expand All @@ -1429,6 +1431,17 @@ public void setFeature(EndpointDebugFeatures feature, boolean enabled) {
}
}

public boolean isFeatureEnabled(EndpointDebugFeatures feature)
{
switch (feature)
{
case PCAP_DUMP:
return transceiver.isFeatureEnabled(Features.TRANSCEIVER_PCAP_DUMP);
}

throw new RuntimeException("Unsupported feature");
}

@Override
public boolean isSendingAudio()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Response setEndpointFeatureState(
throw new NotFoundException("No conference was found with the specified id.");
}

AbstractEndpoint endpoint = conference.getEndpoint(epId);
Endpoint endpoint = conference.getLocalEndpoint(epId);
if (endpoint == null)
{
throw new NotFoundException("No endpoint was found with the specified id.");
Expand All @@ -161,6 +161,35 @@ public Response setEndpointFeatureState(
return Response.ok().build();
}

@GET
@Path("/features/endpoint/{confId}/{epId}/{feature}/")
public Boolean getEndpointFeatureState(
@PathParam("confId") String confId,
@PathParam("epId") String epId,
@PathParam("feature") EndpointDebugFeatures feature)
{
Conference conference = videobridge.getConference(confId);
if (conference == null)
{
throw new NotFoundException("No conference was found with the specified id.");
}

Endpoint endpoint = conference.getLocalEndpoint(epId);
if (endpoint == null)
{
throw new NotFoundException("No endpoint was found with the specified id.");
}

try
{
return endpoint.isFeatureEnabled(feature);
}
catch (Exception e)
{
throw new ServerErrorException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
}
}


private void setFeature(DebugFeatures feature, boolean enabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
package org.jitsi.videobridge.octo

import com.google.common.collect.ImmutableMap
import org.jitsi.nlj.MediaSourceDesc
import org.jitsi.nlj.PacketHandler
import org.jitsi.nlj.PacketInfo
import org.jitsi.nlj.TransceiverEventHandler
import org.jitsi.nlj.format.PayloadType
import org.jitsi.nlj.rtp.RtpExtension
import org.jitsi.utils.MediaType
import org.jitsi.utils.logging2.Logger
import org.jitsi.videobridge.AbstractEndpoint
import org.jitsi.videobridge.Conference
import org.jitsi.videobridge.rest.root.debug.EndpointDebugFeatures
import org.jitsi.nlj.MediaSourceDesc
import org.jitsi.nlj.TransceiverEventHandler
import org.jitsi.videobridge.VideoConstraints
import org.jitsi.videobridge.message.AddReceiverMessage
import org.jitsi.videobridge.message.BridgeChannelMessage
Expand Down Expand Up @@ -95,10 +94,6 @@ class OctoEndpoint(
transceiver.requestKeyframe()
}

override fun setFeature(feature: EndpointDebugFeatures?, enabled: Boolean) {
// NO-OP
}

override fun shouldExpire(): Boolean = !transceiver.hasReceiveSsrcs()

override val mediaSources: Array<MediaSourceDesc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.jitsi.videobridge.octo.config

import org.jitsi.nlj.AudioLevelListener
import org.jitsi.nlj.Event
import org.jitsi.nlj.Features
import org.jitsi.nlj.PacketHandler
import org.jitsi.nlj.PacketInfo
import org.jitsi.nlj.RtpReceiver
Expand Down Expand Up @@ -182,6 +183,14 @@ class OctoRtpReceiver(
TODO("Not yet implemented")
}

override fun setFeature(feature: Features, enabled: Boolean) {
TODO("Not yet implemented")
}

override fun isFeatureEnabled(feature: Features): Boolean {
TODO("Not yet implemented")
}

override fun setSrtpTransformers(srtpTransformers: SrtpTransformers) {}

override fun stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jitsi.videobridge.octo.config

import org.jitsi.nlj.Event
import org.jitsi.nlj.Features
import org.jitsi.nlj.PacketHandler
import org.jitsi.nlj.PacketInfo
import org.jitsi.nlj.RtpSender
Expand Down Expand Up @@ -110,6 +111,14 @@ class OctoRtpSender(

override fun onRttUpdate(newRttMs: Double) {}

override fun isFeatureEnabled(feature: Features): Boolean {
TODO("Not yet implemented")
}

override fun setFeature(feature: Features, enabled: Boolean) {
TODO("Not yet implemented")
}

override fun getPacketStreamStats(): PacketStreamStats.Snapshot = PacketStreamStats.Snapshot(0.bps, 0, 0, 0)

override fun getTransportCcEngineStats(): TransportCcEngine.StatisticsSnapshot =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,31 @@

import javax.ws.rs.*;
import javax.ws.rs.client.*;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.*;

import java.util.logging.*;

import static junit.framework.TestCase.*;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

public class DebugTest extends JerseyTest
{
protected Videobridge videobridge;
protected static final String BASE_URL = "/debug";
Endpoint endpoint;
Conference conference;

@Override
protected Application configure()
{
videobridge = mock(Videobridge.class);
endpoint = mock(Endpoint.class);
conference = mock(Conference.class);

Endpoint endpoint = mock(Endpoint.class);
Conference conference = mock(Conference.class);
when(videobridge.getConference("foo")).thenReturn(conference);
when(conference.getEndpoint("bar")).thenReturn(endpoint);
when(conference.getLocalEndpoint("bar")).thenReturn(endpoint);

enable(TestProperties.LOG_TRAFFIC);
enable(TestProperties.DUMP_ENTITY);
Expand Down Expand Up @@ -148,6 +150,33 @@ public void testEnableEndpointFeature()
assertEquals(HttpStatus.OK_200, resp.getStatus());
}

@Test
public void testGetEndpointFeatureState()
{
when(endpoint.isFeatureEnabled(EndpointDebugFeatures.PCAP_DUMP)).thenReturn(true);
Response resp = target(BASE_URL + "/features/endpoint/foo/bar/" + EndpointDebugFeatures.PCAP_DUMP.getValue())
.request()
.get();
assertEquals(HttpStatus.OK_200, resp.getStatus());
assertTrue(Boolean.parseBoolean(resp.readEntity(String.class)));

when(endpoint.isFeatureEnabled(EndpointDebugFeatures.PCAP_DUMP)).thenReturn(false);
resp = target(BASE_URL + "/features/endpoint/foo/bar/" + EndpointDebugFeatures.PCAP_DUMP.getValue())
.request()
.get();
assertEquals(HttpStatus.OK_200, resp.getStatus());
assertFalse(Boolean.parseBoolean(resp.readEntity(String.class)));
}

@Test
public void testGetNonexistentEndpointFeatureState()
{
Response resp = target(BASE_URL + "/features/endpoint/foo/bar/nonexistent")
.request()
.get();
assertEquals(HttpStatus.NOT_FOUND_404, resp.getStatus());
}

@Test
public void testDisableEndpointFeature()
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-media-transform</artifactId>
<version>1.0-212-g1a77910</version>
<version>1.0-214-gfc6cda2</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down

0 comments on commit 2f43d1b

Please sign in to comment.