Skip to content

Commit

Permalink
ijkplayer: add interface for setting playback volume
Browse files Browse the repository at this point in the history
  • Loading branch information
xinzhengzhang committed Nov 23, 2016
1 parent f5aae3a commit de26bc9
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ff_ffmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define FFP_PROP_FLOAT_VIDEO_DECODE_FRAMES_PER_SECOND 10001
#define FFP_PROP_FLOAT_VIDEO_OUTPUT_FRAMES_PER_SECOND 10002
#define FFP_PROP_FLOAT_PLAYBACK_RATE 10003
#define FFP_PROP_FLOAT_PLAYBACK_VOLUME 10006
#define FFP_PROP_FLOAT_AVDELAY 10004
#define FFP_PROP_FLOAT_AVDIFF 10005

Expand Down
18 changes: 18 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,10 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
ffp->pf_playback_rate_changed = 0;
SDL_AoutSetPlaybackRate(ffp->aout, ffp->pf_playback_rate);
}
if (ffp->pf_playback_volume_changed) {
ffp->pf_playback_volume_changed = 0;
SDL_AoutSetPlaybackVolume(ffp->aout, ffp->pf_playback_volume);
}

while (len > 0) {
if (is->audio_buf_index >= is->audio_buf_size) {
Expand Down Expand Up @@ -3917,6 +3921,14 @@ void ffp_set_playback_rate(FFPlayer *ffp, float rate)
ffp->pf_playback_rate_changed = 1;
}

void ffp_set_playback_volume(FFPlayer *ffp, float volume)
{
if (!ffp)
return;
ffp->pf_playback_volume = volume;
ffp->pf_playback_volume_changed = 1;
}

int ffp_get_video_rotate_degrees(FFPlayer *ffp)
{
VideoState *is = ffp->is;
Expand Down Expand Up @@ -4006,6 +4018,8 @@ float ffp_get_property_float(FFPlayer *ffp, int id, float default_value)
return ffp ? ffp->stat.avdelay : default_value;
case FFP_PROP_FLOAT_AVDIFF:
return ffp ? ffp->stat.avdiff : default_value;
case FFP_PROP_FLOAT_PLAYBACK_VOLUME:
return ffp ? ffp->pf_playback_volume : default_value;
default:
return default_value;
}
Expand All @@ -4016,6 +4030,10 @@ void ffp_set_property_float(FFPlayer *ffp, int id, float value)
switch (id) {
case FFP_PROP_FLOAT_PLAYBACK_RATE:
ffp_set_playback_rate(ffp, value);
break;
case FFP_PROP_FLOAT_PLAYBACK_VOLUME:
ffp_set_playback_volume(ffp, value);
break;
default:
return;
}
Expand Down
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ff_ffplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void ffp_set_video_codec_info(FFPlayer *ffp, const char *module, const char
void ffp_set_audio_codec_info(FFPlayer *ffp, const char *module, const char *codec);

void ffp_set_playback_rate(FFPlayer *ffp, float rate);
void ffp_set_playback_volume(FFPlayer *ffp, float volume);
int ffp_get_video_rotate_degrees(FFPlayer *ffp);
int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected);

Expand Down
4 changes: 4 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ typedef struct FFPlayer {
int af_changed;
float pf_playback_rate;
int pf_playback_rate_changed;
float pf_playback_volume;
int pf_playback_volume_changed;

void *inject_opaque;
FFStatistic stat;
Expand Down Expand Up @@ -773,6 +775,8 @@ inline static void ffp_reset_internal(FFPlayer *ffp)
ffp->af_changed = 0;
ffp->pf_playback_rate = 1.0f;
ffp->pf_playback_rate_changed = 0;
ffp->pf_playback_volume = 1.0f;
ffp->pf_playback_volume_changed = 0;

av_application_closep(&ffp->app_ctx);

Expand Down
11 changes: 11 additions & 0 deletions ijkmedia/ijkplayer/ijkplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ void ijkmp_set_playback_rate(IjkMediaPlayer *mp, float rate)
MPTRACE("%s()=void\n", __func__);
}

void ijkmp_set_playback_volume(IjkMediaPlayer *mp, float volume)
{
assert(mp);

MPTRACE("%s(%f)\n", __func__, volume);
pthread_mutex_lock(&mp->mutex);
ffp_set_playback_volume(mp->ffplayer, volume);
pthread_mutex_unlock(&mp->mutex);
MPTRACE("%s()=void\n", __func__);
}

int ijkmp_set_stream_selected(IjkMediaPlayer *mp, int stream, int selected)
{
assert(mp);
Expand Down
2 changes: 2 additions & 0 deletions ijkmedia/ijkplayer/ijkplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ void ijkmp_set_option_int(IjkMediaPlayer *mp, int opt_category, const
int ijkmp_get_video_codec_info(IjkMediaPlayer *mp, char **codec_info);
int ijkmp_get_audio_codec_info(IjkMediaPlayer *mp, char **codec_info);
void ijkmp_set_playback_rate(IjkMediaPlayer *mp, float rate);
void ijkmp_set_playback_volume(IjkMediaPlayer *mp, float rate);

int ijkmp_set_stream_selected(IjkMediaPlayer *mp, int stream, int selected);

float ijkmp_get_property_float(IjkMediaPlayer *mp, int id, float default_value);
Expand Down
8 changes: 8 additions & 0 deletions ijkmedia/ijksdl/ijksdl_aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ void SDL_AoutSetPlaybackRate(SDL_Aout *aout, float playbackRate)
}
}

void SDL_AoutSetPlaybackVolume(SDL_Aout *aout, float volume)
{
if (aout) {
if (aout->func_set_playback_volume)
aout->func_set_playback_volume(aout, volume);
}
}

int SDL_AoutGetAudioSessionId(SDL_Aout *aout)
{
if (aout) {
Expand Down
2 changes: 2 additions & 0 deletions ijkmedia/ijksdl/ijksdl_aout.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct SDL_Aout {

// optional
void (*func_set_playback_rate)(SDL_Aout *aout, float playbackRate);
void (*func_set_playback_volume)(SDL_Aout *aout, float playbackVolume);
int (*func_get_audio_persecond_callbacks)(SDL_Aout *aout);

// Android only
Expand All @@ -68,6 +69,7 @@ int SDL_AoutGetAudioPerSecondCallBacks(SDL_Aout *aout);

// optional
void SDL_AoutSetPlaybackRate(SDL_Aout *aout, float playbackRate);
void SDL_AoutSetPlaybackVolume(SDL_Aout *aout, float volume);

// android only
int SDL_AoutGetAudioSessionId(SDL_Aout *aout);
Expand Down

0 comments on commit de26bc9

Please sign in to comment.