Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
| 13 | /** |
| 14 | * Interface for a video decoder that can be used in WebRTC. All calls to the class will be made on |
| 15 | * a single decoding thread. |
| 16 | */ |
| 17 | public interface VideoDecoder { |
| 18 | /** Settings passed to the decoder by WebRTC. */ |
| 19 | public class Settings { |
| 20 | public final int numberOfCores; |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 21 | public final int width; |
| 22 | public final int height; |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 23 | |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 24 | public Settings(int numberOfCores, int width, int height) { |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 25 | this.numberOfCores = numberOfCores; |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 26 | this.width = width; |
| 27 | this.height = height; |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | |
| 31 | /** Additional info for decoding. */ |
| 32 | public class DecodeInfo { |
| 33 | public final boolean isMissingFrames; |
| 34 | public final long renderTimeMs; |
| 35 | |
| 36 | public DecodeInfo(boolean isMissingFrames, long renderTimeMs) { |
| 37 | this.isMissingFrames = isMissingFrames; |
| 38 | this.renderTimeMs = renderTimeMs; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public interface Callback { |
| 43 | /** |
| 44 | * Call to return a decoded frame. Can be called on any thread. |
| 45 | * |
| 46 | * @param frame Decoded frame |
| 47 | * @param decodeTimeMs Time it took to decode the frame in milliseconds or null if not available |
| 48 | * @param qp QP value of the decoded frame or null if not available |
| 49 | */ |
| 50 | void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Initializes the decoding process with specified settings. Will be called on the decoding thread |
| 55 | * before any decode calls. |
| 56 | */ |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 57 | VideoCodecStatus initDecode(Settings settings, Callback decodeCallback); |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 58 | /** |
| 59 | * Called when the decoder is no longer needed. Any more calls to decode will not be made. |
| 60 | */ |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 61 | VideoCodecStatus release(); |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 62 | /** |
| 63 | * Request the decoder to decode a frame. |
| 64 | */ |
Bjorn Mellem | b080b46 | 2017-06-20 10:02:36 -0700 | [diff] [blame] | 65 | VideoCodecStatus decode(EncodedImage frame, DecodeInfo info); |
Sami Kalliomäki | e2410e9 | 2017-06-02 14:46:12 +0200 | [diff] [blame] | 66 | /** |
| 67 | * The decoder should return true if it prefers late decoding. That is, it can not decode |
| 68 | * infinite number of frames before the decoded frame is consumed. |
| 69 | */ |
| 70 | boolean getPrefersLateDecoding(); |
| 71 | /** Should return a descriptive name for the implementation. */ |
| 72 | String getImplementationName(); |
| 73 | } |