zhuizhu пре 7 месеци
родитељ
комит
697fabd43d

+ 30 - 5
LearningSmartClient.pro

@@ -105,11 +105,28 @@ include($$PWD/libs/libs.pri)
 
 
 
-
-INCLUDEPATH+="E:/AAA/ffmpeg-7.0.2-full_build-shared/include"
-LIBS+="-LE:/AAA/ffmpeg-7.0.2-full_build-shared/lib"
-win32{
-    LIBS += -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale -lavdevice
+# FFmpeg library configuration
+win32 {
+    INCLUDEPATH += "E:/AAA/ffmpeg-7.0.2-full_build-shared/include"
+    LIBS += -L"E:/AAA/ffmpeg-7.0.2-full_build-shared/lib"
+    
+    # 使用动态库的导入库(适用于MSVC)
+
+    LIBS += -lavdevice
+    LIBS += -lavfilter
+    LIBS += -lavformat
+    LIBS += -lavcodec
+    LIBS += -lswresample
+    LIBS += -lswscale
+    LIBS += -lavutil
+    LIBS += -lpostproc
+
+    
+    # 添加FFmpeg依赖的系统库
+    LIBS += -lbcrypt
+    LIBS += -lsecur32
+    LIBS += -luser32
+    LIBS += -lole32
 }
 win32: LIBS += -lOpenGL32
 LIBS += -lwinmm
@@ -130,6 +147,14 @@ CONFIG(debug, debug|release) {
     TARGET = $$join(TARGET,,,d)
 }
 
+# Copy FFmpeg DLLs to output directory
+win32 {
+    FFMPEG_DLLS = $$files(E:/AAA/ffmpeg-7.0.2-full_build-shared/bin/*.dll)
+    for(dll, FFMPEG_DLLS) {
+        QMAKE_POST_LINK += $$QMAKE_COPY $$shell_path($$dll) $$shell_path($$DESTDIR) $$escape_expand(\n\t)
+    }
+}
+
 
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin

+ 1 - 1
MainPanel.cpp

@@ -186,7 +186,7 @@ MainPanel::MainPanel(QWidget *parent)
     // // 使用解耦版本的音频设备选择器
     // m_audioDeviceSelectorDecoupled = new AudioDeviceSelectorIconDecoupled(this);
     // audioDevicePopover->setContentWidget(m_audioDeviceSelectorDecoupled);
-    // buttonGroup->addButton(audioDeviceBtn, audioDevicePopover);
+    buttonGroup->addButton(audioDeviceBtn, audioDevicePopover);
 
     // // 初始化音频设备选择器
     // initAudioDeviceSelectors();

+ 2 - 64
libs/AvRecorder/ui/av_recorder.cpp

@@ -343,38 +343,7 @@ void AvRecorder::startCapture(CaptureMethod method)
             m_videoRecorder.SetCaptureSource(idx, method);
             ok = true;
         } else if (type == "window" && ::IsWindow((HWND) ptrHwnd)) {
-            HWND hwnd = (HWND) ptrHwnd;
-            
-            // 详细的窗口有效性检查
-            bool isVisible = IsWindowVisible(hwnd);
-            wchar_t title[256] = {0};
-            int titleLen = GetWindowTextW(hwnd, title, 256);
-            QString windowTitle = QString::fromWCharArray(title);
-            
-            RECT rect;
-            bool hasRect = GetWindowRect(hwnd, &rect);
-            
-            qDebug() << "AvRecorder::startCapture - 窗口捕获详情:";
-            qDebug() << "  HWND:" << Qt::hex << ptrHwnd;
-            qDebug() << "  标题:" << windowTitle;
-            qDebug() << "  可见:" << (isVisible ? "是" : "否");
-            qDebug() << "  标题长度:" << titleLen;
-            
-            if (hasRect) {
-                qDebug() << "  位置:" << rect.left << "," << rect.top 
-                         << " 大小:" << (rect.right - rect.left) << "x" << (rect.bottom - rect.top);
-            }
-            
-            // 检查窗口是否适合捕获
-            if (!isVisible) {
-                qWarning() << "AvRecorder::startCapture - 警告: 窗口不可见,可能影响捕获效果";
-            }
-            
-            if (titleLen == 0) {
-                qWarning() << "AvRecorder::startCapture - 警告: 窗口无标题,可能是系统窗口";
-            }
-            
-            m_videoRecorder.SetCaptureSource(hwnd, method);
+            m_videoRecorder.SetCaptureSource((HWND) ptrHwnd, method);
             ok = true;
         }
     } else {
@@ -382,38 +351,7 @@ void AvRecorder::startCapture(CaptureMethod method)
         if (idx < monitorCnt) { // 捕获屏幕
             ok = m_videoRecorder.Open(idx, m_settingsParam.videoParam, method);
         } else if (type == "window" && ::IsWindow((HWND) ptrHwnd)) {
-            HWND hwnd = (HWND) ptrHwnd;
-            
-            // 详细的窗口有效性检查
-            bool isVisible = IsWindowVisible(hwnd);
-            wchar_t title[256] = {0};
-            int titleLen = GetWindowTextW(hwnd, title, 256);
-            QString windowTitle = QString::fromWCharArray(title);
-            
-            RECT rect;
-            bool hasRect = GetWindowRect(hwnd, &rect);
-            
-            qDebug() << "AvRecorder::startCapture - 窗口捕获详情:";
-            qDebug() << "  HWND:" << Qt::hex << ptrHwnd;
-            qDebug() << "  标题:" << windowTitle;
-            qDebug() << "  可见:" << (isVisible ? "是" : "否");
-            qDebug() << "  标题长度:" << titleLen;
-            
-            if (hasRect) {
-                qDebug() << "  位置:" << rect.left << "," << rect.top 
-                         << " 大小:" << (rect.right - rect.left) << "x" << (rect.bottom - rect.top);
-            }
-            
-            // 检查窗口是否适合捕获
-            if (!isVisible) {
-                qWarning() << "AvRecorder::startCapture - 警告: 窗口不可见,可能影响捕获效果";
-            }
-            
-            if (titleLen == 0) {
-                qWarning() << "AvRecorder::startCapture - 警告: 窗口无标题,可能是系统窗口";
-            }
-            
-            ok = m_videoRecorder.Open(hwnd, m_settingsParam.videoParam, method);
+            ok = m_videoRecorder.Open((HWND) ptrHwnd, m_settingsParam.videoParam, method);
         }
     }
     if (!ok) {

+ 0 - 3
libs/AvRecorder/ui/capture_source_widget.cpp

@@ -2,9 +2,6 @@
 #include "qdebug.h"
 
 #include <capturer/finder.h>
-#ifdef _WIN32
-#include <Windows.h>
-#endif
 
 CaptureSourceWidget::CaptureSourceWidget(QWidget* parent)
     : QWidget(parent)

+ 2 - 1
libs/Recorder/common.h

@@ -1,5 +1,5 @@
 #pragma once
-
+extern "C" {
 #include <libavcodec\avcodec.h>
 #include <libavdevice\avdevice.h>
 #include <libavformat\avformat.h>
@@ -7,3 +7,4 @@
 #include <libavutil\avutil.h>
 #include <libswresample\swresample.h>
 #include <libswscale\swscale.h>
+}

+ 7 - 6
libs/Recorder/export.h

@@ -3,12 +3,13 @@
 
 #include <stdint.h>
 
-#ifdef AMRECORDER_IMPORT
-#define AMRECORDER_API extern "C"  __declspec(dllimport)
-#else
-#define AMRECORDER_API extern "C"  __declspec(dllexport)
-#endif
+// #ifdef AMRECORDER_IMPORT
+// #define AMRECORDER_API extern "C"  __declspec(dllimport)
+// #else
+// #define AMRECORDER_API extern "C"  __declspec(dllexport)
+// #endif
 
+#define AMRECORDER_API
 
 /**
 * AMRECORDER_DEVICE
@@ -292,4 +293,4 @@ AMRECORDER_API void recorder_set_preview_enabled(int enable);
 * @param[in] log file path
 */
 AMRECORDER_API void recorder_set_logpath(const char* path);
-#endif
+#endif

+ 4 - 3
libs/Recorder/ffmpeg_compat.h

@@ -8,10 +8,11 @@
 
 extern "C" {
 #include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
+#include <libavcodec/bsf.h>
 #include <libavdevice/avdevice.h>
+#include <libavformat/avformat.h>
 #include <libavutil/channel_layout.h>
-#include <libavcodec/bsf.h>
+#include <libswresample/swresample.h>
 }
 
 // FFmpeg version detection
@@ -478,4 +479,4 @@ inline AVBitStreamFilterContext* ffmpeg_bitstream_filter_init(const char* name)
 #else
     return av_bitstream_filter_init(name);
 #endif
-}
+}

+ 21 - 19
libs/Recorder/headers_ffmpeg.h

@@ -1,25 +1,27 @@
 #pragma once
 
 extern "C" {
-#include <libavcodec\adts_parser.h>
-#include <libavcodec\avcodec.h>
-#include <libavdevice\avdevice.h>
-#include <libavfilter\avfilter.h>
-#include <libavfilter\buffersink.h>
-#include <libavfilter\buffersrc.h>
-#include <libavformat\avformat.h>
-#include <libavutil\avassert.h>
-#include <libavutil\channel_layout.h>
-#include <libavutil\error.h>
-#include <libavutil\imgutils.h>
-#include <libavutil\log.h>
-#include <libavutil\mathematics.h>
-#include <libavutil\opt.h>
-#include <libavutil\samplefmt.h>
-#include <libavutil\time.h>
-#include <libavutil\timestamp.h>
-#include <libswresample\swresample.h>
-#include <libswscale\swscale.h>
+#include <libavcodec/avcodec.h>
+#include <libavcodec/avfft.h>
+#include <libavformat/avformat.h>
+#include <libavutil/bprint.h>
+#include <libavutil/fifo.h>
+#include <libavutil/imgutils.h>
+#include <libavutil/samplefmt.h>
+#include <libavutil/time.h>
+#include <libswresample/swresample.h>
+#include <libswscale/swscale.h>
+
+#include <libavutil/avassert.h>
+
+// #if USE_AVFILTER_AUDIO
+#include <libavfilter/avfilter.h>
+#include <libavfilter/buffersink.h>
+#include <libavfilter/buffersrc.h>
+#include <libavutil/avstring.h>
+#include <libavutil/macros.h>
+#include <libavutil/opt.h>
+// #endif
 }
 
 // Include FFmpeg compatibility layer

+ 2 - 1
libs/Recorder/muxer_ffmpeg.cpp

@@ -1,7 +1,8 @@
 #include "muxer_ffmpeg.h"
-#include "muxer_define.h"
 #include "headers_ffmpeg.h"
 
+#include "muxer_define.h"
+
 #include "encoder_video.h"
 #include "encoder_video_factory.h"
 #include "record_desktop.h"

+ 397 - 405
libs/Recorder/test_main.cpp

@@ -1,499 +1,491 @@
-#include "device_audios.h"
+// #include "device_audios.h"
 
-#include "record_audio_factory.h"
-#include "record_desktop_factory.h"
-#include "headers_mmdevice.h"
+// #include "record_audio_factory.h"
+// #include "record_desktop_factory.h"
+// #include "headers_mmdevice.h"
 
-#include "encoder_aac.h"
-#include "resample_pcm.h"
-#include "filter_aresample.h"
+// #include "encoder_aac.h"
+// #include "resample_pcm.h"
+// #include "filter_aresample.h"
 
-#include "muxer_define.h"
-#include "muxer_ffmpeg.h"
+// #include "muxer_define.h"
+// #include "muxer_ffmpeg.h"
+
+// #include "utils_string.h"
+// #include "system_version.h"
+// #include "error_define.h"
+// #include "log_helper.h"
+// #include "hardware_acceleration.h"
 
-#include "utils_string.h"
-#include "system_version.h"
-#include "error_define.h"
-#include "log_helper.h"
-#include "hardware_acceleration.h"
+// #include "remuxer_ffmpeg.h"
+// #include "headers_ffmpeg.h"
+
+// #include <stdio.h>
+// #include <stdlib.h>
+// #include <stddef.h>
+// #include <stdint.h>
 
-#include "remuxer_ffmpeg.h"
-#include "headers_ffmpeg.h"
+// #define USE_WASAPI 1
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdint.h>
+// #define V_FRAME_RATE 30
+// #define V_BIT_RATE 1280*1000
+// #define V_WIDTH GetSystemMetrics(SM_CXSCREEN)
+// #define V_HEIGHT  GetSystemMetrics(SM_CYSCREEN);
+// #define V_QUALITY 100
 
-#define USE_WASAPI 1
+// #define A_SAMPLE_CHANNEL 2
+// #define A_SAMPLE_RATE 44100
+// #define A_BIT_RATE 128000
 
-#define V_FRAME_RATE 30
-#define V_BIT_RATE 1280*1000
-#define V_WIDTH GetSystemMetrics(SM_CXSCREEN)
-#define V_HEIGHT  GetSystemMetrics(SM_CYSCREEN);
-#define V_QUALITY 100
+// //for test muxer
+// static am::record_audio *_recorder_speaker = nullptr;
+// static am::record_audio *_recorder_microphone = nullptr;
+// static am::record_desktop *_recorder_desktop = nullptr;
+// static am::muxer_file *_muxer;
+// static am::record_audio *audios[2];
 
-#define A_SAMPLE_CHANNEL 2
-#define A_SAMPLE_RATE 44100
-#define A_BIT_RATE 128000
+// //for test audio record
+// static am::record_audio *_recorder_audio = nullptr;
+// static am::encoder_aac *_encoder_aac = nullptr;
+// static am::resample_pcm *_resample_pcm = nullptr;
+// static am::filter_aresample *_filter_aresample = nullptr;
 
+// static int _sample_in = 0;
+// static int _sample_size = 0;
+// static int _resample_size = 0;
+// static uint8_t *_sample_buffer = nullptr;
+// static uint8_t *_resample_buffer = nullptr;
 
-//for test muxer
-static am::record_audio *_recorder_speaker = nullptr;
-static am::record_audio *_recorder_microphone = nullptr;
-static am::record_desktop *_recorder_desktop = nullptr;
-static am::muxer_file *_muxer;
-static am::record_audio *audios[2];
+// int start_muxer() {
+// 	std::string input_id, input_name, out_id, out_name;
 
-//for test audio record
-static am::record_audio *_recorder_audio = nullptr;
-static am::encoder_aac *_encoder_aac = nullptr;
-static am::resample_pcm *_resample_pcm = nullptr;
-static am::filter_aresample *_filter_aresample = nullptr;
+// 	am::device_audios::get_default_input_device(input_id, input_name);
 
-static int _sample_in = 0;
-static int _sample_size = 0;
-static int _resample_size = 0;
-static uint8_t *_sample_buffer = nullptr;
-static uint8_t *_resample_buffer = nullptr;
+// 	al_info("use default input aduio device:%s", input_name.c_str());
 
-int start_muxer() {
-	std::string input_id, input_name, out_id, out_name;
+// 	am::device_audios::get_default_ouput_device(out_id, out_name);
 
-	am::device_audios::get_default_input_device(input_id, input_name);
+// 	al_info("use default output aduio device:%s", out_name.c_str());
 
-	al_info("use default input aduio device:%s", input_name.c_str());
+// 	//first audio resrouce must be speaker,otherwise the audio pts may be not correct,may need to change the filter amix descriptions with duration & sync option
+// #if !USE_WASAPI
 
-	am::device_audios::get_default_ouput_device(out_id, out_name);
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_DSHOW, &_recorder_speaker);
+// 	_recorder_speaker->init(
+// 		am::utils_string::ascii_utf8("audio=virtual-audio-capturer"),
+// 		am::utils_string::ascii_utf8("audio=virtual-audio-capturer"),
+// 		false
+// 	);
 
-	al_info("use default output aduio device:%s", out_name.c_str());
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_DSHOW, &_recorder_microphone);
+// 	_recorder_microphone->init(am::utils_string::ascii_utf8("audio=") + input_name, input_id, true);
+// #else
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_speaker);
+// 	_recorder_speaker->init(out_name, out_id, false);
 
