qt_rtmp_demo/media/audiocaptureff.h

98 lines
2.6 KiB
C++

#ifndef AUDIOCAPTUREFF_H
#define AUDIOCAPTUREFF_H
#include "stdint.h"
#include "../third/portaudio/include/portaudio.h"
#include <vector>
#include <string>
//Windows
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/buffersrc.h"
#include "libavfilter/buffersink.h"
};
#include <functional>
#include <dshow.h>
#include <windows.h>
#include "qedit.h"
#include <mutex>
#include <vector>
#include <thread>
#include "guiddef.h"
using namespace std;
class CaptureAudioFfmpeg {
public:
class CaptureAudioObserver {
public:
virtual void OnAudioData(const void *frameaddress, uint32_t framelen) {};
};
typedef struct _T_MicInfo
{
wstring name;
int index;
}MICInfo;
enum ENCODINGP{
PCM = 1,
AAC = 2,
};
enum CAP_STATUS {
RUNNING = 1,
STOP = 2,
PAUSE = 3,
FAIL = 4,
};
vector<CaptureAudioFfmpeg::MICInfo> EnumSpeakers();
CaptureAudioFfmpeg(uint16_t rate, uint8_t channel);
int InitCapture(wstring url,uint16_t rate,uint8_t channel);
int SetObserver(CaptureAudioObserver*);
int StartCapture();
std::thread::id mThreadId;
/*
~CaptureAudio();
void StopCapture();
int OnCallBack(const void* input, void* output, unsigned long frameCount);
void AddCnt(unsigned int x) {this->mSize += x;};
*/
private:
std::thread *mThread;
uint16_t mSampleRate; //采样率
uint16_t mChanel; //通道号
uint16_t mSamplefmt;
unsigned long mSize;
CAP_STATUS mStatus;
CaptureAudioObserver *mObserver;
int initAudioFilters();
AVFormatContext *mInfmt_ctx = nullptr;
AVFormatContext * mOutfmt_ctx = nullptr;
int64_t mLastReadPacktTime;
AVFilterContext *mBuffersinkCtx = nullptr;
AVFilterContext *mBuffersrcCtx = nullptr;
AVFilterGraph *mFilterGraph = nullptr;
AVCodecContext* mOutPutAudioEncContext = nullptr;
int64_t mAudioCount = 0;
int flush_encoder(AVFormatContext *fmt_ctx, unsigned int stream_index);
AVFrame *DecodeAudio(AVPacket* packet, AVFrame*pSrcAudioFrame);
friend int ThreadCapture(CaptureAudioFfmpeg*p);
};
#endif // AUDIOCAPTUREFF_H