Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.livestream;

// [START livestream_create_channel]

import com.google.cloud.video.livestream.v1.AudioStream;
import com.google.cloud.video.livestream.v1.Channel;
import com.google.cloud.video.livestream.v1.Channel.Output;
import com.google.cloud.video.livestream.v1.CreateChannelRequest;
import com.google.cloud.video.livestream.v1.ElementaryStream;
import com.google.cloud.video.livestream.v1.InputAttachment;
import com.google.cloud.video.livestream.v1.InputName;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import com.google.cloud.video.livestream.v1.Manifest;
import com.google.cloud.video.livestream.v1.Manifest.ManifestType;
import com.google.cloud.video.livestream.v1.MuxStream;
import com.google.cloud.video.livestream.v1.SegmentSettings;
import com.google.cloud.video.livestream.v1.VideoStream;
import com.google.cloud.video.livestream.v1.VideoStream.H264CodecSettings;
import com.google.protobuf.Duration;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateChannel {

public static void main(String[] args) throws Exception {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project-id";
String location = "us-central1";
String channelId = "my-channel-id";
String inputId = "my-input-id";
String outputUri = "gs://my-bucket/my-output-folder/";

createChannel(projectId, location, channelId, inputId, outputUri);
}

public static void createChannel(
String projectId, String location, String channelId, String inputId, String outputUri)
throws InterruptedException, ExecutionException, TimeoutException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// 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());
}
}
}
// [END livestream_create_channel]
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.livestream;

// [START livestream_create_channel_with_backup_input]

import com.google.cloud.video.livestream.v1.AudioStream;
import com.google.cloud.video.livestream.v1.Channel;
import com.google.cloud.video.livestream.v1.Channel.Output;
import com.google.cloud.video.livestream.v1.CreateChannelRequest;
import com.google.cloud.video.livestream.v1.ElementaryStream;
import com.google.cloud.video.livestream.v1.InputAttachment;
import com.google.cloud.video.livestream.v1.InputAttachment.AutomaticFailover;
import com.google.cloud.video.livestream.v1.InputName;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import com.google.cloud.video.livestream.v1.Manifest;
import com.google.cloud.video.livestream.v1.Manifest.ManifestType;
import com.google.cloud.video.livestream.v1.MuxStream;
import com.google.cloud.video.livestream.v1.SegmentSettings;
import com.google.cloud.video.livestream.v1.VideoStream;
import com.google.cloud.video.livestream.v1.VideoStream.H264CodecSettings;
import com.google.protobuf.Duration;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateChannelWithBackupInput {

public static void main(String[] args) throws Exception {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project-id";
String location = "us-central1";
String channelId = "my-channel-id";
String primaryInputId = "my-primary-input-id";
String backupInputId = "my-backup-input-id";
String outputUri = "gs://my-bucket/my-output-folder/";

createChannelWithBackupInput(
projectId, location, channelId, primaryInputId, backupInputId, outputUri);
}

public static void createChannelWithBackupInput(
String projectId,
String location,
String channelId,
String primaryInputId,
String backupInputId,
String outputUri)
throws InterruptedException, ExecutionException, TimeoutException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// 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-primary-input")
.setInput(
InputName.of(projectId, location, primaryInputId).toString())
.setAutomaticFailover(
AutomaticFailover.newBuilder()
.addInputKeys("my-backup-input")
.build())
.build())
.addInputAttachments(
1,
InputAttachment.newBuilder()
.setKey("my-backup-input")
.setInput(
InputName.of(projectId, location, backupInputId).toString()))
.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());
}
}
}
// [END livestream_create_channel_with_backup_input]
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

// [START livestream_create_input]

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.video.livestream.v1.CreateInputRequest;
import com.google.cloud.video.livestream.v1.Input;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import com.google.cloud.video.livestream.v1.LocationName;
import com.google.cloud.video.livestream.v1.OperationMetadata;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -53,9 +51,8 @@ public static void createInput(String projectId, String location, String inputId
.setInput(Input.newBuilder().setType(Input.Type.RTMP_PUSH).build())
.build();

OperationFuture<Input, OperationMetadata> call =
livestreamServiceClient.createInputAsync(createInputRequest);
Input result = call.get(1, TimeUnit.MINUTES);
Input result =
livestreamServiceClient.createInputAsync(createInputRequest).get(1, TimeUnit.MINUTES);
System.out.println("Input: " + result.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.livestream;

// [START livestream_delete_channel]

import com.google.cloud.video.livestream.v1.ChannelName;
import com.google.cloud.video.livestream.v1.DeleteChannelRequest;
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteChannel {

public static void main(String[] args) throws Exception {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project-id";
String location = "us-central1";
String channelId = "my-channel-id";

deleteChannel(projectId, location, channelId);
}

public static void deleteChannel(String projectId, String location, String channelId)
throws InterruptedException, ExecutionException, TimeoutException, IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
var deleteChannelRequest =
DeleteChannelRequest.newBuilder()
.setName(ChannelName.of(projectId, location, channelId).toString())
.build();

livestreamServiceClient.deleteChannelAsync(deleteChannelRequest).get(1, TimeUnit.MINUTES);
System.out.println("Deleted channel");
}
}
}
// [END livestream_delete_channel]
Loading