Skip to content

Commit 3882bdf

Browse files
irataxykurtisvg
andauthored
feat:add Live Stream samples (GoogleCloudPlatform#7159)
* feat:add Live Stream samples * style checker errors * Update media/livestream/src/main/java/com/example/livestream/DeleteInput.java Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> * Update media/livestream/src/test/java/com/example/livestream/TestUtils.java Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> * address feedback * clean up old resources Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
1 parent 970a2d5 commit 3882bdf

12 files changed

Lines changed: 925 additions & 0 deletions

File tree

media/livestream/pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2020 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<groupId>com.example</groupId>
22+
<artifactId>livestream</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
<packaging>jar</packaging>
25+
<!--
26+
The parent pom defines common style checks and testing strategies for our samples.
27+
Removing or replacing it should not affect the execution of the samples in any way.
28+
-->
29+
<parent>
30+
<groupId>com.google.cloud.samples</groupId>
31+
<artifactId>shared-configuration</artifactId>
32+
<version>1.2.0</version>
33+
</parent>
34+
<properties>
35+
<maven.compiler.target>11</maven.compiler.target>
36+
<maven.compiler.source>11</maven.compiler.source>
37+
</properties>
38+
<!-- Using libraries-bom to manage versions.
39+
See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
40+
<dependencyManagement>
41+
<dependencies>
42+
<dependency>
43+
<groupId>com.google.cloud</groupId>
44+
<artifactId>libraries-bom</artifactId>
45+
<version>25.2.0</version>
46+
<type>pom</type>
47+
<scope>import</scope>
48+
</dependency>
49+
</dependencies>
50+
</dependencyManagement>
51+
<dependencies>
52+
<dependency>
53+
<groupId>com.google.cloud</groupId>
54+
<artifactId>google-cloud-live-stream</artifactId>
55+
<version>0.3.0</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.google.cloud</groupId>
59+
<artifactId>google-cloud-core</artifactId>
60+
<scope>compile</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
<version>3.8.1</version>
66+
</dependency>
67+
<!-- Test dependencies -->
68+
<dependency>
69+
<groupId>junit</groupId>
70+
<artifactId>junit</artifactId>
71+
<version>4.13.2</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.livestream;
18+
19+
// [START livestream_create_input]
20+
21+
import com.google.api.gax.longrunning.OperationFuture;
22+
import com.google.cloud.video.livestream.v1.CreateInputRequest;
23+
import com.google.cloud.video.livestream.v1.Input;
24+
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
25+
import com.google.cloud.video.livestream.v1.LocationName;
26+
import com.google.cloud.video.livestream.v1.OperationMetadata;
27+
import java.io.IOException;
28+
import java.util.concurrent.ExecutionException;
29+
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.TimeoutException;
31+
32+
public class CreateInput {
33+
34+
public static void main(String[] args) throws Exception {
35+
// TODO(developer): Replace these variables before running the sample.
36+
String projectId = "my-project-id";
37+
String location = "us-central1";
38+
String inputId = "my-input-id";
39+
40+
createInput(projectId, location, inputId);
41+
}
42+
43+
public static void createInput(String projectId, String location, String inputId)
44+
throws InterruptedException, ExecutionException, TimeoutException, IOException {
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests. After completing all of your requests, call
47+
// the "close" method on the client to safely clean up any remaining background resources.
48+
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
49+
var createInputRequest =
50+
CreateInputRequest.newBuilder()
51+
.setParent(LocationName.of(projectId, location).toString())
52+
.setInputId(inputId)
53+
.setInput(Input.newBuilder().setType(Input.Type.RTMP_PUSH).build())
54+
.build();
55+
56+
OperationFuture<Input, OperationMetadata> call =
57+
livestreamServiceClient.createInputAsync(createInputRequest);
58+
Input result = call.get(1, TimeUnit.MINUTES);
59+
System.out.println("Input: " + result.getName());
60+
}
61+
}
62+
}
63+
// [END livestream_create_input]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.livestream;
18+
19+
// [START livestream_delete_input]
20+
21+
import com.google.cloud.video.livestream.v1.DeleteInputRequest;
22+
import com.google.cloud.video.livestream.v1.InputName;
23+
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
24+
import java.io.IOException;
25+
import java.util.concurrent.ExecutionException;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.TimeoutException;
28+
29+
public class DeleteInput {
30+
31+
public static void main(String[] args) throws Exception {
32+
// TODO(developer): Replace these variables before running the sample.
33+
String projectId = "my-project-id";
34+
String location = "us-central1";
35+
String inputId = "my-input-id";
36+
37+
deleteInput(projectId, location, inputId);
38+
}
39+
40+
public static void deleteInput(String projectId, String location, String inputId)
41+
throws InterruptedException, ExecutionException, TimeoutException, IOException {
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
45+
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
46+
var deleteInputRequest =
47+
DeleteInputRequest.newBuilder()
48+
.setName(InputName.of(projectId, location, inputId).toString())
49+
.build();
50+
51+
livestreamServiceClient.deleteInputAsync(deleteInputRequest).get(1, TimeUnit.MINUTES);
52+
System.out.println("Deleted input");
53+
}
54+
}
55+
}
56+
// [END livestream_delete_input]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.livestream;
18+
19+
// [START livestream_get_input]
20+
21+
import com.google.cloud.video.livestream.v1.Input;
22+
import com.google.cloud.video.livestream.v1.InputName;
23+
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
24+
import java.io.IOException;
25+
26+
public class GetInput {
27+
28+
public static void main(String[] args) throws Exception {
29+
// TODO(developer): Replace these variables before running the sample.
30+
String projectId = "my-project-id";
31+
String location = "us-central1";
32+
String inputId = "my-input-id";
33+
34+
getInput(projectId, location, inputId);
35+
}
36+
37+
public static void getInput(String projectId, String location, String inputId)
38+
throws IOException {
39+
// Initialize client that will be used to send requests. This client only needs to be created
40+
// once, and can be reused for multiple requests. After completing all of your requests, call
41+
// the "close" method on the client to safely clean up any remaining background resources.
42+
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
43+
InputName name = InputName.of(projectId, location, inputId);
44+
Input response = livestreamServiceClient.getInput(name);
45+
System.out.println("Input: " + response.getName());
46+
}
47+
}
48+
}
49+
// [END livestream_get_input]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.livestream;
18+
19+
// [START livestream_list_inputs]
20+
21+
import com.google.cloud.video.livestream.v1.Input;
22+
import com.google.cloud.video.livestream.v1.ListInputsRequest;
23+
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
24+
import com.google.cloud.video.livestream.v1.LocationName;
25+
import java.io.IOException;
26+
27+
public class ListInputs {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
34+
listInputs(projectId, location);
35+
}
36+
37+
public static void listInputs(String projectId, String location) throws IOException {
38+
// Initialize client that will be used to send requests. This client only needs to be created
39+
// once, and can be reused for multiple requests. After completing all of your requests, call
40+
// the "close" method on the client to safely clean up any remaining background resources.
41+
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
42+
var listInputsRequest =
43+
ListInputsRequest.newBuilder()
44+
.setParent(LocationName.of(projectId, location).toString())
45+
.build();
46+
47+
LivestreamServiceClient.ListInputsPagedResponse response =
48+
livestreamServiceClient.listInputs(listInputsRequest);
49+
System.out.println("Inputs:");
50+
51+
for (Input input : response.iterateAll()) {
52+
System.out.println(input.getName());
53+
}
54+
}
55+
}
56+
}
57+
// [END livestream_list_inputs]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.livestream;
18+
19+
// [START livestream_update_input]
20+
21+
import com.google.api.gax.longrunning.OperationFuture;
22+
import com.google.cloud.video.livestream.v1.Input;
23+
import com.google.cloud.video.livestream.v1.InputName;
24+
import com.google.cloud.video.livestream.v1.LivestreamServiceClient;
25+
import com.google.cloud.video.livestream.v1.OperationMetadata;
26+
import com.google.cloud.video.livestream.v1.PreprocessingConfig;
27+
import com.google.cloud.video.livestream.v1.PreprocessingConfig.Crop;
28+
import com.google.cloud.video.livestream.v1.UpdateInputRequest;
29+
import com.google.protobuf.FieldMask;
30+
import java.io.IOException;
31+
import java.util.concurrent.ExecutionException;
32+
import java.util.concurrent.TimeUnit;
33+
import java.util.concurrent.TimeoutException;
34+
35+
public class UpdateInput {
36+
37+
public static void main(String[] args) throws Exception {
38+
// TODO(developer): Replace these variables before running the sample.
39+
String projectId = "my-project-id";
40+
String location = "us-central1";
41+
String inputId = "my-input-id";
42+
43+
updateInput(projectId, location, inputId);
44+
}
45+
46+
public static void updateInput(String projectId, String location, String inputId)
47+
throws InterruptedException, ExecutionException, TimeoutException, IOException {
48+
// Initialize client that will be used to send requests. This client only needs to be created
49+
// once, and can be reused for multiple requests. After completing all of your requests, call
50+
// the "close" method on the client to safely clean up any remaining background resources.
51+
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
52+
var updateInputRequest =
53+
UpdateInputRequest.newBuilder()
54+
.setInput(
55+
Input.newBuilder()
56+
.setName(InputName.of(projectId, location, inputId).toString())
57+
.setPreprocessingConfig(
58+
PreprocessingConfig.newBuilder()
59+
.setCrop(Crop.newBuilder().setTopPixels(5).setBottomPixels(5).build())
60+
.build())
61+
.build())
62+
.setUpdateMask(FieldMask.newBuilder().addPaths("preprocessing_config").build())
63+
.build();
64+
65+
OperationFuture<Input, OperationMetadata> call =
66+
livestreamServiceClient.updateInputAsync(updateInputRequest);
67+
Input result = call.get(1, TimeUnit.MINUTES);
68+
System.out.println("Updated input: " + result.getName());
69+
}
70+
}
71+
}
72+
// [END livestream_update_input]

0 commit comments

Comments
 (0)