int ret = 0;
char* deviceName = ":0";
AVFormatContext *ps = NULL;
char errors [1024];
//注册设备
avdevice_register_all();
//设置格式
AVInputFormat *iformat = av_find_input_format("avfoundation");
//打开设备
ret = avformat_open_input(&ps, deviceName, iformat, NULL);
//小于0表示打开失败
if(ret <0){
//打开失败
av_strerror(ret, errors, 1024);
printf("Faild to open audio devices ,%d%s\n",ret,errors);
}
av_log(NULL, AV_LOG_DEBUG, "open audio ret is %d\n",ret);
//读取数据
AVPacket pkt;
av_init_packet(&pkt);
int count = 0;
ret = av_read_frame(ps, &pkt);
if(ret != 0){
av_strerror(ret, errors, 1024);
printf("Faild to read audio data ,%d %s\n",ret,errors);
}else{
printf("pack size is %d",pkt.size);
}