Add motion photo metadata entry

PiperOrigin-RevId: 337863184
This commit is contained in:
kimvde 2020-10-19 16:49:38 +01:00 committed by Oliver Woodman
parent 2ada01c1e7
commit 021d725c0a
6 changed files with 186 additions and 2 deletions

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.extractor.mp4;
package com.google.android.exoplayer2.metadata.mp4;
import android.os.Parcel;
import android.os.Parcelable;

View File

@ -0,0 +1,116 @@
/*
* Copyright 2020 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.metadata.mp4;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.metadata.Metadata;
/** Metadata of a motion photo file. */
public final class MotionPhoto implements Metadata.Entry {
/** The start offset of the photo data, in bytes. */
public final int photoStartPosition;
/** The size of the photo data, in bytes. */
public final int photoSize;
/** The start offset of the video data, in bytes. */
public final int videoStartPosition;
/** The size of the video data, in bytes. */
public final int videoSize;
/** Creates an instance. */
public MotionPhoto(int photoStartPosition, int photoSize, int videoStartPosition, int videoSize) {
this.photoStartPosition = photoStartPosition;
this.photoSize = photoSize;
this.videoStartPosition = videoStartPosition;
this.videoSize = videoSize;
}
private MotionPhoto(Parcel in) {
photoStartPosition = in.readInt();
photoSize = in.readInt();
videoStartPosition = in.readInt();
videoSize = in.readInt();
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
MotionPhoto other = (MotionPhoto) obj;
return photoStartPosition == other.photoStartPosition
&& photoSize == other.photoSize
&& videoStartPosition == other.videoStartPosition
&& videoSize == other.videoSize;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + photoStartPosition;
result = 31 * result + photoSize;
result = 31 * result + videoStartPosition;
result = 31 * result + videoSize;
return result;
}
@Override
public String toString() {
return "Motion photo: photoStartPosition="
+ photoStartPosition
+ ", photoSize="
+ photoSize
+ ", videoStartPosition="
+ videoStartPosition
+ ", videoSize="
+ videoSize;
}
// Parcelable implementation.
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(photoStartPosition);
dest.writeInt(photoSize);
dest.writeInt(videoStartPosition);
dest.writeInt(videoSize);
}
@Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator<MotionPhoto> CREATOR =
new Parcelable.Creator<MotionPhoto>() {
@Override
public MotionPhoto createFromParcel(Parcel in) {
return new MotionPhoto(in);
}
@Override
public MotionPhoto[] newArray(int size) {
return new MotionPhoto[size];
}
};
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2020 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.
*/
@NonNullApi
package com.google.android.exoplayer2.metadata.mp4;
import com.google.android.exoplayer2.util.NonNullApi;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.extractor.mp4;
package com.google.android.exoplayer2.metadata.mp4;
import static com.google.common.truth.Truth.assertThat;

View File

@ -0,0 +1,48 @@
/*
* Copyright 2020 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.metadata.mp4;
import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Test for {@link MotionPhoto}. */
@RunWith(AndroidJUnit4.class)
public class MotionPhotoTest {
@Test
public void parcelable() {
MotionPhoto motionPhotoToParcel =
new MotionPhoto(
/* photoStartPosition= */ 0,
/* photoSize= */ 10,
/* videoStartPosition= */ 15,
/* videoSize= */ 35);
Parcel parcel = Parcel.obtain();
motionPhotoToParcel.writeToParcel(parcel, /* flags= */ 0);
parcel.setDataPosition(0);
MotionPhoto motionPhotoFromParcel = MotionPhoto.CREATOR.createFromParcel(parcel);
assertThat(motionPhotoFromParcel).isEqualTo(motionPhotoToParcel);
parcel.recycle();
}
}

View File

@ -28,6 +28,7 @@ import com.google.android.exoplayer2.metadata.id3.CommentFrame;
import com.google.android.exoplayer2.metadata.id3.Id3Frame;
import com.google.android.exoplayer2.metadata.id3.InternalFrame;
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
import com.google.android.exoplayer2.metadata.mp4.MdtaMetadataEntry;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.ParsableByteArray;
import java.util.ArrayList;