AudioFile_Stream_Deal.c
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#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("滤波已完成");
//检查滤波器
FF_Filter_Init(AD_Info, 0x01);
//滤波
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);
}