Search in sources :

Example 1 with Input

use of com.google.cloud.video.livestream.v1.Input in project red5-io by Red5.

the class MessageSerializationTest method serializeAndDeserialize.

private <T> T serializeAndDeserialize(T obj, Class<T> type) {
    IoBuffer data = IoBuffer.allocate(0);
    data.setAutoExpand(true);
    Output output = new Output(data);
    output.enforceAMF3();
    Serializer.serialize(output, obj);
    Input input = new Input(data.flip());
    input.enforceAMF3();
    Object result = Deserializer.deserialize(input, type);
    return type.cast(result);
}
Also used : Input(org.red5.io.amf3.Input) Output(org.red5.io.amf3.Output) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 2 with Input

use of com.google.cloud.video.livestream.v1.Input in project java-docs-samples by GoogleCloudPlatform.

the class CreateChannel method createChannel.

public static void createChannel(String projectId, String location, String channelId, String inputId, String outputUri) throws InterruptedException, ExecutionException, TimeoutException, IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        VideoStream videoStream = VideoStream.newBuilder().setH264(H264CodecSettings.newBuilder().setProfile("main").setBitrateBps(1000000).setFrameRate(30).setHeightPixels(720).setWidthPixels(1280)).build();
        AudioStream audioStream = AudioStream.newBuilder().setCodec("aac").setChannelCount(2).setBitrateBps(160000).build();
        var createChannelRequest = CreateChannelRequest.newBuilder().setParent(LocationName.of(projectId, location).toString()).setChannelId(channelId).setChannel(Channel.newBuilder().addInputAttachments(0, InputAttachment.newBuilder().setKey("my-input").setInput(InputName.of(projectId, location, inputId).toString()).build()).setOutput(Output.newBuilder().setUri(outputUri).build()).addElementaryStreams(ElementaryStream.newBuilder().setKey("es_video").setVideoStream(videoStream)).addElementaryStreams(ElementaryStream.newBuilder().setKey("es_audio").setAudioStream(audioStream)).addMuxStreams(MuxStream.newBuilder().setKey("mux_video").addElementaryStreams("es_video").setSegmentSettings(SegmentSettings.newBuilder().setSegmentDuration(Duration.newBuilder().setSeconds(2).build()).build()).build()).addMuxStreams(MuxStream.newBuilder().setKey("mux_audio").addElementaryStreams("es_audio").setSegmentSettings(SegmentSettings.newBuilder().setSegmentDuration(Duration.newBuilder().setSeconds(2).build()).build()).build()).addManifests(Manifest.newBuilder().setFileName("manifest.m3u8").setType(ManifestType.HLS).addMuxStreams("mux_video").addMuxStreams("mux_audio").setMaxSegmentCount(5).build())).build();
        Channel result = livestreamServiceClient.createChannelAsync(createChannelRequest).get(1, TimeUnit.MINUTES);
        System.out.println("Channel: " + result.getName());
    }
}
Also used : AudioStream(com.google.cloud.video.livestream.v1.AudioStream) Channel(com.google.cloud.video.livestream.v1.Channel) VideoStream(com.google.cloud.video.livestream.v1.VideoStream) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient)

Example 3 with Input

use of com.google.cloud.video.livestream.v1.Input in project java-docs-samples by GoogleCloudPlatform.

the class TestUtils method cleanStaleInputs.

public static void cleanStaleInputs(String projectId, String location) {
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        var listInputsRequest = ListInputsRequest.newBuilder().setParent(LocationName.of(projectId, location).toString()).build();
        LivestreamServiceClient.ListInputsPagedResponse response = livestreamServiceClient.listInputs(listInputsRequest);
        for (Input input : response.iterateAll()) {
            if (input.getCreateTime().getSeconds() < Instant.now().getEpochSecond() - DELETION_THRESHOLD_TIME_HOURS_IN_SECONDS) {
                var deleteInputRequest = DeleteInputRequest.newBuilder().setName(input.getName()).build();
                livestreamServiceClient.deleteInputAsync(deleteInputRequest).get(1, TimeUnit.MINUTES);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NotFoundException | InterruptedException | ExecutionException | TimeoutException e) {
        e.printStackTrace();
    }
}
Also used : Input(com.google.cloud.video.livestream.v1.Input) NotFoundException(com.google.api.gax.rpc.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Input

use of com.google.cloud.video.livestream.v1.Input in project java-docs-samples by GoogleCloudPlatform.

the class UpdateChannel method updateChannel.

public static void updateChannel(String projectId, String location, String channelId, String inputId) throws InterruptedException, ExecutionException, TimeoutException, IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        var updateChannelRequest = UpdateChannelRequest.newBuilder().setChannel(Channel.newBuilder().setName(ChannelName.of(projectId, location, channelId).toString()).addInputAttachments(0, InputAttachment.newBuilder().setKey("updated-input").setInput(InputName.of(projectId, location, inputId).toString()).build())).setUpdateMask(FieldMask.newBuilder().addPaths("input_attachments").build()).build();
        Channel result = livestreamServiceClient.updateChannelAsync(updateChannelRequest).get(1, TimeUnit.MINUTES);
        System.out.println("Updated channel: " + result.getName());
    }
}
Also used : Channel(com.google.cloud.video.livestream.v1.Channel) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient)

Example 5 with Input

use of com.google.cloud.video.livestream.v1.Input in project java-docs-samples by GoogleCloudPlatform.

the class UpdateInput method updateInput.

public static void updateInput(String projectId, String location, String inputId) throws InterruptedException, ExecutionException, TimeoutException, IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
        var updateInputRequest = UpdateInputRequest.newBuilder().setInput(Input.newBuilder().setName(InputName.of(projectId, location, inputId).toString()).setPreprocessingConfig(PreprocessingConfig.newBuilder().setCrop(Crop.newBuilder().setTopPixels(5).setBottomPixels(5).build()).build()).build()).setUpdateMask(FieldMask.newBuilder().addPaths("preprocessing_config").build()).build();
        Input result = livestreamServiceClient.updateInputAsync(updateInputRequest).get(1, TimeUnit.MINUTES);
        System.out.println("Updated input: " + result.getName());
    }
}
Also used : Input(com.google.cloud.video.livestream.v1.Input) LivestreamServiceClient(com.google.cloud.video.livestream.v1.LivestreamServiceClient)

Aggregations

LivestreamServiceClient (com.google.cloud.video.livestream.v1.LivestreamServiceClient)9 Input (org.red5.io.amf3.Input)9 Input (com.google.cloud.video.livestream.v1.Input)5 Test (org.junit.Test)5 Channel (com.google.cloud.video.livestream.v1.Channel)3 AudioStream (com.google.cloud.video.livestream.v1.AudioStream)2 VideoStream (com.google.cloud.video.livestream.v1.VideoStream)2 Output (org.red5.io.amf3.Output)2 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 InputName (com.google.cloud.video.livestream.v1.InputName)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 IoBuffer (org.apache.mina.core.buffer.IoBuffer)1 ObjectMap (org.red5.io.utils.ObjectMap)1 RemotingHeader (org.red5.server.net.remoting.RemotingHeader)1