-
Notifications
You must be signed in to change notification settings - Fork 17
/
RtmpH264.h
164 lines (130 loc) · 4.58 KB
/
RtmpH264.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include "faac.h"
#include <winbase.h>
#include "librtmp_send264.h"
#ifdef _BASEFUNC_EXPORT_
#define BASE_API extern "C" __declspec(dllexport)
#else
#define BASE_API __declspec(dllimport)
#endif
#define __STDC_CONSTANT_MACROS
extern "C" {
#include "x264.h"
#include "x264_config.h"
#include "mp4v2\mp4v2.h"
#include "libswscale\swscale.h"
#include "libavutil\opt.h"
#include "libavutil\imgutils.h"
}
//CRITICAL_SECTION m_Cs;// 临界区结构对象
typedef struct
{
// rtmp object
char* szUrl;
RTMP* rtmp;
RTMPPacket packet;
// faac encoder
faacEncHandle hEncoder;
unsigned long nSampleRate;
unsigned long nChannels;
unsigned long nTimeStamp;
unsigned long nTimeDelta;
char* szPcmAudio;
unsigned long nPcmAudioSize;
unsigned long nPcmAudioLen;
char* szAacAudio;
unsigned long nAacAudioSize;
}RTMPMOD_SPublishObj;
typedef unsigned long long QWORD, ULONG64, UINT64, ULONGLONG;
class RtmpH264
{
public:
RtmpH264(void);
~RtmpH264()
{
}
int CreatePublish(char* url, int outChunkSize, int isOpenPrintLog, int logType);
void DeletePublish();
int InitVideoParams(unsigned long width, unsigned long height, unsigned long fps, unsigned long bitrate, bool bConstantsBitrate);
int SendScreenCapture(BYTE * frame, unsigned long Stride, unsigned long Height, unsigned long timespan);
//int WriteVideoParams(unsigned long width, unsigned long height, unsigned long fps, unsigned long bitrate);
//int WriteScreenCapture(BYTE * frame, unsigned long Stride, unsigned long Height, unsigned long timespan);
void FreeEncodeParams(); //释放占用内存资源
public:
DWORD m_startTime;
RTMPMOD_SPublishObj rtmp_PublishObj;
struct SwsContext * m_SwsContext;
int m_width; //宽度
int m_height; // 高度
int m_frameRate; //帧率fps
int m_bitRate; //比特率
int m_audioChannel; //声道数
int m_audioSample; //音频采样率
int m_type;//0 rtmp推流模式, 1 mp4录像模式
bool m_isCreatePublish;
};
/*创建推送流
*<param name="url">推送流地址</param>
*<param name="outChunkSize">发送包大小</param>
*/
BASE_API long RTMP_CreatePublish(char* url, unsigned long outChunkSize, int isOpenPrintLog, int logType);
//删除推送流
BASE_API void RTMP_DeletePublish();
/*初始化编码参数
*<param name="width">视频宽度</param>
*<param name="height">视频高度</param>
*<param name="fps">帧率</param>
*<param name="bitrate">比特率</param>
*<param name="bConstantsBitrate"> 是否恒定码率 </param>
*/
BASE_API long RTMP_InitVideoParams(unsigned long width, unsigned long height, unsigned long fps, unsigned long bitrate,bool bConstantsBitrate = false);
/*初始化编码参数
*<param name="frame">图片地址</param>
*<param name="Stride">图片步幅</param>
*<param name="Height">图片行高</param>
*<param name="timespan">时间戳</param>
*/
BASE_API long RTMP_SendScreenCapture(char * frame, unsigned long Stride, unsigned long Height, unsigned long timespan);
/*初始化编码参数
*<param name="szBuf">音频数据地址</param>
*<param name="nBufLen">音频数据长度 单位字节</param>
*<param name="nSampleRate">采样率</param>
*<param name="nChannels">声道数</param>
*<param name="timespan">时间戳</param>
*/
BASE_API long RTMP_SendAudioFrame(char* szBuf, unsigned long nBufLen, unsigned long nSampleRate, unsigned long nChannels, unsigned long timespan);
///*创建MP4文件
//*<param name="fileName">文件名</param>
//*<param name="audioSample">采样率</param>
//*<param name="audioChannel">声道数</param>
//*/
//BASE_API long RTMP_CreateMp4File(char* fileName, int audioChannel, int audioSample);
//BASE_API void RTMP_CloseMp4File();
//
///*初始化编码参数
//*<param name="width">视频宽度</param>
//*<param name="height">视频高度</param>
//*<param name="fps">帧率</param>
//*<param name="bitrate">比特率</param>
//*/
//BASE_API long RTMP_WriteVideoParams(unsigned long width, unsigned long height, unsigned long fps, unsigned long bitrate);
//
//
///*编码图像数据并写入文件
//*<param name="szBuf">音频数据地址</param>
//*<param name="nBufLen">音频数据长度 单位字节</param>
//*<param name="nSampleRate">采样率</param>
//*<param name="nChannels">声道数</param>
//*<param name="timespan">时间戳</param>
//*/
//BASE_API long RTMP_WriteScreenCapture(char * frame, unsigned long Stride, unsigned long Height, unsigned long timespan);
//
//
///*编码音频数据并写入文件
//*<param name="szBuf">音频数据地址</param>
//*<param name="nBufLen">音频数据长度 单位字节</param>
//*<param name="nSampleRate">采样率</param>
//*<param name="nChannels">声道数</param>
//*<param name="timespan">时间戳</param>
//*/
//BASE_API long RTMP_WriteAudioFrame(char* szBuf, unsigned long nBufLen, unsigned long nSampleRate, unsigned long nChannels, unsigned long timespan);