-	//first audio resrouce must be speaker,otherwise the audio pts may be not correct,may need to change the filter amix descriptions with duration & sync option
-#if !USE_WASAPI
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_microphone);
+// 	_recorder_microphone->init(input_name, input_id, true);
+// #endif // !USE_WASAPI
 
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_DSHOW, &_recorder_speaker);
-	_recorder_speaker->init(
-		am::utils_string::ascii_utf8("audio=virtual-audio-capturer"),
-		am::utils_string::ascii_utf8("audio=virtual-audio-capturer"), 
-		false
-	);
+// 	record_desktop_new(RECORD_DESKTOP_TYPES::DT_DESKTOP_WIN_DUPLICATION, &_recorder_desktop);
 
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_DSHOW, &_recorder_microphone);
-	_recorder_microphone->init(am::utils_string::ascii_utf8("audio=") + input_name, input_id, true);
-#else
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_speaker);
-	_recorder_speaker->init(out_name, out_id, false);
+// 	RECORD_DESKTOP_RECT rect;
+// 	rect.left = 0;
+// 	rect.top = 0;
+// 	rect.right = V_WIDTH;
+// 	rect.bottom = V_HEIGHT;
 
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_microphone);
-	_recorder_microphone->init(input_name, input_id, true);
-#endif // !USE_WASAPI
+// 	_recorder_desktop->init(rect, V_FRAME_RATE);
 
