 Chromium Code Reviews
 Chromium Code Reviews Issue 1396073003:
  Prepare MediaCodecVideoEncoder for surface textures.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1396073003:
  Prepare MediaCodecVideoEncoder for surface textures.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| Index: talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoEncoder.java | 
| diff --git a/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoEncoder.java b/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoEncoder.java | 
| index dfff8f26912fbc62d9dd08fee9997c9ce2867d43..f679e5a96d83aa164f49c5dd9873e74cae7ec726 100644 | 
| --- a/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoEncoder.java | 
| +++ b/talk/app/webrtc/java/src/org/webrtc/MediaCodecVideoEncoder.java | 
| @@ -96,13 +96,13 @@ public class MediaCodecVideoEncoder { | 
| CodecCapabilities.COLOR_QCOM_FormatYUV420SemiPlanar, | 
| COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m | 
| }; | 
| - private int colorFormat; | 
| - // Video encoder type. | 
| private VideoCodecType type; | 
| + private int colorFormat; // Used by native code. | 
| + | 
| // SPS and PPS NALs (Config frame) for H.264. | 
| private ByteBuffer configData = null; | 
| - private MediaCodecVideoEncoder() {} | 
| + MediaCodecVideoEncoder() {} | 
| // Helper struct for findHwEncoder() below. | 
| private static class EncoderProperties { | 
| @@ -207,16 +207,13 @@ public class MediaCodecVideoEncoder { | 
| } | 
| } | 
| - // Return the array of input buffers, or null on failure. | 
| - private ByteBuffer[] initEncode( | 
| - VideoCodecType type, int width, int height, int kbps, int fps) { | 
| + boolean initEncode(VideoCodecType type, int width, int height, int kbps, int fps) { | 
| 
magjed_webrtc
2015/10/12 08:22:53
Add short comment about return value, e.g. "Return
 
perkj_webrtc
2015/10/12 09:16:06
Done.
 | 
| Logging.d(TAG, "Java initEncode: " + type + " : " + width + " x " + height + | 
| - ". @ " + kbps + " kbps. Fps: " + fps + | 
| - ". Color: 0x" + Integer.toHexString(colorFormat)); | 
| + ". @ " + kbps + " kbps. Fps: " + fps + "."); | 
| + | 
| if (mediaCodecThread != null) { | 
| throw new RuntimeException("Forgot to release()?"); | 
| } | 
| - this.type = type; | 
| EncoderProperties properties = null; | 
| String mime = null; | 
| int keyFrameIntervalSec = 0; | 
| @@ -232,6 +229,7 @@ public class MediaCodecVideoEncoder { | 
| if (properties == null) { | 
| throw new RuntimeException("Can not find HW encoder for " + type); | 
| } | 
| + colorFormat = properties.colorFormat; | 
| mediaCodecThread = Thread.currentThread(); | 
| try { | 
| MediaFormat format = MediaFormat.createVideoFormat(mime, width, height); | 
| @@ -242,25 +240,30 @@ public class MediaCodecVideoEncoder { | 
| format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, keyFrameIntervalSec); | 
| Logging.d(TAG, " Format: " + format); | 
| mediaCodec = createByCodecName(properties.codecName); | 
| + this.type = type; | 
| if (mediaCodec == null) { | 
| - return null; | 
| + return false; | 
| } | 
| mediaCodec.configure( | 
| format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); | 
| + | 
| mediaCodec.start(); | 
| - colorFormat = properties.colorFormat; | 
| outputBuffers = mediaCodec.getOutputBuffers(); | 
| - ByteBuffer[] inputBuffers = mediaCodec.getInputBuffers(); | 
| - Logging.d(TAG, "Input buffers: " + inputBuffers.length + | 
| - ". Output buffers: " + outputBuffers.length); | 
| - return inputBuffers; | 
| + | 
| } catch (IllegalStateException e) { | 
| Logging.e(TAG, "initEncode failed", e); | 
| - return null; | 
| + return false; | 
| } | 
| + return true; | 
| + } | 
| + | 
| + ByteBuffer[] getInputBuffers() { | 
| + ByteBuffer[] inputBuffers = mediaCodec.getInputBuffers(); | 
| + Logging.d(TAG, "Input buffers: " + inputBuffers.length); | 
| + return inputBuffers; | 
| } | 
| - private boolean encode( | 
| + boolean encodeBuffer( | 
| boolean isKeyframe, int inputBuffer, int size, | 
| long presentationTimestampUs) { | 
| checkOnMediaCodecThread(); | 
| @@ -280,12 +283,12 @@ public class MediaCodecVideoEncoder { | 
| return true; | 
| } | 
| catch (IllegalStateException e) { | 
| - Logging.e(TAG, "encode failed", e); | 
| + Logging.e(TAG, "encodeBuffer failed", e); | 
| return false; | 
| } | 
| } | 
| - private void release() { | 
| + void release() { | 
| Logging.d(TAG, "Java releaseEncoder"); | 
| checkOnMediaCodecThread(); | 
| try { | 
| @@ -316,7 +319,7 @@ public class MediaCodecVideoEncoder { | 
| // Dequeue an input buffer and return its index, -1 if no input buffer is | 
| // available, or -2 if the codec is no longer operative. | 
| - private int dequeueInputBuffer() { | 
| + int dequeueInputBuffer() { | 
| checkOnMediaCodecThread(); | 
| try { | 
| return mediaCodec.dequeueInputBuffer(DEQUEUE_TIMEOUT); | 
| @@ -327,7 +330,7 @@ public class MediaCodecVideoEncoder { | 
| } | 
| // Helper struct for dequeueOutputBuffer() below. | 
| - private static class OutputBufferInfo { | 
| + static class OutputBufferInfo { | 
| public OutputBufferInfo( | 
| int index, ByteBuffer buffer, | 
| boolean isKeyFrame, long presentationTimestampUs) { | 
| @@ -337,15 +340,15 @@ public class MediaCodecVideoEncoder { | 
| this.presentationTimestampUs = presentationTimestampUs; | 
| } | 
| - private final int index; | 
| - private final ByteBuffer buffer; | 
| - private final boolean isKeyFrame; | 
| - private final long presentationTimestampUs; | 
| + public final int index; | 
| + public final ByteBuffer buffer; | 
| + public final boolean isKeyFrame; | 
| + public final long presentationTimestampUs; | 
| } | 
| // Dequeue and return an output buffer, or null if no output is ready. Return | 
| // a fake OutputBufferInfo with index -1 if the codec is no longer operable. | 
| - private OutputBufferInfo dequeueOutputBuffer() { | 
| + OutputBufferInfo dequeueOutputBuffer() { | 
| checkOnMediaCodecThread(); | 
| try { | 
| MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); | 
| @@ -414,7 +417,7 @@ public class MediaCodecVideoEncoder { | 
| // Release a dequeued output buffer back to the codec for re-use. Return | 
| // false if the codec is no longer operable. | 
| - private boolean releaseOutputBuffer(int index) { | 
| + boolean releaseOutputBuffer(int index) { | 
| checkOnMediaCodecThread(); | 
| try { | 
| mediaCodec.releaseOutputBuffer(index, false); |