[*] 音频采集
This commit is contained in:
@@ -61,6 +61,7 @@ target_link_libraries(
|
|||||||
libhilog_ndk.z.so
|
libhilog_ndk.z.so
|
||||||
# 媒体
|
# 媒体
|
||||||
libohaudio.so
|
libohaudio.so
|
||||||
|
libohcamera.so
|
||||||
libnative_media_aenc.so
|
libnative_media_aenc.so
|
||||||
libnative_media_venc.so
|
libnative_media_venc.so
|
||||||
libnative_media_core.so
|
libnative_media_core.so
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
*
|
*
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/audio-encoding.md
|
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/audio-encoding.md
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/video-encoding.md
|
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/video-encoding.md
|
||||||
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/media/avscreen-capture.md
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/obtain-supported-codecs.md
|
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/obtain-supported-codecs.md
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/using-ohaudio-for-recording.md
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/camera/native-camera-recording.md
|
||||||
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/audio/using-ohaudio-for-recording.md
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/reference/native-lib/third_party_opengl/opengles.md
|
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/reference/native-lib/third_party_opengl/opengles.md
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/reference/native-lib/third_party_opensles/opensles.md
|
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/reference/native-lib/third_party_opensles/opensles.md
|
||||||
*/
|
*/
|
||||||
@@ -16,6 +18,9 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "ohcamera/camera.h"
|
||||||
|
#include "ohcamera/video_output.h"
|
||||||
|
|
||||||
#include "api/media_stream_track.h"
|
#include "api/media_stream_track.h"
|
||||||
|
|
||||||
#include <ohaudio/native_audiocapturer.h>
|
#include <ohaudio/native_audiocapturer.h>
|
||||||
@@ -57,7 +62,6 @@ public:
|
|||||||
// 音频采集器
|
// 音频采集器
|
||||||
OH_AudioCapturer* audioCapturer = nullptr;
|
OH_AudioCapturer* audioCapturer = nullptr;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioCapturer();
|
AudioCapturer();
|
||||||
virtual ~AudioCapturer();
|
virtual ~AudioCapturer();
|
||||||
@@ -73,6 +77,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
class VideoCapturer: public Capturer<rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>> {
|
class VideoCapturer: public Capturer<rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Camera_Device* camera_Device;
|
||||||
|
Camera_Manager* camera_Manager;
|
||||||
|
Camera_VideoOutput* camera_VideoOutput;
|
||||||
|
Camera_VideoProfile* camera_VideoProfile;
|
||||||
|
Camera_OutputCapability* camera_OutputCapability;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoCapturer();
|
VideoCapturer();
|
||||||
virtual ~VideoCapturer();
|
virtual ~VideoCapturer();
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* 播放器
|
* 播放器
|
||||||
*
|
*
|
||||||
* https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/media/using-ohaudio-for-playback.md
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/media/video-playback.md
|
||||||
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/audio/audio-playback-overview.md
|
||||||
|
* https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/media/media/using-ndk-avplayer-for-playerback.md
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TAOYAO_PALYER_H
|
#ifndef TAOYAO_PALYER_H
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
|
|
||||||
#include <ohaudio/native_audiocapturer.h>
|
|
||||||
#include <ohaudio/native_audiostreambuilder.h>
|
|
||||||
|
|
||||||
// 采样率
|
// 采样率
|
||||||
static int32_t samplingRate = 48000;
|
static int32_t samplingRate = 48000;
|
||||||
// 声道数
|
// 声道数
|
||||||
@@ -16,8 +13,8 @@ static OH_AudioStream_LatencyMode latencyMode = OH_AudioStream_LatencyMode::AU
|
|||||||
// 音频格式
|
// 音频格式
|
||||||
static OH_AudioStream_SampleFormat sampleFormat = OH_AudioStream_SampleFormat::AUDIOSTREAM_SAMPLE_S16LE;
|
static OH_AudioStream_SampleFormat sampleFormat = OH_AudioStream_SampleFormat::AUDIOSTREAM_SAMPLE_S16LE;
|
||||||
|
|
||||||
static int32_t OnReadData(OH_AudioCapturer* capturer, void* userData, void* buffer, int32_t length);
|
|
||||||
static int32_t OnError(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error);
|
static int32_t OnError(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error);
|
||||||
|
static int32_t OnReadData(OH_AudioCapturer* capturer, void* userData, void* buffer, int32_t length);
|
||||||
static int32_t OnStreamEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Event event);
|
static int32_t OnStreamEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Event event);
|
||||||
static int32_t OnInterruptEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint);
|
static int32_t OnInterruptEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint);
|
||||||
|
|
||||||
@@ -42,8 +39,8 @@ bool acgist::AudioCapturer::start() {
|
|||||||
OH_LOG_DEBUG(LOG_APP, "配置音频格式:%d %d %o %o", samplingRate, channelCount, latencyMode, sampleFormat);
|
OH_LOG_DEBUG(LOG_APP, "配置音频格式:%d %d %o %o", samplingRate, channelCount, latencyMode, sampleFormat);
|
||||||
// 设置回调函数
|
// 设置回调函数
|
||||||
OH_AudioCapturer_Callbacks callbacks;
|
OH_AudioCapturer_Callbacks callbacks;
|
||||||
callbacks.OH_AudioCapturer_OnReadData = OnReadData;
|
|
||||||
callbacks.OH_AudioCapturer_OnError = OnError;
|
callbacks.OH_AudioCapturer_OnError = OnError;
|
||||||
|
callbacks.OH_AudioCapturer_OnReadData = OnReadData;
|
||||||
callbacks.OH_AudioCapturer_OnStreamEvent = OnStreamEvent;
|
callbacks.OH_AudioCapturer_OnStreamEvent = OnStreamEvent;
|
||||||
callbacks.OH_AudioCapturer_OnInterruptEvent = OnInterruptEvent;
|
callbacks.OH_AudioCapturer_OnInterruptEvent = OnInterruptEvent;
|
||||||
OH_AudioStream_Result ret = OH_AudioStreamBuilder_SetCapturerCallback(builder, callbacks, this);
|
OH_AudioStream_Result ret = OH_AudioStreamBuilder_SetCapturerCallback(builder, callbacks, this);
|
||||||
@@ -54,6 +51,7 @@ bool acgist::AudioCapturer::start() {
|
|||||||
// 开始录制
|
// 开始录制
|
||||||
ret = OH_AudioCapturer_Start(audioCapturer);
|
ret = OH_AudioCapturer_Start(audioCapturer);
|
||||||
OH_LOG_DEBUG(LOG_APP, "开始录制:%o", ret);
|
OH_LOG_DEBUG(LOG_APP, "开始录制:%o", ret);
|
||||||
|
return ret == OH_AudioStream_Result::AUDIOSTREAM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool acgist::AudioCapturer::stop() {
|
bool acgist::AudioCapturer::stop() {
|
||||||
@@ -64,6 +62,12 @@ bool acgist::AudioCapturer::stop() {
|
|||||||
ret = OH_AudioCapturer_Release(audioCapturer);
|
ret = OH_AudioCapturer_Release(audioCapturer);
|
||||||
audioCapturer = nullptr;
|
audioCapturer = nullptr;
|
||||||
OH_LOG_DEBUG(LOG_APP, "释放音频采集器:%o", ret);
|
OH_LOG_DEBUG(LOG_APP, "释放音频采集器:%o", ret);
|
||||||
|
return ret == OH_AudioStream_Result::AUDIOSTREAM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t OnError(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error) {
|
||||||
|
OH_LOG_ERROR(LOG_APP, "音频采集发生异常:%o", error);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t OnReadData(OH_AudioCapturer* capturer, void* userData, void* buffer, int32_t length) {
|
static int32_t OnReadData(OH_AudioCapturer* capturer, void* userData, void* buffer, int32_t length) {
|
||||||
@@ -76,16 +80,15 @@ static int32_t OnReadData(OH_AudioCapturer* capturer, void* userData, void* buff
|
|||||||
) {
|
) {
|
||||||
iterator->second->OnData(buffer, 16, samplingRate, channelCount, sizeof(buffer) / 2, timeMillis);
|
iterator->second->OnData(buffer, 16, samplingRate, channelCount, sizeof(buffer) / 2, timeMillis);
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
static int32_t OnError(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Result error) {
|
|
||||||
OH_LOG_ERROR(LOG_APP, "音频采集发生异常:%o", error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t OnStreamEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Event event) {
|
static int32_t OnStreamEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioStream_Event event) {
|
||||||
OH_LOG_DEBUG(LOG_APP, "音频采集事件:%o", event);
|
OH_LOG_DEBUG(LOG_APP, "音频采集事件:%o", event);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t OnInterruptEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint) {
|
static int32_t OnInterruptEvent(OH_AudioCapturer* capturer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint) {
|
||||||
OH_LOG_DEBUG(LOG_APP, "音频采集打断:%o %o", type, hint);
|
OH_LOG_DEBUG(LOG_APP, "音频采集打断:%o %o", type, hint);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "../include/Capturer.hpp"
|
||||||
|
|
||||||
|
#include "hilog/log.h"
|
||||||
|
#include "ohcamera/camera_input.h"
|
||||||
|
#include "ohcamera/camera_manager.h"
|
||||||
|
#include "ohcamera/capture_session.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,18 +36,42 @@
|
|||||||
"requestPermissions": [
|
"requestPermissions": [
|
||||||
{
|
{
|
||||||
"name": "ohos.permission.CAMERA",
|
"name": "ohos.permission.CAMERA",
|
||||||
|
"reason": "视频",
|
||||||
"usedScene": {
|
"usedScene": {
|
||||||
"when": "always"
|
"when": "always"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ohos.permission.INTERNET",
|
"name": "ohos.permission.INTERNET",
|
||||||
|
"reason": "网络",
|
||||||
"usedScene": {
|
"usedScene": {
|
||||||
"when": "always"
|
"when": "always"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ohos.permission.MICROPHONE",
|
"name": "ohos.permission.MICROPHONE",
|
||||||
|
"reason": "音频",
|
||||||
|
"usedScene": {
|
||||||
|
"when": "always"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.READ_MEDIA",
|
||||||
|
"reason": "录制文件",
|
||||||
|
"usedScene": {
|
||||||
|
"when": "always"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.WRITE_MEDIA",
|
||||||
|
"reason": "录制文件",
|
||||||
|
"usedScene": {
|
||||||
|
"when": "always"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohos.permission.MEDIA_LOCATION",
|
||||||
|
"reason": "地理位置",
|
||||||
"usedScene": {
|
"usedScene": {
|
||||||
"when": "always"
|
"when": "always"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user