blob: 7bf9ac54d7c625915210f0ca3003b0738c3322c5 [file] [log] [blame]
Sami Kalliomäkie2410e92017-06-02 14:46:12 +02001/*
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
11package 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 */
17public interface VideoDecoder {
18 /** Settings passed to the decoder by WebRTC. */
19 public class Settings {
20 public final int numberOfCores;
Bjorn Mellemb080b462017-06-20 10:02:36 -070021 public final int width;
22 public final int height;
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020023
Magnus Jedvert1f2a3e72017-11-23 16:56:44 +010024 @CalledByNative("Settings")
Bjorn Mellemb080b462017-06-20 10:02:36 -070025 public Settings(int numberOfCores, int width, int height) {
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020026 this.numberOfCores = numberOfCores;
Bjorn Mellemb080b462017-06-20 10:02:36 -070027 this.width = width;
28 this.height = height;
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020029 }
30 }
31
32 /** Additional info for decoding. */
33 public class DecodeInfo {
34 public final boolean isMissingFrames;
35 public final long renderTimeMs;
36
37 public DecodeInfo(boolean isMissingFrames, long renderTimeMs) {
38 this.isMissingFrames = isMissingFrames;
39 this.renderTimeMs = renderTimeMs;
40 }
41 }
42
43 public interface Callback {
44 /**
45 * Call to return a decoded frame. Can be called on any thread.
46 *
47 * @param frame Decoded frame
48 * @param decodeTimeMs Time it took to decode the frame in milliseconds or null if not available
49 * @param qp QP value of the decoded frame or null if not available
50 */
51 void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp);
52 }
53
54 /**
55 * Initializes the decoding process with specified settings. Will be called on the decoding thread
56 * before any decode calls.
57 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010058 @CalledByNative VideoCodecStatus initDecode(Settings settings, Callback decodeCallback);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020059 /**
60 * Called when the decoder is no longer needed. Any more calls to decode will not be made.
61 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010062 @CalledByNative VideoCodecStatus release();
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020063 /**
64 * Request the decoder to decode a frame.
65 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010066 @CalledByNative VideoCodecStatus decode(EncodedImage frame, DecodeInfo info);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020067 /**
68 * The decoder should return true if it prefers late decoding. That is, it can not decode
69 * infinite number of frames before the decoded frame is consumed.
70 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010071 @CalledByNative boolean getPrefersLateDecoding();
Sami Kalliomäki5f5fc682017-10-19 11:34:08 +020072 /**
73 * Should return a descriptive name for the implementation. Gets called once and cached. May be
74 * called from arbitrary thread.
75 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010076 @CalledByNative String getImplementationName();
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020077}