-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresampler.h
74 lines (57 loc) · 1.55 KB
/
resampler.h
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
#ifndef RESAMPLER_H
#define RESAMPLER_H
#define __STDC_CONSTANT_MACROS
#ifdef __cplusplus
extern "C"
{
#endif
#include "libavutil/audio_fifo.h"
#include "libavutil/opt.h"
#include "libavutil/avutil.h"
#include "libavutil/fifo.h"
#include "libswresample/swresample.h"
#include "libavutil/error.h"
#include "libavutil/frame.h"
#include "libavcodec/avcodec.h"
#ifdef __cplusplus
}
#endif
#include "util.h"
class Resampler
{
public:
Resampler();
~Resampler();
bool Init(uint64_t src_channel_layout,
enum AVSampleFormat src_sample_fmt,
int src_sample_rate,
uint64_t dst_channel_layout,
enum AVSampleFormat dst_sample_fmt,
int dst_sample_rate);
int SendFrame(AVFrame* frame);
AVFrame* RecvFrame(int nb_samples);
private:
bool AllocResampleData();
void ResetPts(int64_t pts);
AVFrame* GetOneFrame(int nb_samples);
private:
uint64_t src_channel_layout_;
enum AVSampleFormat src_sample_fmt_;
int src_sample_rate_;
uint64_t dst_channel_layout_;
enum AVSampleFormat dst_sample_fmt_;
int dst_sample_rate_;
struct SwrContext* swr_ctx_ = NULL;
int src_channels_;
int dst_channels_;
AVAudioFifo* audio_fifo_ = NULL;
bool is_fifo_only_ = false;
uint8_t** resample_data_ = NULL;
int resample_data_size_;
int64_t in_start_pts_ = AV_NOPTS_VALUE;
int64_t in_last_pts_ = AV_NOPTS_VALUE;
int64_t out_start_pts_ = AV_NOPTS_VALUE;
int64_t out_cur_pts_ = AV_NOPTS_VALUE;
bool is_flushed_ = false;
};
#endif // RESAMPLER_H