blob: f5d8850c9d422c442259e00c07de4d0137cfd744 [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
Bjorn Mellemb080b462017-06-20 10:02:36 -070024 public Settings(int numberOfCores, int width, int height) {
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020025 this.numberOfCores = numberOfCores;
Bjorn Mellemb080b462017-06-20 10:02:36 -070026 this.width = width;
27 this.height = height;
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020028 }
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 Mellemb080b462017-06-20 10:02:36 -070057 VideoCodecStatus initDecode(Settings settings, Callback decodeCallback);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020058 /**
59 * Called when the decoder is no longer needed. Any more calls to decode will not be made.
60 */
Bjorn Mellemb080b462017-06-20 10:02:36 -070061 VideoCodecStatus release();
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020062 /**
63 * Request the decoder to decode a frame.
64 */
Bjorn Mellemb080b462017-06-20 10:02:36 -070065 VideoCodecStatus decode(EncodedImage frame, DecodeInfo info);
Sami Kalliomäkie2410e92017-06-02 14:46:12 +020066 /**
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}