summaryrefslogtreecommitdiff
path: root/chromium/media/cast/net/rtp/rtp_parser.h
blob: b87e2aca178c82021731ced62bdb2de9ba978c36 (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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_NET_RTP_RTP_PARSER_H_
#define MEDIA_CAST_NET_RTP_RTP_PARSER_H_

#include <stddef.h>
#include <stdint.h>

#include "base/macros.h"
#include "media/cast/net/cast_transport_defines.h"
#include "media/cast/net/rtp/rtp_defines.h"

namespace media {
namespace cast {

// TODO(miu): RtpParser and RtpPacketizer should be consolidated into a single
// module that handles all RTP/Cast packet serialization and deserialization
// throughout the media/cast library.
class RtpParser {
 public:
  RtpParser(uint32_t expected_sender_ssrc, uint8_t expected_payload_type);

  RtpParser(const RtpParser&) = delete;
  RtpParser& operator=(const RtpParser&) = delete;

  virtual ~RtpParser();

  // Parses the |packet|, expecting an RTP header along with a Cast header at
  // the beginning of the the RTP payload.  This method populates the structure
  // pointed to by |rtp_header| and sets the |payload_data| pointer and
  // |payload_size| to the memory region within |packet| containing the Cast
  // payload data.  Returns false if the data appears to be invalid, is not from
  // the expected sender (as identified by the SSRC field), or is not the
  // expected payload type.
  bool ParsePacket(const uint8_t* packet,
                   size_t length,
                   RtpCastHeader* rtp_header,
                   const uint8_t** payload_data,
                   size_t* payload_size);

  static bool ParseSsrc(const uint8_t* packet, size_t length, uint32_t* ssrc);

 private:
  const uint32_t expected_sender_ssrc_;
  const uint8_t expected_payload_type_;

  // Tracks recently-parsed values so that the truncated values can be
  // re-expanded into full-form.
  RtpTimeTicks last_parsed_rtp_timestamp_;
  FrameId last_parsed_frame_id_;
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_NET_RTP_RTP_PARSER_H_