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

Change: Add basic audio data callback framework to the API #4833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,21 @@ static int audio_decode_frame(FFPlayer *ffp)
is->audio_src.fmt = af->frame->format;
}

#if NOMIT_AUDIO_DSP_CALLBACK_FN==1
/** Digital Signal Processing, multi-channel signal *********************************/
/* Run DSP callback function. In-place processing on playback audio data buffer. */
if( ffp->pAudioDSPCbFn )
{
unsigned int numSamples = af->frame->nb_samples;
unsigned int format = af->frame->format;
ffp->pAudioDSPCbFn( (void**) af->frame->extended_data, numSamples,
(void**) af->frame->extended_data, &numSamples,
af->frame->sample_rate, af->frame->channels,
format );

}
#endif

if (is->swr_ctx) {
const uint8_t **in = (const uint8_t **)af->frame->extended_data;
uint8_t **out = &is->audio_buf1;
Expand Down
5 changes: 5 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "ff_ffmsg_queue.h"
#include "ff_ffpipenode.h"
#include "ijkmeta.h"
#include "ijkaudiocallback.h"

#define DEFAULT_HIGH_WATER_MARK_IN_BYTES (256 * 1024)

Expand Down Expand Up @@ -632,6 +633,10 @@ typedef struct FFPlayer {
SDL_Surface *screen;
#endif

#if NOMIT_AUDIO_DSP_CALLBACK_FN==1
AUDIO_DSP_CBFN pAudioDSPCbFn;
#endif

/* extra fields */
SDL_Aout *aout;
SDL_Vout *vout;
Expand Down
33 changes: 33 additions & 0 deletions ijkmedia/ijkplayer/ijkaudiocallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* ijkaudiocallback.h
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef IJKPLAYER__IJKAUDIOCALLBACK_H
#define IJKPLAYER__IJKAUDIOCALLBACK_H

/* Include support for DSP callback function in library build */
#define NOMIT_AUDIO_DSP_CALLBACK_FN (0)

/* Callback function prototype */
typedef int (*AUDIO_DSP_CBFN) ( void **inData, unsigned int numInSamples,
void **outData, unsigned int *numOutSamples,
unsigned int sampleRate, unsigned int numChans,
unsigned int format);

#endif//IJKPLAYER__IJKAUDIOCALLBACK_H
8 changes: 8 additions & 0 deletions ijkmedia/ijkplayer/ijkplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ static int ijkmp_msg_loop(void *arg)
return ret;
}

void ijkmp_setAudioDSPCallbackFn( IjkMediaPlayer *mp, AUDIO_DSP_CBFN audioCbFn )
{
#if NOMIT_AUDIO_DSP_CALLBACK_FN==1
mp->pAudioDSPCbFn = audioCbFn;
mp->ffplayer->pAudioDSPCbFn = audioCbFn;
#endif
}

static int ijkmp_prepare_async_l(IjkMediaPlayer *mp)
{
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 @@ -28,6 +28,7 @@
#include "ff_ffmsg_queue.h"

#include "ijkmeta.h"
#include "ijkaudiocallback.h"

#ifndef MPTRACE
#define MPTRACE ALOGD
Expand Down Expand Up @@ -197,6 +198,7 @@ void ijkmp_dec_ref(IjkMediaPlayer *mp);
void ijkmp_dec_ref_p(IjkMediaPlayer **pmp);

int ijkmp_set_data_source(IjkMediaPlayer *mp, const char *url);
void ijkmp_setAudioDSPCallbackFn( IjkMediaPlayer *mp, AUDIO_DSP_CBFN audioCbFn );
int ijkmp_prepare_async(IjkMediaPlayer *mp);
int ijkmp_start(IjkMediaPlayer *mp);
int ijkmp_pause(IjkMediaPlayer *mp);
Expand Down
4 changes: 4 additions & 0 deletions ijkmedia/ijkplayer/ijkplayer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct IjkMediaPlayer {
int restart_from_beginning;
int seek_req;
long seek_msec;

#if NOMIT_AUDIO_DSP_CALLBACK_FN==1
AUDIO_DSP_CBFN pAudioDSPCbFn;
#endif
};

#endif
2 changes: 2 additions & 0 deletions ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3CA61AE3230E25EF003CCA37 /* ijkaudiocallback.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ijkaudiocallback.h; sourceTree = "<group>"; };
454316201A66493700676070 /* ffpipeline_ios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ffpipeline_ios.c; path = ijkmedia/ijkplayer/ios/pipeline/ffpipeline_ios.c; sourceTree = "<group>"; };
454316211A66493700676070 /* ffpipeline_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ffpipeline_ios.h; path = ijkmedia/ijkplayer/ios/pipeline/ffpipeline_ios.h; sourceTree = "<group>"; };
454316221A66493700676070 /* ffpipenode_ios_videotoolbox_vdec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ffpipenode_ios_videotoolbox_vdec.h; path = ijkmedia/ijkplayer/ios/pipeline/ffpipenode_ios_videotoolbox_vdec.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -744,6 +745,7 @@
E6903FDC17EAFC6100CFD954 /* ff_ffplay.h */,
E69BE5491B93FED300AFBA3F /* ijkavformat */,
E69BE54E1B93FED300AFBA3F /* ijkavutil */,
3CA61AE3230E25EF003CCA37 /* ijkaudiocallback.h */,
E6FAD9551A515CE300725002 /* ijkmeta.c */,
E6FAD9561A515CE300725002 /* ijkmeta.h */,
E66F8DEE17EFEA9400354D80 /* ijkplayer_internal.h */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ - (void)setPauseInBackground:(BOOL)pause
_pauseInBackground = pause;
}

- (void)setAudioDSPCallbackFn:(AUDIO_DSP_CBFN)pAudioDSPCbFn
{
if (!_mediaPlayer)
return;

ijkmp_setAudioDSPCallbackFn( _mediaPlayer, pAudioDSPCbFn );
}

- (BOOL)isVideoToolboxOpen
{
if (!_mediaPlayer)
Expand Down
7 changes: 7 additions & 0 deletions ios/IJKMediaPlayer/IJKMediaPlayer/IJKMediaPlayback.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ typedef NS_ENUM(NSInteger, IJKMPMovieFinishReason) {
IJKMPMovieFinishReasonUserExited
};

/* Callback function prototype */
typedef int (*AUDIO_DSP_CBFN) ( void **inData, unsigned int numInSamples,
void **outData, unsigned int *numOutSamples,
unsigned int sampleRate, unsigned int numChans,
unsigned int format );

// -----------------------------------------------------------------------------
// Thumbnails

Expand All @@ -74,6 +80,7 @@ typedef NS_ENUM(NSInteger, IJKMPMovieTimeOption) {
- (BOOL)isPlaying;
- (void)shutdown;
- (void)setPauseInBackground:(BOOL)pause;
- (void)setAudioDSPCallbackFn:(AUDIO_DSP_CBFN)pAudioDSPCbFn;

@property(nonatomic, readonly) UIView *view;
@property(nonatomic) NSTimeInterval currentPlaybackTime;
Expand Down