blob: 2822677868db4f3aa531e1e7bd4bf3c2dc6ff176 [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;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000032 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {
33 return -1;
34 }
35
36 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; }
37};
38
39class VideoDecoder {
40 public:
41 enum DecoderType {
Zeke Chin71f6f442015-06-29 14:34:58 -070042 kH264,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000043 kVp8,
Peter Boström7252a2b2015-05-18 19:42:03 +020044 kVp9,
45 kUnsupportedCodec,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000046 };
47
48 static VideoDecoder* Create(DecoderType codec_type);
49
50 virtual ~VideoDecoder() {}
51
Peter Boström7252a2b2015-05-18 19:42:03 +020052 virtual int32_t InitDecode(const VideoCodec* codec_settings,
53 int32_t number_of_cores) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000054
Peter Boström7252a2b2015-05-18 19:42:03 +020055 virtual int32_t Decode(const EncodedImage& input_image,
56 bool missing_frames,
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000057 const RTPFragmentationHeader* fragmentation,
Peter Boström7252a2b2015-05-18 19:42:03 +020058 const CodecSpecificInfo* codec_specific_info = NULL,
59 int64_t render_time_ms = -1) = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000060
61 virtual int32_t RegisterDecodeCompleteCallback(
62 DecodedImageCallback* callback) = 0;
63
64 virtual int32_t Release() = 0;
65 virtual int32_t Reset() = 0;
pbos@webrtc.org776e6f22014-10-29 15:28:39 +000066};
67
Peter Boström7252a2b2015-05-18 19:42:03 +020068// Class used to wrap external VideoDecoders to provide a fallback option on
69// software decoding when a hardware decoder fails to decode a stream due to
70// hardware restrictions, such as max resolution.
71class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
72 public:
73 VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
74 VideoDecoder* decoder);
75
76 int32_t InitDecode(const VideoCodec* codec_settings,
77 int32_t number_of_cores) override;
78
79 int32_t Decode(const EncodedImage& input_image,
80 bool missing_frames,
81 const RTPFragmentationHeader* fragmentation,
82 const CodecSpecificInfo* codec_specific_info,
83 int64_t render_time_ms) override;
84
85 int32_t RegisterDecodeCompleteCallback(
86 DecodedImageCallback* callback) override;
87
88 int32_t Release() override;
89 int32_t Reset() override;
90
91 private:
92 bool InitFallbackDecoder();
93
94 const DecoderType decoder_type_;
95 VideoDecoder* const decoder_;
96
97 VideoCodec codec_settings_;
98 int32_t number_of_cores_;
99 rtc::scoped_ptr<VideoDecoder> fallback_decoder_;
100 DecodedImageCallback* callback_;
101};
102
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000103} // namespace webrtc
104
105#endif // WEBRTC_VIDEO_DECODER_H_