Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Unified Diff: webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java

Issue 1732533002: Add an option to soft reset HW decoder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments - 2 Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java
diff --git a/webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java b/webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java
index fe2c7dc4680d2de2833898b373459f462586dae3..6a3e7107691287a821dc4090317a9135a3190e15 100644
--- a/webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java
+++ b/webrtc/api/java/src/org/webrtc/MediaCodecVideoDecoder.java
@@ -239,12 +239,14 @@ public class MediaCodecVideoDecoder {
// Pass null in |surfaceTextureHelper| to configure the codec for ByteBuffer output.
private boolean initDecode(
- VideoCodecType type, int width, int height, SurfaceTextureHelper surfaceTextureHelper) {
+ VideoCodecType type, int width, int height,
+ SurfaceTextureHelper surfaceTextureHelper) {
if (mediaCodecThread != null) {
- throw new RuntimeException("Forgot to release()?");
+ throw new RuntimeException("initDecode: Forgot to release()?");
}
- useSurface = (surfaceTextureHelper != null);
+
String mime = null;
+ useSurface = (surfaceTextureHelper != null);
String[] supportedCodecPrefixes = null;
if (type == VideoCodecType.VIDEO_CODEC_VP8) {
mime = VP8_MIME_TYPE;
@@ -256,15 +258,17 @@ public class MediaCodecVideoDecoder {
mime = H264_MIME_TYPE;
supportedCodecPrefixes = supportedH264HwCodecPrefixes;
} else {
- throw new RuntimeException("Non supported codec " + type);
+ throw new RuntimeException("initDecode: Non-supported codec " + type);
}
DecoderProperties properties = findDecoder(mime, supportedCodecPrefixes);
if (properties == null) {
throw new RuntimeException("Cannot find HW decoder for " + type);
}
+
Logging.d(TAG, "Java initDecode: " + type + " : "+ width + " x " + height +
". Color: 0x" + Integer.toHexString(properties.colorFormat) +
". Use Surface: " + useSurface);
+
runningInstance = this; // Decoder is now running and can be queried for stack traces.
mediaCodecThread = Thread.currentThread();
try {
@@ -283,14 +287,14 @@ public class MediaCodecVideoDecoder {
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, properties.colorFormat);
}
Logging.d(TAG, " Format: " + format);
- mediaCodec =
- MediaCodecVideoEncoder.createByCodecName(properties.codecName);
+ mediaCodec = MediaCodecVideoEncoder.createByCodecName(properties.codecName);
if (mediaCodec == null) {
Logging.e(TAG, "Can not create media decoder");
return false;
}
mediaCodec.configure(format, surface, null, 0);
mediaCodec.start();
+
colorFormat = properties.colorFormat;
outputBuffers = mediaCodec.getOutputBuffers();
inputBuffers = mediaCodec.getInputBuffers();
@@ -307,6 +311,24 @@ public class MediaCodecVideoDecoder {
}
}
+ // Resets the decoder so it can start decoding frames with new resolution.
+ // Flushes MediaCodec and clears decoder output buffers.
+ private void reset(int width, int height) {
+ if (mediaCodecThread == null || mediaCodec == null) {
+ throw new RuntimeException("Incorrect reset call for non-initialized decoder.");
+ }
+ Logging.d(TAG, "Java reset: " + width + " x " + height);
+
+ mediaCodec.flush();
+
+ this.width = width;
+ this.height = height;
+ decodeStartTimeMs.clear();
+ dequeuedSurfaceOutputBuffers.clear();
+ hasDecodedFirstFrame = false;
+ droppedFrames = 0;
+ }
+
private void release() {
Logging.d(TAG, "Java releaseDecoder. Total number of dropped frames: " + droppedFrames);
checkOnMediaCodecThread();

Powered by Google App Engine
This is Rietveld 408576698