OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.webrtc; | 11 package org.webrtc; |
12 | 12 |
13 import android.annotation.TargetApi; | 13 import android.annotation.TargetApi; |
14 import android.media.MediaCodec; | 14 import android.media.MediaCodec; |
15 import android.media.MediaCodecInfo.CodecCapabilities; | 15 import android.media.MediaCodecInfo.CodecCapabilities; |
16 import android.media.MediaFormat; | 16 import android.media.MediaFormat; |
17 import android.os.SystemClock; | 17 import android.os.SystemClock; |
18 import android.view.Surface; | 18 import android.view.Surface; |
19 import java.io.IOException; | 19 import java.io.IOException; |
20 import java.nio.ByteBuffer; | 20 import java.nio.ByteBuffer; |
21 import java.util.concurrent.BlockingDeque; | 21 import java.util.concurrent.BlockingDeque; |
22 import java.util.concurrent.LinkedBlockingDeque; | 22 import java.util.concurrent.LinkedBlockingDeque; |
| 23 import java.util.concurrent.TimeUnit; |
23 import org.webrtc.ThreadUtils.ThreadChecker; | 24 import org.webrtc.ThreadUtils.ThreadChecker; |
24 | 25 |
25 /** Android hardware video decoder. */ | 26 /** Android hardware video decoder. */ |
26 @TargetApi(16) | 27 @TargetApi(16) |
27 @SuppressWarnings("deprecation") // Cannot support API 16 without using deprecat
ed methods. | 28 @SuppressWarnings("deprecation") // Cannot support API 16 without using deprecat
ed methods. |
28 class HardwareVideoDecoder | 29 class HardwareVideoDecoder |
29 implements VideoDecoder, SurfaceTextureHelper.OnTextureFrameAvailableListene
r { | 30 implements VideoDecoder, SurfaceTextureHelper.OnTextureFrameAvailableListene
r { |
30 private static final String TAG = "HardwareVideoDecoder"; | 31 private static final String TAG = "HardwareVideoDecoder"; |
31 | 32 |
32 // TODO(magjed): Use MediaFormat.KEY_* constants when part of the public API. | 33 // TODO(magjed): Use MediaFormat.KEY_* constants when part of the public API. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 276 } |
276 | 277 |
277 if (buffer.capacity() < size) { | 278 if (buffer.capacity() < size) { |
278 Logging.e(TAG, "decode() - HW buffer too small"); | 279 Logging.e(TAG, "decode() - HW buffer too small"); |
279 return VideoCodecStatus.ERROR; | 280 return VideoCodecStatus.ERROR; |
280 } | 281 } |
281 buffer.put(frame.buffer); | 282 buffer.put(frame.buffer); |
282 | 283 |
283 frameInfos.offer(new FrameInfo(SystemClock.elapsedRealtime(), frame.rotation
)); | 284 frameInfos.offer(new FrameInfo(SystemClock.elapsedRealtime(), frame.rotation
)); |
284 try { | 285 try { |
285 codec.queueInputBuffer( | 286 codec.queueInputBuffer(index, 0 /* offset */, size, |
286 index, 0 /* offset */, size, frame.captureTimeMs * 1000, 0 /* flags */
); | 287 TimeUnit.NANOSECONDS.toMicros(frame.captureTimeNs), 0 /* flags */); |
287 } catch (IllegalStateException e) { | 288 } catch (IllegalStateException e) { |
288 Logging.e(TAG, "queueInputBuffer failed", e); | 289 Logging.e(TAG, "queueInputBuffer failed", e); |
289 frameInfos.pollLast(); | 290 frameInfos.pollLast(); |
290 return VideoCodecStatus.ERROR; | 291 return VideoCodecStatus.ERROR; |
291 } | 292 } |
292 if (keyFrameRequired) { | 293 if (keyFrameRequired) { |
293 keyFrameRequired = false; | 294 keyFrameRequired = false; |
294 } | 295 } |
295 return VideoCodecStatus.OK; | 296 return VideoCodecStatus.OK; |
296 } | 297 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 691 |
691 private boolean isSupportedColorFormat(int colorFormat) { | 692 private boolean isSupportedColorFormat(int colorFormat) { |
692 for (int supported : MediaCodecUtils.DECODER_COLOR_FORMATS) { | 693 for (int supported : MediaCodecUtils.DECODER_COLOR_FORMATS) { |
693 if (supported == colorFormat) { | 694 if (supported == colorFormat) { |
694 return true; | 695 return true; |
695 } | 696 } |
696 } | 697 } |
697 return false; | 698 return false; |
698 } | 699 } |
699 } | 700 } |
OLD | NEW |