+// 	audios[0] = _recorder_microphone;
+// 	audios[1] = _recorder_speaker;
 
-	record_desktop_new(RECORD_DESKTOP_TYPES::DT_DESKTOP_WIN_DUPLICATION, &_recorder_desktop);
+// 	_muxer = new am::muxer_ffmpeg();
 
-	RECORD_DESKTOP_RECT rect;
-	rect.left = 0;
-	rect.top = 0;
-	rect.right = V_WIDTH;
-	rect.bottom = V_HEIGHT;
+// 	am::MUX_SETTING setting;
+// 	setting.v_frame_rate = V_FRAME_RATE;
+// 	setting.v_bit_rate = V_BIT_RATE;
+// 	setting.v_width = V_WIDTH;
+// 	setting.v_height = V_HEIGHT;
+// 	setting.v_qb = V_QUALITY;
+// 	setting.v_encoder_id = am::EID_VIDEO_X264;
+// 	setting.v_out_width = 1920;
+// 	setting.v_out_height = 1080;
 
-	_recorder_desktop->init(rect, V_FRAME_RATE);
+// 	setting.a_nb_channel = A_SAMPLE_CHANNEL;
+// 	setting.a_sample_fmt = AV_SAMPLE_FMT_FLTP;
+// 	setting.a_sample_rate = A_SAMPLE_RATE;
+// 	setting.a_bit_rate = A_BIT_RATE;
 
