OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 27 matching lines...) Expand all Loading... |
38 import android.os.Bundle; | 38 import android.os.Bundle; |
39 import android.view.Surface; | 39 import android.view.Surface; |
40 | 40 |
41 import org.webrtc.Logging; | 41 import org.webrtc.Logging; |
42 | 42 |
43 import java.nio.ByteBuffer; | 43 import java.nio.ByteBuffer; |
44 import java.util.Arrays; | 44 import java.util.Arrays; |
45 import java.util.List; | 45 import java.util.List; |
46 import java.util.concurrent.CountDownLatch; | 46 import java.util.concurrent.CountDownLatch; |
47 | 47 |
48 import javax.microedition.khronos.egl.EGLContext; | |
49 | |
50 // Java-side of peerconnection_jni.cc:MediaCodecVideoEncoder. | 48 // Java-side of peerconnection_jni.cc:MediaCodecVideoEncoder. |
51 // This class is an implementation detail of the Java PeerConnection API. | 49 // This class is an implementation detail of the Java PeerConnection API. |
52 @TargetApi(19) | 50 @TargetApi(19) |
53 @SuppressWarnings("deprecation") | 51 @SuppressWarnings("deprecation") |
54 public class MediaCodecVideoEncoder { | 52 public class MediaCodecVideoEncoder { |
55 // This class is constructed, operated, and destroyed by its C++ incarnation, | 53 // This class is constructed, operated, and destroyed by its C++ incarnation, |
56 // so the class and its methods have non-public visibility. The API this | 54 // so the class and its methods have non-public visibility. The API this |
57 // class exposes aims to mimic the webrtc::VideoEncoder API as closely as | 55 // class exposes aims to mimic the webrtc::VideoEncoder API as closely as |
58 // possibly to minimize the amount of translation work necessary. | 56 // possibly to minimize the amount of translation work necessary. |
59 | 57 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 try { | 261 try { |
264 // In the L-SDK this call can throw IOException so in order to work in | 262 // In the L-SDK this call can throw IOException so in order to work in |
265 // both cases catch an exception. | 263 // both cases catch an exception. |
266 return MediaCodec.createByCodecName(codecName); | 264 return MediaCodec.createByCodecName(codecName); |
267 } catch (Exception e) { | 265 } catch (Exception e) { |
268 return null; | 266 return null; |
269 } | 267 } |
270 } | 268 } |
271 | 269 |
272 boolean initEncode(VideoCodecType type, int width, int height, int kbps, int f
ps, | 270 boolean initEncode(VideoCodecType type, int width, int height, int kbps, int f
ps, |
273 EGLContext sharedContext) { | 271 EglBase.Context sharedContext) { |
274 final boolean useSurface = sharedContext != null; | 272 final boolean useSurface = sharedContext != null; |
275 Logging.d(TAG, "Java initEncode: " + type + " : " + width + " x " + height + | 273 Logging.d(TAG, "Java initEncode: " + type + " : " + width + " x " + height + |
276 ". @ " + kbps + " kbps. Fps: " + fps + ". Encode from texture : " + useS
urface); | 274 ". @ " + kbps + " kbps. Fps: " + fps + ". Encode from texture : " + useS
urface); |
277 | 275 |
278 if (mediaCodecThread != null) { | 276 if (mediaCodecThread != null) { |
279 throw new RuntimeException("Forgot to release()?"); | 277 throw new RuntimeException("Forgot to release()?"); |
280 } | 278 } |
281 EncoderProperties properties = null; | 279 EncoderProperties properties = null; |
282 String mime = null; | 280 String mime = null; |
283 int keyFrameIntervalSec = 0; | 281 int keyFrameIntervalSec = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 mediaCodec = createByCodecName(properties.codecName); | 314 mediaCodec = createByCodecName(properties.codecName); |
317 this.type = type; | 315 this.type = type; |
318 if (mediaCodec == null) { | 316 if (mediaCodec == null) { |
319 Logging.e(TAG, "Can not create media encoder"); | 317 Logging.e(TAG, "Can not create media encoder"); |
320 return false; | 318 return false; |
321 } | 319 } |
322 mediaCodec.configure( | 320 mediaCodec.configure( |
323 format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); | 321 format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); |
324 | 322 |
325 if (useSurface) { | 323 if (useSurface) { |
326 eglBase = new EglBase(sharedContext, EglBase.ConfigType.RECORDABLE); | 324 eglBase = EglBase.create(sharedContext, EglBase.ConfigType.RECORDABLE); |
327 // Create an input surface and keep a reference since we must release th
e surface when done. | 325 // Create an input surface and keep a reference since we must release th
e surface when done. |
328 inputSurface = mediaCodec.createInputSurface(); | 326 inputSurface = mediaCodec.createInputSurface(); |
329 eglBase.createSurface(inputSurface); | 327 eglBase.createSurface(inputSurface); |
330 drawer = new GlRectDrawer(); | 328 drawer = new GlRectDrawer(); |
331 } | 329 } |
332 mediaCodec.start(); | 330 mediaCodec.start(); |
333 outputBuffers = mediaCodec.getOutputBuffers(); | 331 outputBuffers = mediaCodec.getOutputBuffers(); |
334 Logging.d(TAG, "Output buffers: " + outputBuffers.length); | 332 Logging.d(TAG, "Output buffers: " + outputBuffers.length); |
335 | 333 |
336 } catch (IllegalStateException e) { | 334 } catch (IllegalStateException e) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 checkOnMediaCodecThread(); | 563 checkOnMediaCodecThread(); |
566 try { | 564 try { |
567 mediaCodec.releaseOutputBuffer(index, false); | 565 mediaCodec.releaseOutputBuffer(index, false); |
568 return true; | 566 return true; |
569 } catch (IllegalStateException e) { | 567 } catch (IllegalStateException e) { |
570 Logging.e(TAG, "releaseOutputBuffer failed", e); | 568 Logging.e(TAG, "releaseOutputBuffer failed", e); |
571 return false; | 569 return false; |
572 } | 570 } |
573 } | 571 } |
574 } | 572 } |
OLD | NEW |