当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryPool::allocateVideoFrames方法代码示例

本文整理汇总了C++中MemoryPool::allocateVideoFrames方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryPool::allocateVideoFrames方法的具体用法?C++ MemoryPool::allocateVideoFrames怎么用?C++ MemoryPool::allocateVideoFrames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryPool的用法示例。


在下文中一共展示了MemoryPool::allocateVideoFrames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {

  std::string settings_file = rx_get_exe_path() +"connection_test.xml";
  if(!vs.loadSettings(settings_file)) {
    STREAMER_ERROR("error: cannot find the connection_test.xml file: %s.", settings_file.c_str());
    ::exit(EXIT_FAILURE);
  }

#if MIC_IN

  AudioSettings audio_settings;
  audio_settings.samplerate = AV_AUDIO_SAMPLERATE_44100;
  audio_settings.mode = AV_AUDIO_MODE_STEREO;
  audio_settings.bitsize = AV_AUDIO_BITSIZE_S16;
  audio_settings.quality = 6;
  audio_settings.bitrate = 64;
  audio_settings.in_bitsize = AV_AUDIO_BITSIZE_S16;
  audio_settings.in_interleaved = true;

  PAudio paudio;
  paudio.listDevices();
  if(!paudio.openInputStream(paudio.getDefaultInputDevice(), 2, paInt16, 44100, 512)) {
    STREAMER_ERROR("error: cannot set port audio.");
    ::exit(EXIT_FAILURE);
  }
  STREAMER_VERBOSE("Using input audio device: %d.", paudio.getDefaultInputDevice());

  paudio.setCallback(on_audio_in, NULL);

  vs.setAudioSettings(audio_settings);

  //std::string output_file = rx_get_exe_path() +"test.flv";
  //vs.setOutputFile(output_file);
#endif


  if(!tp.setup(vs.getVideoWidth(), vs.getVideoHeight(), vs.getFrameRate(), vs.getSampleRate())) {
    STREAMER_ERROR("error: cannot setup the test pattern.");
    ::exit(EXIT_FAILURE);
  }

  STREAMER_VERBOSE("Loaded streamer with: %d x %d @ %d, samplerate: %d.", vs.getVideoWidth(), vs.getVideoHeight(), vs.getFrameRate(), vs.getSampleRate());
  
  mempool.allocateVideoFrames(10, tp.getNumVideoBytes());
  mempool.allocateAudioFrames(512, tp.getNumAudioBytes());

  signal(SIGINT, sighandler);

  if(!vs.setup()) {
    ::exit(EXIT_FAILURE);
  }

  if(!vs.start()) {
    ::exit(EXIT_FAILURE);
  }

#if MIC_IN
  paudio.start();
#endif

  tp.start();

  int nbytes_video = vs.getVideoWidth() * vs.getVideoHeight() + (2 * (vs.getVideoWidth() * 0.5) * (vs.getVideoHeight() * 0.5));

  must_run = true;

  while(must_run) {

    tp.update();

    if(tp.hasVideoFrame()) {
      AVPacket* vid_pkt = mempool.getFreeVideoPacket(); // packet is owned by memory pool and released by 
      if(vid_pkt) {
        tp.generateVideoFrame(vid_pkt->data, vid_pkt->planes, vid_pkt->strides);
        vid_pkt->makeVideoPacket();
        vid_pkt->setTimeStamp(tp.getTimeStamp());
        vs.addVideo(vid_pkt);
      }
    }
    
#if MIC_IN == 0 && USE_AUDIO == 1
    if(tp.hasAudioFrame()) {
      AVPacket* au_pkt = mempool.getFreeAudioPacket();
      if(au_pkt) {
        tp.generateAudioFrame(au_pkt->data);
        au_pkt->setTimeStamp(tp.getTimeStamp());
        vs.addAudio(au_pkt);
      }
      else {
        STREAMER_ERROR("error: cannot get new audio frame.");
      }
    }
#endif
  }



#if MIC_IN
  paudio.stop();
#endif
//.........这里部分代码省略.........
开发者ID:AlexSnet,项目名称:video_streamer,代码行数:101,代码来源:main.cpp


注:本文中的MemoryPool::allocateVideoFrames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。