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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // surface. | 86 // surface. |
87 private EglBase14 textureEglBase; | 87 private EglBase14 textureEglBase; |
88 // Input surface for the codec. The encoder will draw input textures onto thi
s surface. | 88 // Input surface for the codec. The encoder will draw input textures onto thi
s surface. |
89 private Surface textureInputSurface; | 89 private Surface textureInputSurface; |
90 // Drawer used to draw input textures onto the codec's input surface. | 90 // Drawer used to draw input textures onto the codec's input surface. |
91 private GlRectDrawer textureDrawer; | 91 private GlRectDrawer textureDrawer; |
92 | 92 |
93 private MediaCodec codec; | 93 private MediaCodec codec; |
94 private Callback callback; | 94 private Callback callback; |
95 | 95 |
| 96 private boolean automaticResizeOn; |
96 private int width; | 97 private int width; |
97 private int height; | 98 private int height; |
98 | 99 |
99 // Contents of the last observed config frame output by the MediaCodec. Used b
y H.264. | 100 // Contents of the last observed config frame output by the MediaCodec. Used b
y H.264. |
100 private ByteBuffer configBuffer = null; | 101 private ByteBuffer configBuffer = null; |
101 | 102 |
102 /** | 103 /** |
103 * Creates a new HardwareVideoEncoder with the given codecName, codecType, col
orFormat, key frame | 104 * Creates a new HardwareVideoEncoder with the given codecName, codecType, col
orFormat, key frame |
104 * intervals, and bitrateAdjuster. | 105 * intervals, and bitrateAdjuster. |
105 * | 106 * |
(...skipping 21 matching lines...) Expand all Loading... |
127 } | 128 } |
128 this.keyFrameIntervalSec = keyFrameIntervalSec; | 129 this.keyFrameIntervalSec = keyFrameIntervalSec; |
129 this.forcedKeyFrameNs = TimeUnit.MILLISECONDS.toNanos(forceKeyFrameIntervalM
s); | 130 this.forcedKeyFrameNs = TimeUnit.MILLISECONDS.toNanos(forceKeyFrameIntervalM
s); |
130 this.bitrateAdjuster = bitrateAdjuster; | 131 this.bitrateAdjuster = bitrateAdjuster; |
131 this.outputBuilders = new LinkedBlockingDeque<>(); | 132 this.outputBuilders = new LinkedBlockingDeque<>(); |
132 this.textureContext = textureContext; | 133 this.textureContext = textureContext; |
133 } | 134 } |
134 | 135 |
135 @Override | 136 @Override |
136 public VideoCodecStatus initEncode(Settings settings, Callback callback) { | 137 public VideoCodecStatus initEncode(Settings settings, Callback callback) { |
| 138 automaticResizeOn = settings.automaticResizeOn; |
| 139 |
137 return initEncodeInternal( | 140 return initEncodeInternal( |
138 settings.width, settings.height, settings.startBitrate, settings.maxFram
erate, callback); | 141 settings.width, settings.height, settings.startBitrate, settings.maxFram
erate, callback); |
139 } | 142 } |
140 | 143 |
141 private VideoCodecStatus initEncodeInternal( | 144 private VideoCodecStatus initEncodeInternal( |
142 int width, int height, int bitrateKbps, int fps, Callback callback) { | 145 int width, int height, int bitrateKbps, int fps, Callback callback) { |
143 Logging.d( | 146 Logging.d( |
144 TAG, "initEncode: " + width + " x " + height + ". @ " + bitrateKbps + "k
bps. Fps: " + fps); | 147 TAG, "initEncode: " + width + " x " + height + ". @ " + bitrateKbps + "k
bps. Fps: " + fps); |
145 this.width = width; | 148 this.width = width; |
146 this.height = height; | 149 this.height = height; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 public VideoCodecStatus setRateAllocation(BitrateAllocation bitrateAllocation,
int framerate) { | 376 public VideoCodecStatus setRateAllocation(BitrateAllocation bitrateAllocation,
int framerate) { |
374 if (framerate > MAX_VIDEO_FRAMERATE) { | 377 if (framerate > MAX_VIDEO_FRAMERATE) { |
375 framerate = MAX_VIDEO_FRAMERATE; | 378 framerate = MAX_VIDEO_FRAMERATE; |
376 } | 379 } |
377 bitrateAdjuster.setTargets(bitrateAllocation.getSum(), framerate); | 380 bitrateAdjuster.setTargets(bitrateAllocation.getSum(), framerate); |
378 return updateBitrate(); | 381 return updateBitrate(); |
379 } | 382 } |
380 | 383 |
381 @Override | 384 @Override |
382 public ScalingSettings getScalingSettings() { | 385 public ScalingSettings getScalingSettings() { |
383 // TODO(mellem): Implement scaling settings. | 386 return new ScalingSettings(automaticResizeOn); |
384 return null; | |
385 } | 387 } |
386 | 388 |
387 @Override | 389 @Override |
388 public String getImplementationName() { | 390 public String getImplementationName() { |
389 return "HardwareVideoEncoder: " + codecName; | 391 return "HardwareVideoEncoder: " + codecName; |
390 } | 392 } |
391 | 393 |
392 private VideoCodecStatus resetCodec(int newWidth, int newHeight) { | 394 private VideoCodecStatus resetCodec(int newWidth, int newHeight) { |
393 VideoCodecStatus status = release(); | 395 VideoCodecStatus status = release(); |
394 if (status != VideoCodecStatus.OK) { | 396 if (status != VideoCodecStatus.OK) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar: | 553 case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar: |
552 case MediaCodecInfo.CodecCapabilities.COLOR_QCOM_FormatYUV420SemiPlanar: | 554 case MediaCodecInfo.CodecCapabilities.COLOR_QCOM_FormatYUV420SemiPlanar: |
553 case MediaCodecUtils.COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m: | 555 case MediaCodecUtils.COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m: |
554 return NV12; | 556 return NV12; |
555 default: | 557 default: |
556 throw new IllegalArgumentException("Unsupported colorFormat: " + color
Format); | 558 throw new IllegalArgumentException("Unsupported colorFormat: " + color
Format); |
557 } | 559 } |
558 } | 560 } |
559 } | 561 } |
560 } | 562 } |
OLD | NEW |