blob: 1ab8a1e186560b3a3c081f42421fb80f9b821246 [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
14#include "modules/video_coding/decoder_database.h"
15#include "modules/video_coding/encoded_frame.h"
16#include "modules/video_coding/generic_decoder.h"
17#include "modules/video_coding/timing.h"
18#include "rtc_base/thread_checker.h"
19#include "system_wrappers/include/clock.h"
20
21namespace webrtc {
22
23// This class is a copy of vcm::VideoReceiver, trimmed down to what's used by
24// VideoReceive stream, with the aim to incrementally trim it down further and
25// ultimately delete it. It's difficult to do this incrementally with the
26// original VideoReceiver class, since it is used by the legacy
27// VideoCodingModule api.
28class VideoReceiver2 {
29 public:
30 VideoReceiver2(Clock* clock, VCMTiming* timing);
31 ~VideoReceiver2();
32
33 int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
34 int32_t numberOfCores,
35 bool requireKeyFrame);
36
37 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
38 uint8_t payloadType);
39 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
40
41 int32_t Decode(const webrtc::VCMEncodedFrame* frame);
42
43 void TriggerDecoderShutdown();
44
45 // Notification methods that are used to check our internal state and validate
46 // threading assumptions. These are called by VideoReceiveStream.
47 // See |IsDecoderThreadRunning()| for more details.
48 void DecoderThreadStarting();
49 void DecoderThreadStopped();
50
51 private:
52 // Used for DCHECKing thread correctness.
53 // In build where DCHECKs are enabled, will return false before
54 // DecoderThreadStarting is called, then true until DecoderThreadStopped
55 // is called.
56 // In builds where DCHECKs aren't enabled, it will return true.
57 bool IsDecoderThreadRunning();
58
59 rtc::ThreadChecker construction_thread_checker_;
60 rtc::ThreadChecker decoder_thread_checker_;
61 Clock* const clock_;
62 VCMTiming* timing_;
63 VCMDecodedFrameCallback decodedFrameCallback_;
64
65 // Callbacks are set before the decoder thread starts.
66 // Once the decoder thread has been started, usage of |_codecDataBase| moves
67 // over to the decoder thread.
68 VCMDecoderDataBase codecDataBase_;
69
70#if RTC_DCHECK_IS_ON
71 bool decoder_thread_is_running_ = false;
72#endif
73};
74
75} // namespace webrtc
76
77#endif // MODULES_VIDEO_CODING_VIDEO_RECEIVER2_H_