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..9c634264ef597f378b5c2705b288fbd9d77cc176 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()?"); |
pbos-webrtc
2016/03/04 10:23:13
Forgot
AlexG
2016/03/04 18:44:12
Done.
|
} |
- 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); |
pbos-webrtc
2016/03/04 10:23:13
Non-supported codec
AlexG
2016/03/04 18:44:12
Done.
|
} |
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("reset for non initialized decoder."); |
pbos-webrtc
2016/03/04 10:23:13
Incorrect reset call for non-initialized decoder.
AlexG
2016/03/04 18:44:12
Done.
|
+ } |
+ 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(); |