Search in sources :

Example 1 with Pipeline

use of org.freedesktop.gstreamer.Pipeline in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSServiceTest method testStopRecordingJob_JobStop.

@Test
public void testStopRecordingJob_JobStop(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    Pipeline mockedPipeline = Mockito.mock(Pipeline.class);
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).liveStreamingStartTime(LIVE_STREAMING_START_TIME).liveStreamingDurationInMinutes(LIVE_STREAMING_DURATION_IN_MINUTES).captureStartTime(START_TIME_ALWAYS).videoRecordFolderPath(tempDir).videoRecorder(videoRecorder).build();
    edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
    // Mock for initConfiguration
    when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
    // Mock for initSecretsManager
    when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
    // Mock for videoRecorder status
    when(videoRecorder.getStatus()).thenReturn(RecorderStatus.STOPPED);
    // Mock for videoRecorder pipeline
    when(videoRecorder.getPipeline()).thenReturn(mockedPipeline);
    // then
    edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
    edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
    Thread.sleep(2000);
    edgeConnectorForKVSService.schedulerStopTaskCallback(Constants.JobType.LOCAL_VIDEO_CAPTURE, MOCK_KINESIS_VIDEO_STREAM_NAME);
    Thread.sleep(1000);
    // verify
    assertEquals(0, edgeConnectorForKVSConfigurationList.get(0).getRecordingRequestsCount());
}
Also used : ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Pipeline(org.freedesktop.gstreamer.Pipeline) Test(org.junit.jupiter.api.Test)

Example 2 with Pipeline

use of org.freedesktop.gstreamer.Pipeline in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoRecorderUnitTest method registerCustomized_customizedModule_exceptionDoesNotThrow.

@Test
public void registerCustomized_customizedModule_exceptionDoesNotThrow() {
    VideoRecorder recorder = null;
    VideoRecorderBuilder builder = new VideoRecorderBuilder(mockGst, STATE_CALLBACK);
    GstDao dao = builder.getGstDao();
    Pipeline pipe = builder.getPipeline();
    Assertions.assertNotNull(builder.getPipeline());
    RecorderCameraRtsp cameraSrc = new RecorderCameraRtsp(dao, pipe, SRC_URL);
    RecorderBranchFile filePath = new RecorderBranchFile(ContainerType.MATROSKA, dao, pipe, "./record");
    // Add cam
    Assertions.assertThrows(RejectedExecutionException.class, () -> builder.construct());
    Assertions.assertTrue(builder.registerCustomCamera(cameraSrc));
    Assertions.assertFalse(builder.registerCustomCamera(cameraSrc));
    // Add branch
    Assertions.assertThrows(RejectedExecutionException.class, () -> builder.construct());
    Assertions.assertTrue(builder.registerCustomBranch(filePath, "customBranch"));
    Assertions.assertFalse(builder.registerCustomBranch(filePath, "customBranch"));
    // Get branch
    recorder = builder.construct();
    Assertions.assertNotNull(recorder.getBranch("customBranch"));
    Assertions.assertTrue(null == recorder.getBranch("NoSuchBranch"));
}
Also used : GstDao(com.aws.iot.edgeconnectorforkvs.videorecorder.util.GstDao) Pipeline(org.freedesktop.gstreamer.Pipeline) Test(org.junit.jupiter.api.Test)

Example 3 with Pipeline

use of org.freedesktop.gstreamer.Pipeline in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoRecorderUnitTest method toggleAppDataAnyTest_notRegistered_returnFalse.

@Test
public void toggleAppDataAnyTest_notRegistered_returnFalse() {
    VideoRecorder recorder = null;
    VideoRecorderBuilder builder = new VideoRecorderBuilder(mockGst, STATE_CALLBACK);
    try {
        testOutputStream = new FileOutputStream("/dev/null");
    } catch (FileNotFoundException e) {
        Assertions.fail();
    }
    builder.registerCamera(REC_TYPE, SRC_URL);
    builder.registerFileSink(CON_TYPE, "./record");
    recorder = builder.construct();
    // enable/disable invalid pipeline branches should get FALSE
    Assertions.assertFalse(recorder.toggleAppDataCallback(true));
    Assertions.assertFalse(recorder.toggleAppDataCallback(false));
    Assertions.assertFalse(recorder.toggleAppDataOutputStream(true));
    Assertions.assertFalse(recorder.toggleAppDataOutputStream(false));
    Assertions.assertFalse(recorder.setAppDataCallback((rec, buff) -> {
    }));
    Assertions.assertFalse(recorder.setAppDataOutputStream(testOutputStream));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bus(org.freedesktop.gstreamer.Bus) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ContainerType(com.aws.iot.edgeconnectorforkvs.videorecorder.model.ContainerType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Pipeline(org.freedesktop.gstreamer.Pipeline) Mock(org.mockito.Mock) StatusCallback(com.aws.iot.edgeconnectorforkvs.videorecorder.callback.StatusCallback) AppSink(org.freedesktop.gstreamer.elements.AppSink) ByteBuffer(java.nio.ByteBuffer) Element(org.freedesktop.gstreamer.Element) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Buffer(org.freedesktop.gstreamer.Buffer) GstDao(com.aws.iot.edgeconnectorforkvs.videorecorder.util.GstDao) MockedConstruction(org.mockito.MockedConstruction) OutputStream(java.io.OutputStream) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) Sample(org.freedesktop.gstreamer.Sample) FileNotFoundException(java.io.FileNotFoundException) Pad(org.freedesktop.gstreamer.Pad) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) BDDMockito(org.mockito.BDDMockito) AfterEach(org.junit.jupiter.api.AfterEach) CameraType(com.aws.iot.edgeconnectorforkvs.videorecorder.model.CameraType) Assertions(org.junit.jupiter.api.Assertions) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test)

