summaryrefslogtreecommitdiff
path: root/video_receive_stream.h
blob: 8b4f64347b5363195fccdfea3f2d2888e692ce61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_

#include <string>
#include <vector>

#include "webrtc/common_types.h"
#include "webrtc/config.h"
#include "webrtc/frame_callback.h"
#include "webrtc/transport.h"
#include "webrtc/video_renderer.h"

namespace webrtc {

namespace newapi {
// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
// RTCP mode is described by RFC 5506.
enum RtcpMode {
  kRtcpCompound,
  kRtcpReducedSize
};
}  // namespace newapi

class VideoDecoder;

// TODO(mflodman) Move all these settings to VideoDecoder and move the
// declaration to common_types.h.
struct ExternalVideoDecoder {
  ExternalVideoDecoder()
      : decoder(NULL), payload_type(0), renderer(false), expected_delay_ms(0) {}
  // The actual decoder.
  VideoDecoder* decoder;

  // Received RTP packets with this payload type will be sent to this decoder
  // instance.
  int payload_type;

  // 'true' if the decoder handles rendering as well.
  bool renderer;

  // The expected delay for decoding and rendering, i.e. the frame will be
  // delivered this many milliseconds, if possible, earlier than the ideal
  // render time.
  // Note: Ignored if 'renderer' is false.
  int expected_delay_ms;
};

class VideoReceiveStream {
 public:
  struct Stats {
    Stats()
        : network_frame_rate(0),
          decode_frame_rate(0),
          render_frame_rate(0),
          key_frames(0),
          delta_frames(0),
          video_packets(0),
          retransmitted_packets(0),
          fec_packets(0),
          padding_packets(0),
          discarded_packets(0),
          received_bitrate_bps(0),
          receive_side_delay_ms(0) {}
    RtpStatistics rtp_stats;
    int network_frame_rate;
    int decode_frame_rate;
    int render_frame_rate;
    uint32_t key_frames;
    uint32_t delta_frames;
    uint32_t video_packets;
    uint32_t retransmitted_packets;
    uint32_t fec_packets;
    uint32_t padding_packets;
    uint32_t discarded_packets;
    int32_t received_bitrate_bps;
    int receive_side_delay_ms;
  };

  class StatsCallback {
   public:
    virtual ~StatsCallback() {}
    virtual void ReceiveStats(const Stats& stats) = 0;
  };

  struct Config {
    Config()
        : renderer(NULL),
          render_delay_ms(0),
          audio_channel_id(0),
          pre_decode_callback(NULL),
          pre_render_callback(NULL),
          target_delay_ms(0) {}
    // Codecs the receive stream can receive.
    std::vector<VideoCodec> codecs;

    // Receive-stream specific RTP settings.
    struct Rtp {
      Rtp() : ssrc(0), rtcp_mode(newapi::kRtcpReducedSize) {}

      // TODO(mflodman) Do we require a set ssrc? What happens if the ssrc
      // changes?
      uint32_t ssrc;

      // See RtcpMode for description.
      newapi::RtcpMode rtcp_mode;

      // See NackConfig for description.
      NackConfig nack;

      // See FecConfig for description.
      FecConfig fec;

      // RTX settings for possible payloads. RTX is disabled if the vector is
      // empty.
      std::vector<RtxConfig> rtx;

      // RTP header extensions used for the received stream.
      std::vector<RtpExtension> extensions;
    } rtp;

    // VideoRenderer will be called for each decoded frame. 'NULL' disables
    // rendering of this stream.
    VideoRenderer* renderer;

    // Expected delay needed by the renderer, i.e. the frame will be delivered
    // this many milliseconds, if possible, earlier than the ideal render time.
    // Only valid if 'renderer' is set.
    int render_delay_ms;

    // Audio channel corresponding to this video stream, used for audio/video
    // synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
    // when creating the VideoEngine instance. '-1' disables a/v sync.
    int audio_channel_id;

    // Called for each incoming video frame, i.e. in encoded state. E.g. used
    // when
    // saving the stream to a file. 'NULL' disables the callback.
    EncodedFrameObserver* pre_decode_callback;

    // Called for each decoded frame. E.g. used when adding effects to the
    // decoded
    // stream. 'NULL' disables the callback.
    I420FrameCallback* pre_render_callback;

    // External video decoders to be used if incoming payload type matches the
    // registered type for an external decoder.
    std::vector<ExternalVideoDecoder> external_decoders;

    // Target delay in milliseconds. A positive value indicates this stream is
    // used for streaming instead of a real-time call.
    int target_delay_ms;

    // Callback for periodically receiving receiver stats.
    StatsCallback* stats_callback;
  };

  virtual void StartReceiving() = 0;
  virtual void StopReceiving() = 0;

  // TODO(mflodman) Replace this with callback.
  virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;

 protected:
  virtual ~VideoReceiveStream() {}
};

}  // namespace webrtc

#endif  // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_