Search in sources :

Example 1 with Metadata

use of androidx.media3.common.Metadata in project media by androidx.

the class Format method toBundle.

@UnstableApi
@Override
public Bundle toBundle() {
    Bundle bundle = new Bundle();
    bundle.putString(keyForField(FIELD_ID), id);
    bundle.putString(keyForField(FIELD_LABEL), label);
    bundle.putString(keyForField(FIELD_LANGUAGE), language);
    bundle.putInt(keyForField(FIELD_SELECTION_FLAGS), selectionFlags);
    bundle.putInt(keyForField(FIELD_ROLE_FLAGS), roleFlags);
    bundle.putInt(keyForField(FIELD_AVERAGE_BITRATE), averageBitrate);
    bundle.putInt(keyForField(FIELD_PEAK_BITRATE), peakBitrate);
    bundle.putString(keyForField(FIELD_CODECS), codecs);
    // Metadata is currently not Bundleable because Metadata.Entry is an Interface,
    // which would be difficult to unbundle in a backward compatible way.
    // The entries are additionally of limited usefulness to remote processes.
    bundle.putParcelable(keyForField(FIELD_METADATA), metadata);
    // Container specific.
    bundle.putString(keyForField(FIELD_CONTAINER_MIME_TYPE), containerMimeType);
    // Sample specific.
    bundle.putString(keyForField(FIELD_SAMPLE_MIME_TYPE), sampleMimeType);
    bundle.putInt(keyForField(FIELD_MAX_INPUT_SIZE), maxInputSize);
    for (int i = 0; i < initializationData.size(); i++) {
        bundle.putByteArray(keyForInitializationData(i), initializationData.get(i));
    }
    // DrmInitData doesn't need to be Bundleable as it's only used in the playing process to
    // initialize the decoder.
    bundle.putParcelable(keyForField(FIELD_DRM_INIT_DATA), drmInitData);
    bundle.putLong(keyForField(FIELD_SUBSAMPLE_OFFSET_US), subsampleOffsetUs);
    // Video specific.
    bundle.putInt(keyForField(FIELD_WIDTH), width);
    bundle.putInt(keyForField(FIELD_HEIGHT), height);
    bundle.putFloat(keyForField(FIELD_FRAME_RATE), frameRate);
    bundle.putInt(keyForField(FIELD_ROTATION_DEGREES), rotationDegrees);
    bundle.putFloat(keyForField(FIELD_PIXEL_WIDTH_HEIGHT_RATIO), pixelWidthHeightRatio);
    bundle.putByteArray(keyForField(FIELD_PROJECTION_DATA), projectionData);
    bundle.putInt(keyForField(FIELD_STEREO_MODE), stereoMode);
    bundle.putBundle(keyForField(FIELD_COLOR_INFO), BundleableUtil.toNullableBundle(colorInfo));
    // Audio specific.
    bundle.putInt(keyForField(FIELD_CHANNEL_COUNT), channelCount);
    bundle.putInt(keyForField(FIELD_SAMPLE_RATE), sampleRate);
    bundle.putInt(keyForField(FIELD_PCM_ENCODING), pcmEncoding);
    bundle.putInt(keyForField(FIELD_ENCODER_DELAY), encoderDelay);
    bundle.putInt(keyForField(FIELD_ENCODER_PADDING), encoderPadding);
    // Text specific.
    bundle.putInt(keyForField(FIELD_ACCESSIBILITY_CHANNEL), accessibilityChannel);
    // Source specific.
    bundle.putInt(keyForField(FIELD_CRYPTO_TYPE), cryptoType);
    return bundle;
}
Also used : Bundle(android.os.Bundle) UnstableApi(androidx.media3.common.util.UnstableApi)

Example 2 with Metadata

use of androidx.media3.common.Metadata in project media by androidx.

the class FormatTest method createTestFormat.

private static Format createTestFormat() {
    byte[] initData1 = new byte[] { 1, 2, 3 };
    byte[] initData2 = new byte[] { 4, 5, 6 };
    List<byte[]> initializationData = new ArrayList<>();
    initializationData.add(initData1);
    initializationData.add(initData2);
    DrmInitData.SchemeData drmData1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, buildTestData(128, 1));
    DrmInitData.SchemeData drmData2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, buildTestData(128, 1));
    DrmInitData drmInitData = new DrmInitData(drmData1, drmData2);
    byte[] projectionData = new byte[] { 1, 2, 3 };
    Metadata metadata = new Metadata(new FakeMetadataEntry("id1"), new FakeMetadataEntry("id2"));
    ColorInfo colorInfo = new ColorInfo(C.COLOR_SPACE_BT709, C.COLOR_RANGE_LIMITED, C.COLOR_TRANSFER_SDR, new byte[] { 1, 2, 3, 4, 5, 6, 7 });
    return new Format.Builder().setId("id").setLabel("label").setLanguage("language").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setRoleFlags(C.ROLE_FLAG_MAIN).setAverageBitrate(1024).setPeakBitrate(2048).setCodecs("codec").setMetadata(metadata).setContainerMimeType(VIDEO_MP4).setSampleMimeType(MimeTypes.VIDEO_H264).setMaxInputSize(5000).setInitializationData(initializationData).setDrmInitData(drmInitData).setSubsampleOffsetUs(Format.OFFSET_SAMPLE_RELATIVE).setWidth(1920).setHeight(1080).setFrameRate(24).setRotationDegrees(90).setPixelWidthHeightRatio(4).setProjectionData(projectionData).setStereoMode(C.STEREO_MODE_TOP_BOTTOM).setColorInfo(colorInfo).setChannelCount(6).setSampleRate(44100).setPcmEncoding(C.ENCODING_PCM_24BIT).setEncoderDelay(1001).setEncoderPadding(1002).setAccessibilityChannel(2).setCryptoType(C.CRYPTO_TYPE_CUSTOM_BASE).build();
}
Also used : FakeMetadataEntry(androidx.media3.test.utils.FakeMetadataEntry) ArrayList(java.util.ArrayList)