-	audios[0] = _recorder_microphone;
-	audios[1] = _recorder_speaker;
+// 	int error = _muxer->init(am::utils_string::ascii_utf8("..\\..\\save.mp4").c_str(), _recorder_desktop, audios, 2, setting);
+// 	if (error != AE_NO) {
+// 		return error;
+// 	}
 
-	_muxer = new am::muxer_ffmpeg();
+// 	_muxer->start();
 
+// 	return error;
+// }
 
-	am::MUX_SETTING setting;
-	setting.v_frame_rate = V_FRAME_RATE;
-	setting.v_bit_rate = V_BIT_RATE;
-	setting.v_width = V_WIDTH;
-	setting.v_height = V_HEIGHT;
-	setting.v_qb = V_QUALITY;
-	setting.v_encoder_id = am::EID_VIDEO_X264;
-	setting.v_out_width = 1920;
-	setting.v_out_height = 1080;
+// void stop_muxer()
+// {
+// 	_muxer->stop();
 
-	setting.a_nb_channel = A_SAMPLE_CHANNEL;
-	setting.a_sample_fmt = AV_SAMPLE_FMT_FLTP;
-	setting.a_sample_rate = A_SAMPLE_RATE;
-	setting.a_bit_rate = A_BIT_RATE;
+// 	delete _recorder_desktop;
 
-	int error = _muxer->init(am::utils_string::ascii_utf8("..\\..\\save.mp4").c_str(), _recorder_desktop, audios, 2, setting);
-	if (error != AE_NO) {
-		return error;
-	}
+// 	if(_recorder_speaker)
+// 		delete _recorder_speaker;
 
-	_muxer->start();
+// 	if (_recorder_microphone)
+// 		delete _recorder_microphone;
 
-	return error;
-}
+// 	delete _muxer;
+// }
 
-void stop_muxer()
-{
-	_muxer->stop();
+// void test_recorder()
+// {
+// 	//av_log_set_level(AV_LOG_DEBUG);
 
-	delete _recorder_desktop;
+// 	start_muxer();
 
-	if(_recorder_speaker)
-		delete _recorder_speaker;
+// 	getchar();
 
-	if (_recorder_microphone)
-		delete _recorder_microphone;
+// 	//stop have bug that sometime will stuck
+// 	stop_muxer();
 
-	delete _muxer;
-}
+// 	al_info("record stoped...");
+// }
 
-void test_recorder()
-{
-	//av_log_set_level(AV_LOG_DEBUG);
+// void show_devices()
+// {
+// 	std::list<am::DEVICE_AUDIOS> devices;
 
-	start_muxer();
+// 	am::device_audios::get_input_devices(devices);
 
-	getchar();
+// 	for each (auto device in devices)
+// 	{
+// 		al_info("audio input name:%s id:%s", device.name.c_str(), device.id.c_str());
+// 	}
+
+// 	am::device_audios::get_output_devices(devices);
+
+// 	for each (auto device in devices)
+// 	{
+// 		al_info("audio output name:%s id:%s", device.name.c_str(), device.id.c_str());
+// 	}
+// }
 
-	//stop have bug that sometime will stuck
-	stop_muxer();
+// void on_aac_data(AVPacket *packet) {
+// 	al_debug("on aac data :%d", packet->size);
+// }
 
-	al_info("record stoped...");
-}
+// void on_aac_error(int) {
 
-void show_devices()
-{
-	std::list<am::DEVICE_AUDIOS> devices;
+// }
 
-	am::device_audios::get_input_devices(devices);
+// void on_pcm_error(int, int) {
 
-	for each (auto device in devices)
-	{
-		al_info("audio input name:%s id:%s", device.name.c_str(), device.id.c_str());
-	}
-
-	am::device_audios::get_output_devices(devices);
-
-	for each (auto device in devices)
-	{
-		al_info("audio output name:%s id:%s", device.name.c_str(), device.id.c_str());
-	}
-}
+// }
 
-void on_aac_data(AVPacket *packet) {
-	al_debug("on aac data :%d", packet->size);
-}
+// void on_pcm_data1(AVFrame *frame, int index) {
 
-void on_aac_error(int) {
+// 	int copied_len = 0;
+// 	int sample_len = av_samples_get_buffer_size(NULL, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
+// 	int remain_len = sample_len;
 
-}
+// 	int is_planner = av_sample_fmt_is_planar((AVSampleFormat)frame->format);
 
