video_decoder.h revision 327d8babc81913410dbb3125a62be3ff0e46e9f4
1/*
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
31  virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
32  // 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
42  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 {
52    kH264,
53    kVp8,
54    kVp9,
55    kUnsupportedCodec,
56  };
57
58  static VideoDecoder* Create(DecoderType codec_type);
59
60  virtual ~VideoDecoder() {}
61
62  virtual int32_t InitDecode(const VideoCodec* codec_settings,
63                             int32_t number_of_cores) = 0;
64
65  virtual int32_t Decode(const EncodedImage& input_image,
66                         bool missing_frames,
67                         const RTPFragmentationHeader* fragmentation,
68                         const CodecSpecificInfo* codec_specific_info = NULL,
69                         int64_t render_time_ms = -1) = 0;
70
71  virtual int32_t RegisterDecodeCompleteCallback(
72      DecodedImageCallback* callback) = 0;
73
74  virtual int32_t Release() = 0;
75  virtual int32_t Reset() = 0;
76};
77
78// Class used to wrap external VideoDecoders to provide a fallback option on
79// software decoding when a hardware decoder fails to decode a stream due to
80// hardware restrictions, such as max resolution.
81class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
82 public:
83  VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type,
84                                      VideoDecoder* decoder);
85
86  int32_t InitDecode(const VideoCodec* codec_settings,
87                     int32_t number_of_cores) override;
88
89  int32_t Decode(const EncodedImage& input_image,
90                 bool missing_frames,
91                 const RTPFragmentationHeader* fragmentation,
92                 const CodecSpecificInfo* codec_specific_info,
93                 int64_t render_time_ms) override;
94
95  int32_t RegisterDecodeCompleteCallback(
96      DecodedImageCallback* callback) override;
97
98  int32_t Release() override;
99  int32_t Reset() override;
100
101 private:
102  bool InitFallbackDecoder();
103
104  const DecoderType decoder_type_;
105  VideoDecoder* const decoder_;
106
107  VideoCodec codec_settings_;
108  int32_t number_of_cores_;
109  rtc::scoped_ptr<VideoDecoder> fallback_decoder_;
110  DecodedImageCallback* callback_;
111};
112
113}  // namespace webrtc
114
115#endif  // WEBRTC_VIDEO_DECODER_H_
116