blob: 30e27792e978c4822c09f2d45f5f338e3ffd7a67 [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
14#include <vector>
15
16#include "webrtc/common_types.h"
17#include "webrtc/typedefs.h"
18#include "webrtc/video_frame.h"
19
20namespace webrtc {
21
22class RTPFragmentationHeader;
23// TODO(pbos): Expose these through a public (root) header or change these APIs.
24struct CodecSpecificInfo;
25struct VideoCodec;
26
27class DecodedImageCallback {
28 public:
29 virtual ~DecodedImageCallback() {}
30
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070031 virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
Per327d8ba2015-11-10 14:00:27 +010032 // Provides an alternative interface that allows the decoder to specify the
33 // decode time excluding waiting time for any previous pending frame to
34 // return. This is necessary for breaking positive feedback in the delay
35 // estimation when the decoder has a single output buffer.
36 // TODO(perkj): Remove default implementation when chromium has been updated.
37 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) {
38 // The default implementation ignores custom decode time value.
39 return Decoded(decodedImage);
40 }
41
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000042 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {
43 return -1;
44 }
45
46 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; }
47};
48
49class VideoDecoder {
50 public:
51 enum DecoderType {
Zeke Chin71f6f442015-06-29 14:34:58 -070052 kH264,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000053 kVp8,
Peter Boström7252a2b2015-05-18 19:42:03 +020054 kVp9,
55 kUnsupportedCodec,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000056 };
57
58 static VideoDecoder* Create(DecoderType codec_type);
59
60 virtual ~VideoDecoder() {}
61
Peter Boström7252a2b2015-05-18 19:42:03 +020062 virtual int32_t InitDecode(const VideoCodec* codec_settings,
63 int32_t number_of_cores) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000064
Peter Boström7252a2b2015-05-18 19:42:03 +020065 virtual int32_t Decode(const EncodedImage& input_image,
66 bool missing_frames,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000067 const RTPFragmentationHeader* fragmentation,
Peter Boström7252a2b2015-05-18 19:42:03 +020068 const CodecSpecificInfo* codec_specific_info = NULL,
69 int64_t render_time_ms = -1) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000070
71 virtual int32_t RegisterDecodeCompleteCallback(
72 DecodedImageCallback* callback) = 0;
73
74 virtual int32_t Release() = 0;
75 virtual int32_t Reset() = 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; }
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000081};
82
Peter Boström7252a2b2015-05-18 19:42:03 +020083// Class used to wrap external VideoDecoders to provide a fallback option on
84// software decoding when a hardware decoder fails to decode a stream due to
85// hardware restrictions, such as max resolution.
86class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
87 public:
88 VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
89 VideoDecoder* decoder);
90
91 int32_t InitDecode(const VideoCodec* codec_settings,
92 int32_t number_of_cores) override;
93
94 int32_t Decode(const EncodedImage& input_image,
95 bool missing_frames,
96 const RTPFragmentationHeader* fragmentation,
97 const CodecSpecificInfo* codec_specific_info,
98 int64_t render_time_ms) override;
99
100 int32_t RegisterDecodeCompleteCallback(
101 DecodedImageCallback* callback) override;
102
103 int32_t Release() override;
104 int32_t Reset() override;
perkj796cfaf2015-12-10 09:27:38 -0800105 bool PrefersLateDecoding() const override;
Peter Boström7252a2b2015-05-18 19:42:03 +0200106
107 private:
108 bool InitFallbackDecoder();
109
110 const DecoderType decoder_type_;
111 VideoDecoder* const decoder_;
112
113 VideoCodec codec_settings_;
114 int32_t number_of_cores_;
115 rtc::scoped_ptr<VideoDecoder> fallback_decoder_;
116 DecodedImageCallback* callback_;
117};
118
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000119} // namespace webrtc
120
121#endif // WEBRTC_VIDEO_DECODER_H_