blob: 7a41840ba8fbf9b3d357c0bd730e84d1cd1c47dd [file] [log] [blame]
pbos@webrtc.org776e6f22014-10-29 15:28:39 +00001/*
2 * Copyright (c) 2014 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#ifndef WEBRTC_VIDEO_DECODER_H_
12#define WEBRTC_VIDEO_DECODER_H_
13
kwibergc891eb42016-03-02 03:41:34 -080014#include <memory>
Peter Boströmb7d9a972015-12-18 16:01:11 +010015#include <string>
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000016#include <vector>
17
18#include "webrtc/common_types.h"
19#include "webrtc/typedefs.h"
20#include "webrtc/video_frame.h"
21
22namespace webrtc {
23
24class RTPFragmentationHeader;
25// TODO(pbos): Expose these through a public (root) header or change these APIs.
26struct CodecSpecificInfo;
hta257dc392016-10-25 09:05:06 -070027class VideoCodec;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000028
29class DecodedImageCallback {
30 public:
31 virtual ~DecodedImageCallback() {}
32
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070033 virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
Per327d8ba2015-11-10 14:00:27 +010034 // Provides an alternative interface that allows the decoder to specify the
35 // decode time excluding waiting time for any previous pending frame to
36 // return. This is necessary for breaking positive feedback in the delay
37 // estimation when the decoder has a single output buffer.
38 // TODO(perkj): Remove default implementation when chromium has been updated.
39 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) {
40 // The default implementation ignores custom decode time value.
41 return Decoded(decodedImage);
42 }
43
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000044 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {
45 return -1;
46 }
47
48 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; }
49};
50
51class VideoDecoder {
52 public:
53 enum DecoderType {
Zeke Chin71f6f442015-06-29 14:34:58 -070054 kH264,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000055 kVp8,
Peter Boström7252a2b2015-05-18 19:42:03 +020056 kVp9,
57 kUnsupportedCodec,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000058 };
59
60 static VideoDecoder* Create(DecoderType codec_type);
61
62 virtual ~VideoDecoder() {}
63
Peter Boström7252a2b2015-05-18 19:42:03 +020064 virtual int32_t InitDecode(const VideoCodec* codec_settings,
65 int32_t number_of_cores) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000066
Peter Boström7252a2b2015-05-18 19:42:03 +020067 virtual int32_t Decode(const EncodedImage& input_image,
68 bool missing_frames,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000069 const RTPFragmentationHeader* fragmentation,
Peter Boström7252a2b2015-05-18 19:42:03 +020070 const CodecSpecificInfo* codec_specific_info = NULL,
71 int64_t render_time_ms = -1) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000072
73 virtual int32_t RegisterDecodeCompleteCallback(
74 DecodedImageCallback* callback) = 0;
75
76 virtual int32_t Release() = 0;
perkj796cfaf2015-12-10 09:27:38 -080077
78 // Returns true if the decoder prefer to decode frames late.
79 // That is, it can not decode infinite number of frames before the decoded
80 // frame is consumed.
81 virtual bool PrefersLateDecoding() const { return true; }
Peter Boströmb7d9a972015-12-18 16:01:11 +010082
83 virtual const char* ImplementationName() const { return "unknown"; }
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000084};
85
Peter Boström7252a2b2015-05-18 19:42:03 +020086// Class used to wrap external VideoDecoders to provide a fallback option on
87// software decoding when a hardware decoder fails to decode a stream due to
88// hardware restrictions, such as max resolution.
89class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
90 public:
91 VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
92 VideoDecoder* decoder);
93
94 int32_t InitDecode(const VideoCodec* codec_settings,
95 int32_t number_of_cores) override;
96
97 int32_t Decode(const EncodedImage& input_image,
98 bool missing_frames,
99 const RTPFragmentationHeader* fragmentation,
100 const CodecSpecificInfo* codec_specific_info,
101 int64_t render_time_ms) override;
102
103 int32_t RegisterDecodeCompleteCallback(
104 DecodedImageCallback* callback) override;
105
106 int32_t Release() override;
perkj796cfaf2015-12-10 09:27:38 -0800107 bool PrefersLateDecoding() const override;
Peter Boström7252a2b2015-05-18 19:42:03 +0200108
Peter Boströmb7d9a972015-12-18 16:01:11 +0100109 const char* ImplementationName() const override;
110
Peter Boström7252a2b2015-05-18 19:42:03 +0200111 private:
112 bool InitFallbackDecoder();
113
114 const DecoderType decoder_type_;
115 VideoDecoder* const decoder_;
116
117 VideoCodec codec_settings_;
118 int32_t number_of_cores_;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100119 std::string fallback_implementation_name_;
kwibergc891eb42016-03-02 03:41:34 -0800120 std::unique_ptr<VideoDecoder> fallback_decoder_;
Peter Boström7252a2b2015-05-18 19:42:03 +0200121 DecodedImageCallback* callback_;
122};
123
jbauche03ac512016-02-03 05:51:48 -0800124// Video decoder class to be used for unknown codecs. Doesn't support decoding
125// but logs messages to LS_ERROR.
126class NullVideoDecoder : public VideoDecoder {
127 public:
128 NullVideoDecoder();
129
130 int32_t InitDecode(const VideoCodec* codec_settings,
131 int32_t number_of_cores) override;
132
133 int32_t Decode(const EncodedImage& input_image,
134 bool missing_frames,
135 const RTPFragmentationHeader* fragmentation,
136 const CodecSpecificInfo* codec_specific_info,
137 int64_t render_time_ms) override;
138
139 int32_t RegisterDecodeCompleteCallback(
140 DecodedImageCallback* callback) override;
141
142 int32_t Release() override;
jbauche03ac512016-02-03 05:51:48 -0800143
144 const char* ImplementationName() const override;
145};
146
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000147} // namespace webrtc
148
149#endif // WEBRTC_VIDEO_DECODER_H_