NekoX/TMessagesProj/src/main/java/com/google/android/exoplayer2/decoder/SimpleOutputBuffer.java

66 lines
1.8 KiB
Java
Raw Normal View History

2017-03-31 01:58:05 +02:00
/*
* Copyright (C) 2016 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.
*/
2018-08-27 10:33:11 +02:00
package com.google.android.exoplayer2.decoder;
2017-03-31 01:58:05 +02:00
2020-07-26 10:03:38 +02:00
import androidx.annotation.Nullable;
2017-03-31 01:58:05 +02:00
import java.nio.ByteBuffer;
2017-12-08 18:35:59 +01:00
import java.nio.ByteOrder;
2017-03-31 01:58:05 +02:00
/**
* Buffer for {@link SimpleDecoder} output.
*/
public class SimpleOutputBuffer extends OutputBuffer {
private final SimpleDecoder<?, SimpleOutputBuffer, ?> owner;
2020-07-26 10:03:38 +02:00
@Nullable public ByteBuffer data;
2017-03-31 01:58:05 +02:00
public SimpleOutputBuffer(SimpleDecoder<?, SimpleOutputBuffer, ?> owner) {
this.owner = owner;
}
/**
* Initializes the buffer.
*
* @param timeUs The presentation timestamp for the buffer, in microseconds.
* @param size An upper bound on the size of the data that will be written to the buffer.
* @return The {@link #data} buffer, for convenience.
*/
public ByteBuffer init(long timeUs, int size) {
this.timeUs = timeUs;
if (data == null || data.capacity() < size) {
2017-12-08 18:35:59 +01:00
data = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
2017-03-31 01:58:05 +02:00
}
data.position(0);
data.limit(size);
return data;
}
@Override
public void clear() {
super.clear();
if (data != null) {
data.clear();
}
}
@Override
public void release() {
owner.releaseOutputBuffer(this);
}
}