Example 4 with Pipeline

use of org.freedesktop.gstreamer.Pipeline in project iris by mnit-rtmc.

the class VidStreamMgrGst method closeStream.

/**
 * Close the video stream
 */
private synchronized void closeStream() {
    Pipeline p = pipe;
    if (p != null) {
        // NOTE - uncomment the lines below to generate debug DOT files of
        // the GStreamer pipeline. You must have the GST_DEBUG_DUMP_DOT_DIR
        // environment variable set for this to work.
        // pipe.debugToDotFile(Bin.DebugGraphDetails.SHOW_ALL,
        // getDOTFileName());
        pipe = null;
        if (appsink == null)
            System.out.println("appsink is null");
        else {
            appsink.disconnect((AppSink.NEW_SAMPLE) appsinkListener);
            appsink.disconnect((AppSink.EOS) appsinkListener);
        }
        if (bus == null)
            System.out.println("bus is null");
        else {
            bus.disconnect((Bus.ERROR) busListener);
            bus.disconnect((Bus.WARNING) busListener);
            bus.disconnect((Bus.INFO) busListener);
        }
        gstComponent.disconnectAll();
        gstComponent = null;
        try {
            p.setState(State.NULL);
            p.getState();
            System.out.println("CloseStream finished");
        } catch (java.lang.IllegalStateException e) {
            e.printStackTrace();
        }
    }
}
Also used : AppSink(org.freedesktop.gstreamer.elements.AppSink) Bus(org.freedesktop.gstreamer.Bus) Pipeline(org.freedesktop.gstreamer.Pipeline)

Example 5 with Pipeline

use of org.freedesktop.gstreamer.Pipeline in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class GstDaoUnitTest method gstDaoTest_invokeConstructor_noException.

@Test
void gstDaoTest_invokeConstructor_noException() {
    // Test: new Pipeline
    try (MockedConstruction<Pipeline> mockPipe = mockConstruction(Pipeline.class)) {
        Pipeline pipe = mockGst.newPipeline();
        Assertions.assertNotNull(pipe);
    }
    // Test: new EOSEvent
    try (MockedConstruction<EOSEvent> mockEosEvent = mockConstruction(EOSEvent.class)) {
        EOSEvent event = mockGst.newEosEvent();
        Assertions.assertNotNull(event);
    }
    // Test: new Pipeline
    try (MockedConstruction<EOSMessage> mockEosMsg = mockConstruction(EOSMessage.class)) {
        EOSMessage msg = mockGst.newEosMessage(null);
        Assertions.assertNotNull(msg);
    }
}
Also used : EOSMessage(org.freedesktop.gstreamer.message.EOSMessage) EOSEvent(org.freedesktop.gstreamer.event.EOSEvent) Pipeline(org.freedesktop.gstreamer.Pipeline) Test(org.junit.jupiter.api.Test)

Aggregations

Pipeline (org.freedesktop.gstreamer.Pipeline)6 Test (org.junit.jupiter.api.Test)4 GstDao (com.aws.iot.edgeconnectorforkvs.videorecorder.util.GstDao)2 Bus (org.freedesktop.gstreamer.Bus)2 AppSink (org.freedesktop.gstreamer.elements.AppSink)2 EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)1 StatusCallback (com.aws.iot.edgeconnectorforkvs.videorecorder.callback.StatusCallback)1 CameraType (com.aws.iot.edgeconnectorforkvs.videorecorder.model.CameraType)1 ContainerType (com.aws.iot.edgeconnectorforkvs.videorecorder.model.ContainerType)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1