blob: e99183fdefe1e023fac7ca364c0fa1f67fe6382e [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;
perkj796cfaf2015-12-10 09:27:38 -080076
77 // Returns true if the decoder prefer to decode frames late.
78 // That is, it can not decode infinite number of frames before the decoded
79 // frame is consumed.
80 virtual bool PrefersLateDecoding() const { return true; }
Peter Boströmb7d9a972015-12-18 16:01:11 +010081
82 virtual const char* ImplementationName() const { return "unknown"; }
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000083};
84
Peter Boström7252a2b2015-05-18 19:42:03 +020085// Class used to wrap external VideoDecoders to provide a fallback option on
86// software decoding when a hardware decoder fails to decode a stream due to
87// hardware restrictions, such as max resolution.
88class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
89 public:
90 VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
91 VideoDecoder* decoder);
92
93 int32_t InitDecode(const VideoCodec* codec_settings,
94 int32_t number_of_cores) override;
95
96 int32_t Decode(const EncodedImage& input_image,
97 bool missing_frames,
98 const RTPFragmentationHeader* fragmentation,
99 const CodecSpecificInfo* codec_specific_info,
100 int64_t render_time_ms) override;
101
102 int32_t RegisterDecodeCompleteCallback(
103 DecodedImageCallback* callback) override;
104
105 int32_t Release() override;
perkj796cfaf2015-12-10 09:27:38 -0800106 bool PrefersLateDecoding() const override;
Peter Boström7252a2b2015-05-18 19:42:03 +0200107
Peter Boströmb7d9a972015-12-18 16:01:11 +0100108 const char* ImplementationName() const override;
109
Peter Boström7252a2b2015-05-18 19:42:03 +0200110 private:
111 bool InitFallbackDecoder();
112
113 const DecoderType decoder_type_;
114 VideoDecoder* const decoder_;
115
116 VideoCodec codec_settings_;
117 int32_t number_of_cores_;
Peter Boströmb7d9a972015-12-18 16:01:11 +0100118 std::string fallback_implementation_name_;
Peter Boström7252a2b2015-05-18 19:42:03 +0200119 rtc::scoped_ptr<VideoDecoder> fallback_decoder_;
120 DecodedImageCallback* callback_;
121};
122
jbauche03ac512016-02-03 05:51:48 -0800123// Video decoder class to be used for unknown codecs. Doesn't support decoding
124// but logs messages to LS_ERROR.
125class NullVideoDecoder : public VideoDecoder {
126 public:
127 NullVideoDecoder();
128
129 int32_t InitDecode(const VideoCodec* codec_settings,
130 int32_t number_of_cores) override;
131
132 int32_t Decode(const EncodedImage& input_image,
133 bool missing_frames,
134 const RTPFragmentationHeader* fragmentation,
135 const CodecSpecificInfo* codec_specific_info,
136 int64_t render_time_ms) override;
137
138 int32_t RegisterDecodeCompleteCallback(
139 DecodedImageCallback* callback) override;
140
141 int32_t Release() override;
jbauche03ac512016-02-03 05:51:48 -0800142
143 const char* ImplementationName() const override;
144};
145
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000146} // namespace webrtc
147
148#endif // WEBRTC_VIDEO_DECODER_H_