MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
rtmpchunks.h
Go to the documentation of this file.
1 
4 #pragma once
5 #include <map>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <sys/time.h>
9 #include <string>
10 #include <arpa/inet.h>
11 #include "socket.h"
12 
13 //forward declaration of FLV::Tag to avoid circular dependencies.
14 namespace FLV {
15  class Tag;
16 }
17 
19 namespace RTMPStream {
20 
21  extern unsigned int chunk_rec_max;
22  extern unsigned int chunk_snd_max;
23  extern unsigned int rec_window_size;
24  extern unsigned int snd_window_size;
25  extern unsigned int rec_window_at;
26  extern unsigned int snd_window_at;
27  extern unsigned int rec_cnt;
28  extern unsigned int snd_cnt;
29 
30  extern timeval lastrec;
31 
33  class Chunk {
34  public:
35  unsigned char headertype;
36  unsigned int cs_id;
37  unsigned int timestamp;
38  unsigned int ts_delta;
39  unsigned int ts_header;
40  unsigned int len;
41  unsigned int real_len;
42  unsigned int len_left;
43  unsigned char msg_type_id;
44  unsigned int msg_stream_id;
45  std::string data;
46 
47  Chunk();
48  bool Parse(Socket::Buffer & data);
49  std::string & Pack();
50  };
51  //RTMPStream::Chunk
52 
53  extern std::map<unsigned int, Chunk> lastsend;
54  extern std::map<unsigned int, Chunk> lastrecv;
55 
56  std::string & SendChunk(unsigned int cs_id, unsigned char msg_type_id, unsigned int msg_stream_id, std::string data);
57  std::string & SendMedia(unsigned char msg_type_id, unsigned char * data, int len, unsigned int ts);
58  std::string & SendMedia(FLV::Tag & tag);
59  std::string & SendCTL(unsigned char type, unsigned int data);
60  std::string & SendCTL(unsigned char type, unsigned int data, unsigned char data2);
61  std::string & SendUSR(unsigned char type, unsigned int data);
62  std::string & SendUSR(unsigned char type, unsigned int data, unsigned int data2);
63 
65  extern std::string handshake_in;
67  extern std::string handshake_out;
69  bool doHandshake();
70 } //RTMPStream namespace
unsigned int cs_id
ContentStream ID.
Definition: rtmpchunks.h:36
unsigned int len_left
Length not yet received, out of complete chunk.
Definition: rtmpchunks.h:42
unsigned int snd_window_at
Current position of the sending window.
Definition: rtmpchunks.h:26
unsigned int rec_window_at
Current position of the receiving window.
Definition: rtmpchunks.h:25
timeval lastrec
Timestamp of last time data was received.
Definition: rtmpchunks.h:30
This class is used to hold, work with and get information about a single FLV tag. ...
Definition: flv_tag.h:29
A buffer made out of std::string objects that can be efficiently read from and written to...
Definition: socket.h:28
std::string handshake_out
This value is the handshake response that is to be sent out.
Definition: rtmpchunks.h:67
std::string handshake_in
This value should be set to the first 1537 bytes received.
Definition: rtmpchunks.h:65
unsigned int real_len
Length of this particular part of it.
Definition: rtmpchunks.h:41
std::string & SendUSR(unsigned char type, unsigned int data, unsigned int data2)
Packs up a chunk for a user control message with 2 arguments.
Definition: rtmpchunks.cpp:310
unsigned int timestamp
Timestamp of this chunk.
Definition: rtmpchunks.h:37
unsigned int rec_cnt
Counter for total data received, in bytes.
Definition: rtmpchunks.h:27
bool doHandshake()
Does the handshake. Expects handshake_in to be filled, and fills handshake_out.
Definition: rtmpchunks.cpp:506
unsigned int len
Length of the complete chunk.
Definition: rtmpchunks.h:40
unsigned int msg_stream_id
Message Stream ID.
Definition: rtmpchunks.h:44
std::map< unsigned int, Chunk > lastsend
Holds the last sent chunk for every msg_id.
Definition: rtmpchunks.h:53
unsigned char msg_type_id
Message Type ID.
Definition: rtmpchunks.h:43
unsigned int ts_header
Last header timestamp without extensions or deltas.
Definition: rtmpchunks.h:39
unsigned int ts_delta
Last timestamp delta.
Definition: rtmpchunks.h:38
unsigned int rec_window_size
Window size for receiving.
Definition: rtmpchunks.h:23
std::string data
Payload of chunk.
Definition: rtmpchunks.h:45
std::string & SendCTL(unsigned char type, unsigned int data, unsigned char data2)
Packs up a chunk for a control message with 2 arguments.
Definition: rtmpchunks.cpp:277
This namespace holds all FLV-parsing related functionality.
Definition: flv_tag.h:18
unsigned int snd_window_size
Window size for sending.
Definition: rtmpchunks.h:24
Holds a single RTMP chunk, either send or receive direction.
Definition: rtmpchunks.h:33
unsigned char headertype
For input chunks, the type of header. This is calculated automatically for output chunks...
Definition: rtmpchunks.h:35
std::string & SendMedia(FLV::Tag &tag)
Packs up a chunk with media contents.
Definition: rtmpchunks.cpp:238
std::string & SendChunk(unsigned int cs_id, unsigned char msg_type_id, unsigned int msg_stream_id, std::string data)
Packs up a chunk with the given arguments as properties.
Definition: rtmpchunks.cpp:205
std::map< unsigned int, Chunk > lastrecv
Holds the last received chunk for every msg_id.
Definition: rtmpchunks.h:54
unsigned int snd_cnt
Counter for total data sent, in bytes.
Definition: rtmpchunks.h:28
unsigned int chunk_rec_max
Maximum size for a received chunk.
Definition: rtmpchunks.h:21
Contains all functions and classes needed for RTMP connections.
Definition: flv_tag.h:13
ts
Definition: CMakeLists.txt:323
unsigned int chunk_snd_max
Maximum size for a sent chunk.
Definition: rtmpchunks.h:22