mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 02:08:40 +00:00
Remove now-unused colorInfo parsing from video transcoding.
This commit is contained in:
committed by
Alex Hart
parent
3b5376ef8b
commit
ffdd5b62ae
@@ -150,11 +150,6 @@ final class VideoTrackConverter {
|
||||
outputHeightRotated = outputHeight;
|
||||
}
|
||||
|
||||
final ColorInfo colorInfo = preDecodeColorInfo(mVideoExtractor, inputVideoFormat);
|
||||
// IMPORTANT: reset extractor after probing
|
||||
mVideoExtractor.unselectTrack(videoInputTrack);
|
||||
mVideoExtractor.selectTrack(videoInputTrack);
|
||||
mVideoExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
||||
final MediaFormat outputVideoFormat = MediaFormat.createVideoFormat(videoCodec, outputWidthRotated, outputHeightRotated);
|
||||
|
||||
// Set some properties. Failing to specify some of these can cause the MediaCodec
|
||||
@@ -192,82 +187,6 @@ final class VideoTrackConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private ColorInfo preDecodeColorInfo(MediaExtractor extractor, MediaFormat inputFormat) throws IOException {
|
||||
MediaCodec decoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
|
||||
decoder.configure(inputFormat, null, null, 0);
|
||||
decoder.start();
|
||||
|
||||
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
|
||||
boolean outputFormatKnown = false;
|
||||
Integer colorStandard = null, colorTransfer = null, colorRange = null;
|
||||
|
||||
boolean inputDone = false;
|
||||
|
||||
while (!outputFormatKnown) {
|
||||
|
||||
// ---- FEED INPUT ----
|
||||
if (!inputDone) {
|
||||
int inIndex = decoder.dequeueInputBuffer(20000);
|
||||
if (inIndex >= 0) {
|
||||
ByteBuffer inputBuffer = decoder.getInputBuffer(inIndex);
|
||||
int sampleSize = extractor.readSampleData(inputBuffer, 0);
|
||||
|
||||
if (sampleSize < 0) {
|
||||
decoder.queueInputBuffer(
|
||||
inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM
|
||||
);
|
||||
inputDone = true;
|
||||
} else {
|
||||
long pts = extractor.getSampleTime();
|
||||
decoder.queueInputBuffer(inIndex, 0, sampleSize, pts, 0);
|
||||
extractor.advance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- DRAIN OUTPUT ----
|
||||
int outIndex = decoder.dequeueOutputBuffer(info, 20000);
|
||||
|
||||
if (outIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
|
||||
MediaFormat fmt = decoder.getOutputFormat();
|
||||
if (fmt.containsKey(MediaFormat.KEY_COLOR_STANDARD))
|
||||
colorStandard = fmt.getInteger(MediaFormat.KEY_COLOR_STANDARD);
|
||||
if (fmt.containsKey(MediaFormat.KEY_COLOR_TRANSFER))
|
||||
colorTransfer = fmt.getInteger(MediaFormat.KEY_COLOR_TRANSFER);
|
||||
if (fmt.containsKey(MediaFormat.KEY_COLOR_RANGE))
|
||||
colorRange = fmt.getInteger(MediaFormat.KEY_COLOR_RANGE);
|
||||
outputFormatKnown = true;
|
||||
} else if (outIndex >= 0) {
|
||||
// We won't render, but must release output buffers
|
||||
decoder.releaseOutputBuffer(outIndex, false);
|
||||
}
|
||||
|
||||
// If EOS reached and still no format → decoder doesn’t provide it
|
||||
if (inputDone && outIndex == MediaCodec.INFO_TRY_AGAIN_LATER) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
decoder.stop();
|
||||
decoder.release();
|
||||
|
||||
return new ColorInfo(colorStandard, colorTransfer, colorRange);
|
||||
}
|
||||
|
||||
|
||||
private boolean isHdr(MediaFormat inputVideoFormat) {
|
||||
if (Build.VERSION.SDK_INT < 24) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final int colorInfo = inputVideoFormat.getInteger(MediaFormat.KEY_COLOR_TRANSFER);
|
||||
return colorInfo == MediaFormat.COLOR_TRANSFER_ST2084 || colorInfo == MediaFormat.COLOR_TRANSFER_HLG;
|
||||
} catch (NullPointerException npe) {
|
||||
// color transfer key does not exist, no color data supplied
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void setMuxer(final @NonNull Muxer muxer) throws IOException {
|
||||
mMuxer = muxer;
|
||||
if (mEncoderOutputVideoFormat != null) {
|
||||
@@ -626,16 +545,5 @@ final class VideoTrackConverter {
|
||||
return MediaConverter.getMimeTypeFor(format).startsWith("video/");
|
||||
}
|
||||
|
||||
private class ColorInfo {
|
||||
public final Integer colorStandard;
|
||||
public final Integer colorTransfer;
|
||||
public final Integer colorRange;
|
||||
|
||||
public ColorInfo(Integer colorSpace, Integer transfer, Integer primaries) {
|
||||
this.colorStandard = colorSpace;
|
||||
this.colorTransfer = transfer;
|
||||
this.colorRange = primaries;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user