PerforceDepotView::PerforceDepotView(ClientApiPtr clientApi, const char* depotPath, const char* clientPath) : impl_(new PerforceDepotViewImplementation(std::move(clientApi), depotPath, clientPath)) { // Find the matching parent stream specified by the depotPath and replace it with the current depot path auto clientInfo = GetClientInfo(); if (clientInfo.find("clientRoot") == clientInfo.end()) return; auto clientRoot = clientInfo["clientRoot"]; std::string rootDepotPath = GetRootDepotPath(clientRoot); if (rootDepotPath.empty()) return; auto streams = GetStreams(); // Find the parent stream specified in the depot path for (auto& stream : streams) { if (impl_->depotPath_.compare(0, stream.first.size(), stream.first) == 0) { impl_->depotPath_.replace(0, stream.first.size(), rootDepotPath); break; } }; }
int CDVDDemux::GetNrOfStreams(StreamType streamType) { int iCounter = 0; for (auto pStream : GetStreams()) { if (pStream && pStream->type == streamType) iCounter++; } return iCounter; }
CMIOStreamID Device::GetStreamByIndex(CMIOObjectPropertyScope scope, UInt32 index) const { CMIOStreamID answer = 0; UInt32 numberStreams = GetNumberStreams(scope); if ((numberStreams > 0) && (index < numberStreams)) { CAAutoArrayDelete<CMIOStreamID> streamList(numberStreams); GetStreams(scope, numberStreams, streamList); answer = streamList[index]; } return answer; }
AudioObjectID CAHALAudioDevice::GetStreamByIndex(bool inIsInput, UInt32 inIndex) const { AudioObjectID theAnswer = kAudioObjectUnknown; UInt32 theNumberStreams = GetNumberStreams(inIsInput); if((theNumberStreams > 0) && (inIndex < theNumberStreams)) { CAAutoArrayDelete<AudioObjectID> theStreamList(theNumberStreams); GetStreams(inIsInput, theNumberStreams, theStreamList); if((theNumberStreams > 0) && (inIndex < theNumberStreams)) { theAnswer = theStreamList[inIndex]; } } return theAnswer; }
bool OMXReader::Open(std::string filename, bool dump_format) { if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load()) return false; m_iCurrentPts = DVD_NOPTS_VALUE; m_filename = filename; m_speed = DVD_PLAYSPEED_NORMAL; m_program = UINT_MAX; const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; ClearStreams(); m_dllAvFormat.av_register_all(); m_dllAvFormat.avformat_network_init(); m_dllAvUtil.av_log_set_level(AV_LOG_QUIET); int result = -1; AVInputFormat *iformat = NULL; unsigned char *buffer = NULL; unsigned int flags = READ_TRUNCATED | READ_BITRATE | READ_CHUNKED; #ifndef STANDALONE if( CFileItem(m_filename, false).IsInternetStream() ) flags |= READ_CACHED; #endif if(m_filename.substr(0, 8) == "shout://" ) m_filename.replace(0, 8, "http://"); if(m_filename.substr(0,6) == "mms://" || m_filename.substr(0,7) == "http://" || m_filename.substr(0,7) == "rtmp://" || m_filename.substr(0,6) == "udp://") { // ffmpeg dislikes the useragent from AirPlay urls //int idx = m_filename.Find("|User-Agent=AppleCoreMedia"); size_t idx = m_filename.find("|"); if(idx != string::npos) m_filename = m_filename.substr(0, idx); result = m_dllAvFormat.avformat_open_input(&m_pFormatContext, m_filename.c_str(), iformat, NULL); if(result < 0) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - avformat_open_input %s ", m_filename.c_str()); Close(); return false; } } else { m_pFile = new CFile(); if (!m_pFile->Open(m_filename, flags)) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - %s ", m_filename.c_str()); Close(); return false; } buffer = (unsigned char*)m_dllAvUtil.av_malloc(FFMPEG_FILE_BUFFER_SIZE); m_ioContext = m_dllAvFormat.avio_alloc_context(buffer, FFMPEG_FILE_BUFFER_SIZE, 0, m_pFile, dvd_file_read, NULL, dvd_file_seek); m_ioContext->max_packet_size = 6144; if(m_ioContext->max_packet_size) m_ioContext->max_packet_size *= FFMPEG_FILE_BUFFER_SIZE / m_ioContext->max_packet_size; if(m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL) == 0) m_ioContext->seekable = 0; m_dllAvFormat.av_probe_input_buffer(m_ioContext, &iformat, m_filename.c_str(), NULL, 0, 0); if(!iformat) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - av_probe_input_buffer %s ", m_filename.c_str()); Close(); return false; } m_pFormatContext = m_dllAvFormat.avformat_alloc_context(); m_pFormatContext->pb = m_ioContext; result = m_dllAvFormat.avformat_open_input(&m_pFormatContext, m_filename.c_str(), iformat, NULL); if(result < 0) { Close(); return false; } } // set the interrupt callback, appeared in libavformat 53.15.0 m_pFormatContext->interrupt_callback = int_cb; m_bMatroska = strncmp(m_pFormatContext->iformat->name, "matroska", 8) == 0; // for "matroska.webm" m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0; m_bMpeg = strcmp(m_pFormatContext->iformat->name, "mpeg") == 0; // if format can be nonblocking, let's use that m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; // analyse very short to speed up mjpeg playback start if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && m_ioContext->seekable == 0) m_pFormatContext->max_analyze_duration = 500000; #ifdef STANDALONE if(/*m_bAVI || */m_bMatroska) m_pFormatContext->max_analyze_duration = 0; #endif result = m_dllAvFormat.avformat_find_stream_info(m_pFormatContext, NULL); if(result < 0) { Close(); return false; } if(!GetStreams()) { Close(); return false; } if(m_pFile) { int64_t len = m_pFile->GetLength(); int64_t tim = GetStreamLength(); if(len > 0 && tim > 0) { unsigned rate = len * 1000 / tim; unsigned maxrate = rate + 1024 * 1024 / 8; if(m_pFile->IoControl(IOCTRL_CACHE_SETRATE, &maxrate) >= 0) CLog::Log(LOGDEBUG, "COMXPlayer::OpenFile - set cache throttle rate to %u bytes per second", maxrate); } } printf("file : %s reult %d format %s audio streams %d video streams %d chapters %d subtitles %d\n", m_filename.c_str(), result, m_pFormatContext->iformat->name, m_audio_count, m_video_count, m_chapter_count, m_subtitle_count); m_speed = DVD_PLAYSPEED_NORMAL; if(dump_format) m_dllAvFormat.av_dump_format(m_pFormatContext, 0, m_filename.c_str(), 0); UpdateCurrentPTS(); m_open = true; return true; }
bool OMXReader::Open(std::string filename, bool dump_format, bool live /* =false */, float timeout /* = 0.0f */, std::string cookie /* = "" */, std::string user_agent /* = "" */) { if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllAvFormat.Load()) return false; timeout_default_duration = (int64_t) (timeout * 1e9); m_iCurrentPts = DVD_NOPTS_VALUE; m_filename = filename; m_speed = DVD_PLAYSPEED_NORMAL; m_program = UINT_MAX; const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; RESET_TIMEOUT(3); ClearStreams(); m_dllAvFormat.av_register_all(); m_dllAvFormat.avformat_network_init(); m_dllAvUtil.av_log_set_level(dump_format ? AV_LOG_INFO:AV_LOG_QUIET); int result = -1; AVInputFormat *iformat = NULL; unsigned char *buffer = NULL; unsigned int flags = READ_TRUNCATED | READ_BITRATE | READ_CHUNKED; m_pFormatContext = m_dllAvFormat.avformat_alloc_context(); if (!m_pFormatContext) { log_err("Failed to create format context."); return false; } // set the interrupt callback, appeared in libavformat 53.15.0 m_pFormatContext->interrupt_callback = int_cb; // if format can be nonblocking, let's use that m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; if(m_filename.substr(0, 8) == "shout://" ) m_filename.replace(0, 8, "http://"); if(m_filename.substr(0,6) == "mms://" || m_filename.substr(0,7) == "mmsh://" || m_filename.substr(0,7) == "mmst://" || m_filename.substr(0,7) == "mmsu://" || m_filename.substr(0,7) == "http://" || m_filename.substr(0,8) == "https://" || m_filename.substr(0,7) == "rtmp://" || m_filename.substr(0,6) == "udp://" || m_filename.substr(0,7) == "rtsp://" || m_filename.substr(0,6) == "rtp://" || m_filename.substr(0,6) == "ftp://" || m_filename.substr(0,7) == "sftp://" || m_filename.substr(0,6) == "smb://") { // ffmpeg dislikes the useragent from AirPlay urls //int idx = m_filename.Find("|User-Agent=AppleCoreMedia"); size_t idx = m_filename.find("|"); if(idx != string::npos) m_filename = m_filename.substr(0, idx); AVDictionary *d = NULL; // Enable seeking if http, ftp if(!live && (m_filename.substr(0,7) == "http://" || m_filename.substr(0,6) == "ftp://" || m_filename.substr(0,7) == "sftp://" || m_filename.substr(0,6) == "smb://")) { av_dict_set(&d, "seekable", "1", 0); if(!cookie.empty()) { av_dict_set(&d, "cookies", cookie.c_str(), 0); } if(!user_agent.empty()) { av_dict_set(&d, "user_agent", user_agent.c_str(), 0); } } CLog::Log(LOGDEBUG, "COMXPlayer::OpenFile - avformat_open_input %s ", m_filename.c_str()); result = m_dllAvFormat.avformat_open_input(&m_pFormatContext, m_filename.c_str(), iformat, &d); if(av_dict_count(d) == 0) { CLog::Log(LOGDEBUG, "COMXPlayer::OpenFile - avformat_open_input enabled SEEKING "); if(m_filename.substr(0,7) == "http://") m_pFormatContext->pb->seekable = AVIO_SEEKABLE_NORMAL; } av_dict_free(&d); if(result < 0) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - avformat_open_input %s ", m_filename.c_str()); Close(); return false; } } else { m_pFile = new CFile(); if (!m_pFile->Open(m_filename, flags)) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - %s ", m_filename.c_str()); Close(); return false; } buffer = (unsigned char*)m_dllAvUtil.av_malloc(FFMPEG_FILE_BUFFER_SIZE); m_ioContext = m_dllAvFormat.avio_alloc_context(buffer, FFMPEG_FILE_BUFFER_SIZE, 0, m_pFile, dvd_file_read, NULL, dvd_file_seek); if (!m_ioContext) { log_err("Failed to create avio context."); return false; } m_ioContext->max_packet_size = 6144; if(m_ioContext->max_packet_size) m_ioContext->max_packet_size *= FFMPEG_FILE_BUFFER_SIZE / m_ioContext->max_packet_size; if(m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL) == 0) m_ioContext->seekable = 0; m_dllAvFormat.av_probe_input_buffer(m_ioContext, &iformat, m_filename.c_str(), NULL, 0, 0); if(!iformat) { CLog::Log(LOGERROR, "COMXPlayer::OpenFile - av_probe_input_buffer %s ", m_filename.c_str()); Close(); return false; } m_pFormatContext->pb = m_ioContext; if (!m_pFormatContext->internal) { log_err("AVFormat internal null."); abort(); } result = m_dllAvFormat.avformat_open_input(&m_pFormatContext, m_filename.c_str(), iformat, NULL); if(result < 0) { Close(); return false; } } m_bMatroska = strncmp(m_pFormatContext->iformat->name, "matroska", 8) == 0; // for "matroska.webm" m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0; // analyse very short to speed up mjpeg playback start if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && m_ioContext->seekable == 0) m_pFormatContext->max_analyze_duration = 500000; if(/*m_bAVI || */m_bMatroska) m_pFormatContext->max_analyze_duration = 0; if (live) m_pFormatContext->flags |= AVFMT_FLAG_NOBUFFER; result = m_dllAvFormat.avformat_find_stream_info(m_pFormatContext, NULL); if(result < 0) { Close(); return false; } if(!GetStreams()) { Close(); return false; } if(m_pFile) { int64_t len = m_pFile->GetLength(); int64_t tim = GetStreamLength(); if(len > 0 && tim > 0) { unsigned rate = len * 1000 / tim; unsigned maxrate = rate + 1024 * 1024 / 8; if(m_pFile->IoControl(IOCTRL_CACHE_SETRATE, &maxrate) >= 0) CLog::Log(LOGDEBUG, "COMXPlayer::OpenFile - set cache throttle rate to %u bytes per second", maxrate); } } m_speed = DVD_PLAYSPEED_NORMAL; if(dump_format) m_dllAvFormat.av_dump_format(m_pFormatContext, 0, m_filename.c_str(), 0); UpdateCurrentPTS(); m_open = true; return true; }