Implement org.webrtc.VideoEncoder using the android MediaCodec.
BUG=webrtc:7760 Change-Id: I22134fe616d5c5b77148c80f01f1ea1119ae786c Reviewed-on: https://chromium-review.googlesource.com/526074 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Peter Thatcher <pthatcher@webrtc.org> Commit-Queue: Bjorn Mellem <mellem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18573}
This commit is contained in:
@ -46,11 +46,11 @@ public class EncodedImage {
|
||||
this.qp = qp;
|
||||
}
|
||||
|
||||
public Builder builder() {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
public static class Builder {
|
||||
private ByteBuffer buffer;
|
||||
private int encodedWidth;
|
||||
private int encodedHeight;
|
||||
|
||||
41
webrtc/sdk/android/api/org/webrtc/VideoCodecStatus.java
Normal file
41
webrtc/sdk/android/api/org/webrtc/VideoCodecStatus.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
/**
|
||||
* Status codes reported by video encoding/decoding components. This should be kept in sync with
|
||||
* video_error_codes.h.
|
||||
*/
|
||||
public enum VideoCodecStatus {
|
||||
REQUEST_SLI(2),
|
||||
NO_OUTPUT(1),
|
||||
OK(0),
|
||||
ERROR(-1),
|
||||
LEVEL_EXCEEDED(-2),
|
||||
MEMORY(-3),
|
||||
ERR_PARAMETER(-4),
|
||||
ERR_SIZE(-5),
|
||||
TIMEOUT(-6),
|
||||
UNINITIALIZED(-7),
|
||||
ERR_REQUEST_SLI(-12),
|
||||
FALLBACK_SOFTWARE(-13),
|
||||
TARGET_BITRATE_OVERSHOOT(-14);
|
||||
|
||||
private final int number;
|
||||
|
||||
private VideoCodecStatus(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
}
|
||||
@ -18,9 +18,17 @@ public interface VideoEncoder {
|
||||
/** Settings passed to the encoder by WebRTC. */
|
||||
public class Settings {
|
||||
public final int numberOfCores;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public final int startBitrate; // Kilobits per second.
|
||||
public final int maxFramerate;
|
||||
|
||||
public Settings(int numberOfCores) {
|
||||
public Settings(int numberOfCores, int width, int height, int startBitrate, int maxFramerate) {
|
||||
this.numberOfCores = numberOfCores;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.startBitrate = startBitrate;
|
||||
this.maxFramerate = maxFramerate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,23 +57,23 @@ public interface VideoEncoder {
|
||||
*/
|
||||
public class BitrateAllocation {
|
||||
// First index is the spatial layer and second the temporal layer.
|
||||
public final long[][] bitratesBbs;
|
||||
public final int[][] bitratesBbs;
|
||||
|
||||
/**
|
||||
* Initializes the allocation with a two dimensional array of bitrates. The first index of the
|
||||
* array is the spatial layer and the second index in the temporal layer.
|
||||
*/
|
||||
public BitrateAllocation(long[][] bitratesBbs) {
|
||||
public BitrateAllocation(int[][] bitratesBbs) {
|
||||
this.bitratesBbs = bitratesBbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total bitrate allocated for all layers.
|
||||
*/
|
||||
public long getSum() {
|
||||
long sum = 0;
|
||||
for (long[] spatialLayer : bitratesBbs) {
|
||||
for (long bitrate : spatialLayer) {
|
||||
public int getSum() {
|
||||
int sum = 0;
|
||||
for (int[] spatialLayer : bitratesBbs) {
|
||||
for (int bitrate : spatialLayer) {
|
||||
sum += bitrate;
|
||||
}
|
||||
}
|
||||
@ -101,24 +109,24 @@ public interface VideoEncoder {
|
||||
/**
|
||||
* Initializes the encoding process. Call before any calls to encode.
|
||||
*/
|
||||
void initEncode(Settings settings, Callback encodeCallback);
|
||||
VideoCodecStatus initEncode(Settings settings, Callback encodeCallback);
|
||||
/**
|
||||
* Releases the encoder. No more calls to encode will be made after this call.
|
||||
*/
|
||||
void release();
|
||||
VideoCodecStatus release();
|
||||
/**
|
||||
* Requests the encoder to encode a frame.
|
||||
*/
|
||||
void encode(VideoFrame frame, EncodeInfo info);
|
||||
VideoCodecStatus encode(VideoFrame frame, EncodeInfo info);
|
||||
/**
|
||||
* Informs the encoder of the packet loss and the round-trip time of the network.
|
||||
*
|
||||
* @param packetLoss How many packets are lost on average per 255 packets.
|
||||
* @param roundTripTimeMs Round-trip time of the network in milliseconds.
|
||||
*/
|
||||
void setChannelParameters(short packetLoss, long roundTripTimeMs);
|
||||
VideoCodecStatus setChannelParameters(short packetLoss, long roundTripTimeMs);
|
||||
/** Sets the bitrate allocation and the target framerate for the encoder. */
|
||||
void setRateAllocation(BitrateAllocation allocation, long framerate);
|
||||
VideoCodecStatus setRateAllocation(BitrateAllocation allocation, int framerate);
|
||||
/** Any encoder that wants to use WebRTC provided quality scaler must implement this method. */
|
||||
ScalingSettings getScalingSettings();
|
||||
/** Should return a descriptive name for the implementation. */
|
||||
|
||||
Reference in New Issue
Block a user