void Demuxer::update() { std::map<int, std::shared_ptr<Stream> > streams = getStreams(); std::map<int, std::shared_ptr<Stream> >::iterator it; for(std::pair<int, std::shared_ptr<Stream> > pair : streams) { pair.second->update(); } }
bool YouTubeEnclosureRequest::getEnclosure(const QString &url, const QVariantMap &settings) { if (status() == Active) { return false; } const QString videoId = url.section(QRegExp("v=|list=|/"), -1).section(QRegExp("&|\\?"), 0, 0); if (videoId.isEmpty()) { setErrorString(tr("Cannot extract video ID from URL")); setResult(Enclosure()); setStatus(Error); emit finished(this); return false; } m_settings = settings; m_settings["videoId"] = videoId; setStatus(Active); getStreams(); return true; }
bool OMXReader::open(std::string filename, bool doSkipAvProbe) { currentPTS = DVD_NOPTS_VALUE; fileName = filename; speed = DVD_PLAYSPEED_NORMAL; programID = UINT_MAX; AVIOInterruptCB int_cb = { interrupt_cb, NULL }; ClearStreams(); int result = -1; AVInputFormat *iformat = NULL; unsigned char *buffer = NULL; unsigned int flags = READ_TRUNCATED | READ_BITRATE | READ_CHUNKED; if(fileName.substr(0, 8) == "shout://" ) fileName.replace(0, 8, "http://"); if(fileName.substr(0,6) == "mms://" || fileName.substr(0,7) == "mmsh://" || fileName.substr(0,7) == "mmst://" || fileName.substr(0,7) == "mmsu://" || fileName.substr(0,7) == "http://" || fileName.substr(0,7) == "rtmp://" || fileName.substr(0,6) == "udp://" || fileName.substr(0,7) == "rtsp://" ) { doSkipAvProbe = false; // ffmpeg dislikes the useragent from AirPlay urls //int idx = fileName.Find("|User-Agent=AppleCoreMedia"); size_t idx = fileName.find("|"); if(idx != string::npos) fileName = fileName.substr(0, idx); AVDictionary *d = NULL; // Enable seeking if http if(fileName.substr(0,7) == "http://") { av_dict_set(&d, "seekable", "1", 0); } ofLog(OF_LOG_VERBOSE, "OMXPlayer::OpenFile - avformat_open_input %s ", fileName.c_str()); result = avformat_open_input(&avFormatContext, fileName.c_str(), iformat, &d); if(av_dict_count(d) == 0) { ofLog(OF_LOG_VERBOSE, "OMXPlayer::OpenFile - avformat_open_input enabled SEEKING "); if(fileName.substr(0,7) == "http://") avFormatContext->pb->seekable = AVIO_SEEKABLE_NORMAL; } av_dict_free(&d); if(result < 0) { ofLog(OF_LOG_ERROR, "OMXPlayer::OpenFile - avformat_open_input %s ", fileName.c_str()); close(); return false; } } else { fileObject = new File(); if (!fileObject->open(fileName, flags)) { ofLog(OF_LOG_ERROR, "OMXPlayer::OpenFile - %s ", fileName.c_str()); close(); return false; } buffer = (unsigned char*)av_malloc(FFMPEG_FILE_BUFFER_SIZE); avioContext = avio_alloc_context(buffer, FFMPEG_FILE_BUFFER_SIZE, 0, fileObject, read_callback, NULL, seek_callback); avioContext->max_packet_size = 6144; if(avioContext->max_packet_size) avioContext->max_packet_size *= FFMPEG_FILE_BUFFER_SIZE / avioContext->max_packet_size; if(fileObject->IoControl(IOCTRL_SEEK_POSSIBLE, NULL) == 0) avioContext->seekable = 0; av_probe_input_buffer(avioContext, &iformat, fileName.c_str(), NULL, 0, 0); if(!iformat) { ofLog(OF_LOG_ERROR, "OMXPlayer::OpenFile - av_probe_input_buffer %s ", fileName.c_str()); close(); return false; } //#warning experimental //iformat->flags |= AVFMT_SEEK_TO_PTS; avFormatContext = avformat_alloc_context(); avFormatContext->pb = avioContext; result = avformat_open_input(&avFormatContext, fileName.c_str(), iformat, NULL); if(result < 0) { close(); return false; } } // set the interrupt callback, appeared in libavformat 53.15.0 avFormatContext->interrupt_callback = int_cb; isMatroska = strncmp(avFormatContext->iformat->name, "matroska", 8) == 0; // for "matroska.webm" isAVI = strcmp(avFormatContext->iformat->name, "avi") == 0; // if format can be nonblocking, let's use that avFormatContext->flags |= AVFMT_FLAG_NONBLOCK; // analyse very short to speed up mjpeg playback start if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && avioContext->seekable == 0) avFormatContext->max_analyze_duration = 500000; if(/*isAVI || */isMatroska) avFormatContext->max_analyze_duration = 0; if(!doSkipAvProbe) { unsigned long long startTime = ofGetElapsedTimeMillis(); result = avformat_find_stream_info(avFormatContext, NULL); unsigned long long endTime = ofGetElapsedTimeMillis(); ofLogNotice(__func__) << "avformat_find_stream_info TOOK " << endTime-startTime << " MS"; if(result < 0) { close(); return false; } } if(!getStreams()) { close(); return false; } if(fileObject) { int64_t len = fileObject->GetLength(); int64_t tim = getStreamLength(); if(len > 0 && tim > 0) { unsigned rate = len * 1000 / tim; unsigned maxrate = rate + 1024 * 1024 / 8; if(fileObject->IoControl(IOCTRL_CACHE_SETRATE, &maxrate) >= 0) ofLog(OF_LOG_VERBOSE, "OMXPlayer::OpenFile - set cache throttle rate to %u bytes per second", maxrate); } } speed = DVD_PLAYSPEED_NORMAL; /* if(dump_format) av_dump_format(avFormatContext, 0, fileName.c_str(), 0);*/ updateCurrentPTS(); isOpen = true; return true; }