-void on_pcm_error(int, int) {
+// 	while (remain_len > 0) {//should add is_planner codes
+// 							//cache pcm
+// 		copied_len = min(_sample_size - _sample_in, remain_len);
+// 		if (copied_len) {
+// 			memcpy(_sample_buffer + _sample_in, frame->data[0] + sample_len - remain_len, copied_len);
+// 			_sample_in += copied_len;
+// 			remain_len = remain_len - copied_len;
+// 		}
+
+// 		//got enough pcm to encoder,resample and mix
+// 		if (_sample_in == _sample_size) {
+// 			int ret = _resample_pcm->convert(_sample_buffer, _sample_size, _resample_buffer,_resample_size);
+// 			if (ret > 0) {
+// 				_encoder_aac->put(_resample_buffer, _resample_size, frame);
+// 			}
+// 			else {
+// 				al_debug("resample audio %d failed,%d", index, ret);
+// 			}
+
+// 			_sample_in = 0;
+// 		}
+// 	}
+// }
+
+// void on_pcm_data(AVFrame *frame, int index) {
+// 	_filter_aresample->add_frame(frame);
+// }
+
+// void on_aresample_data(AVFrame * frame,int index) {
+// 	int copied_len = 0;
+// 	int sample_len = av_samples_get_buffer_size(frame->linesize, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
+// 	sample_len = av_samples_get_buffer_size(NULL, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
+
+// 	int remain_len = sample_len;
+
+// 	//for data is planar,should copy data[0] data[1] to correct buff pos
+// 	if (av_sample_fmt_is_planar((AVSampleFormat)frame->format) == 0) {
+// 		while (remain_len > 0) {
+// 			//cache pcm
+// 			copied_len = min(_sample_size - _sample_in, remain_len);
+// 			if (copied_len) {
+// 				memcpy(_resample_buffer + _sample_in, frame->data[0] + sample_len - remain_len, copied_len);
+// 				_sample_in += copied_len;
+// 				remain_len = remain_len - copied_len;
+// 			}
+
+// 			//got enough pcm to encoder,resample and mix
+// 			if (_sample_in == _sample_size) {
+// 				_encoder_aac->put(_resample_buffer, _sample_size, frame);
+
+// 				_sample_in = 0;
+// 			}
+// 		}
+// 	}
+// 	else {//resample size is channels*frame->linesize[0],for 2 channels
+// 		while (remain_len > 0) {
+// 			copied_len = min(_sample_size - _sample_in, remain_len);
+// 			if (copied_len) {
+// 				memcpy(_resample_buffer + _sample_in / 2, frame->data[0] + (sample_len - remain_len) / 2, copied_len / 2);
+// 				memcpy(_resample_buffer + _sample_size / 2 + _sample_in / 2, frame->data[1] + (sample_len - remain_len) / 2, copied_len / 2);
+// 				_sample_in += copied_len;
+// 				remain_len = remain_len - copied_len;
+// 			}
+
+// 			if (_sample_in == _sample_size) {
+// 				_encoder_aac->put(_resample_buffer, _sample_size, frame);
+
+// 				_sample_in = 0;
+// 			}
+// 		}
+// 	}
+// }
+
+// void on_aresample_error(int error,int index) {
+
+// }
+
+// void save_aac() {
+// 	std::string input_id, input_name, out_id, out_name;
+
+// 	am::device_audios::get_default_input_device(input_id, input_name);
+
+// 	am::device_audios::get_default_ouput_device(out_id, out_name);
+
+// #if 0
+// 	al_info("use default \r\noutput aduio device name:%s \r\noutput audio device id:%s ",
+// 		out_name.c_str(), out_id.c_str());
+
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_audio);
+// 	_recorder_audio->init(out_name, out_id, false);
+// #else
+// 	al_info("use default \r\ninput aduio device name:%s \r\ninput audio device id:%s ",
+// 		input_name.c_str(), input_id.c_str());
+
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_audio);
+// 	_recorder_audio->init(input_name, input_id, true);
+// #endif
+
+// 	_recorder_audio->registe_cb(on_pcm_data, on_pcm_error, 0);
+
+// 	_encoder_aac = new am::encoder_aac();
+// 	_encoder_aac->init(A_SAMPLE_CHANNEL, A_SAMPLE_RATE, AV_SAMPLE_FMT_FLTP, A_BIT_RATE);
+
+// 	am::SAMPLE_SETTING src, dst = { 0 };
+// 	src = {
+// 		_encoder_aac->get_nb_samples(),
+// 		(int64_t)ffmpeg_get_default_channel_layout(_recorder_audio->get_channel_num()),
+// 		_recorder_audio->get_channel_num(),
+// 		_recorder_audio->get_fmt(),
+// 		_recorder_audio->get_sample_rate()
+// 	};
+// 	dst = {
+// 		_encoder_aac->get_nb_samples(),
+// 		(int64_t)ffmpeg_get_default_channel_layout(A_SAMPLE_CHANNEL),
+// 		A_SAMPLE_CHANNEL,
+// 		AV_SAMPLE_FMT_FLTP,
+// 		A_SAMPLE_RATE
+// 	};
+
+// 	_resample_pcm = new am::resample_pcm();
+// 	_resample_pcm->init(&src, &dst, &_resample_size);
+// 	_resample_buffer = new uint8_t[_resample_size];
+
+// 	_sample_size = av_samples_get_buffer_size(NULL, A_SAMPLE_CHANNEL, _encoder_aac->get_nb_samples(), _recorder_audio->get_fmt(), 1);
+// 	_sample_buffer = new uint8_t[_sample_size];
+
+// 	_filter_aresample = new am::filter_aresample();
+// 	_filter_aresample->init({
+// 		NULL,NULL,
+// 		_recorder_audio->get_time_base(),
+// 		_recorder_audio->get_sample_rate(),
+// 		_recorder_audio->get_fmt(),
+// 		_recorder_audio->get_channel_num(),
+// 		(int64_t)ffmpeg_get_default_channel_layout(_recorder_audio->get_channel_num())
+// 	}, {
+// 		NULL,NULL,
+// 		{ 1,AV_TIME_BASE },
+// 		A_SAMPLE_RATE,
+// 		AV_SAMPLE_FMT_FLTP,
+// 		A_SAMPLE_CHANNEL,
+// 		(int64_t)ffmpeg_get_default_channel_layout(A_SAMPLE_CHANNEL)
+// 	},0);
+// 	_filter_aresample->registe_cb(on_aresample_data, on_aresample_error);
+
+// 	_filter_aresample->start();
+// 	_encoder_aac->start();
+// 	_recorder_audio->start();
+
+// 	getchar();
+
+// 	_recorder_audio->stop();
+// 	_filter_aresample->stop();
+
+// 	delete _recorder_audio;
+// 	delete _encoder_aac;
+// 	delete _resample_pcm;
+// 	delete _filter_aresample;
+
+// 	delete[] _sample_buffer;
+// 	delete[] _resample_buffer;
+// }
 
