LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc - video_send_stream.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 15 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 28 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2013 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_SEND_STREAM_H_
      12             : #define WEBRTC_VIDEO_SEND_STREAM_H_
      13             : 
      14             : #include <map>
      15             : #include <string>
      16             : #include <utility>
      17             : #include <vector>
      18             : #include <utility>
      19             : 
      20             : #include "webrtc/api/call/transport.h"
      21             : #include "webrtc/base/platform_file.h"
      22             : #include "webrtc/common_types.h"
      23             : #include "webrtc/common_video/include/frame_callback.h"
      24             : #include "webrtc/config.h"
      25             : #include "webrtc/media/base/videosinkinterface.h"
      26             : #include "webrtc/media/base/videosourceinterface.h"
      27             : 
      28             : namespace webrtc {
      29             : 
      30             : class VideoEncoder;
      31             : 
      32           0 : class VideoSendStream {
      33             :  public:
      34           0 :   struct StreamStats {
      35             :     std::string ToString() const;
      36             : 
      37             :     FrameCounts frame_counts;
      38             :     bool is_rtx = false;
      39             :     bool is_flexfec = false;
      40             :     int width = 0;
      41             :     int height = 0;
      42             :     // TODO(holmer): Move bitrate_bps out to the webrtc::Call layer.
      43             :     int total_bitrate_bps = 0;
      44             :     int retransmit_bitrate_bps = 0;
      45             :     int avg_delay_ms = 0;
      46             :     int max_delay_ms = 0;
      47             :     StreamDataCounters rtp_stats;
      48             :     RtcpPacketTypeCounter rtcp_packet_type_counts;
      49             :     RtcpStatistics rtcp_stats;
      50             :   };
      51             : 
      52           0 :   struct Stats {
      53             :     std::string ToString(int64_t time_ms) const;
      54             :     std::string encoder_implementation_name = "unknown";
      55             :     int input_frame_rate = 0;
      56             :     int encode_frame_rate = 0;
      57             :     int avg_encode_time_ms = 0;
      58             :     int encode_usage_percent = 0;
      59             :     uint32_t frames_encoded = 0;
      60             :     rtc::Optional<uint64_t> qp_sum;
      61             :     // Bitrate the encoder is currently configured to use due to bandwidth
      62             :     // limitations.
      63             :     int target_media_bitrate_bps = 0;
      64             :     // Bitrate the encoder is actually producing.
      65             :     int media_bitrate_bps = 0;
      66             :     // Media bitrate this VideoSendStream is configured to prefer if there are
      67             :     // no bandwidth limitations.
      68             :     int preferred_media_bitrate_bps = 0;
      69             :     bool suspended = false;
      70             :     bool bw_limited_resolution = false;
      71             :     bool cpu_limited_resolution = false;
      72             :     // Total number of times resolution as been requested to be changed due to
      73             :     // CPU adaptation.
      74             :     int number_of_cpu_adapt_changes = 0;
      75             :     std::map<uint32_t, StreamStats> substreams;
      76             :   };
      77             : 
      78           0 :   struct Config {
      79             :    public:
      80             :     Config() = delete;
      81           0 :     Config(Config&&) = default;
      82           0 :     explicit Config(Transport* send_transport)
      83           0 :         : send_transport(send_transport) {}
      84             : 
      85             :     Config& operator=(Config&&) = default;
      86             :     Config& operator=(const Config&) = delete;
      87             : 
      88             :     // Mostly used by tests.  Avoid creating copies if you can.
      89           0 :     Config Copy() const { return Config(*this); }
      90             : 
      91             :     std::string ToString() const;
      92             : 
      93           0 :     struct EncoderSettings {
      94           0 :       EncoderSettings() = default;
      95             :       EncoderSettings(std::string payload_name,
      96             :                       int payload_type,
      97             :                       VideoEncoder* encoder)
      98             :           : payload_name(std::move(payload_name)),
      99             :             payload_type(payload_type),
     100             :             encoder(encoder) {}
     101             :       std::string ToString() const;
     102             : 
     103             :       std::string payload_name;
     104             :       int payload_type = -1;
     105             : 
     106             :       // TODO(sophiechang): Delete this field when no one is using internal
     107             :       // sources anymore.
     108             :       bool internal_source = false;
     109             : 
     110             :       // Allow 100% encoder utilization. Used for HW encoders where CPU isn't
     111             :       // expected to be the limiting factor, but a chip could be running at
     112             :       // 30fps (for example) exactly.
     113             :       bool full_overuse_time = false;
     114             : 
     115             :       // Uninitialized VideoEncoder instance to be used for encoding. Will be
     116             :       // initialized from inside the VideoSendStream.
     117             :       VideoEncoder* encoder = nullptr;
     118             :     } encoder_settings;
     119             : 
     120             :     static const size_t kDefaultMaxPacketSize = 1500 - 40;  // TCP over IPv4.
     121           0 :     struct Rtp {
     122             :       std::string ToString() const;
     123             : 
     124             :       std::vector<uint32_t> ssrcs;
     125             : 
     126             :       // See RtcpMode for description.
     127             :       RtcpMode rtcp_mode = RtcpMode::kCompound;
     128             : 
     129             :       // Max RTP packet size delivered to send transport from VideoEngine.
     130             :       size_t max_packet_size = kDefaultMaxPacketSize;
     131             : 
     132             :       // RTP header extensions to use for this send stream.
     133             :       std::vector<RtpExtension> extensions;
     134             : 
     135             :       // See NackConfig for description.
     136             :       NackConfig nack;
     137             : 
     138             :       // See UlpfecConfig for description.
     139             :       UlpfecConfig ulpfec;
     140             : 
     141           0 :       struct Flexfec {
     142             :         // Payload type of FlexFEC. Set to -1 to disable sending FlexFEC.
     143             :         int payload_type = -1;
     144             : 
     145             :         // SSRC of FlexFEC stream.
     146             :         uint32_t ssrc = 0;
     147             : 
     148             :         // Vector containing a single element, corresponding to the SSRC of the
     149             :         // media stream being protected by this FlexFEC stream.
     150             :         // The vector MUST have size 1.
     151             :         //
     152             :         // TODO(brandtr): Update comment above when we support
     153             :         // multistream protection.
     154             :         std::vector<uint32_t> protected_media_ssrcs;
     155             :       } flexfec;
     156             : 
     157             :       // Settings for RTP retransmission payload format, see RFC 4588 for
     158             :       // details.
     159           0 :       struct Rtx {
     160             :         std::string ToString() const;
     161             :         // SSRCs to use for the RTX streams.
     162             :         std::vector<uint32_t> ssrcs;
     163             : 
     164             :         // Payload type to use for the RTX stream.
     165             :         int payload_type = -1;
     166             :       } rtx;
     167             : 
     168             :       // RTCP CNAME, see RFC 3550.
     169             :       std::string c_name;
     170             : 
     171             :       std::vector<std::string> rids;
     172             :     } rtp;
     173             : 
     174             :     // Transport for outgoing packets.
     175             :     Transport* send_transport = nullptr;
     176             : 
     177             :     // Called for each I420 frame before encoding the frame. Can be used for
     178             :     // effects, snapshots etc. 'nullptr' disables the callback.
     179             :     rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback = nullptr;
     180             : 
     181             :     // Called for each encoded frame, e.g. used for file storage. 'nullptr'
     182             :     // disables the callback. Also measures timing and passes the time
     183             :     // spent on encoding. This timing will not fire if encoding takes longer
     184             :     // than the measuring window, since the sample data will have been dropped.
     185             :     EncodedFrameObserver* post_encode_callback = nullptr;
     186             : 
     187             :     // Expected delay needed by the renderer, i.e. the frame will be delivered
     188             :     // this many milliseconds, if possible, earlier than expected render time.
     189             :     // Only valid if |local_renderer| is set.
     190             :     int render_delay_ms = 0;
     191             : 
     192             :     // Target delay in milliseconds. A positive value indicates this stream is
     193             :     // used for streaming instead of a real-time call.
     194             :     int target_delay_ms = 0;
     195             : 
     196             :     // True if the stream should be suspended when the available bitrate fall
     197             :     // below the minimum configured bitrate. If this variable is false, the
     198             :     // stream may send at a rate higher than the estimated available bitrate.
     199             :     bool suspend_below_min_bitrate = false;
     200             : 
     201             :     // Enables periodic bandwidth probing in application-limited region.
     202             :     bool periodic_alr_bandwidth_probing = false;
     203             : 
     204             :    private:
     205             :     // Access to the copy constructor is private to force use of the Copy()
     206             :     // method for those exceptional cases where we do use it.
     207           0 :     Config(const Config&) = default;
     208             :   };
     209             : 
     210             :   // Starts stream activity.
     211             :   // When a stream is active, it can receive, process and deliver packets.
     212             :   virtual void Start() = 0;
     213             :   // Stops stream activity.
     214             :   // When a stream is stopped, it can't receive, process or deliver packets.
     215             :   virtual void Stop() = 0;
     216             : 
     217             :   // Based on the spec in
     218             :   // https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
     219             :   enum class DegradationPreference {
     220             :     kMaintainResolution,
     221             :     // TODO(perkj): Implement kMaintainFrameRate. kBalanced will drop frames
     222             :     // if the encoder overshoots or the encoder can not encode fast enough.
     223             :     kBalanced,
     224             :   };
     225             :   virtual void SetSource(
     226             :       rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
     227             :       const DegradationPreference& degradation_preference) = 0;
     228             : 
     229             :   // Gets interface used to signal the current CPU work level to the encoder.
     230             :   // Valid as long as the VideoSendStream is valid.
     231             :   virtual CPULoadStateObserver* LoadStateObserver() = 0;
     232             : 
     233             :   // Set which streams to send. Must have at least as many SSRCs as configured
     234             :   // in the config. Encoder settings are passed on to the encoder instance along
     235             :   // with the VideoStream settings.
     236             :   virtual void ReconfigureVideoEncoder(VideoEncoderConfig config) = 0;
     237             : 
     238             :   virtual Stats GetStats() = 0;
     239             : 
     240             :   // Takes ownership of each file, is responsible for closing them later.
     241             :   // Calling this method will close and finalize any current logs.
     242             :   // Some codecs produce multiple streams (VP8 only at present), each of these
     243             :   // streams will log to a separate file. kMaxSimulcastStreams in common_types.h
     244             :   // gives the max number of such streams. If there is no file for a stream, or
     245             :   // the file is rtc::kInvalidPlatformFileValue, frames from that stream will
     246             :   // not be logged.
     247             :   // If a frame to be written would make the log too large the write fails and
     248             :   // the log is closed and finalized. A |byte_limit| of 0 means no limit.
     249             :   virtual void EnableEncodedFrameRecording(
     250             :       const std::vector<rtc::PlatformFile>& files,
     251             :       size_t byte_limit) = 0;
     252             :   inline void DisableEncodedFrameRecording() {
     253             :     EnableEncodedFrameRecording(std::vector<rtc::PlatformFile>(), 0);
     254             :   }
     255             : 
     256             :  protected:
     257           0 :   virtual ~VideoSendStream() {}
     258             : };
     259             : 
     260             : }  // namespace webrtc
     261             : 
     262             : #endif  // WEBRTC_VIDEO_SEND_STREAM_H_

Generated by: LCOV version 1.13