[*] 资源释放优化
This commit is contained in:
@@ -52,6 +52,9 @@ namespace acgist {
|
|||||||
template <typename Sink>
|
template <typename Sink>
|
||||||
class Capturer {
|
class Capturer {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool running = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// id = rtc::scoped_refptr
|
// id = rtc::scoped_refptr
|
||||||
std::map<std::string, Sink*> map;
|
std::map<std::string, Sink*> map;
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ acgist::AudioCapturer::~AudioCapturer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool acgist::AudioCapturer::start() {
|
bool acgist::AudioCapturer::start() {
|
||||||
|
if(this->running) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this->running = true;
|
||||||
// 构造音频采集器
|
// 构造音频采集器
|
||||||
OH_AudioStream_Result ret = OH_AudioStreamBuilder_GenerateCapturer(this->builder, &this->audioCapturer);
|
OH_AudioStream_Result ret = OH_AudioStreamBuilder_GenerateCapturer(this->builder, &this->audioCapturer);
|
||||||
OH_LOG_DEBUG(LOG_APP, "构造音频采集器:%o", ret);
|
OH_LOG_DEBUG(LOG_APP, "构造音频采集器:%o", ret);
|
||||||
@@ -49,6 +53,10 @@ bool acgist::AudioCapturer::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool acgist::AudioCapturer::stop() {
|
bool acgist::AudioCapturer::stop() {
|
||||||
|
if(!this->running) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this->running = false;
|
||||||
if(this->audioCapturer == nullptr) {
|
if(this->audioCapturer == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ acgist::VideoCapturer::~VideoCapturer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool acgist::VideoCapturer::start() {
|
bool acgist::VideoCapturer::start() {
|
||||||
|
if (this->running) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this->running = true;
|
||||||
OH_CaptureSession_BeginConfig(this->cameraCaptureSession);
|
OH_CaptureSession_BeginConfig(this->cameraCaptureSession);
|
||||||
Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(this->cameraCaptureSession, this->cameraVideoOutput);
|
Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(this->cameraCaptureSession, this->cameraVideoOutput);
|
||||||
OH_LOG_INFO(LOG_APP, "视频捕获绑定会话:%o", ret);
|
OH_LOG_INFO(LOG_APP, "视频捕获绑定会话:%o", ret);
|
||||||
@@ -90,6 +94,10 @@ bool acgist::VideoCapturer::start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool acgist::VideoCapturer::stop() {
|
bool acgist::VideoCapturer::stop() {
|
||||||
|
if (!this->running) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this->running = false;
|
||||||
OH_NativeImage_DetachContext(this->nativeImage);
|
OH_NativeImage_DetachContext(this->nativeImage);
|
||||||
OH_CaptureSession_BeginConfig(this->cameraCaptureSession);
|
OH_CaptureSession_BeginConfig(this->cameraCaptureSession);
|
||||||
Camera_ErrorCode ret = OH_CaptureSession_RemoveVideoOutput(this->cameraCaptureSession, this->cameraVideoOutput);
|
Camera_ErrorCode ret = OH_CaptureSession_RemoveVideoOutput(this->cameraCaptureSession, this->cameraVideoOutput);
|
||||||
@@ -106,7 +114,8 @@ bool acgist::VideoCapturer::stop() {
|
|||||||
void acgist::VideoCapturer::initOpenGLES() {
|
void acgist::VideoCapturer::initOpenGLES() {
|
||||||
// IMAGE WINDOW
|
// IMAGE WINDOW
|
||||||
glGenTextures(this->textureSize, &this->textureId);
|
glGenTextures(this->textureSize, &this->textureId);
|
||||||
this->nativeImage = OH_NativeImage_Create(this->textureId, GL_TEXTURE_2D);
|
this->nativeImage = OH_NativeImage_Create(this->textureId, GL_TEXTURE_2D);
|
||||||
|
// TODO: 验证是否需要window
|
||||||
// this->nativeWindow = OH_NativeImage_AcquireNativeWindow(this->nativeImage);
|
// this->nativeWindow = OH_NativeImage_AcquireNativeWindow(this->nativeImage);
|
||||||
// OH_NativeWindow_NativeWindowHandleOpt(this->nativeWindow, SET_BUFFER_GEOMETRY, acgist::width, acgist::height);
|
// OH_NativeWindow_NativeWindowHandleOpt(this->nativeWindow, SET_BUFFER_GEOMETRY, acgist::width, acgist::height);
|
||||||
// OH_NativeWindow_NativeWindowHandleOpt(this->nativeWindow, SET_TIMEOUT, 100'000);
|
// OH_NativeWindow_NativeWindowHandleOpt(this->nativeWindow, SET_TIMEOUT, 100'000);
|
||||||
@@ -168,15 +177,30 @@ void acgist::VideoCapturer::initOpenGLES() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void acgist::VideoCapturer::releaseOpenGLES() {
|
void acgist::VideoCapturer::releaseOpenGLES() {
|
||||||
glDeleteTextures(this->textureSize, &this->textureId);
|
if(this->textureId != 0) {
|
||||||
EGLBoolean ret = eglDestroySurface(this->eglDisplay, this->eglSurface);
|
glDeleteTextures(this->textureSize, &this->textureId);
|
||||||
OH_LOG_INFO(LOG_APP, "销毁EGLSurface:%d", ret);
|
this->textureId = 0;
|
||||||
ret = eglDestroyContext(this->eglDisplay, this->eglContext);
|
}
|
||||||
OH_LOG_INFO(LOG_APP, "销毁EGLContext:%d", ret);
|
if(this->eglSurface != EGL_NO_SURFACE) {
|
||||||
OH_NativeImage_Destroy(&this->nativeImage);
|
EGLBoolean ret = eglDestroySurface(this->eglDisplay, this->eglSurface);
|
||||||
this->nativeImage = nullptr;
|
this->eglSurface = EGL_NO_SURFACE;
|
||||||
OH_NativeWindow_DestroyNativeWindow(this->nativeWindow);
|
OH_LOG_INFO(LOG_APP, "销毁EGLSurface:%d", ret);
|
||||||
this->nativeWindow = nullptr;
|
}
|
||||||
|
if(this->eglContext != EGL_NO_CONTEXT) {
|
||||||
|
EGLBoolean ret = eglDestroyContext(this->eglDisplay, this->eglContext);
|
||||||
|
this->eglContext = EGL_NO_CONTEXT;
|
||||||
|
OH_LOG_INFO(LOG_APP, "销毁EGLContext:%d", ret);
|
||||||
|
}
|
||||||
|
if(this->nativeImage != nullptr) {
|
||||||
|
OH_NativeImage_Destroy(&this->nativeImage);
|
||||||
|
this->nativeImage = nullptr;
|
||||||
|
OH_LOG_INFO(LOG_APP, "销毁nativeImage");
|
||||||
|
}
|
||||||
|
if(this->nativeWindow != nullptr) {
|
||||||
|
OH_NativeWindow_DestroyNativeWindow(this->nativeWindow);
|
||||||
|
this->nativeWindow = nullptr;
|
||||||
|
OH_LOG_INFO(LOG_APP, "销毁nativeWindow");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onError(Camera_VideoOutput* videoOutput, Camera_ErrorCode errorCode) {
|
static void onError(Camera_VideoOutput* videoOutput, Camera_ErrorCode errorCode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user