static void enc_process(MSFilter *f) { mblk_t *im,*om; uint64_t timems=f->ticker->time; uint32_t timestamp=timems*90; EncState *s=(EncState*)f->data; unsigned int flags = 0; vpx_codec_err_t err; YuvBuf yuv; ms_filter_lock(f); while((im=ms_queue_get(f->inputs[0]))!=NULL){ vpx_image_t img; om = NULL; flags = 0; ms_yuv_buf_init_from_mblk(&yuv, im); vpx_img_wrap(&img, VPX_IMG_FMT_I420, s->vconf.vsize.width, s->vconf.vsize.height, 1, yuv.planes[0]); if (video_starter_need_i_frame (&s->starter,f->ticker->time)){ /*sends an I frame at 2 seconds and 4 seconds after the beginning of the call*/ s->req_vfu=TRUE; } if (s->req_vfu){ flags = VPX_EFLAG_FORCE_KF; s->req_vfu=FALSE; } err = vpx_codec_encode(&s->codec, &img, s->frame_count, 1, flags, VPX_DL_REALTIME); if (err) { ms_error("vpx_codec_encode failed : %d %s (%s)\n", err, vpx_codec_err_to_string(err), vpx_codec_error_detail(&s->codec)); } else { vpx_codec_iter_t iter = NULL; const vpx_codec_cx_pkt_t *pkt; s->frame_count++; if (s->frame_count==1){ video_starter_first_frame (&s->starter,f->ticker->time); } while( (pkt = vpx_codec_get_cx_data(&s->codec, &iter)) ) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if (pkt->data.frame.sz > 0) { om = allocb(pkt->data.frame.sz,0); memcpy(om->b_wptr, pkt->data.frame.buf, pkt->data.frame.sz); om->b_wptr += pkt->data.frame.sz; #ifdef FRAGMENT_ON_PARTITIONS vp8_fragment_and_send(f, s, om, timestamp, pkt, (pkt->data.frame.partition_id == s->token_partition_count)); #else vp8_fragment_and_send(f, s, om, timestamp, pkt, 1); #endif } } } } freemsg(im); } ms_filter_unlock(f); }
static void enc_process(MSFilter *f){ EncData *d=(EncData*)f->data; uint32_t ts=f->ticker->time*90LL; mblk_t *im; MSPicture pic; MSQueue nalus; ms_queue_init(&nalus); while((im=ms_queue_get(f->inputs[0]))!=NULL){ if (ms_yuv_buf_init_from_mblk(&pic,im)==0){ x264_picture_t xpic; x264_picture_t oxpic; x264_nal_t *xnals=NULL; int num_nals=0; memset(&xpic, 0, sizeof(xpic)); memset(&oxpic, 0, sizeof(oxpic)); /*send I frame 2 seconds and 4 seconds after the beginning */ if (video_starter_need_i_frame(&d->starter,f->ticker->time)) d->generate_keyframe=TRUE; if (d->generate_keyframe){ xpic.i_type=X264_TYPE_IDR; d->generate_keyframe=FALSE; }else xpic.i_type=X264_TYPE_AUTO; xpic.i_qpplus1=0; xpic.i_pts=d->framenum; xpic.param=NULL; xpic.img.i_csp=X264_CSP_I420; xpic.img.i_plane=3; xpic.img.i_stride[0]=pic.strides[0]; xpic.img.i_stride[1]=pic.strides[1]; xpic.img.i_stride[2]=pic.strides[2]; xpic.img.i_stride[3]=0; xpic.img.plane[0]=pic.planes[0]; xpic.img.plane[1]=pic.planes[1]; xpic.img.plane[2]=pic.planes[2]; xpic.img.plane[3]=0; if (x264_encoder_encode(d->enc,&xnals,&num_nals,&xpic,&oxpic)>=0){ x264_nals_to_msgb(xnals,num_nals,&nalus); /*if (num_nals == 0) ms_message("Delayed frames info: current=%d max=%d\n", x264_encoder_delayed_frames(d->enc), x264_encoder_maximum_delayed_frames(d->enc)); */ rfc3984_pack(d->packer,&nalus,f->outputs[0],ts); d->framenum++; if (d->framenum==0) video_starter_first_frame(&d->starter,f->ticker->time); }else{ ms_error("x264_encoder_encode() error."); } } freemsg(im); } }