-}
+// void test_audio()
+// {
+// 	std::string input_id, input_name, out_id, out_name;
 
-void on_pcm_data1(AVFrame *frame, int index) {
+// 	am::device_audios::get_default_input_device(input_id, input_name);
 
-	int copied_len = 0;
-	int sample_len = av_samples_get_buffer_size(NULL, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
-	int remain_len = sample_len;
+// 	al_info("use default \r\ninput aduio device name:%s \r\ninput audio device id:%s ",
+// 		input_name.c_str(), input_id.c_str());
 
-	int is_planner = av_sample_fmt_is_planar((AVSampleFormat)frame->format);
+// 	am::device_audios::get_default_ouput_device(out_id, out_name);
 
-	while (remain_len > 0) {//should add is_planner codes
-							//cache pcm
-		copied_len = min(_sample_size - _sample_in, remain_len);
-		if (copied_len) {
-			memcpy(_sample_buffer + _sample_in, frame->data[0] + sample_len - remain_len, copied_len);
-			_sample_in += copied_len;
-			remain_len = remain_len - copied_len;
-		}
-
-		//got enough pcm to encoder,resample and mix
-		if (_sample_in == _sample_size) {
-			int ret = _resample_pcm->convert(_sample_buffer, _sample_size, _resample_buffer,_resample_size);
-			if (ret > 0) {
-				_encoder_aac->put(_resample_buffer, _resample_size, frame);
-			}
-			else {
-				al_debug("resample audio %d failed,%d", index, ret);
-			}
-
-			_sample_in = 0;
-		}
-	}
-}
-
-void on_pcm_data(AVFrame *frame, int index) {
-	_filter_aresample->add_frame(frame);
-}
-
-void on_aresample_data(AVFrame * frame,int index) {
-	int copied_len = 0;
-	int sample_len = av_samples_get_buffer_size(frame->linesize, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
-	sample_len = av_samples_get_buffer_size(NULL, ffmpeg_get_frame_channels(frame), frame->nb_samples, (AVSampleFormat)frame->format, 1);
-
-	int remain_len = sample_len;
-
-	//for data is planar,should copy data[0] data[1] to correct buff pos
-	if (av_sample_fmt_is_planar((AVSampleFormat)frame->format) == 0) {
-		while (remain_len > 0) {
-			//cache pcm
-			copied_len = min(_sample_size - _sample_in, remain_len);
-			if (copied_len) {
-				memcpy(_resample_buffer + _sample_in, frame->data[0] + sample_len - remain_len, copied_len);
-				_sample_in += copied_len;
-				remain_len = remain_len - copied_len;
-			}
-
-			//got enough pcm to encoder,resample and mix
-			if (_sample_in == _sample_size) {
-				_encoder_aac->put(_resample_buffer, _sample_size, frame);
-
-				_sample_in = 0;
-			}
-		}
-	}
-	else {//resample size is channels*frame->linesize[0],for 2 channels
-		while (remain_len > 0) {
-			copied_len = min(_sample_size - _sample_in, remain_len);
-			if (copied_len) {
-				memcpy(_resample_buffer + _sample_in / 2, frame->data[0] + (sample_len - remain_len) / 2, copied_len / 2);
-				memcpy(_resample_buffer + _sample_size / 2 + _sample_in / 2, frame->data[1] + (sample_len - remain_len) / 2, copied_len / 2);
-				_sample_in += copied_len;
-				remain_len = remain_len - copied_len;
-			}
-
-			if (_sample_in == _sample_size) {
-				_encoder_aac->put(_resample_buffer, _sample_size, frame);
-
-				_sample_in = 0;
-			}
-		}
-	}
-}
-
-void on_aresample_error(int error,int index) {
-
-}
-
-void save_aac() {
-	std::string input_id, input_name, out_id, out_name;
-
-	am::device_audios::get_default_input_device(input_id, input_name);
-
-	am::device_audios::get_default_ouput_device(out_id, out_name);
-
-#if 0
-	al_info("use default \r\noutput aduio device name:%s \r\noutput audio device id:%s ",
-		out_name.c_str(), out_id.c_str());
-
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_audio);
-	_recorder_audio->init(out_name, out_id, false);
-#else
-	al_info("use default \r\ninput aduio device name:%s \r\ninput audio device id:%s ",
-		input_name.c_str(), input_id.c_str());
-
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_audio);
-	_recorder_audio->init(input_name, input_id, true);
-#endif
-
-	_recorder_audio->registe_cb(on_pcm_data, on_pcm_error, 0);
-
-	_encoder_aac = new am::encoder_aac();
-	_encoder_aac->init(A_SAMPLE_CHANNEL, A_SAMPLE_RATE, AV_SAMPLE_FMT_FLTP, A_BIT_RATE);
-
-	am::SAMPLE_SETTING src, dst = { 0 };
-	src = {
-		_encoder_aac->get_nb_samples(),
-		(int64_t)ffmpeg_get_default_channel_layout(_recorder_audio->get_channel_num()),
-		_recorder_audio->get_channel_num(),
-		_recorder_audio->get_fmt(),
-		_recorder_audio->get_sample_rate()
-	};
-	dst = {
-		_encoder_aac->get_nb_samples(),
-		(int64_t)ffmpeg_get_default_channel_layout(A_SAMPLE_CHANNEL),
-		A_SAMPLE_CHANNEL,
-		AV_SAMPLE_FMT_FLTP,
-		A_SAMPLE_RATE
-	};
-
-	_resample_pcm = new am::resample_pcm();
-	_resample_pcm->init(&src, &dst, &_resample_size);
-	_resample_buffer = new uint8_t[_resample_size];
-
-	_sample_size = av_samples_get_buffer_size(NULL, A_SAMPLE_CHANNEL, _encoder_aac->get_nb_samples(), _recorder_audio->get_fmt(), 1);
-	_sample_buffer = new uint8_t[_sample_size];
-
-	_filter_aresample = new am::filter_aresample();
-	_filter_aresample->init({
-		NULL,NULL,
-		_recorder_audio->get_time_base(),
-		_recorder_audio->get_sample_rate(),
-		_recorder_audio->get_fmt(),
-		_recorder_audio->get_channel_num(),
-		(int64_t)ffmpeg_get_default_channel_layout(_recorder_audio->get_channel_num())
-	}, {
-		NULL,NULL,
-		{ 1,AV_TIME_BASE },
-		A_SAMPLE_RATE,
-		AV_SAMPLE_FMT_FLTP,
-		A_SAMPLE_CHANNEL,
-		(int64_t)ffmpeg_get_default_channel_layout(A_SAMPLE_CHANNEL)
-	},0);
-	_filter_aresample->registe_cb(on_aresample_data, on_aresample_error);
-
-
-	_filter_aresample->start();
-	_encoder_aac->start();
-	_recorder_audio->start();
-
-	getchar();
-
-	_recorder_audio->stop();
-	_filter_aresample->stop();
-
-	delete _recorder_audio;
-	delete _encoder_aac;
-	delete _resample_pcm;
-	delete _filter_aresample;
+// 	al_info("use default \r\noutput aduio device name:%s \r\noutput audio device id:%s ",
+// 		out_name.c_str(), out_id.c_str());
 
-	delete[] _sample_buffer;
-	delete[] _resample_buffer;
-}
+// 	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_speaker);
+// 	_recorder_speaker->init(am::utils_string::ascii_utf8("Default"), am::utils_string::ascii_utf8("Default"), false);
 
