blob: 55751764ef357dbbf0267c8691dfbd6352002a04 [file] [log] [blame]
philipel2fee4d62018-03-21 16:52:13 +01001/*
2 * Copyright (c) 2018 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 VIDEO_VIDEO_STREAM_DECODER_IMPL_H_
12#define VIDEO_VIDEO_STREAM_DECODER_IMPL_H_
13
philipel2fee4d62018-03-21 16:52:13 +010014#include <map>
15#include <memory>
16#include <utility>
17
philipel79aab3f2018-03-26 14:31:23 +020018#include "api/optional.h"
philipel2fee4d62018-03-21 16:52:13 +010019#include "api/video/video_stream_decoder.h"
philipel97187112018-03-23 10:43:21 +010020#include "modules/video_coding/frame_buffer2.h"
21#include "modules/video_coding/jitter_estimator.h"
22#include "modules/video_coding/timing.h"
23#include "rtc_base/task_queue.h"
24#include "rtc_base/thread_checker.h"
25#include "system_wrappers/include/clock.h"
philipel2fee4d62018-03-21 16:52:13 +010026
27namespace webrtc {
28
29class VideoStreamDecoderImpl : public VideoStreamDecoder,
30 private DecodedImageCallback {
31 public:
32 VideoStreamDecoderImpl(
33 VideoStreamDecoder::Callbacks* callbacks,
34 VideoDecoderFactory* decoder_factory,
35 std::map<int, std::pair<SdpVideoFormat, int>> decoder_settings);
36
37 ~VideoStreamDecoderImpl() override;
38
39 void OnFrame(std::unique_ptr<video_coding::EncodedFrame> frame) override;
40
41 private:
philipel79aab3f2018-03-26 14:31:23 +020042 VideoDecoder* GetDecoder(int payload_type);
43
philipel2fee4d62018-03-21 16:52:13 +010044 // Implements DecodedImageCallback interface
45 int32_t Decoded(VideoFrame& decodedImage) override;
46 int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override;
47 void Decoded(VideoFrame& decodedImage,
48 rtc::Optional<int32_t> decode_time_ms,
49 rtc::Optional<uint8_t> qp) override;
50
philipel97187112018-03-23 10:43:21 +010051 VideoStreamDecoder::Callbacks* const callbacks_
52 RTC_PT_GUARDED_BY(bookkeeping_queue_);
53 VideoDecoderFactory* const decoder_factory_;
philipel2fee4d62018-03-21 16:52:13 +010054 std::map<int, std::pair<SdpVideoFormat, int>> decoder_settings_;
philipel97187112018-03-23 10:43:21 +010055
56 // The |bookkeeping_queue_| is used to:
57 // - Make |callbacks_|.
58 // - Insert/extract frames from the |frame_buffer_|
59 // - Synchronize with whatever thread that makes the Decoded callback.
60 rtc::TaskQueue bookkeeping_queue_;
61
62 VCMJitterEstimator jitter_estimator_;
63 VCMTiming timing_;
64 video_coding::FrameBuffer frame_buffer_;
65 video_coding::VideoLayerFrameId last_continuous_id_;
philipel79aab3f2018-03-26 14:31:23 +020066 rtc::Optional<int> current_payload_type_;
67 std::unique_ptr<VideoDecoder> decoder_;
philipel2fee4d62018-03-21 16:52:13 +010068};
69
70} // namespace webrtc
71
72#endif // VIDEO_VIDEO_STREAM_DECODER_IMPL_H_