mirror of
https://github.com/gtxaspec/wz_mini_hacks.git
synced 2025-08-09 20:14:04 +00:00
fix rtsp audio for channel 1
This commit is contained in:
@@ -19,6 +19,9 @@ static uint32_t (*real_local_sdk_audio_set_pcm_frame_callback)(int ch, void *cal
|
||||
static void *audio_pcm_cb = NULL;
|
||||
static int AudioCaptureEnable = 0;
|
||||
|
||||
static void *audio_pcm_cb1 = NULL;
|
||||
static int AudioCaptureEnable1 = 0;
|
||||
|
||||
char *AudioCapture(int fd, char *tokenPtr) {
|
||||
|
||||
char *p = strtok_r(NULL, " \t\r\n", &tokenPtr);
|
||||
@@ -28,14 +31,25 @@ char *AudioCapture(int fd, char *tokenPtr) {
|
||||
fprintf(stderr, "[command] audio capute on\n", p);
|
||||
return "ok";
|
||||
}
|
||||
if(!strcmp(p, "on1")) {
|
||||
AudioCaptureEnable1 = 1;
|
||||
fprintf(stderr, "[command] audio capute on\n", p);
|
||||
return "ok";
|
||||
}
|
||||
if(!strcmp(p, "off")) {
|
||||
AudioCaptureEnable = 0;
|
||||
fprintf(stderr, "[command] audio capute off\n", p);
|
||||
return "ok";
|
||||
}
|
||||
if(!strcmp(p, "off1")) {
|
||||
AudioCaptureEnable1 = 0;
|
||||
fprintf(stderr, "[command] audio capute off\n", p);
|
||||
return "ok";
|
||||
}
|
||||
return "error";
|
||||
}
|
||||
|
||||
//channel 0
|
||||
static uint32_t audio_pcm_capture(struct frames_st *frames) {
|
||||
|
||||
static struct pcm *pcm = NULL;
|
||||
@@ -60,10 +74,10 @@ static uint32_t audio_pcm_capture(struct frames_st *frames) {
|
||||
};
|
||||
pcm = pcm_open(card, device, flags, &config);
|
||||
if(pcm == NULL) {
|
||||
fprintf(stderr, "failed to allocate memory for PCM\n");
|
||||
fprintf(stderr, "failed to allocate memory for PCM CH0\n");
|
||||
} else if(!pcm_is_ready(pcm)) {
|
||||
pcm_close(pcm);
|
||||
fprintf(stderr, "failed to open PCM\n");
|
||||
fprintf(stderr, "failed to open PCM CH0\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,16 +91,68 @@ static uint32_t audio_pcm_capture(struct frames_st *frames) {
|
||||
return ((framecb)audio_pcm_cb)(frames);
|
||||
}
|
||||
|
||||
//channel1
|
||||
static uint32_t audio_pcm_capture1(struct frames_st *frames) {
|
||||
|
||||
static struct pcm *pcm = NULL;
|
||||
static int firstEntry = 0;
|
||||
uint32_t *buf = frames->buf;
|
||||
|
||||
if(!firstEntry) {
|
||||
firstEntry++;
|
||||
unsigned int card = 0;
|
||||
unsigned int device = 0;
|
||||
int flags = PCM_OUT | PCM_MMAP;
|
||||
const struct pcm_config config = {
|
||||
.channels = 1,
|
||||
.rate = 8000,
|
||||
.format = PCM_FORMAT_S16_LE,
|
||||
.period_size = 128,
|
||||
.period_count = 8,
|
||||
.start_threshold = 320,
|
||||
.silence_threshold = 0,
|
||||
.silence_size = 0,
|
||||
.stop_threshold = 320 * 4
|
||||
};
|
||||
pcm = pcm_open(card, device, flags, &config);
|
||||
if(pcm == NULL) {
|
||||
fprintf(stderr, "failed to allocate memory for PCM CH1\n");
|
||||
} else if(!pcm_is_ready(pcm)) {
|
||||
pcm_close(pcm);
|
||||
fprintf(stderr, "failed to open PCM CH1\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(pcm && AudioCaptureEnable1) {
|
||||
int avail = pcm_mmap_avail(pcm);
|
||||
int delay = pcm_get_delay(pcm);
|
||||
int ready = pcm_is_ready(pcm);
|
||||
int err = pcm_writei(pcm, buf, pcm_bytes_to_frames(pcm, frames->length));
|
||||
if(err < 0) fprintf(stderr, "pcm_writei err=%d\n", err);
|
||||
}
|
||||
return ((framecb)audio_pcm_cb1)(frames);
|
||||
}
|
||||
|
||||
uint32_t local_sdk_audio_set_pcm_frame_callback(int ch, void *callback) {
|
||||
|
||||
fprintf(stderr, "local_sdk_audio_set_pcm_frame_callback streamChId=%d, callback=0x%x\n", ch, callback);
|
||||
|
||||
static int ch_count = 0;
|
||||
|
||||
if( (ch == 0) && ch_count == 0) {
|
||||
audio_pcm_cb = callback;
|
||||
fprintf(stderr,"enc func injection save audio_pcm_cb=0x%x\n", audio_pcm_cb);
|
||||
fprintf(stderr,"enc func injection CH0 save audio_pcm_cb=0x%x\n", audio_pcm_cb);
|
||||
callback = audio_pcm_capture;
|
||||
}
|
||||
ch_count=ch_count+1
|
||||
|
||||
if( (ch == 1) && ch_count == 1) {
|
||||
audio_pcm_cb1 = callback;
|
||||
fprintf(stderr,"enc func injection CH1 save audio_pcm_cb=0x%x\n", audio_pcm_cb1);
|
||||
callback = audio_pcm_capture1;
|
||||
}
|
||||
|
||||
ch_count=ch_count+1;
|
||||
|
||||
return real_local_sdk_audio_set_pcm_frame_callback(ch, callback);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user