Example 3 with Metadata

use of androidx.media3.common.Metadata in project media by androidx.

the class DownloadHelper method getRendererCapabilities.

/**
 * Extracts renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory) {
    Renderer[] renderers = renderersFactory.createRenderers(Util.createHandlerForCurrentOrMainLooper(), new VideoRendererEventListener() {
    }, new AudioRendererEventListener() {
    }, (cues) -> {
    }, (metadata) -> {
    });
    RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
    for (int i = 0; i < renderers.length; i++) {
        capabilities[i] = renderers[i].getCapabilities();
    }
    return capabilities;
}
Also used : Renderer(androidx.media3.exoplayer.Renderer) VideoRendererEventListener(androidx.media3.exoplayer.video.VideoRendererEventListener) AudioRendererEventListener(androidx.media3.exoplayer.audio.AudioRendererEventListener) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities)

Example 4 with Metadata

use of androidx.media3.common.Metadata in project media by androidx.

the class MetadataRenderer method readMetadata.

private void readMetadata() {
    if (!inputStreamEnded && pendingMetadata == null) {
        buffer.clear();
        FormatHolder formatHolder = getFormatHolder();
        @ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
        0);
        if (result == C.RESULT_BUFFER_READ) {
            if (buffer.isEndOfStream()) {
                inputStreamEnded = true;
            } else {
                buffer.subsampleOffsetUs = subsampleOffsetUs;
                buffer.flip();
                @Nullable Metadata metadata = castNonNull(decoder).decode(buffer);
                if (metadata != null) {
                    List<Metadata.Entry> entries = new ArrayList<>(metadata.length());
                    decodeWrappedMetadata(metadata, entries);
                    if (!entries.isEmpty()) {
                        Metadata expandedMetadata = new Metadata(entries);
                        pendingMetadata = expandedMetadata;
                        pendingMetadataTimestampUs = buffer.timeUs;
                    }
                }
            }
        } else if (result == C.RESULT_FORMAT_READ) {
            subsampleOffsetUs = Assertions.checkNotNull(formatHolder.format).subsampleOffsetUs;
        }
    }
}
Also used : ReadDataResult(androidx.media3.exoplayer.source.SampleStream.ReadDataResult) FormatHolder(androidx.media3.exoplayer.FormatHolder) Metadata(androidx.media3.common.Metadata) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Example 5 with Metadata

use of androidx.media3.common.Metadata in project media by androidx.

the class IcyDataSource method readMetadata.

/**
 * Reads an ICY stream metadata block, passing it to {@link #listener} unless the block is empty.
 *
 * @return True if the block was extracted, including if its length byte indicated a length of
 *     zero. False if the end of the stream was reached.
 * @throws IOException If an error occurs reading from the wrapped {@link DataSource}.
 */
private boolean readMetadata() throws IOException {
    int bytesRead = upstream.read(metadataLengthByteHolder, 0, 1);
    if (bytesRead == C.RESULT_END_OF_INPUT) {
        return false;
    }
    int metadataLength = (metadataLengthByteHolder[0] & 0xFF) << 4;
    if (metadataLength == 0) {
        return true;
    }
    int offset = 0;
    int lengthRemaining = metadataLength;
    byte[] metadata = new byte[metadataLength];
    while (lengthRemaining > 0) {
        bytesRead = upstream.read(metadata, offset, lengthRemaining);
        if (bytesRead == C.RESULT_END_OF_INPUT) {
            return false;
        }
        offset += bytesRead;
        lengthRemaining -= bytesRead;
    }
    // Discard trailing zero bytes.
    while (metadataLength > 0 && metadata[metadataLength - 1] == 0) {
        metadataLength--;
    }
    if (metadataLength > 0) {
        listener.onIcyMetadata(new ParsableByteArray(metadata, metadataLength));
    }
    return true;
}
Also used : ParsableByteArray(androidx.media3.common.util.ParsableByteArray)

Aggregations

Metadata (androidx.media3.common.Metadata)81 Test (org.junit.Test)79 Nullable (androidx.annotation.Nullable)46 Format (androidx.media3.common.Format)18 MediaMetadata (androidx.media3.common.MediaMetadata)17 ArrayList (java.util.ArrayList)17 MediaItem (androidx.media3.common.MediaItem)16 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)14 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)13 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 MotionPhotoMetadata (androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata)8 Player (androidx.media3.common.Player)7 MediumTest (androidx.test.filters.MediumTest)7 TrackGroupArray (androidx.media3.common.TrackGroupArray)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 MediaDescriptionCompat (android.support.v4.media.MediaDescriptionCompat)5 Timeline (androidx.media3.common.Timeline)5 DatabaseIOException (androidx.media3.database.DatabaseIOException)5 TrackOutput (androidx.media3.extractor.TrackOutput)5