亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? audio_oss_source.cpp

?? MPEG4音頻視頻壓縮編碼(含G.711/ACC/H.261等)
?? CPP
字號:
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ *  * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. *  * The Original Code is MPEG4IP. *  * The Initial Developer of the Original Code is Cisco Systems Inc. * Portions created by Cisco Systems Inc. are * Copyright (C) Cisco Systems Inc. 2000-2002.  All Rights Reserved. *  * Contributor(s):  *		Dave Mackie		dmackie@cisco.com *		Bill May 		wmay@cisco.com */#include "mp4live.h"#include "audio_oss_source.h"#include "audio_encoder.h"//#define DEBUG_TIMESTAMPS 1COSSAudioSource::COSSAudioSource(CLiveConfig *pConfig) : CMediaSource() {  SetConfig(pConfig);  m_audioDevice = -1;  m_prevTimestamp = 0;  m_timestampOverflowArray = NULL;  m_timestampOverflowArrayIndex = 0;  m_audioOssMaxBufferSize = 0;  // NOTE: This used to be CAVMediaFlow::SetAudioInput();  // if mixer is specified, then user takes responsibility for  // configuring mixer to set the appropriate input sources  // this allows multiple inputs to be used, for example  if (!strcasecmp(m_pConfig->GetStringValue(CONFIG_AUDIO_INPUT_NAME),		  "mix")) {    return;  }  // else set the mixer input source to the one specified  static char* inputNames[] = SOUND_DEVICE_NAMES;  const char* mixerName =     m_pConfig->GetStringValue(CONFIG_AUDIO_MIXER_NAME);  int mixer = open(mixerName, O_RDONLY);  if (mixer < 0) {    error_message("Couldn't open mixer %s", mixerName);    return;  }  u_int8_t i;  int recmask = 0;  for (i = 0; i < sizeof(inputNames) / sizeof(char*); i++) {    if (!strcasecmp(m_pConfig->GetStringValue(CONFIG_AUDIO_INPUT_NAME),		    inputNames[i])) {      recmask |= (1 << i);      ioctl(mixer, SOUND_MIXER_WRITE_RECSRC, &recmask);      break;    }  }  close(mixer);}int COSSAudioSource::ThreadMain(void) {  debug_message("oss start");  while (true) {    int rc;    if (m_source) {      rc = SDL_SemTryWait(m_myMsgQueueSemaphore);    } else {      rc = SDL_SemWait(m_myMsgQueueSemaphore);    }    // semaphore error    if (rc == -1) {      break;    }     // message pending    if (rc == 0) {      CMsg* pMsg = m_myMsgQueue.get_message();		      if (pMsg != NULL) {        switch (pMsg->get_value()) {        case MSG_NODE_STOP_THREAD:          DoStopCapture();	// ensure things get cleaned up          delete pMsg;	  debug_message("oss stop thread");          return 0;        case MSG_NODE_START:          DoStartCapture();          break;        case MSG_NODE_STOP:          DoStopCapture();          break;        }        delete pMsg;      }    }    if (m_source) {      try {	//debug_message("processaudio");        ProcessAudio();      }      catch (...) {	error_message("oss stop capture");        DoStopCapture();	        break;      }    }  }  debug_message("oss thread exit");  return -1;}void COSSAudioSource::DoStartCapture(){  if (m_source) {    return;  }  if (!Init()) {    return;  }  m_source = true;}void COSSAudioSource::DoStopCapture(){  if (!m_source) {    return;  }  //  CMediaSource::DoStopAudio();  close(m_audioDevice);  m_audioDevice = -1;  CHECK_AND_FREE(m_timestampOverflowArray);  m_source = false;}bool COSSAudioSource::Init(void){  bool rc = InitAudio(true);  if (!rc) {    return false;  }  if (!InitDevice()) {    return false;  }  //#error we will have to remove this below - the sample rate will be  rc = SetAudioSrc(                   PCMAUDIOFRAME,                   m_channelsConfigured,                   m_pConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE));  if (!rc) {    return false;  }  // for live capture we can match the source to the destination  //  m_audioSrcSamplesPerFrame = m_audioDstSamplesPerFrame;  // gets set   m_pcmFrameSize =     m_audioSrcSamplesPerFrame * m_audioSrcChannels * sizeof(u_int16_t);  debug_message("Audio input size is %u", m_pcmFrameSize);  if (m_audioOssMaxBufferSize > 0) {    size_t array_size;    m_audioOssMaxBufferFrames = m_audioOssMaxBufferSize / m_pcmFrameSize;    if (m_audioOssMaxBufferFrames == 0) {      m_audioOssMaxBufferFrames = 1;    }    array_size = m_audioOssMaxBufferFrames * sizeof(*m_timestampOverflowArray);    m_timestampOverflowArray = (Timestamp *)Malloc(array_size);    memset(m_timestampOverflowArray, 0, array_size);  }      // maximum number of passes in ProcessAudio, approx 1 sec.  m_maxPasses = m_audioSrcSampleRate / m_audioSrcSamplesPerFrame;  return true;#if 0 init_failure:  debug_message("audio initialization failed");  close(m_audioDevice);  m_audioDevice = -1;  return false;#endif}bool COSSAudioSource::InitDevice(void){  int rc;  const char* deviceName = m_pConfig->GetStringValue(CONFIG_AUDIO_SOURCE_NAME);  // open the audio device  m_audioDevice = open(deviceName, O_RDONLY);  if (m_audioDevice < 0) {    error_message("Failed to open %s", deviceName);    return false;  }  int enablebits;  // Disable the audio input until we can start it below  ioctl(m_audioDevice, SNDCTL_DSP_GETTRIGGER, &enablebits);  enablebits &= ~PCM_ENABLE_INPUT;  ioctl(m_audioDevice, SNDCTL_DSP_SETTRIGGER, &enablebits);#ifdef WORDS_BIGENDIAN#define OUR_FORMAT AFMT_S16_BE#else#define OUR_FORMAT AFMT_S16_LE#endif  int format = OUR_FORMAT;  rc = ioctl(m_audioDevice, SNDCTL_DSP_SETFMT, &format);  if (rc < 0 || format != OUR_FORMAT) {    error_message("Couldn't set format for %s", deviceName);    close(m_audioDevice);    return false;  }  m_channelsConfigured = m_pConfig->GetIntegerValue(CONFIG_AUDIO_CHANNELS);  rc = ioctl(m_audioDevice, SNDCTL_DSP_CHANNELS, &m_channelsConfigured);  if (rc < 0) {    error_message("Couldn't set audio channels for %s", deviceName);    close(m_audioDevice);    return false;  }  if (m_channelsConfigured != m_pConfig->GetIntegerValue(CONFIG_AUDIO_CHANNELS)) {    error_message("Channels not set to configured driver says %d - configured %d", 		  m_channelsConfigured, 		  m_pConfig->GetIntegerValue(CONFIG_AUDIO_CHANNELS));  }  u_int32_t samplingRate =     m_pConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE);  u_int32_t targetSamplingRate = samplingRate;  rc = ioctl(m_audioDevice, SNDCTL_DSP_SPEED, &samplingRate);  if (rc < 0 || abs(samplingRate - targetSamplingRate) > 1) {    error_message("Couldn't set sampling rate for %s", deviceName);    close(m_audioDevice);    return false;  }  if (m_pConfig->GetBoolValue(CONFIG_AUDIO_OSS_USE_SMALL_FRAGS)) {    // from rca.  set OSS audio fragment size to a small value.    // value is 0xMMMMSSSS where MMMM is number of buffers     // (configuration value CONFIG_AUDIO_OSS_FRAGMENTS) and SSSS is    // power of 2 sized fragment value    //     // Reason for this is OSS will block on read until a complete    // fragment is read - even if correct number of bytes is in buffers    debug_message("Using small frags");    int fragSize = m_pConfig->GetIntegerValue(CONFIG_AUDIO_OSS_FRAG_SIZE);    int bufcfg = m_pConfig->GetIntegerValue(CONFIG_AUDIO_OSS_FRAGMENTS);    bufcfg <<= 16; // shift over    bufcfg |= fragSize;    rc = ioctl(m_audioDevice, SNDCTL_DSP_SETFRAGMENT, &bufcfg);    if (rc) {      error_message("Error - could not set OSS Input fragment size %d", rc);      close(m_audioDevice);      return false;    }  }  audio_buf_info info;  rc = ioctl(m_audioDevice, SNDCTL_DSP_GETISPACE, &info);  if (rc < 0) {    error_message("Failed to query OSS GETISPACE");    error_message("This means you will not get accurate audio timestamps");    error_message("Please think about updating your audio card or driver");    m_audioOssMaxBufferSize = 0;    return true;  }  #ifdef DEBUG_TIMESTAMPS  debug_message("fragstotal = %d", info.fragstotal);  debug_message("fragsize = %d", info.fragsize);#endif  m_audioOssMaxBufferSize = info.fragstotal * info.fragsize;  debug_message("oss init done");  return true;}void COSSAudioSource::ProcessAudio(void){#ifdef SNDCTL_DSP_GETERROR  audio_errinfo errinfo;  if (m_audioSrcFrameNumber == 0) {    ioctl(m_audioDevice, SNDCTL_DSP_GETERROR, &errinfo);  } else {    ioctl(m_audioDevice, SNDCTL_DSP_GETERROR, &errinfo);    if (errinfo.rec_overruns > 0) {      debug_message("overrun error found in audio - adding "U64" samples",		    SrcBytesToSamples(errinfo.rec_ptradjust));      close(m_audioDevice);      InitDevice();      m_audioSrcSampleNumber = 0;    }  }#endif  if (m_audioSrcFrameNumber == 0) {    // Pull the trigger and start the audio input    int enablebits;    ioctl(m_audioDevice, SNDCTL_DSP_GETTRIGGER, &enablebits);    enablebits |= PCM_ENABLE_INPUT;    ioctl(m_audioDevice, SNDCTL_DSP_SETTRIGGER, &enablebits);    //debug_message("oss input enable");  }  // for efficiency, process 1 second before returning to check for commands  for (int pass = 0; pass < m_maxPasses && m_stop_thread == false; pass++) {    audio_buf_info info;    int rc = ioctl(m_audioDevice, SNDCTL_DSP_GETISPACE, &info);    Timestamp currentTime = GetTimestamp();    if (rc<0) {      error_message("Failed to query OSS GETISPACE");      info.bytes = 0;    }    //debug_message("reading %u", m_pcmFrameSize);    u_int8_t*     pcmFrameBuffer;    pcmFrameBuffer = (u_int8_t*)malloc(m_pcmFrameSize);    uint32_t bytesRead = read(m_audioDevice, pcmFrameBuffer, m_pcmFrameSize);    if (bytesRead < m_pcmFrameSize) {      debug_message("bad audio read");      free(pcmFrameBuffer);      continue;    }    //debug_message("oss read");    Timestamp timestamp;    if (info.bytes == m_audioOssMaxBufferSize) {      // means the audio buffer is full, and not capturing      // we want to make the timestamp based on the previous one      // When we hit this case, we start using the m_timestampOverflowArray      // This will give us a timestamp for when the array is full.      //       // In other words, if we have a full audio buffer (ie: it's not loading      // any more), we start storing the current timestamp into the array.      // This will let us "catch up", and have a somewhat accurate timestamp      // when we loop around      //       // wmay - I'm not convinced that this actually works - if the buffer      // cleans up, we'll ignore m_timestampOverflowArray      if (m_timestampOverflowArray != NULL && 	  m_timestampOverflowArray[m_timestampOverflowArrayIndex] != 0) {	timestamp = m_timestampOverflowArray[m_timestampOverflowArrayIndex];      } else {	timestamp = m_prevTimestamp + SrcSamplesToTicks(m_audioSrcSamplesPerFrame);      }      if (m_timestampOverflowArray != NULL)	m_timestampOverflowArray[m_timestampOverflowArrayIndex] = currentTime;      debug_message("audio buffer full !");    } else {      // buffer is not full - so, we make the timestamp based on the number      // of bytes in the buffer that we read.      timestamp = currentTime - SrcSamplesToTicks(SrcBytesToSamples(info.bytes));      if (m_timestampOverflowArray != NULL)	m_timestampOverflowArray[m_timestampOverflowArrayIndex] = 0;    }#ifdef DEBUG_TIMESTAMPS    debug_message("info.bytes=%d t="U64" timestamp="U64" delta="U64,                  info.bytes, currentTime, timestamp, timestamp - m_prevTimestamp);#endif    m_prevTimestamp = timestamp;    if (m_timestampOverflowArray != NULL) {      m_timestampOverflowArrayIndex = (m_timestampOverflowArrayIndex + 1) % 	m_audioOssMaxBufferFrames;    }#ifdef DEBUG_TIMESTAMPS    debug_message("pcm forward "U64" %u", timestamp, m_pcmFrameSize);#endif    if (m_audioSrcFrameNumber == 0 && m_videoSource != NULL) {      m_videoSource->RequestKeyFrame(timestamp);    }    m_audioSrcFrameNumber++;    CMediaFrame *frame = new CMediaFrame(PCMAUDIOFRAME,					 pcmFrameBuffer, 					 m_pcmFrameSize, 					 timestamp);    ForwardFrame(frame);  }}bool CAudioCapabilities::ProbeDevice(){  int rc;  if (allSampleRateTableSize > NUM_ELEMENTS_IN_ARRAY(m_samplingRates)) {    error_message("Number of sample rates exceeds audio cap array");    return false;  }  // open the audio device  int audioDevice = open(m_deviceName, O_RDONLY);  if (audioDevice < 0) {    return false;  }  m_canOpen = true;  // union of valid sampling rates for MP3 and AAC  // for all possible sampling rates  u_int8_t i;  for (i = 0; i < allSampleRateTableSize; i++) {    u_int32_t targetRate = allSampleRateTable[i];    u_int32_t samplingRate = targetRate;    // attempt to set sound card to this sampling rate    rc = ioctl(audioDevice, SNDCTL_DSP_SPEED, &samplingRate);    // invalid sampling rate, allow deviation of 1 sample/sec    if (rc < 0 || abs(samplingRate - targetRate) > 1) {      debug_message("audio device %s doesn't support sampling rate %u",                    m_deviceName, targetRate);      continue;    }    // valid sampling rate    m_samplingRates[m_numSamplingRates++] = targetRate;  }  // zero out remaining sampling rate entries  for (i = m_numSamplingRates; i < allSampleRateTableSize; i++) {    m_samplingRates[i] = 0;  }  close(audioDevice);  return true;}void CAudioCapabilities::Display (CLiveConfig *pConfig, 				  char *msg, 				  uint32_t max_len){  // might want to parse out CONFIG_AUDIO_INPUT_NAME a bit to make it  // more English like...  snprintf(msg, max_len,	   "%s, %s, %s, %u Hz, %s", 	   pConfig->GetStringValue(CONFIG_AUDIO_SOURCE_TYPE),	   pConfig->GetStringValue(CONFIG_AUDIO_SOURCE_NAME),	   pConfig->GetStringValue(CONFIG_AUDIO_INPUT_NAME),	   pConfig->GetIntegerValue(CONFIG_AUDIO_SAMPLE_RATE),	   pConfig->GetIntegerValue(CONFIG_AUDIO_CHANNELS) == 1 ? 	   "mono" : "stereo");}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品久久久久久久99樱桃| 日本不卡免费在线视频| 欧美在线免费播放| 99综合电影在线视频| 久久精品国产99国产| 日本欧美一区二区| 久久黄色级2电影| 色视频欧美一区二区三区| 91丝袜美腿高跟国产极品老师 | 成人午夜又粗又硬又大| 极品美女销魂一区二区三区免费| 日本系列欧美系列| 色狠狠桃花综合| 欧美在线观看视频一区二区| 国产欧美日韩综合| 国产精品欧美极品| 综合在线观看色| 一区二区不卡在线播放| 亚洲成av人片在线观看无码| 五月天中文字幕一区二区| 一本大道久久a久久精二百| 国产网红主播福利一区二区| 综合自拍亚洲综合图不卡区| 成人自拍视频在线| 欧美zozo另类异族| 国产精品免费丝袜| 成人三级伦理片| 中文字幕不卡三区| 亚洲成人动漫在线观看| 欧美日韩国产在线播放网站| 精品国产制服丝袜高跟| 亚洲免费色视频| 久草精品在线观看| 日韩亚洲欧美在线| 国产精品久久久久久久久搜平片| 日日欢夜夜爽一区| 91一区在线观看| 一区二区三区在线视频免费| 色综合色狠狠天天综合色| 亚洲综合一区二区| 国产成人午夜精品影院观看视频 | 国产91精品精华液一区二区三区| 91美女蜜桃在线| 亚洲精品免费在线播放| 国产河南妇女毛片精品久久久| 日韩美女天天操| 亚洲自拍另类综合| 91.xcao| 一区二区三区.www| 在线电影国产精品| 一区二区欧美精品| 91精品国产综合久久香蕉麻豆| 麻豆91精品91久久久的内涵| 欧美日韩成人综合在线一区二区 | 91精品国产综合久久久久久| 日本人妖一区二区| 国产三级精品三级| 在线观看欧美精品| 久久精品国产免费看久久精品| 久久久91精品国产一区二区精品| 成年人网站91| 中文字幕精品—区二区四季| 色综合久久88色综合天天| 天堂久久一区二区三区| 国产三级精品三级| 欧美精品三级在线观看| 国产成人日日夜夜| 亚洲成人在线免费| 国产精品毛片无遮挡高清| 欧美日韩国产在线播放网站| 福利视频网站一区二区三区| 香蕉久久夜色精品国产使用方法| 久久久精品影视| 国产伦精品一区二区三区免费| 在线播放/欧美激情| 国产传媒久久文化传媒| 天天综合色天天综合色h| 国产欧美日韩精品在线| 欧美精品乱码久久久久久按摩| 国产乱码精品1区2区3区| 精品粉嫩aⅴ一区二区三区四区 | 狠狠久久亚洲欧美| 亚洲精品一区二区三区精华液| 99re成人在线| 亚洲一区二区综合| 国产女人水真多18毛片18精品视频| 欧美亚洲国产一区二区三区va| 亚洲综合丝袜美腿| 国产日产精品一区| 日韩写真欧美这视频| 日本道免费精品一区二区三区| 国产一区二区三区免费播放| 日韩av不卡一区二区| 亚洲免费观看高清完整| 日本一区二区三区国色天香| 欧美成人vps| 51午夜精品国产| 欧美日韩午夜精品| 激情久久久久久久久久久久久久久久| 一区二区三区四区不卡在线 | 久久精品亚洲精品国产欧美kt∨| 欧美久久久久免费| 欧美性欧美巨大黑白大战| 99免费精品在线观看| 成人三级伦理片| 国产不卡高清在线观看视频| 国产盗摄女厕一区二区三区| 国产酒店精品激情| 国内国产精品久久| 韩国理伦片一区二区三区在线播放| 免费三级欧美电影| 蜜桃精品视频在线| 六月婷婷色综合| 激情久久五月天| 国产精品自产自拍| 丁香六月综合激情| 99麻豆久久久国产精品免费优播| 懂色av噜噜一区二区三区av| 国产91色综合久久免费分享| 成人国产精品免费观看| 不卡的av电影在线观看| 99久久777色| 欧洲国内综合视频| 欧美日韩精品福利| 欧美一级二级三级蜜桃| 精品国产乱子伦一区| 国产午夜精品在线观看| 国产精品进线69影院| 一区二区三区中文免费| 日韩中文欧美在线| 国产乱子伦视频一区二区三区 | 国模大尺度一区二区三区| 国产一区二区三区视频在线播放| 粉嫩一区二区三区在线看| 99久久精品国产导航| 欧美日韩在线免费视频| 日韩丝袜美女视频| 国产精品久久久久久久久动漫| 亚洲精品国产精品乱码不99| 日本va欧美va欧美va精品| 国产高清不卡一区| 欧美午夜理伦三级在线观看| 欧美一级黄色片| 中文字幕亚洲综合久久菠萝蜜| 久久久综合九色合综国产精品| 国产精品国产三级国产普通话蜜臀 | 日韩一区二区三区精品视频| 久久久久久毛片| 亚洲一二三四在线| 国产中文字幕一区| 成人免费av资源| 538prom精品视频线放| 日本一区二区免费在线观看视频 | 亚洲欧洲综合另类| 捆绑调教一区二区三区| 97精品超碰一区二区三区| 欧美一级专区免费大片| 欧美久久久久久蜜桃| 欧美国产日本视频| 麻豆中文一区二区| 91免费观看国产| 久久日韩精品一区二区五区| 亚洲精品一区二区三区精华液 | 欧美日韩国产一级片| 国产女主播在线一区二区| 日韩国产高清影视| 91蜜桃网址入口| 国产日韩欧美不卡| 青青草伊人久久| 欧美日韩免费一区二区三区| 国产精品乱子久久久久| 久久国产精品72免费观看| 欧美图区在线视频| 亚洲欧美另类在线| 成人综合激情网| 国产亚洲一二三区| 蜜臀av国产精品久久久久 | 欧美成人一区二区三区在线观看| 一区二区国产视频| 99r国产精品| 中文字幕一区免费在线观看| 国模无码大尺度一区二区三区| 欧美精品九九99久久| 亚洲在线免费播放| 91色乱码一区二区三区| 国产精品超碰97尤物18| 国产99久久久国产精品| 久久久精品黄色| 天堂一区二区在线| 日韩精品一区二区三区中文不卡| 91麻豆精东视频| 国产精品一线二线三线| 粉嫩在线一区二区三区视频| 精品国产123| 黄色小说综合网站| 日韩一区二区在线看片| 美腿丝袜亚洲三区| 精品美女一区二区| 久久99久久99| 精品国免费一区二区三区|