blob: 5e087d333f52d85915798c9b57ef948cd484c2f8 [file] [log] [blame]
Niels Mölleree3d9952019-09-09 12:51:55 +02001/*
2 * Copyright (c) 2019 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 MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_
12#define MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_
13
Artem Titovd15a5752021-02-10 14:31:24 +010014#include "api/sequence_checker.h"
Danil Chapovalov355b8d22021-08-13 16:50:37 +020015#include "api/video_codecs/video_decoder.h"
Niels Mölleree3d9952019-09-09 12:51:55 +020016#include "modules/video_coding/decoder_database.h"
17#include "modules/video_coding/encoded_frame.h"
18#include "modules/video_coding/generic_decoder.h"
19#include "modules/video_coding/timing.h"
Niels Mölleree3d9952019-09-09 12:51:55 +020020#include "system_wrappers/include/clock.h"
21
22namespace webrtc {
23
24// This class is a copy of vcm::VideoReceiver, trimmed down to what's used by
25// VideoReceive stream, with the aim to incrementally trim it down further and
26// ultimately delete it. It's difficult to do this incrementally with the
27// original VideoReceiver class, since it is used by the legacy
28// VideoCodingModule api.
29class VideoReceiver2 {
30 public:
31 VideoReceiver2(Clock* clock, VCMTiming* timing);
32 ~VideoReceiver2();
33
Danil Chapovalovba0a3062021-08-13 18:15:55 +020034 void RegisterReceiveCodec(uint8_t payload_type,
Danil Chapovalov355b8d22021-08-13 16:50:37 +020035 const VideoDecoder::Settings& decoder_settings);
Niels Mölleree3d9952019-09-09 12:51:55 +020036
37 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
38 uint8_t payloadType);
Johannes Kron16359f62021-02-18 23:37:22 +010039 bool IsExternalDecoderRegistered(uint8_t payloadType) const;
Niels Mölleree3d9952019-09-09 12:51:55 +020040 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
41
42 int32_t Decode(const webrtc::VCMEncodedFrame* frame);
43
Niels Mölleree3d9952019-09-09 12:51:55 +020044 // Notification methods that are used to check our internal state and validate
45 // threading assumptions. These are called by VideoReceiveStream.
Artem Titovdcd7fc72021-08-09 13:02:57 +020046 // See `IsDecoderThreadRunning()` for more details.
Niels Mölleree3d9952019-09-09 12:51:55 +020047 void DecoderThreadStarting();
48 void DecoderThreadStopped();
49
50 private:
51 // Used for DCHECKing thread correctness.
52 // In build where DCHECKs are enabled, will return false before
53 // DecoderThreadStarting is called, then true until DecoderThreadStopped
54 // is called.
55 // In builds where DCHECKs aren't enabled, it will return true.
56 bool IsDecoderThreadRunning();
57
Johannes Kron16359f62021-02-18 23:37:22 +010058 SequenceChecker construction_sequence_checker_;
59 SequenceChecker decoder_sequence_checker_;
Niels Mölleree3d9952019-09-09 12:51:55 +020060 Clock* const clock_;
61 VCMTiming* timing_;
62 VCMDecodedFrameCallback decodedFrameCallback_;
63
64 // Callbacks are set before the decoder thread starts.
Artem Titovdcd7fc72021-08-09 13:02:57 +020065 // Once the decoder thread has been started, usage of `_codecDataBase` moves
Niels Mölleree3d9952019-09-09 12:51:55 +020066 // over to the decoder thread.
67 VCMDecoderDataBase codecDataBase_;
68
69#if RTC_DCHECK_IS_ON
70 bool decoder_thread_is_running_ = false;
71#endif
72};
73
74} // namespace webrtc
75
76#endif // MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_