Rename occurences of transform in demo app

PiperOrigin-RevId: 510384933
This commit is contained in:
kimvde 2023-02-17 11:01:31 +00:00 committed by christosts
parent a1f7960eab
commit 58d653b702
4 changed files with 45 additions and 48 deletions

View File

@ -55,7 +55,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/** /**
* An {@link Activity} that sets the configuration to use for transforming and playing media, using * An {@link Activity} that sets the configuration to use for exporting and playing media, using
* {@link TransformerActivity}. * {@link TransformerActivity}.
*/ */
public final class ConfigurationActivity extends AppCompatActivity { public final class ConfigurationActivity extends AppCompatActivity {
@ -73,7 +73,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
public static final String TRIM_END_MS = "trim_end_ms"; public static final String TRIM_END_MS = "trim_end_ms";
public static final String ENABLE_FALLBACK = "enable_fallback"; public static final String ENABLE_FALLBACK = "enable_fallback";
public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview"; public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview";
public static final String ABORT_SLOW_TRANSFORMATION = "abort_slow_transformation"; public static final String ABORT_SLOW_EXPORT = "abort_slow_export";
public static final String HDR_MODE = "hdr_mode"; public static final String HDR_MODE = "hdr_mode";
public static final String AUDIO_EFFECTS_SELECTIONS = "audio_effects_selections"; public static final String AUDIO_EFFECTS_SELECTIONS = "audio_effects_selections";
public static final String VIDEO_EFFECTS_SELECTIONS = "video_effects_selections"; public static final String VIDEO_EFFECTS_SELECTIONS = "video_effects_selections";
@ -222,7 +222,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
private @MonotonicNonNull CheckBox trimCheckBox; private @MonotonicNonNull CheckBox trimCheckBox;
private @MonotonicNonNull CheckBox enableFallbackCheckBox; private @MonotonicNonNull CheckBox enableFallbackCheckBox;
private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox; private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox;
private @MonotonicNonNull CheckBox abortSlowTransformationCheckBox; private @MonotonicNonNull CheckBox abortSlowExportCheckBox;
private @MonotonicNonNull Spinner hdrModeSpinner; private @MonotonicNonNull Spinner hdrModeSpinner;
private @MonotonicNonNull Button selectAudioEffectsButton; private @MonotonicNonNull Button selectAudioEffectsButton;
private @MonotonicNonNull Button selectVideoEffectsButton; private @MonotonicNonNull Button selectVideoEffectsButton;
@ -255,7 +255,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.configuration_activity); setContentView(R.layout.configuration_activity);
findViewById(R.id.transform_button).setOnClickListener(this::startTransformation); findViewById(R.id.export_button).setOnClickListener(this::startExport);
selectPresetFileButton = findViewById(R.id.select_preset_file_button); selectPresetFileButton = findViewById(R.id.select_preset_file_button);
selectPresetFileButton.setOnClickListener(this::selectPresetFile); selectPresetFileButton.setOnClickListener(this::selectPresetFile);
@ -325,7 +325,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
enableFallbackCheckBox = findViewById(R.id.enable_fallback_checkbox); enableFallbackCheckBox = findViewById(R.id.enable_fallback_checkbox);
enableDebugPreviewCheckBox = findViewById(R.id.enable_debug_preview_checkbox); enableDebugPreviewCheckBox = findViewById(R.id.enable_debug_preview_checkbox);
abortSlowTransformationCheckBox = findViewById(R.id.abort_slow_transformation_checkbox); abortSlowExportCheckBox = findViewById(R.id.abort_slow_export_checkbox);
ArrayAdapter<String> hdrModeAdapter = ArrayAdapter<String> hdrModeAdapter =
new ArrayAdapter<>(/* context= */ this, R.layout.spinner_item); new ArrayAdapter<>(/* context= */ this, R.layout.spinner_item);
@ -394,12 +394,12 @@ public final class ConfigurationActivity extends AppCompatActivity {
"trimCheckBox", "trimCheckBox",
"enableFallbackCheckBox", "enableFallbackCheckBox",
"enableDebugPreviewCheckBox", "enableDebugPreviewCheckBox",
"abortSlowTransformationCheckBox", "abortSlowExportCheckBox",
"hdrModeSpinner", "hdrModeSpinner",
"audioEffectsSelections", "audioEffectsSelections",
"videoEffectsSelections" "videoEffectsSelections"
}) })
private void startTransformation(View view) { private void startExport(View view) {
Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class); Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean(SHOULD_REMOVE_AUDIO, removeAudioCheckbox.isChecked()); bundle.putBoolean(SHOULD_REMOVE_AUDIO, removeAudioCheckbox.isChecked());
@ -435,7 +435,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
} }
bundle.putBoolean(ENABLE_FALLBACK, enableFallbackCheckBox.isChecked()); bundle.putBoolean(ENABLE_FALLBACK, enableFallbackCheckBox.isChecked());
bundle.putBoolean(ENABLE_DEBUG_PREVIEW, enableDebugPreviewCheckBox.isChecked()); bundle.putBoolean(ENABLE_DEBUG_PREVIEW, enableDebugPreviewCheckBox.isChecked());
bundle.putBoolean(ABORT_SLOW_TRANSFORMATION, abortSlowTransformationCheckBox.isChecked()); bundle.putBoolean(ABORT_SLOW_EXPORT, abortSlowExportCheckBox.isChecked());
String selectedhdrMode = String.valueOf(hdrModeSpinner.getSelectedItem()); String selectedhdrMode = String.valueOf(hdrModeSpinner.getSelectedItem());
bundle.putInt(HDR_MODE, checkNotNull(HDR_MODE_DESCRIPTIONS.get(selectedhdrMode))); bundle.putInt(HDR_MODE, checkNotNull(HDR_MODE_DESCRIPTIONS.get(selectedhdrMode)));
bundle.putBooleanArray(AUDIO_EFFECTS_SELECTIONS, audioEffectsSelections); bundle.putBooleanArray(AUDIO_EFFECTS_SELECTIONS, audioEffectsSelections);

