<commit_before>/*
 * Copyright 2021 The Android Open Source Project
 *
 * 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.google.android.exoplayer2.transformer;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static java.lang.Math.abs;
import static java.lang.Math.max;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Pixel test for frame processing via {@link FrameEditor#processData()}. Expected images are taken
 * from emulators, so tests on physical devices may fail. To test on physical devices, please modify
 * the MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE.
 */
@RunWith(AndroidJUnit4.class)
public final class FrameEditorDataProcessingTest {

  private static final String TAG = "FrameEditorDataProcessingTest";

  // Input MP4 file to transform.
  private static final String INPUT_MP4_ASSET_STRING = "media/mp4/sample.mp4";

  /* Expected first frames after transformation.
   * To generate new "expected" assets:
   * 1. Insert this code into a test, to download some editedBitmap.
   *  + try (FileOutputStream fileOutputStream = new FileOutputStream("/sdcard/tmp.png")) {
   *  +    // quality is ignored
   *  +   editedBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
   *  + }
   * 2. Run the test on a "Nexus 6P API 23" emulator. Emulators are preferred as the automated
   *    presubmit that will run this test will also be an emulator. API versions 29+ have storage
   *    restrictions that complicate file generation.
   * 3. Open the "Device File Explorer", find "/sdcard/tmp.png", and "Save As..." the file.
   */<commit_msg>Reduce the length of the FrameEditorDataProcessingTest TAG.<commit_after>/*
 * Copyright 2021 The Android Open Source Project
 *
 * 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.google.android.exoplayer2.transformer;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static java.lang.Math.abs;
import static java.lang.Math.max;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Pixel test for frame processing via {@link FrameEditor#processData()}. Expected images are taken
 * from emulators, so tests on physical devices may fail. To test on physical devices, please modify
 * the MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE.
 */
@RunWith(AndroidJUnit4.class)
public final class FrameEditorDataProcessingTest {

  private static final String TAG = "FrameEditorDataTest";

  // Input MP4 file to transform.
  private static final String INPUT_MP4_ASSET_STRING = "media/mp4/sample.mp4";

  /* Expected first frames after transformation.
   * To generate new "expected" assets:
   * 1. Insert this code into a test, to download some editedBitmap.
   *  + try (FileOutputStream fileOutputStream = new FileOutputStream("/sdcard/tmp.png")) {
   *  +    // quality is ignored
   *  +   editedBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
   *  + }
   * 2. Run the test on a "Nexus 6P API 23" emulator. Emulators are preferred as the automated
   *    presubmit that will run this test will also be an emulator. API versions 29+ have storage
   *    restrictions that complicate file generation.
   * 3. Open the "Device File Explorer", find "/sdcard/tmp.png", and "Save As..." the file.
   */
{'fraction_non_alphanumeric': 0.08732439335887612, 'fraction_numerical': 0.009259259259259259, 'mean_word_length': 4.59375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6547217', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1734, 'n_words': 582}