Add NetworkMonitor
[rtmpclient.git] / app / src / main / jni / FfmpegHelper.h
1 #ifndef __FFMPEG_HELPER_H__
2 #define __FFMPEG_HELPER_H__
3
4 #include <jni.h>
5 #include <string>
6
7 extern "C" {
8     #include "libavformat/avformat.h"
9     #include "libavcodec/avcodec.h"
10     #include "libswscale/swscale.h"
11     #include "libavutil/imgutils.h"
12     #include "libavutil/time.h"
13     #include "libavdevice/avdevice.h"
14 }
15
16 class FfmpegHelper {
17 public:
18     static jint nativeOnLoad(JavaVM * jvm, void* reserved);
19     static jint nativeInitEncoder(JNIEnv *env, jclass cls, jint width, jint height, jstring url);
20     static jint nativeProcessFrame(JNIEnv *env, jclass cls, jbyteArray data);
21     static jint nativeClose();
22
23 private:
24     static void av_log_cb (void *ptr, int level, const char* fmt, va_list vl);
25     void javaPrint(const char* str, int level);
26     static void init();
27     int processFrame(uint8_t *data);
28     int initEncoder(int width, int height, const char* url);
29     int close();
30    
31 private:
32     FfmpegHelper(JavaVM* vm, jclass cls);
33
34 private:
35     static FfmpegHelper* singleton;
36     JavaVM *jvm;
37     jclass ai_suanzi_rtmpclient_FfmpegHelper;
38     static bool isInit;
39
40     AVFormatContext* formatCtx;
41     AVCodecContext* codecCtx;
42     AVCodec* codec;
43     AVStream* vStream;
44     AVPacket encPkt;
45     AVFrame *pFrameYUV;
46     int pWidth;
47     int pHeight;
48     unsigned int frameCnt;
49     int64_t startTime;
50 };
51
52 #endif /* __FFMPEG_HELPER_H__ */