mirror of
https://github.com/openharmony/applications_sample_camera.git
synced 2026-07-20 13:44:37 -04:00
add audio capture service
Signed-off-by: starfish002 <shaoyuan.zhang@huawei.com>
This commit is contained in:
@@ -29,6 +29,24 @@ executable("camera_sample") {
|
||||
output_dir = "$root_out_dir/dev_tools"
|
||||
}
|
||||
|
||||
executable("audio_capture_sample") {
|
||||
sources = [ "audio_capture_sample.cpp" ]
|
||||
cflags = [ "-Wall" ]
|
||||
cflags_cc = cflags
|
||||
|
||||
include_dirs = [ "//foundation/multimedia/audio_lite/interfaces/kits" ]
|
||||
include_dirs += [ "//foundation/multimedia/utils/lite/interfaces/kits" ]
|
||||
|
||||
ldflags = [ "-lstdc++" ]
|
||||
ldflags += [ "-lpthread" ]
|
||||
ldflags += [ "-Wl,-rpath-link=$ohos_root_path/$root_out_dir" ]
|
||||
deps = [
|
||||
"//foundation/multimedia/audio_lite/frameworks:audio_capturer_lite",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
output_dir = "$root_out_dir/dev_tools"
|
||||
}
|
||||
|
||||
executable("player_sample") {
|
||||
sources = [ "player_sample.cpp" ]
|
||||
cflags = [ "-Wall" ]
|
||||
@@ -48,5 +66,6 @@ lite_component("media_sample") {
|
||||
features = [
|
||||
":camera_sample",
|
||||
":player_sample",
|
||||
":audio_capture_sample",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include "audio_capturer.h"
|
||||
#include "media_errors.h"
|
||||
#include "securec.h"
|
||||
@@ -93,6 +94,7 @@ static char *GernerateFileName(AudioCodecFormat format)
|
||||
|
||||
static void AudioInputSourceProcess(AudioSourceInput *audioSourceInput)
|
||||
{
|
||||
const int32_t waitTimeUs = 20000;
|
||||
std::cout << "audioSourceInput: " << audioSourceInput << std::endl;
|
||||
if (audioSourceInput == nullptr) {
|
||||
return;
|
||||
@@ -114,8 +116,9 @@ static void AudioInputSourceProcess(AudioSourceInput *audioSourceInput)
|
||||
while (audioSourceInput->bThreadRun) {
|
||||
int ret = audioSourceInput->audioCap->Read(audioSourceInput->buffer,
|
||||
audioSourceInput->framesize, false);
|
||||
if (ret == -1) {
|
||||
if (ret <= 0) {
|
||||
std::cout << "audioCap Read failed ret:" << ret << std::endl;
|
||||
usleep(waitTimeUs);
|
||||
continue;
|
||||
}
|
||||
if (fwrite(audioSourceInput->buffer, 1, ret, pfd) != ret) {
|
||||
|
||||
Reference in New Issue
Block a user