提交 828fbeca 编写于 作者: Z Zhang Rui

ff_ffplay: merge: f1a9583305d90533acb54c9cadf6afac2c4dc3fa

ffplay: add support for interactive volume control

This is a feature heavily inspired by the mpv player. At the moment, methods
for adjusting volume in ffplay are rather clumsy: either one needs to set it
system-wide, or one needs to set it via the volume filter.

This patch adds key bindings identical to the mpv defaults for muting/unmuting
and increasing/decreasing the volume interactively without any introduction of
external dependencies.

TODO: doc update, possible mouse button bindings (mpv has this).
Signed-off-by: NGanesh Ajjanagadde <gajjanagadde@gmail.com>
Signed-off-by: NMarton Balint <cus@passwd.hu>
上级 d4829bcf
......@@ -992,6 +992,9 @@ static void toggle_pause(FFPlayer *ffp, int pause_on)
SDL_UnlockMutex(ffp->is->play_mutex);
}
// FFP_MERGE: toggle_mute
// FFP_MERGE: update_volume
static void step_to_next_frame_l(FFPlayer *ffp)
{
VideoState *is = ffp->is;
......@@ -2063,7 +2066,13 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
len1 = is->audio_buf_size - is->audio_buf_index;
if (len1 > len)
len1 = len;
memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
if (!is->muted && is->audio_volume == SDL_MIX_MAXVOLUME)
memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
else {
memset(stream, is->silence_buf[0], len1);
if (!is->muted)
SDL_MixAudio(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1, is->audio_volume);
}
len -= len1;
stream += len1;
is->audio_buf_index += len1;
......@@ -2984,6 +2993,8 @@ static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputForma
init_clock(&is->audclk, &is->audioq.serial);
init_clock(&is->extclk, &is->extclk.serial);
is->audio_clock_serial = -1;
is->audio_volume = SDL_MIX_MAXVOLUME;
is->muted = 0;
is->av_sync_type = ffp->av_sync_type;
is->play_mutex = SDL_CreateMutex();
......
......@@ -93,6 +93,9 @@
/* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
#define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 30
/* Step size for volume control */
#define SDL_VOLUME_STEP (SDL_MIX_MAXVOLUME / 50)
/* no AV sync correction is done if below the minimum AV sync threshold */
#define AV_SYNC_THRESHOLD_MIN 0.04
/* AV sync correction is done if above the maximum AV sync threshold */
......@@ -295,6 +298,8 @@ typedef struct VideoState {
unsigned int audio_buf1_size;
int audio_buf_index; /* in bytes */
int audio_write_buf_size;
int audio_volume;
int muted;
struct AudioParams audio_src;
#if CONFIG_AVFILTER
struct AudioParams audio_filter_src;
......
......@@ -37,3 +37,11 @@ void SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
spec->size *= spec->channels;
spec->size *= spec->samples;
}
void SDL_MixAudio(Uint8* dst,
const Uint8* src,
Uint32 len,
int volume)
{
// do nothing;
}
......@@ -71,6 +71,8 @@ typedef uint16_t SDL_AudioFormat;
#define AUDIO_F32SYS AUDIO_F32MSB
#endif
#define SDL_MIX_MAXVOLUME (128)
typedef void (*SDL_AudioCallback) (void *userdata, Uint8 * stream,
int len);
......@@ -89,4 +91,9 @@ typedef struct SDL_AudioSpec
void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
void SDL_MixAudio(Uint8* dst,
const Uint8* src,
Uint32 len,
int volume);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册