houxiao
2016-12-28 31e0d0c171b4d6a7dc9b9697e69e165651d3fe93
RtspFace/PL_H264Encoder.cpp
@@ -5,8 +5,9 @@
{
   #include <libavcodec/avcodec.h>
   #include <libavutil/frame.h>
   #include <libavformat/avformat.h>
   #include <libavutil/imgutils.h>
   #include <libavutil/opt.h>
   #include <libavformat/avformat.h>
   
   #include <libyuv.h>
}
@@ -104,11 +105,12 @@
    in->pAVCodecContext->height = 600;//#todo from config
    in->pAVCodecContext->time_base.num=1;
    in->pAVCodecContext->time_base.den=25;
    in->pAVCodecContext->gop_size = 25;
    in->pAVCodecContext->gop_size = 2;
    in->pAVCodecContext->max_b_frames = 0;
   //in->pAVCodecContext->profile = FF_PROFILE_H264_MAIN;
    in->pAVCodecContext->pix_fmt = AV_PIX_FMT_YUV420P;
   
   //av_opt_set(c->priv_data, "preset", "superfast", 0);
   av_opt_set(in->pAVCodecContext->priv_data, "preset", "superfast", 0);
   //av_opt_set(c->priv_data, "tune", "zerolatency", 0);
   if(avcodec_open2(in->pAVCodecContext, avCodec, NULL) >= 0)
@@ -261,6 +263,17 @@
   return !(in->payError);
}
bool encodeH264(H264Encoder_Internal* in, uint8_t* buffer, timeval pts)
{
   AVFrame avFrame;
   avFrame.width = 1920;//#todo
   avFrame.height = 1080;
   avFrame.data[0] = buffer;
   avFrame.data[1] = buffer + 1920*1080;
   avFrame.data[2] = buffer + 1920*1080 + 1920*1080/4;
   return encodeH264(in, &avFrame, pts);
}
bool PL_H264Encoder::pay(const PipeMaterial& pm)
{
   H264Encoder_Internal* in = (H264Encoder_Internal*)internal;
@@ -289,13 +302,20 @@
      return false;
   
   MB_Frame* frame = (MB_Frame*)pm.buffer;
   if (frame->type != MB_Frame::MBFT_PTR_AVFRAME)
   bool ret;
   if (frame->type == MB_Frame::MBFT_PTR_AVFRAME)
      ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts);
   else if (frame->type == MB_Frame::MBFT_YUV420)
      ret = encodeH264(in, (uint8_t*)(frame->buffer), frame->pts);
   else
   {
      printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME\n");
      printf("PL_H264Encoder::pay only support MBFT_PTR_AVFRAME / MBFT_YUV420\n");
      in->payError = true;
      return false;
   }
   bool ret = encodeH264(in, (AVFrame*)(frame->buffer), frame->pts);
   in->payError = !ret;
   
   if (ret)