-void test_audio() 
-{
-	std::string input_id, input_name, out_id, out_name;
+// 	//record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_microphone);
+// 	//_recorder_microphone->init(input_name,input_id, true);
 
-	am::device_audios::get_default_input_device(input_id, input_name);
+// 	_recorder_speaker->start();
 
-	al_info("use default \r\ninput aduio device name:%s \r\ninput audio device id:%s ", 
-		input_name.c_str(), input_id.c_str());
+// 	//_recorder_microphone->start();
 
-	am::device_audios::get_default_ouput_device(out_id, out_name);
+// 	getchar();
 
-	al_info("use default \r\noutput aduio device name:%s \r\noutput audio device id:%s ", 
-		out_name.c_str(), out_id.c_str());
+// 	_recorder_speaker->stop();
+// 	//_recorder_microphone->stop();
+// }
 
-	record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_speaker);
-	_recorder_speaker->init(am::utils_string::ascii_utf8("Default"), am::utils_string::ascii_utf8("Default"), false);
+// void on_remux_progress(const char *src, int progress, int total)
+// {
+// 	al_debug("on remux progress:%s %d %d", src, progress, total);
+// }
 
+// void on_remux_state(const char *src, int state, int error) {
+// 	al_debug("on remux state:%s %d %d", src, state, error);
+// }
 
-	//record_audio_new(RECORD_AUDIO_TYPES::AT_AUDIO_WAS, &_recorder_microphone);
-	//_recorder_microphone->init(input_name,input_id, true);
+// void test_remux() {
+// #if TEST_MULTI_THREAD
+// 	for (int i = 0; i < 20; i++) {
+// 		am::REMUXER_PARAM param = { 0 };
+// 		sprintf_s(param.src, 260, "%d", i);
+// 		am::remuxer_ffmpeg::instance()->create_remux(param);
+// 	}
+// #else
+// 	am::REMUXER_PARAM param = { 0 };
 
-	_recorder_speaker->start();
+// 	sprintf_s(param.src, 260, "%s", am::utils_string::ascii_utf8("..\\..\\save.mkv").c_str());
+// 	sprintf_s(param.dst, 260, "%s", am::utils_string::ascii_utf8("..\\..\\save.mp4").c_str());
 
-	//_recorder_microphone->start();
+// 	param.cb_progress = on_remux_progress;
 
-	getchar();
+// 	param.cb_state = on_remux_state;
 
-	_recorder_speaker->stop();
-	//_recorder_microphone->stop();
-}
+// 	am::remuxer_ffmpeg::instance()->create_remux(param);
+// #endif
+// }
 
+// void test_scale() {
+// 	static const double scaled_vals[] = { 1.0,         1.25, (1.0 / 0.75), 1.5,
+// 		(1.0 / 0.6), 1.75, 2.0,          2.25,
+// 		2.5,         2.75, 3.0,          0.0 };
 
-void on_remux_progress(const char *src, int progress, int total)
-{
-	al_debug("on remux progress:%s %d %d", src, progress, total);
-}
+// 	auto get_valid_out_resolution = [](int src_width, int src_height, int * out_width, int * out_height)
+// 	{
+// 		int scale_cx = src_width;
+// 		int scale_cy = src_height;
 
