blob: ae9a2d2368b3da95b284193e9978a6bb8ba06113 [file] [log] [blame]
Stefan Holmerf7044682018-07-17 10:16:41 +02001/*
2 * Copyright (c) 2018 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 CALL_RTP_PAYLOAD_PARAMS_H_
12#define CALL_RTP_PAYLOAD_PARAMS_H_
13
Elad Alonf5b216a2019-01-28 14:25:17 +010014#include <array>
Stefan Holmerf7044682018-07-17 10:16:41 +020015
Elad Alonf5b216a2019-01-28 14:25:17 +010016#include "absl/types/optional.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020017#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020018#include "call/rtp_config.h"
philipelbf2b6202018-08-27 14:33:18 +020019#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020020#include "modules/rtp_rtcp/source/rtp_video_header.h"
Elad Alonf5b216a2019-01-28 14:25:17 +010021#include "modules/video_coding/include/video_codec_interface.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020022
23namespace webrtc {
24
Stefan Holmerf7044682018-07-17 10:16:41 +020025class RtpRtcp;
26
Stefan Holmerf7044682018-07-17 10:16:41 +020027// State for setting picture id and tl0 pic idx, for VP8 and VP9
28// TODO(nisse): Make these properties not codec specific.
29class RtpPayloadParams final {
30 public:
31 RtpPayloadParams(const uint32_t ssrc, const RtpPayloadState* state);
philipelbf2b6202018-08-27 14:33:18 +020032 RtpPayloadParams(const RtpPayloadParams& other);
Stefan Holmerf7044682018-07-17 10:16:41 +020033 ~RtpPayloadParams();
34
philipelbf2b6202018-08-27 14:33:18 +020035 RTPVideoHeader GetRtpVideoHeader(const EncodedImage& image,
36 const CodecSpecificInfo* codec_specific_info,
37 int64_t shared_frame_id);
Stefan Holmerf7044682018-07-17 10:16:41 +020038
39 uint32_t ssrc() const;
40
41 RtpPayloadState state() const;
42
43 private:
philipelbf2b6202018-08-27 14:33:18 +020044 void SetCodecSpecific(RTPVideoHeader* rtp_video_header,
45 bool first_frame_in_picture);
Elad Alonf5b216a2019-01-28 14:25:17 +010046 void SetGeneric(const CodecSpecificInfo* codec_specific_info,
47 int64_t frame_id,
philipelbf2b6202018-08-27 14:33:18 +020048 bool is_keyframe,
49 RTPVideoHeader* rtp_video_header);
Stefan Holmerf7044682018-07-17 10:16:41 +020050
Elad Alonf5b216a2019-01-28 14:25:17 +010051 void Vp8ToGeneric(const CodecSpecificInfoVP8& vp8_info,
52 int64_t shared_frame_id,
philipelbf2b6202018-08-27 14:33:18 +020053 bool is_keyframe,
54 RTPVideoHeader* rtp_video_header);
55
philipel8aba8fe2019-06-13 15:13:16 +020056 void H264ToGeneric(const CodecSpecificInfoH264& h264_info,
57 int64_t shared_frame_id,
58 bool is_keyframe,
59 RTPVideoHeader* rtp_video_header);
60
61 void GenericToGeneric(int64_t shared_frame_id,
62 bool is_keyframe,
63 RTPVideoHeader* rtp_video_header);
64
Elad Alonf5b216a2019-01-28 14:25:17 +010065 // TODO(bugs.webrtc.org/10242): Remove once all encoder-wrappers are updated.
philipelbf2b6202018-08-27 14:33:18 +020066 // Holds the last shared frame id for a given (spatial, temporal) layer.
67 std::array<std::array<int64_t, RtpGenericFrameDescriptor::kMaxTemporalLayers>,
68 RtpGenericFrameDescriptor::kMaxSpatialLayers>
69 last_shared_frame_id_;
Elad Alonf5b216a2019-01-28 14:25:17 +010070
71 // TODO(eladalon): When additional codecs are supported,
72 // set kMaxCodecBuffersCount to the max() of these codecs' buffer count.
73 static constexpr size_t kMaxCodecBuffersCount =
74 CodecSpecificInfoVP8::kBuffersCount;
75
76 // Maps buffer IDs to the frame-ID stored in them.
77 std::array<int64_t, kMaxCodecBuffersCount> buffer_id_to_frame_id_;
78
Stefan Holmerf7044682018-07-17 10:16:41 +020079 const uint32_t ssrc_;
80 RtpPayloadState state_;
philipelbf2b6202018-08-27 14:33:18 +020081
82 const bool generic_picture_id_experiment_;
philipel569397f2018-09-26 12:25:31 +020083 const bool generic_descriptor_experiment_;
Stefan Holmerf7044682018-07-17 10:16:41 +020084};
85} // namespace webrtc
86#endif // CALL_RTP_PAYLOAD_PARAMS_H_