|
// typedef struct _BVCSP_VideoCodec
// {
// SAVCodec_ID codec; // 编码方式 SAVCODEC_ID_H264、SAVCODEC_ID_H265
// int iWidth; // 视频图像宽度。单位像素
// int iHeight; // 视频图像高度。单位像素
// char* pExtraData; //sps/pps/vps等打包的h264/h265帧数据(含0x00000001头)
// int iExtraDataSize; // pExtraData数据长度
// } BVCSP_VideoCodec;
static void* writeVideoData(void* arg) {
getMGBvcsp()->dialog_param->szMyselfVideo.codec=SAVCODEC_ID_H265;
getMGBvcsp()->dialog_param->szMyselfVideo.iWidth=1280;
getMGBvcsp()->dialog_param->szMyselfVideo.iHeight=720;
int currentSize =0;
while(getMGBvcsp()->isOpenSession){
if(currentSize!=getMGBvcsp()->videoSize){
getMGBvcsp()->dialog_param->szMyselfVideo.pExtraData = reinterpret_cast<char*>(getMGBvcsp()->videoData);
getMGBvcsp()->dialog_param->szMyselfVideo.iExtraDataSize = getMGBvcsp()->videoSize;
BVCSP_Packet packet;
memset(&packet, 0, sizeof(packet));
packet.iDataType = BVCSP_DATA_TYPE_VIDEO;
packet.iDataSize = getMGBvcsp()->videoSize;
packet.bKeyFrame = 1;
packet.pData = getMGBvcsp()->videoData;
BVCU_Result result = BVCSP_Dialog_Write(getMGBvcsp()->bvhDialog, &packet);
LOGD("BVCSP_Dialog_Write writeVideoData,BVCU_Result=%d ,videoSize=%d", result,getMGBvcsp()->videoSize);
currentSize=getMGBvcsp()->videoSize;
}
usleep(10);
}
pthread_exit (NULL);
if (getMGBvcsp()->thr[0] != 0) {
pthread_join(getMGBvcsp()->thr[0], NULL);
}
}
// typedef struct _BVCSP_AudioCodec
// {
// SAVCodec_ID codec; // 编码方式 SAVCODEC_ID_G726、SAVCODEC_ID_AAC
// int iBitrate; // 波特率 32000、16000
// int iChannelCount; // 声道数 1
// int iSampleRate; // 采样率 8000
// SAV_SampleFormat eSampleFormat; // 采样精度 SAV_SAMPLE_FMT_S16
// char* pExtraData; // config字段解出的二进制数据(AAC音频编码时config有意义)。
// int iExtraDataSize; // pExtraData数据长度
// } BVCSP_AudioCodec;
static void* writeAudioData(void* arg) {
getMGBvcsp()->dialog_param->szMyselfAudio.codec = SAVCODEC_ID_AAC;
getMGBvcsp()->dialog_param->szMyselfAudio.iBitrate = 16000;
getMGBvcsp()->dialog_param->szMyselfAudio.iChannelCount = 2;
getMGBvcsp()->dialog_param->szMyselfAudio.iSampleRate = 16000;
getMGBvcsp()->dialog_param->szMyselfAudio.eSampleFormat =
SAV_SAMPLE_FMT_S16;
int currentSize = 0;
while (getMGBvcsp()->isOpenSession) {
if (currentSize != getMGBvcsp()->audioSize) {
getMGBvcsp()->dialog_param->szMyselfAudio.pExtraData =
reinterpret_cast<char*>(getMGBvcsp()->audioData);
getMGBvcsp()->dialog_param->szMyselfAudio.iExtraDataSize =
getMGBvcsp()->audioSize;
BVCSP_Packet packet;
memset(&packet, 0, sizeof(packet));
packet.iDataType = BVCSP_DATA_TYPE_AUDIO;
packet.iDataSize = getMGBvcsp()->audioSize;
packet.bKeyFrame = 1;
packet.pData = getMGBvcsp()->audioData;
BVCU_Result result = BVCSP_Dialog_Write(getMGBvcsp()->bvhDialog, &packet);
LOGD("BVCSP_Dialog_Write writeAudioData,BVCU_Result=%d,audioSize=%d", result,getMGBvcsp()->audioSize);
currentSize=getMGBvcsp()->audioSize;
}
usleep(100);
}
pthread_exit (NULL);
if (getMGBvcsp()->thr[2] != 0) {
pthread_join(getMGBvcsp()->thr[2], NULL);
}
}
上面是我写了两个线程,分别处理音频和视频,视频写入通道一直不成功(-65521),当pc端只传音频时,
音频写入通道成功,在pc端听到的声音是杂音。 |
|