-
Notifications
You must be signed in to change notification settings - Fork 3
/
rtmppusher.h
70 lines (62 loc) · 2 KB
/
rtmppusher.h
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
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef RTMPPUSHER_H
#define RTMPPUSHER_H
#include "librtmp/rtmp.h"
#include "mediabase.h"
#include "rtmpbase.h"
#include "naluloop.h"
#include "dlog.h"
namespace LQF
{
enum RTMPPusherMES
{
RTMPPUSHER_MES_H264_DATA = 1,
RTMPPUSHER_MES_AAC_DATA = 2
};
typedef struct _RTMPMetadata
{
// video, must be h264 type
unsigned int nWidth;
unsigned int nHeight;
unsigned int nFrameRate; // fps
unsigned int nVideoDataRate; // bps
unsigned int nSpsLen;
unsigned char Sps[1024];
unsigned int nPpsLen;
unsigned char Pps[1024];
// audio, must be aac type
bool bHasAudio;
unsigned int audio_sample_rate; //audiosamplerate
unsigned int audio_sample_size; //audiosamplesize
unsigned int nAudioChannels;
char pAudioSpecCfg;
unsigned int nAudioSpecCfgLen;
} RTMPMetadata, *LPRTMPMetadata;
// 实现异步发送
class RTMPPusher : public NaluLoop,public RTMPBase
{
typedef RTMPBase Super;
public:
RTMPPusher():RTMPBase(RTMP_BASE_TYPE_PUSH),NaluLoop(30){LogInfo("RTMPPusher create!");}
// MetaData
bool SendMetadata(FLVMetadataMsg *metadata);
bool SendAudioSpecificConfig(char* data,int length);
private:
virtual void handle(int what, MsgBaseObj *data);
bool sendH264SequenceHeader(VideoSequenceHeaderMsg *seq_header);
bool sendH264Packet(char *data,int size, bool is_keyframe, unsigned int timestamp);
//bool SendAACPacket(char *data,int size, unsigned int timestamp);
int sendPacket(unsigned int packet_type, unsigned char *data, unsigned int size, unsigned int nTimestamp);
int64_t time_ = 0; //在SendMetadata获取时间比较准确
enum
{
FLV_CODECID_H264 = 7,
FLV_CODECID_AAC = 10,
};
bool is_first_metadata_ = false; // 发送metadata
bool is_first_video_sequence_ = false;
bool is_first_video_frame_ = false;
bool is_first_audio_sequence_ = false;
bool is_first_audio_frame_ = false;
};
}
#endif // RTMPPUSHER_H