From 09f830ddd1806ecd55bc3096647c026a7031c9e8 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Sun, 8 Dec 2019 16:11:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=92=E6=96=A5=E9=94=81?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E8=B6=85=E6=97=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新互斥锁等待超时方法 --- app/src/main/cpp/media_player.c | 17 ++++++++++------- app/src/main/res/layout/activity_main.xml | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/cpp/media_player.c b/app/src/main/cpp/media_player.c index a8ad55b..d58a25b 100644 --- a/app/src/main/cpp/media_player.c +++ b/app/src/main/cpp/media_player.c @@ -24,6 +24,9 @@ #define MIN_SLEEP_TIME_US 1000ll #define AUDIO_TIME_ADJUST_US -200000ll +struct timeval now; +struct timespec timeout; + typedef struct MediaPlayer{ AVFormatContext* format_context; int video_stream_index; @@ -177,9 +180,13 @@ void player_wait_for_frame(MediaPlayer *player, int64_t stream_time) { // and check everything again sleep_time = 500000ll; } - //等待指定时长 - pthread_cond_timeout_np(&player->cond, &player->mutex, - (unsigned int) (sleep_time / 1000ll)); + //TODO:等待指定时长 +// pthread_cond_timeout_np(&player->cond, &player->mutex, +// (unsigned int) (sleep_time / 1000ll)); +// gettimeofday(&now, NULL); +// timeout.tv_sec = now.tv_sec; +// timeout.tv_nsec = (now.tv_usec + sleep_time) * 1000; +// pthread_cond_timedwait(&player->cond, &player->mutex, &timeout); } pthread_mutex_unlock(&player->mutex); } @@ -254,14 +261,11 @@ int decode_video(MediaPlayer* player, AVPacket* packet){ ANativeWindow_unlockAndPost(player->native_window); } -// //延迟等待 -// usleep(1000 * 16); return 0; } //音频解码初始化 void audio_decoder_prepare(MediaPlayer* player) { - //frame->16bit 44100 PCM 统一音频采样格式与采样率 player->swrContext = swr_alloc(); //输入的采样格式 @@ -354,7 +358,6 @@ int decode_audio(MediaPlayer* player, AVPacket* packet){ audio_sample_array,0,out_buffer_size); //释放局部引用 (*env)->DeleteLocalRef(env,audio_sample_array); -// usleep(1000 * 16); } } if(javaVM != NULL){ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a56038b..6cafb0e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -36,7 +36,8 @@ android:text="@string/media_play" android:layout_marginTop="10dp" android:layout_centerHorizontal="true" - android:layout_below="@+id/btn_media"/> + android:layout_below="@+id/btn_media" + android:visibility="gone"/>