Commit 70f74fde by sheenachhabra Committed by microkatz

Change UnsupportedEncodingException to IllegalArgumentException

In startTransformation method we were throwing UnsupportedEncodingException (IOException) when mediaItem with unsupported arguments is passed.
Changed this to IllegalArgumentException which seems more logical here.

PiperOrigin-RevId: 487259296
(cherry picked from commit 4598cc92)
parent 1ffe6a73
...@@ -49,8 +49,6 @@ import com.google.android.exoplayer2.util.Util; ...@@ -49,8 +49,6 @@ import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -669,17 +667,11 @@ public final class Transformer { ...@@ -669,17 +667,11 @@ public final class Transformer {
* @param mediaItem The {@link MediaItem} to transform. * @param mediaItem The {@link MediaItem} to transform.
* @param path The path to the output file. * @param path The path to the output file.
* @throws IllegalArgumentException If the path is invalid. * @throws IllegalArgumentException If the path is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread. * @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress. * @throws IllegalStateException If a transformation is already in progress.
* @throws IOException If {@link MediaItem} is not supported.
*/ */
public void startTransformation(MediaItem mediaItem, String path) throws IOException { public void startTransformation(MediaItem mediaItem, String path) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& transformationRequest.flattenForSlowMotion) {
// TODO(b/233986762): Support clipping with SEF flattening.
throw new UnsupportedEncodingException(
"Clipping is not supported when slow motion flattening is requested");
}
this.outputPath = path; this.outputPath = path;
this.outputParcelFileDescriptor = null; this.outputParcelFileDescriptor = null;
startTransformationInternal(mediaItem); startTransformationInternal(mediaItem);
...@@ -703,6 +695,7 @@ public final class Transformer { ...@@ -703,6 +695,7 @@ public final class Transformer {
* transformation is completed. It is the responsibility of the caller to close the * transformation is completed. It is the responsibility of the caller to close the
* ParcelFileDescriptor. This can be done after this method returns. * ParcelFileDescriptor. This can be done after this method returns.
* @throws IllegalArgumentException If the file descriptor is invalid. * @throws IllegalArgumentException If the file descriptor is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread. * @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress. * @throws IllegalStateException If a transformation is already in progress.
*/ */
...@@ -714,6 +707,12 @@ public final class Transformer { ...@@ -714,6 +707,12 @@ public final class Transformer {
} }
private void startTransformationInternal(MediaItem mediaItem) { private void startTransformationInternal(MediaItem mediaItem) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& transformationRequest.flattenForSlowMotion) {
// TODO(b/233986762): Support clipping with SEF flattening.
throw new IllegalArgumentException(
"Clipping is not supported when slow motion flattening is requested");
}
verifyApplicationThread(); verifyApplicationThread();
if (transformationInProgress) { if (transformationInProgress) {
throw new IllegalStateException("There is already a transformation in progress."); throw new IllegalStateException("There is already a transformation in progress.");
......
...@@ -581,8 +581,6 @@ public final class TransformerEndToEndTest { ...@@ -581,8 +581,6 @@ public final class TransformerEndToEndTest {
() -> { () -> {
try { try {
transformer.startTransformation(mediaItem, outputPath); transformer.startTransformation(mediaItem, outputPath);
} catch (IOException e) {
// Do nothing.
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
illegalStateException.set(e); illegalStateException.set(e);
} finally { } finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment