mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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_VIDEO_STREAM_DECODER_H_ |
| 12 | #define WEBRTC_VIDEO_VIDEO_STREAM_DECODER_H_ |
| 13 | |
| 14 | #include <list> |
| 15 | #include <map> |
| 16 | #include <memory> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "webrtc/base/criticalsection.h" |
| 20 | #include "webrtc/base/platform_thread.h" |
| 21 | #include "webrtc/base/scoped_ref_ptr.h" |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 22 | #include "webrtc/media/base/videosinkinterface.h" |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 23 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 24 | #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 25 | #include "webrtc/typedefs.h" |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | class CallStatsObserver; |
| 30 | class ChannelStatsObserver; |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 31 | class EncodedImageCallback; |
| 32 | class I420FrameCallback; |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 33 | class ReceiveStatisticsProxy; |
| 34 | class VideoRenderCallback; |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 35 | |
| 36 | namespace vcm { |
| 37 | class VideoReceiver; |
| 38 | } // namespace vcm |
| 39 | |
| 40 | enum StreamType { |
| 41 | kViEStreamTypeNormal = 0, // Normal media stream |
| 42 | kViEStreamTypeRtx = 1 // Retransmission media stream |
| 43 | }; |
| 44 | |
| 45 | class VideoStreamDecoder : public VCMReceiveCallback, |
| 46 | public VCMReceiveStatisticsCallback, |
| 47 | public VCMDecoderTimingCallback, |
| 48 | public CallStatsObserver { |
| 49 | public: |
| 50 | friend class ChannelStatsObserver; |
| 51 | |
| 52 | VideoStreamDecoder(vcm::VideoReceiver* video_receiver, |
| 53 | VCMFrameTypeCallback* vcm_frame_type_callback, |
| 54 | VCMPacketRequestCallback* vcm_packet_request_callback, |
| 55 | bool enable_nack, |
mflodman | dc7d0d2 | 2016-05-06 05:32:22 -0700 | [diff] [blame] | 56 | bool enable_fec, |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 57 | ReceiveStatisticsProxy* receive_statistics_proxy, |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 58 | rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream, |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 59 | I420FrameCallback* pre_render_callback); |
| 60 | ~VideoStreamDecoder(); |
| 61 | |
| 62 | // Implements VCMReceiveCallback. |
| 63 | int32_t FrameToRender(VideoFrame& video_frame) override; // NOLINT |
| 64 | int32_t ReceivedDecodedReferenceFrame(const uint64_t picture_id) override; |
| 65 | void OnIncomingPayloadType(int payload_type) override; |
| 66 | void OnDecoderImplementationName(const char* implementation_name) override; |
| 67 | |
| 68 | // Implements VCMReceiveStatisticsCallback. |
| 69 | void OnReceiveRatesUpdated(uint32_t bit_rate, uint32_t frame_rate) override; |
| 70 | void OnDiscardedPacketsUpdated(int discarded_packets) override; |
| 71 | void OnFrameCountsUpdated(const FrameCounts& frame_counts) override; |
| 72 | |
| 73 | // Implements VCMDecoderTimingCallback. |
| 74 | void OnDecoderTiming(int decode_ms, |
| 75 | int max_decode_ms, |
| 76 | int current_delay_ms, |
| 77 | int target_delay_ms, |
| 78 | int jitter_buffer_ms, |
| 79 | int min_playout_delay_ms, |
| 80 | int render_delay_ms) override; |
| 81 | |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 82 | void RegisterReceiveStatisticsProxy( |
| 83 | ReceiveStatisticsProxy* receive_statistics_proxy); |
| 84 | |
| 85 | // Implements StatsObserver. |
| 86 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 87 | |
| 88 | private: |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 89 | // Used for all registered callbacks except rendering. |
| 90 | rtc::CriticalSection crit_; |
| 91 | |
| 92 | vcm::VideoReceiver* const video_receiver_; |
| 93 | |
| 94 | ReceiveStatisticsProxy* const receive_stats_callback_; |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 95 | rtc::VideoSinkInterface<VideoFrame>* const incoming_video_stream_; |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 96 | |
tommi | 2e82f38 | 2016-06-21 00:26:43 -0700 | [diff] [blame] | 97 | // TODO(tommi): This callback is basically the same thing as the one above. |
| 98 | // We shouldn't need to support both. |
mflodman | cfc8e3b | 2016-05-03 21:22:04 -0700 | [diff] [blame] | 99 | I420FrameCallback* const pre_render_callback_; |
| 100 | |
| 101 | int64_t last_rtt_ms_ GUARDED_BY(crit_); |
| 102 | }; |
| 103 | |
| 104 | } // namespace webrtc |
| 105 | |
| 106 | #endif // WEBRTC_VIDEO_VIDEO_STREAM_DECODER_H_ |