|
发表于 2022-1-12 09:14:42
只看该作者
板凳
好吧,
另外问一下
1.rkmedia能不能调用麦克风设备,我试了一下音频功能,好像只能从传输声卡发出的声音
2.另外rk 里带librtsp那个库的接口怎么用,视频推流可以,音频推流模仿的视频推流的写法,好像没效果
代码:
void video_packet_cb(MEDIA_BUFFER mb) {
static RK_S32 packet_cnt = 0;
// printf("#Get packet-%d, size %zu\n", packet_cnt, RK_MPI_MB_GetSize(mb));
if (g_rtsplive && g_rtsp_session) {
rtsp_tx_video(g_rtsp_session, RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetSize(mb),
RK_MPI_MB_GetTimestamp(mb));
rtsp_do_event(g_rtsplive);
}
RK_MPI_MB_ReleaseBuffer(mb);
packet_cnt++;
}
static void audio_packet_cb(MEDIA_BUFFER mb) {
static RK_S32 packet_cnt = 0;
// printf("#Get packet-%d, size %zu\n", packet_cnt, RK_MPI_MB_GetSize(mb));
if (g_rtsplive && g_rtsp_session) {
rtsp_tx_audio(g_rtsp_session, RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetSize(mb),
RK_MPI_MB_GetTimestamp(mb));
rtsp_do_event(g_rtsplive);
}
RK_MPI_MB_ReleaseBuffer(mb);
packet_cnt++;
}
g_rtsplive = create_rtsp_demo(554);
g_rtsp_session = rtsp_new_session(g_rtsplive, "/live/main_stream");
rtsp_set_video(g_rtsp_session, RTSP_CODEC_ID_VIDEO_H264, NULL, 0);
rtsp_set_audio(g_rtsp_session, RTSP_CODEC_ID_AUDIO_AAC, NULL, 0);
rtsp_sync_video_ts(g_rtsp_session, rtsp_get_reltime(), rtsp_get_ntptime());
rtsp_sync_audio_ts(g_rtsp_session, rtsp_get_reltime(), rtsp_get_ntptime());
// MPP_CHN_S stEncChn;
stEncChn.enModId = RK_ID_VENC;
stEncChn.s32DevId = 0;
stEncChn.s32ChnId = 0;
ret = RK_MPI_SYS_RegisterOutCb(&stEncChn, video_packet_cb);
if (ret) {
printf("ERROR: register output callback for VENC[0] error! ret=%d\n", ret);
}
stSrcChn.enModId = RK_ID_RGA;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = 2;
stDestChn.enModId = RK_ID_VENC;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 0;
ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (ret) {
printf("ERROR: Bind VI[0] and VENC[0] error! ret=%d\n", ret);
}
//audio
fp = fopen("/data/work/out.mp2", "w+");
// RK_MPI_SYS_Init();
// MPP_CHN_S mpp_chn_ai, mpp_chn_aenc;
mpp_chn_ai.enModId = RK_ID_AI;
mpp_chn_ai.s32ChnId = 0;
mpp_chn_aenc.enModId = RK_ID_AENC;
mpp_chn_aenc.s32ChnId = 0;
// AI_CHN_ATTR_S ai_attr;
ai_attr.pcAudioNode = ALSA_PATH;
ai_attr.enSampleFormat = RK_SAMPLE_FMT_S16;
ai_attr.u32NbSamples = 1024;
ai_attr.u32SampleRate = 16000;
ai_attr.u32Channels = 2;
ai_attr.enAiLayout = AI_LAYOUT_NORMAL; // chanel layout: [ref:mic]; remove
// ref, output mic mono
// AENC_CHN_ATTR_S aenc_attr;
aenc_attr.enCodecType = RK_CODEC_TYPE_MP2;
aenc_attr.u32Bitrate = 64000;
aenc_attr.u32Quality = 1;
aenc_attr.stAencMP2.u32Channels = 1;
aenc_attr.stAencMP2.u32SampleRate = 16000;
// 1. create AI
RK_MPI_AI_SetChnAttr(mpp_chn_ai.s32ChnId, &ai_attr);
RK_MPI_AI_EnableChn(mpp_chn_ai.s32ChnId);
// 2. create AENC
RK_MPI_AENC_CreateChn(mpp_chn_aenc.s32ChnId, &aenc_attr);
RK_U32 ret = RK_MPI_SYS_RegisterOutCb(&mpp_chn_aenc, audio_packet_cb);
printf("ret = %d.\n", ret);
// 3. bind AI-AENC
RK_MPI_SYS_Bind(&mpp_chn_ai, &mpp_chn_aenc);
帮忙看一下哪里错了~ |
|