View File

@ -105,7 +105,7 @@ import java.util.concurrent.TimeUnit;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/** An {@link Activity} that transforms and plays media using {@link Transformer}. */ /** An {@link Activity} that exports and plays media using {@link Transformer}. */
public final class TransformerActivity extends AppCompatActivity { public final class TransformerActivity extends AppCompatActivity {
private static final String TAG = "TransformerActivity"; private static final String TAG = "TransformerActivity";
@ -119,7 +119,7 @@ public final class TransformerActivity extends AppCompatActivity {
private @MonotonicNonNull TextView informationTextView; private @MonotonicNonNull TextView informationTextView;
private @MonotonicNonNull ViewGroup progressViewGroup; private @MonotonicNonNull ViewGroup progressViewGroup;
private @MonotonicNonNull LinearProgressIndicator progressIndicator; private @MonotonicNonNull LinearProgressIndicator progressIndicator;
private @MonotonicNonNull Stopwatch transformationStopwatch; private @MonotonicNonNull Stopwatch exportStopwatch;
private @MonotonicNonNull AspectRatioFrameLayout debugFrame; private @MonotonicNonNull AspectRatioFrameLayout debugFrame;
@Nullable private DebugTextViewHelper debugTextViewHelper; @Nullable private DebugTextViewHelper debugTextViewHelper;
@ -146,7 +146,7 @@ public final class TransformerActivity extends AppCompatActivity {
displayInputButton = findViewById(R.id.display_input_button); displayInputButton = findViewById(R.id.display_input_button);
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay); displayInputButton.setOnClickListener(this::toggleInputVideoDisplay);
transformationStopwatch = exportStopwatch =
Stopwatch.createUnstarted( Stopwatch.createUnstarted(
new Ticker() { new Ticker() {
@Override @Override
@ -162,7 +162,7 @@ public final class TransformerActivity extends AppCompatActivity {
checkNotNull(progressIndicator); checkNotNull(progressIndicator);
checkNotNull(informationTextView); checkNotNull(informationTextView);
checkNotNull(transformationStopwatch); checkNotNull(exportStopwatch);
checkNotNull(inputCardView); checkNotNull(inputCardView);
checkNotNull(inputTextView); checkNotNull(inputTextView);
checkNotNull(inputImageView); checkNotNull(inputImageView);
@ -172,7 +172,7 @@ public final class TransformerActivity extends AppCompatActivity {
checkNotNull(progressViewGroup); checkNotNull(progressViewGroup);
checkNotNull(debugFrame); checkNotNull(debugFrame);
checkNotNull(displayInputButton); checkNotNull(displayInputButton);
startTransformation(); startExport();
inputPlayerView.onResume(); inputPlayerView.onResume();
outputPlayerView.onResume(); outputPlayerView.onResume();
@ -185,9 +185,9 @@ public final class TransformerActivity extends AppCompatActivity {
checkNotNull(transformer).cancel(); checkNotNull(transformer).cancel();
transformer = null; transformer = null;
// The stop watch is reset after cancelling the transformation, in case cancelling causes the // The stop watch is reset after cancelling the export, in case cancelling causes the stop watch
// stop watch to be stopped in a transformer callback. // to be stopped in a transformer callback.
checkNotNull(transformationStopwatch).reset(); checkNotNull(exportStopwatch).reset();
checkNotNull(inputPlayerView).onPause(); checkNotNull(inputPlayerView).onPause();
checkNotNull(outputPlayerView).onPause(); checkNotNull(outputPlayerView).onPause();
@ -207,11 +207,11 @@ public final class TransformerActivity extends AppCompatActivity {
"debugTextView", "debugTextView",
"informationTextView", "informationTextView",
"progressIndicator", "progressIndicator",
"transformationStopwatch", "exportStopwatch",
"progressViewGroup", "progressViewGroup",
"debugFrame", "debugFrame",
}) })
private void startTransformation() { private void startExport() {
requestReadVideoPermission(/* activity= */ this); requestReadVideoPermission(/* activity= */ this);
Intent intent = getIntent(); Intent intent = getIntent();
@ -227,7 +227,7 @@ public final class TransformerActivity extends AppCompatActivity {
try { try {
Transformer transformer = createTransformer(bundle, filePath); Transformer transformer = createTransformer(bundle, filePath);
EditedMediaItem editedMediaItem = createEditedMediaItem(mediaItem, bundle); EditedMediaItem editedMediaItem = createEditedMediaItem(mediaItem, bundle);
transformationStopwatch.start(); exportStopwatch.start();
transformer.start(editedMediaItem, filePath); transformer.start(editedMediaItem, filePath);
this.transformer = transformer; this.transformer = transformer;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
@ -235,7 +235,7 @@ public final class TransformerActivity extends AppCompatActivity {
} }
inputCardView.setVisibility(View.GONE); inputCardView.setVisibility(View.GONE);
outputPlayerView.setVisibility(View.GONE); outputPlayerView.setVisibility(View.GONE);
informationTextView.setText(R.string.transformation_started); informationTextView.setText(R.string.export_started);
progressViewGroup.setVisibility(View.VISIBLE); progressViewGroup.setVisibility(View.VISIBLE);
Handler mainHandler = new Handler(getMainLooper()); Handler mainHandler = new Handler(getMainLooper());
ProgressHolder progressHolder = new ProgressHolder(); ProgressHolder progressHolder = new ProgressHolder();
@ -247,9 +247,7 @@ public final class TransformerActivity extends AppCompatActivity {
&& transformer.getProgress(progressHolder) != PROGRESS_STATE_NOT_STARTED) { && transformer.getProgress(progressHolder) != PROGRESS_STATE_NOT_STARTED) {
progressIndicator.setProgress(progressHolder.progress); progressIndicator.setProgress(progressHolder.progress);
informationTextView.setText( informationTextView.setText(
getString( getString(R.string.export_timer, exportStopwatch.elapsed(TimeUnit.SECONDS)));
R.string.transformation_timer,
transformationStopwatch.elapsed(TimeUnit.SECONDS)));
mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500); mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500);
} }
} }
@ -283,7 +281,7 @@ public final class TransformerActivity extends AppCompatActivity {
"displayInputButton", "displayInputButton",
"debugTextView", "debugTextView",
"informationTextView", "informationTextView",
"transformationStopwatch", "exportStopwatch",
"progressViewGroup", "progressViewGroup",
"debugFrame", "debugFrame",
}) })
@ -310,7 +308,7 @@ public final class TransformerActivity extends AppCompatActivity {
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK)) .setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
.build()); .build());
if (!bundle.getBoolean(ConfigurationActivity.ABORT_SLOW_TRANSFORMATION)) { if (!bundle.getBoolean(ConfigurationActivity.ABORT_SLOW_EXPORT)) {
transformerBuilder.setMuxerFactory( transformerBuilder.setMuxerFactory(
new DefaultMuxer.Factory(/* maxDelayBetweenSamplesMs= */ C.TIME_UNSET)); new DefaultMuxer.Factory(/* maxDelayBetweenSamplesMs= */ C.TIME_UNSET));
} }
@ -345,10 +343,10 @@ public final class TransformerActivity extends AppCompatActivity {
private File createExternalCacheFile(String fileName) throws IOException { private File createExternalCacheFile(String fileName) throws IOException {
File file = new File(getExternalCacheDir(), fileName); File file = new File(getExternalCacheDir(), fileName);
if (file.exists() && !file.delete()) { if (file.exists() && !file.delete()) {
throw new IllegalStateException("Could not delete the previous transformer output file"); throw new IllegalStateException("Could not delete the previous export output file");
} }
if (!file.createNewFile()) { if (!file.createNewFile()) {
throw new IllegalStateException("Could not create the transformer output file"); throw new IllegalStateException("Could not create the export output file");
} }
return file; return file;
} }
@ -356,7 +354,7 @@ public final class TransformerActivity extends AppCompatActivity {
@RequiresNonNull({ @RequiresNonNull({
"inputCardView", "inputCardView",
"outputPlayerView", "outputPlayerView",
"transformationStopwatch", "exportStopwatch",
"progressViewGroup", "progressViewGroup",
}) })
private EditedMediaItem createEditedMediaItem(MediaItem mediaItem, @Nullable Bundle bundle) private EditedMediaItem createEditedMediaItem(MediaItem mediaItem, @Nullable Bundle bundle)
@ -618,13 +616,13 @@ public final class TransformerActivity extends AppCompatActivity {
"informationTextView", "informationTextView",
"progressViewGroup", "progressViewGroup",
"debugFrame", "debugFrame",
"transformationStopwatch", "exportStopwatch",
}) })
private void onError(ExportException exportException) { private void onError(ExportException exportException) {
if (transformationStopwatch.isRunning()) { if (exportStopwatch.isRunning()) {
transformationStopwatch.stop(); exportStopwatch.stop();
} }
informationTextView.setText(R.string.transformation_error); informationTextView.setText(R.string.export_error);
progressViewGroup.setVisibility(View.GONE); progressViewGroup.setVisibility(View.GONE);
debugFrame.removeAllViews(); debugFrame.removeAllViews();
Toast.makeText(getApplicationContext(), "Export error: " + exportException, Toast.LENGTH_LONG) Toast.makeText(getApplicationContext(), "Export error: " + exportException, Toast.LENGTH_LONG)
@ -643,13 +641,12 @@ public final class TransformerActivity extends AppCompatActivity {
"informationTextView", "informationTextView",
"progressViewGroup", "progressViewGroup",
"debugFrame", "debugFrame",
"transformationStopwatch", "exportStopwatch",
}) })
private void onCompleted(String filePath, MediaItem inputMediaItem) { private void onCompleted(String filePath, MediaItem inputMediaItem) {
transformationStopwatch.stop(); exportStopwatch.stop();
informationTextView.setText( informationTextView.setText(
getString( getString(R.string.export_completed, exportStopwatch.elapsed(TimeUnit.SECONDS)));
R.string.transformation_completed, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
progressViewGroup.setVisibility(View.GONE); progressViewGroup.setVisibility(View.GONE);
debugFrame.removeAllViews(); debugFrame.removeAllViews();
inputCardView.setVisibility(View.VISIBLE); inputCardView.setVisibility(View.VISIBLE);
@ -774,7 +771,7 @@ public final class TransformerActivity extends AppCompatActivity {
public SurfaceView getDebugPreviewSurfaceView(int width, int height) { public SurfaceView getDebugPreviewSurfaceView(int width, int height) {
checkState( checkState(
surfaceView == null || (this.width == width && this.height == height), surfaceView == null || (this.width == width && this.height == height),
"Transformer should not change the output size mid-transformation."); "Transformer should not change the output size mid-export.");
if (surfaceView != null) { if (surfaceView != null) {
return surfaceView; return surfaceView;
} }

View File

@ -210,9 +210,9 @@
android:layout_weight="1"> android:layout_weight="1">
<TextView <TextView
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/abort_slow_transformation" /> android:text="@string/abort_slow_export" />
<CheckBox <CheckBox
android:id="@+id/abort_slow_transformation_checkbox" android:id="@+id/abort_slow_export_checkbox"
android:layout_gravity="end"/> android:layout_gravity="end"/>
</TableRow> </TableRow>
<TableRow <TableRow
@ -247,17 +247,17 @@
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:text="@string/select_video_effects" android:text="@string/select_video_effects"
app:layout_constraintBottom_toTopOf="@+id/transform_button" app:layout_constraintBottom_toTopOf="@+id/export_button"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<Button <Button
android:id="@+id/transform_button" android:id="@+id/export_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="28dp" android:layout_marginBottom="28dp"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:text="@string/transform" android:text="@string/export"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />

View File

@ -29,20 +29,20 @@
<string name="rotate" translatable="false">Rotate video (degrees)</string> <string name="rotate" translatable="false">Rotate video (degrees)</string>
<string name="enable_fallback" translatable="false">Enable fallback</string> <string name="enable_fallback" translatable="false">Enable fallback</string>
<string name="enable_debug_preview" translatable="false">Enable debug preview</string> <string name="enable_debug_preview" translatable="false">Enable debug preview</string>
<string name="abort_slow_transformation" translatable="false">Abort slow transformation</string> <string name="abort_slow_export" translatable="false">Abort slow export</string>
<string name="trim" translatable="false">Trim</string> <string name="trim" translatable="false">Trim</string>
<string name="hdr_mode" translatable="false">HDR mode</string> <string name="hdr_mode" translatable="false">HDR mode</string>
<string name="select_audio_effects" translatable="false">Add audio effects</string> <string name="select_audio_effects" translatable="false">Add audio effects</string>
<string name="select_video_effects" translatable="false">Add video effects</string> <string name="select_video_effects" translatable="false">Add video effects</string>
<string name="periodic_vignette_options" translatable="false">Periodic vignette options</string> <string name="periodic_vignette_options" translatable="false">Periodic vignette options</string>
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipeShaderProgram. Check the README for instructions.</string> <string name="no_media_pipe_error" translatable="false">Failed to load MediaPipeShaderProgram. Check the README for instructions.</string>
<string name="transform" translatable="false">Transform</string> <string name="export" translatable="false">Export</string>
<string name="debug_preview" translatable="false">Debug preview:</string> <string name="debug_preview" translatable="false">Debug preview:</string>
<string name="debug_preview_not_available" translatable="false">No debug preview available.</string> <string name="debug_preview_not_available" translatable="false">No debug preview available.</string>
<string name="transformation_started" translatable="false">Transformation started</string> <string name="export_started" translatable="false">Export started</string>
<string name="transformation_timer" translatable="false">Transformation started %d seconds ago.</string> <string name="export_timer" translatable="false">Export started %d seconds ago.</string>
<string name="transformation_completed" translatable="false">Transformation completed in %d seconds.</string> <string name="export_completed" translatable="false">Export completed in %d seconds.</string>
<string name="transformation_error" translatable="false">Transformation error</string> <string name="export_error" translatable="false">Export error</string>
<string name="trim_range">Bounds in seconds</string> <string name="trim_range">Bounds in seconds</string>
<string-array name="color_filter_options"> <string-array name="color_filter_options">
<item>Grayscale</item> <item>Grayscale</item>