AudioFile_Stream_Deal.c 2.4 KB
#include "libavutil/opt.h"
#include "libavutil/channel_layout.h"
#include "libavutil/samplefmt.h"
#include "libavformat/avformat.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"
#include "libavcodec/avcodec.h"

#include "AudioDeal/FF_Statement.h"

#include <stdio.h>
#include "JZsdkLib.h"
#include "../AudioDeal.h"
#include "../Resample/pcm_Resample.h"
#include "../Filter/FF_Filter.h"
#include "../Alsa/pcm_AlsaPlay.h"
#include "./AudioStreamDeal.h"

/***************************
 * 
 *   文件播放的数据入口
 * 
 * ************/
T_JZsdkReturnCode AudioFile_Stream_Interface_PcmData(struct AudioDealInfo *AD_Info, AVFrame *frame)
{
    AVFrame *eq_frame = av_frame_alloc();
    AVFrame *temp_frame = av_frame_alloc();

    if (!eq_frame || !temp_frame) 
    {  
        JZSDK_LOG_ERROR("Could not allocate packet or frame");  
        return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
    }  

    int out_nb_samples = 0;

    //丢进重采样器
    void* resampledData = FF_Resample_Send_And_Get_ResampleData(AD_Info ,frame->data, frame->nb_samples, &out_nb_samples);

    //JZSDK_LOG_INFO("滤波已完成");

    //滤波
    if(AD_Info->FilterMode != JZ_FLAGCODE_OFF)
    {
        temp_frame->data[0] = (unsigned char*)resampledData;
        temp_frame->nb_samples = out_nb_samples;

        //将临时帧 放入 均衡滤波器
        FF_Filter_push_frame_to_fliter(AD_Info, temp_frame);

        //JZSDK_LOG_INFO("放入均衡器");

        while(AD_Info->AudioDeal_ResampleAndFilter_Execute_Flag == JZ_FLAGCODE_ON)
        {
            //得到滤波器输出的音频帧 eq_frame
            int fret = FF_Filter_get_frame_from_filter(AD_Info, eq_frame);
            if (fret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
            {
                break;
            }

            //播放改滤波后的帧
            Pcm_AlsaPlay(AD_Info, (unsigned char*)eq_frame->data[0], eq_frame->nb_samples);
            //JZSDK_LOG_INFO("代替播放 %d", eq_frame->nb_samples);

            av_frame_unref(eq_frame);
        }

        av_frame_unref(temp_frame);
    }
    else //不滤波
    {
        //直接播放
        //JZSDK_LOG_INFO("播放 %d 数据",out_nb_samples);
        Pcm_AlsaPlay(AD_Info ,resampledData, out_nb_samples);
    }

    FF_Resample_freeReasmpleData(resampledData);

    av_frame_free(&eq_frame);
    av_frame_free(&temp_frame);
}