IJKPlayer获取实时数据(上)- 添加外部接口

一、添加接口

1、在IJKMediaPlayBack.h添加三个方法
IJKPlayer获取实时数据(上)- 添加外部接口_第1张图片
image.png
- (CVPixelBufferRef)framePixelbuffer;
- (void)framePixelbufferLock;
- (void)framePixelbufferUnlock;
2、在ff_ffplay_def.h 的 FFPlayer 数据结构中添加如下:
IJKPlayer获取实时数据(上)- 添加外部接口_第2张图片
image.png
// 引入头文件
#include 
  
CVPixelBufferRef szt_pixelbuffer;
pthread_mutex_t szt_pixelbuffer_mutex;
3、在ijkplayer.h中添加:
IJKPlayer获取实时数据(上)- 添加外部接口_第3张图片
image.png
// 引入头文件
#include 

CVPixelBufferRef ijkmp_get_pixelbuffer(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_init(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_lock(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_unlock(IjkMediaPlayer *mp);
4、在ijkplayer.c添加:
CVPixelBufferRef ijkmp_get_pixelbuffer(IjkMediaPlayer *mp)
{
    return mp->ffplayer->szt_pixelbuffer;
}

int ijkmp_pixelbuffer_mutex_init(IjkMediaPlayer *mp)
{
    int ret = ffp_pixelbuffer_mutex_init(mp->ffplayer);
    return ret;
}

int ijkmp_pixelbuffer_mutex_lock(IjkMediaPlayer *mp)
{
    int ret = ffp_pixelbuffer_lock(mp->ffplayer);
    return ret;
}

int ijkmp_pixelbuffer_mutex_unlock(IjkMediaPlayer *mp)
{
    int ret = ffp_pixelbuffer_unlock(mp->ffplayer);
    return ret;
}
5、在ff_ffplay.h添加:
IJKPlayer获取实时数据(上)- 添加外部接口_第4张图片
image.png
int       ffp_pixelbuffer_mutex_init(FFPlayer *ffp);
int       ffp_pixelbuffer_lock(FFPlayer *ffp);
int       ffp_pixelbuffer_unlock(FFPlayer *ffp);
6、在ff_ffplay.c添加:
int ffp_pixelbuffer_mutex_init(FFPlayer *ffp)
{
    int ret = pthread_mutex_init(&ffp->szt_pixelbuffer_mutex, NULL);
    return ret;
}
            
int ffp_pixelbuffer_lock(FFPlayer *ffp)
{
    int ret = pthread_mutex_lock(&ffp->szt_pixelbuffer_mutex);
    return ret;
}
            
int ffp_pixelbuffer_unlock(FFPlayer *ffp)
{
    int ret = pthread_mutex_unlock(&ffp->szt_pixelbuffer_mutex);
    return ret;
}
7、在IJKFFMoviePlayerController.h添加:
IJKPlayer获取实时数据(上)- 添加外部接口_第5张图片
image.png
- (CVPixelBufferRef)framePixelbuffer;
- (void)framePixelbufferLock;
- (void)framePixelbufferUnlock;
8、在IJKFFMoviePlayerController.m添加:
- (CVPixelBufferRef)framePixelbuffer
{
    if (_mediaPlayer)
    {
        return ijkmp_get_pixelbuffer(_mediaPlayer);
    }
    
    return NULL;
}

- (void)framePixelbufferLock
{
    if (_mediaPlayer)
    {
        ijkmp_pixelbuffer_mutex_lock(_mediaPlayer);
    }
}

- (void)framePixelbufferUnlock
{
    if (_mediaPlayer)
    {
        ijkmp_pixelbuffer_mutex_unlock(_mediaPlayer);
    }
}

二、如何使用:

[self.ijkplayer framePixelbufferLock];
CVPixelBufferRef pixelBuffer = [self.ijkplayer framePixelbuffer];
[self.ijkplayer framePixelbufferUnlock];

你可能感兴趣的:(IJKPlayer获取实时数据(上)- 添加外部接口)