-void on_remux_state(const char *src, int state, int error) {
-	al_debug("on remux state:%s %d %d", src, state, error);
-}
+// 		int i = 0;
 
-void test_remux() {
-#if TEST_MULTI_THREAD
-	for (int i = 0; i < 20; i++) {
-		am::REMUXER_PARAM param = { 0 };
-		sprintf_s(param.src, 260, "%d", i);
-		am::remuxer_ffmpeg::instance()->create_remux(param);
-	}
-#else
-	am::REMUXER_PARAM param = { 0 };
+// 		while (((scale_cx * scale_cy) > (1920 * 1080)) && scaled_vals[i] > 0.0) {
+// 			double scale = scaled_vals[i++];
+// 			scale_cx = uint32_t(double(src_width) / scale);
+// 			scale_cy = uint32_t(double(src_height) / scale);
+// 		}
 
-	sprintf_s(param.src, 260, "%s", am::utils_string::ascii_utf8("..\\..\\save.mkv").c_str());
-	sprintf_s(param.dst, 260, "%s", am::utils_string::ascii_utf8("..\\..\\save.mp4").c_str());
+// 		if (scale_cx % 2 != 0) {
+// 			scale_cx += 1;
+// 		}
 
-	param.cb_progress = on_remux_progress;
+// 		if (scale_cy % 2 != 0) {
+// 			scale_cy += 1;
+// 		}
 
-	param.cb_state = on_remux_state;
-	
-	am::remuxer_ffmpeg::instance()->create_remux(param);
-#endif
-}
+// 		*out_width = scale_cx;
+// 		*out_height = scale_cy;
 
-void test_scale() {
-	static const double scaled_vals[] = { 1.0,         1.25, (1.0 / 0.75), 1.5,
-		(1.0 / 0.6), 1.75, 2.0,          2.25,
-		2.5,         2.75, 3.0,          0.0 };
+// 		al_info("get valid output resolution from %dx%d to %dx%d,with scale:%lf", src_width, src_height, scale_cx, scale_cy, scaled_vals[i]);
+// 	};
 
-	auto get_valid_out_resolution = [](int src_width, int src_height, int * out_width, int * out_height)
-	{
-		int scale_cx = src_width;
-		int scale_cy = src_height;
+// 	int src_width=2736, src_height=1824;
+// 	int dst_width, dst_height;
 
-		int i = 0;
+// 	get_valid_out_resolution(src_width, src_height, &dst_width, &dst_height);
+// }
 
-		while (((scale_cx * scale_cy) > (1920 * 1080)) && scaled_vals[i] > 0.0) {
-			double scale = scaled_vals[i++];
-			scale_cx = uint32_t(double(src_width) / scale);
-			scale_cy = uint32_t(double(src_height) / scale);
-		}
+// int main(int argc, char **argv)
+// {
+// 	al_info("record start...");
 
-		if (scale_cx % 2 != 0) {
-			scale_cx += 1;
-		}
+// 	am::winversion_info ver = { 0 };
 
-		if (scale_cy % 2 != 0) {
-			scale_cy += 1;
-		}
+// 	am::system_version::get_win(&ver);
 
+// 	bool is_win8_or_above = am::system_version::is_win8_or_above();
 
-		*out_width = scale_cx;
-		*out_height = scale_cy;
+// 	bool is_ia32 = am::system_version::is_32();
 
-		al_info("get valid output resolution from %dx%d to %dx%d,with scale:%lf", src_width, src_height, scale_cx, scale_cy, scaled_vals[i]);
-	};
+// 	al_info("win version: %d.%d.%d.%d", ver.major, ver.minor, ver.build, ver.revis);
+// 	al_info("is win8 or above: %s", is_win8_or_above ? "true" : "false");
 
-	int src_width=2736, src_height=1824;
-	int dst_width, dst_height;
+// 	//auto hw_encoders = am::hardware_acceleration::get_supported_video_encoders();
 
-	get_valid_out_resolution(src_width, src_height, &dst_width, &dst_height);
-}
+// 	//show_devices();
 
-int main(int argc, char **argv)
-{
-	al_info("record start...");
+// 	//test_audio();
 
-	am::winversion_info ver = { 0 };
+// 	test_recorder();
 
-	am::system_version::get_win(&ver);
+// 	//test_remux();
 
-	bool is_win8_or_above = am::system_version::is_win8_or_above();
+// 	//save_aac();
 
-	bool is_ia32 = am::system_version::is_32();
+// 	//test_scale();
 
-	al_info("win version: %d.%d.%d.%d", ver.major, ver.minor, ver.build, ver.revis);
-	al_info("is win8 or above: %s", is_win8_or_above ? "true" : "false");
+// 	al_info("press any key to exit...");
+// 	system("pause");
 
-	//auto hw_encoders = am::hardware_acceleration::get_supported_video_encoders();
-
-	//show_devices();
-
-	//test_audio();
-
-	test_recorder();
-
-	//test_remux();
-
-	//save_aac();
-
-	//test_scale();
-
-
-	al_info("press any key to exit...");
-	system("pause");
-
-	return 0;
-}
+// 	return 0;
+// }

+ 6 - 13
libs/Recorder/transcode_aac.cpp

@@ -30,20 +30,13 @@
 
 #include <stdio.h>
 
-#include "libavformat/avformat.h"
-#include "libavformat/avio.h"
+extern "C" {
+#include <libavformat/avformat.h>
+#include <libavformat/avio.h>
 
-#include "libavcodec/avcodec.h"
-
-#include "libavutil/audio_fifo.h"
-#include "libavutil/avassert.h"
-#include "libavutil/avstring.h"
-#include "libavutil/frame.h"
-#include "libavutil/opt.h"
-
-#include "libswresample/swresample.h"
-
-#include "common.h"
+#include <libavutil/audio_fifo.h>
+#include <libswresample/swresample.h>
+}
 #include "headers_ffmpeg.h"
 
 /* The output bit rate in bit/s */