-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmediarecorder_output.h
139 lines (114 loc) · 3.63 KB
/
mediarecorder_output.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
#ifndef SCREENREC_MEDIARECORDER_OUTPUT_H
#define SCREENREC_MEDIARECORDER_OUTPUT_H
#include "screenrec.h"
#include <stdio.h>
#include <fcntl.h>
#include <pthread.h>
#include <cutils/log.h>
#include <sys/statfs.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <media/AudioRecord.h>
#include <media/mediarecorder.h>
#if SCR_SDK_VERSION >= 16
#include <gui/Surface.h>
#else
#include <surfaceflinger/Surface.h>
#endif // SCR_SDK_VERSION
#if SCR_SDK_VERSION >= 18
#include <ui/GraphicBuffer.h>
#else
#include <gui/SurfaceTextureClient.h>
#endif
#define MSDOS_FS_LIMIT 4294967295ull
#define USE_64BIT_OFFSET_LIMIT 2147483647ull
using namespace android;
class AbstractMediaRecorderOutput : public ScrOutput {
public:
AbstractMediaRecorderOutput() : mr(NULL), mSTC(NULL), mANW(NULL), videoSourceError(false) {}
virtual ~AbstractMediaRecorderOutput() {}
virtual void setupOutput();
virtual void renderFrame() = 0;
virtual void closeOutput(bool fromMainThread);
protected:
// MediaRecorder
sp<MediaRecorder> mr;
sp<Surface> mSTC;
sp<ANativeWindow> mANW;
bool videoSourceError;
void setupMediaRecorder();
void checkAudioSource(audio_source_t source);
void setFileSizeLimit();
void tearDownMediaRecorder(bool async);
static void* stoppingThreadStart(void* args);
void stopMediaRecorder();
void stopMediaRecorderAsync();
uint64_t getAvailableSpace();
};
class GLMediaRecorderOutput : public AbstractMediaRecorderOutput {
public:
GLMediaRecorderOutput() :
mEglDisplay(EGL_NO_DISPLAY), mEglSurface(EGL_NO_SURFACE), mEglContext(EGL_NO_CONTEXT) {
memset(vertices, 0, sizeof(vertices));
memset(texCoordinates, 0, sizeof(texCoordinates));
}
virtual ~GLMediaRecorderOutput() {}
virtual void setupOutput();
virtual void renderFrame();
virtual void closeOutput(bool fromMainThread);
private:
// EGL
EGLDisplay mEglDisplay;
EGLSurface mEglSurface;
EGLContext mEglContext;
EGLConfig mEglconfig;
// OpenGL
GLuint mProgram;
GLuint mvPositionHandle;
GLuint mvTransformHandle;
GLuint mColorTransformHandle;
GLuint mTexCoordHandle;
GLuint mTexture;
uint32_t *mPixels;
GLfloat *transformMatrix;
static GLfloat flipAndRotateMatrix[16];
static GLfloat flipMatrix[16];
GLfloat *colorMatrix;
static GLfloat rgbaMatrix[16];
static GLfloat bgraMatrix[16];
GLfloat vertices[12];
GLfloat texCoordinates[12];
void setupEgl();
void setupGl();
void tearDownEgl();
int getTexSize(int size);
// OpenGL helpers
void checkGlError(const char* op, bool critical);
void checkGlError(const char* op);
GLuint loadShader(GLenum shaderType, const char* pSource);
GLuint createProgram(const char* pVertexSource, const char* pFragmentSource);
};
class CPUMediaRecorderOutput : public AbstractMediaRecorderOutput {
public:
CPUMediaRecorderOutput() {}
virtual ~CPUMediaRecorderOutput() {}
virtual void setupOutput();
virtual void renderFrame();
virtual void closeOutput(bool fromMainThread);
private:
void fillBuffer(sp<GraphicBuffer> buf);
void copyRotateYUVBuf(uint8_t* yuvPixels, uint8_t* screen, int stride);
void copyRotateBuf(uint32_t* bufPixels, uint32_t* screen, int stride);
void copyYUVBuf(uint8_t* yuvPixels, uint8_t* screen, int stride);
void copyBuf(uint32_t* bufPixels, uint32_t* screen, int stride);
inline uint32_t convertColor(uint32_t color);
};
class SCRListener : public MediaRecorderListener
{
public:
SCRListener() : firstError(true) {};
void notify(int msg, int ext1, int ext2);
private:
volatile bool firstError;
};
#endif