blob: 368b846e14af5a62a3cf056a83d3319d989f5a38 [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
Peter Boströmb7d9a972015-12-18 16:01:11 +010014#include <string>
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000015#include <vector>
16
17#include "webrtc/common_types.h"
18#include "webrtc/typedefs.h"
19#include "webrtc/video_frame.h"
20
21namespace webrtc {
22
23class RTPFragmentationHeader;
24// TODO(pbos): Expose these through a public (root) header or change these APIs.
25struct CodecSpecificInfo;
26struct VideoCodec;
27
28class DecodedImageCallback {
29 public:
30 virtual ~DecodedImageCallback() {}
31
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070032 virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
Per327d8ba2015-11-10 14:00:27 +010033 // Provides an alternative interface that allows the decoder to specify the
34 // decode time excluding waiting time for any previous pending frame to
35 // return. This is necessary for breaking positive feedback in the delay
36 // estimation when the decoder has a single output buffer.
37 // TODO(perkj): Remove default implementation when chromium has been updated.
38 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) {
39 // The default implementation ignores custom decode time value.
40 return Decoded(decodedImage);
41 }
42
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000043 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {
44 return -1;
45 }
46
47 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; }
48};
49
50class VideoDecoder {
51 public:
52 enum DecoderType {
Zeke Chin71f6f442015-06-29 14:34:58 -070053 kH264,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000054 kVp8,
Peter Boström7252a2b2015-05-18 19:42:03 +020055 kVp9,
56 kUnsupportedCodec,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000057 };
58
59 static VideoDecoder* Create(DecoderType codec_type);
60
61 virtual ~VideoDecoder() {}
62
Peter Boström7252a2b2015-05-18 19:42:03 +020063 virtual int32_t InitDecode(const VideoCodec* codec_settings,
64 int32_t number_of_cores) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000065
Peter Boström7252a2b2015-05-18 19:42:03 +020066 virtual int32_t Decode(const EncodedImage& input_image,
67 bool missing_frames,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000068 const RTPFragmentationHeader* fragmentation,
Peter Boström7252a2b2015-05-18 19:42:03 +020069 const CodecSpecificInfo* codec_specific_info = NULL,
70 int64_t render_time_ms = -1) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000071
72 virtual int32_t RegisterDecodeCompleteCallback(
73 DecodedImageCallback* callback) = 0;
74
75 virtual int32_t Release() = 0;
Peter Boströmed3277b2016-02-02 15:40:04 +010076 // TODO(pbos): Remove, this is no longer called. A no-op implementation is
77 // added here to permit removal elsewhere.
78 virtual int32_t Reset() { return 0; }
perkj796cfaf2015-12-10 09:27:38 -080079
80 // Returns true if the decoder prefer to decode frames late.
81 // That is, it can not decode infinite number of frames before the decoded
82 // frame is consumed.
83 virtual bool PrefersLateDecoding() const { return true; }
Peter Boströmb7d9a972015-12-18 16:01:11 +010084
85 virtual const char* ImplementationName() const { return "unknown"; }
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000086};
87
Peter Boström7252a2b2015-05-18 19:42:03 +020088// Class used to wrap external VideoDecoders to provide a fallback option on
89// software decoding when a hardware decoder fails to decode a stream due to
90// hardware restrictions, such as max resolution.
91class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
92 public:
93 VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
94 VideoDecoder* decoder);
95
96 int32_t InitDecode(const VideoCodec* codec_settings,
97 int32_t number_of_cores) override;
98
99 int32_t Decode(const EncodedImage& input_image,
100 bool missing_frames,
101 const RTPFragmentationHeader* fragmentation,
102 const CodecSpecificInfo* codec_specific_info,
103 int64_t render_time_ms) override;
104
105 int32_t RegisterDecodeCompleteCallback(
106 DecodedImageCallback* callback) override;
107
108 int32_t Release() override;
perkj796cfaf2015-12-10 09:27:38 -0800109 bool PrefersLateDecoding() const override;
Peter Boström7252a2b2015-05-18 19:42:03 +0200110
Peter Boströmb7d9a972015-12-18 16:01:11 +0100111 const char* ImplementationName() const override;
112
Peter Boström7252a2b2015-05-18 19:42:03 +0200113 private:
114 bool InitFallbackDecoder();
115
116 const DecoderType decoder_type_;
117 VideoDecoder* const decoder_;
118
119 VideoCodec codec_settings_;
120 int32_t number_of_cores_;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100121 std::string fallback_implementation_name_;
Peter Boström7252a2b2015-05-18 19:42:03 +0200122 rtc::scoped_ptr<VideoDecoder> fallback_decoder_;
123 DecodedImageCallback* callback_;
124};
125
jbauche03ac512016-02-03 05:51:48 -0800126// Video decoder class to be used for unknown codecs. Doesn't support decoding
127// but logs messages to LS_ERROR.
128class NullVideoDecoder : public VideoDecoder {
129 public:
130 NullVideoDecoder();
131
132 int32_t InitDecode(const VideoCodec* codec_settings,
133 int32_t number_of_cores) override;
134
135 int32_t Decode(const EncodedImage& input_image,
136 bool missing_frames,
137 const RTPFragmentationHeader* fragmentation,
138 const CodecSpecificInfo* codec_specific_info,
139 int64_t render_time_ms) override;
140
141 int32_t RegisterDecodeCompleteCallback(
142 DecodedImageCallback* callback) override;
143
144 int32_t Release() override;
145 int32_t Reset() override;
146
147 const char* ImplementationName() const override;
148};
149
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000150} // namespace webrtc
151
152#endif // WEBRTC_VIDEO_DECODER_H_