Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 高分辨率录像多次点击开始/结束导致崩溃 #271

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions libcam/libcam/camview.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static uint8_t soundTakePhoto = 1;//拍照声音提示

static char status_message[80];

static int encode_thread_running = 0;


void set_video_time_capture(double video_time)
{
Expand Down Expand Up @@ -1290,13 +1292,18 @@ void *capture_loop(void *data)
*/
int start_encoder_thread(void *data)
{
if (encode_thread_running)
return 0;

int ret = __THREAD_CREATE(&encoder_thread, encoder_loop, data);

if(ret)
if(ret) {
fprintf(stderr, "deepin-camera: encoder thread creation failed (%i)\n", ret);
else if(debug_level > 2)
printf("deepin-camera: created encoder thread with tid: %u\n",
(unsigned int) encoder_thread);
} else {
if(debug_level > 2)
printf("deepin-camera: created encoder thread with tid: %u\n", (unsigned int) encoder_thread);
encode_thread_running = 1;
}

return ret;
}
Expand Down Expand Up @@ -1324,6 +1331,8 @@ int stop_encoder_thread()
if(debug_level > 1)
printf("deepin-camera: encoder thread terminated and joined\n");

encode_thread_running = 0;

return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions libcam/libcam_encoder/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ static int libav_send_encode(AVCodecContext *avctx, AVFrame *frame)
fprintf(stderr, "ENCODER: codec not an encoder\n");

if (frame) {

if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && frame->nb_samples != avctx->frame_size)
fprintf(stderr, "ENCODER: audio samples differ from frame size\n");
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && frame->channels <= 0) {
Expand Down Expand Up @@ -1756,7 +1755,7 @@ int encoder_encode_audio(encoder_context_t *encoder_ctx, void *audio_data)
int outsize = 0;

if (!audio_data) {
fprintf(stderr, "ENCODER: audio_data is empty.");
fprintf(stderr, "ENCODER: audio_data is empty.\n");
return outsize;
}

Expand Down Expand Up @@ -1994,7 +1993,7 @@ void encoder_close(encoder_context_t *encoder_ctx)
/*close audio codec*/
if (enc_audio_ctx) {
//测试video时长是否正常
printf("video_duration:%d", enc_audio_ctx->duration);
printf("video_duration:%d\n", enc_audio_ctx->duration);
audio_codec_data = (encoder_codec_data_t *) enc_audio_ctx->codec_data;
if (audio_codec_data) {
getLoadLibsInstance()->m_avcodec_flush_buffers(audio_codec_data->codec_context);
Expand Down