blob: 879b694b28fa564fb4ac6680eddd64b5d46db6bf [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 /**
Rasmus Brandt42a2fc92018-07-09 13:38:01 +020055 * The decoder implementation backing this interface is either 1) a Java
56 * decoder (e.g., an Android platform decoder), or alternatively 2) a native
57 * decoder (e.g., a software decoder or a C++ decoder adapter).
58 *
59 * For case 1), createNativeVideoDecoder() should return zero.
60 * In this case, we expect the native library to call the decoder through
61 * JNI using the Java interface declared below.
62 *
63 * For case 2), createNativeVideoDecoder() should return a non-zero value.
64 * In this case, we expect the native library to treat the returned value as
65 * a raw pointer of type webrtc::VideoDecoder* (ownership is transferred to
66 * the caller). The native library should then directly call the
67 * webrtc::VideoDecoder interface without going through JNI. All calls to
68 * the Java interface methods declared below should thus throw an
69 * UnsupportedOperationException.
70 */
71 @CalledByNative
72 default long createNativeVideoDecoder() {
73 return 0;
74 }
75
76 /**
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020077 * Initializes the decoding process with specified settings. Will be called on the decoding thread
78 * before any decode calls.
79 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010080 @CalledByNative VideoCodecStatus initDecode(Settings settings, Callback decodeCallback);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020081 /**
82 * Called when the decoder is no longer needed. Any more calls to decode will not be made.
83 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010084 @CalledByNative VideoCodecStatus release();
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020085 /**
86 * Request the decoder to decode a frame.
87 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010088 @CalledByNative VideoCodecStatus decode(EncodedImage frame, DecodeInfo info);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020089 /**
90 * The decoder should return true if it prefers late decoding. That is, it can not decode
91 * infinite number of frames before the decoded frame is consumed.
92 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010093 @CalledByNative boolean getPrefersLateDecoding();
Sami Kalliomäki5f5fc682017-10-19 11:34:08 +020094 /**
95 * Should return a descriptive name for the implementation. Gets called once and cached. May be
96 * called from arbitrary thread.
97 */
Magnus Jedvert4eb01882017-11-20 22:33:40 +010098 @CalledByNative String getImplementationName();
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020099}