1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_CAST_NET_RTP_RTP_PACKETIZER_H_ 6 #define MEDIA_CAST_NET_RTP_RTP_PACKETIZER_H_ 7 8 #include <cmath> 9 #include <list> 10 #include <map> 11 12 #include "base/time/time.h" 13 #include "media/cast/net/rtp/packet_storage.h" 14 15 namespace base { 16 class TickClock; 17 } 18 19 namespace media { 20 namespace cast { 21 22 class PacedSender; 23 24 struct RtpPacketizerConfig { 25 RtpPacketizerConfig(); 26 ~RtpPacketizerConfig(); 27 28 // General. 29 int payload_type; 30 uint16 max_payload_length; 31 uint16 sequence_number; 32 33 // SSRC. 34 unsigned int ssrc; 35 }; 36 37 // This object is only called from the main cast thread. 38 // This class break encoded audio and video frames into packets and add an RTP 39 // header to each packet. 40 class RtpPacketizer { 41 public: 42 RtpPacketizer(PacedSender* const transport, 43 PacketStorage* packet_storage, 44 RtpPacketizerConfig rtp_packetizer_config); 45 ~RtpPacketizer(); 46 47 void SendFrameAsPackets(const EncodedFrame& frame); 48 49 // Return the next sequence number, and increment by one. Enables unique 50 // incremental sequence numbers for every packet (including retransmissions). 51 uint16 NextSequenceNumber(); 52 send_packet_count()53 size_t send_packet_count() const { return send_packet_count_; } send_octet_count()54 size_t send_octet_count() const { return send_octet_count_; } 55 56 private: 57 void BuildCommonRTPheader(Packet* packet, bool marker_bit, uint32 time_stamp); 58 59 RtpPacketizerConfig config_; 60 PacedSender* const transport_; // Not owned by this class. 61 PacketStorage* packet_storage_; 62 63 uint16 sequence_number_; 64 uint32 rtp_timestamp_; 65 uint16 packet_id_; 66 67 size_t send_packet_count_; 68 size_t send_octet_count_; 69 }; 70 71 } // namespace cast 72 } // namespace media 73 74 #endif // MEDIA_CAST_NET_RTP_RTP_PACKETIZER_H_ 75