static void logCb(void *ptr, int level, const char *fmt, va_list vargs) { if(level == AV_LOG_WARNING){ /* HACK, can we extract this information from the headers structures somehow? */ if(!strcmp(fmt, "DRM protected stream detected, decoding will likely fail!\n")){ FlogI("DRM protected stream"); drm = true; } else if(!strcmp(fmt, "Ext DRM protected stream detected, decoding will likely fail!\n")){ FlogI("Ext DRM protected stream"); drm = true; } else if(!strcmp(fmt, "Digital signature detected, decoding will likely fail!\n")){ FlogI("Digitally signed stream"); drm = true; } } if (level <= av_log_get_level()){ char tmp[1024]; vsprintf(tmp, fmt, vargs); FlogD("ffmpeg says: " << tmp); } }
int main(int argc, char** argv) { Flog_Init("Testapp"); Flog_AddTargetStream(stdout, Flog_SDebug1 |Flog_SDebug2 | Flog_SDebug3 | Flog_SVerbose | Flog_SInfo | Flog_SWarning, 1); Flog_AddTargetStream(stderr, Flog_SError | Flog_SFatal, 1); if( !Flog_AddTargetServer("localhost", Flog_DefaultPort, Flog_SAll) ){ printf("couldn't connect to server\n"); return 1; } std::string testString = "value"; FlogExpD1(testString); FlogD1("debug level " << 1); FlogD2("debug level " << 2); FlogD3("debug level " << 3); FlogD("debug default level"); FlogV("verbose"); FlogI("info"); FlogW("warning"); FlogE("error"); FlogF("fatal error"); FlogAssert(argc == 1, "Not one arugment, exiting"); FlogDie("DEATH"); return 0; }
int main() { Flog_Init(SPANK_NAME); Flog_AddTargetStream(stdout, Flog_SDebug1 |Flog_SDebug2 | Flog_SDebug3 | Flog_SVerbose | Flog_SInfo | Flog_SWarning, 1); Flog_AddTargetStream(stderr, Flog_SError | Flog_SFatal, 1); FlogI("Welcome to " << SPANK_NAME << " " << SPANK_VERSION); Server server; // Memory cached static data server.AddRequestHandler("/", new Cached(new StaticResource("data/index.html"))); server.AddRequestHandler("/favicon.ico", new Cached(new StaticResource("data/favicon.ico"))); // Non-cached static data server.AddRequestHandler("/heart.png", new StaticResource("data/heart.png")); // Non-cached dynamic page server.AddRequestHandler("/dynamic", new DynamicTest()); // Cached dynamic page server.AddRequestHandler("/time", new Cached(new ServerTime())); FlogAssert( signal(SIGHUP, HandleSigHup) != SIG_ERR, "Could not set signal handler"); server.ListenForever(); return 0; }
void openFile(StreamPtr stream, IAudioDevicePtr audioDevice) { FlogI("Trying to load file: " << stream->GetPath()); int ret; this->stream = stream; this->audioDevice = audioDevice; timeHandler = TimeHandler::Create(audioDevice); audioDevice->SetPaused(true); pFormatCtx = avformat_alloc_context(); pFormatCtx->pb = stream->GetAVIOContext(); if((ret = avformat_open_input(&pFormatCtx, stream->GetPath().c_str(), NULL, NULL)) != 0){ char ebuf[512]; av_strerror(ret, ebuf, sizeof(ebuf)); FlogE("couldn't open file"); FlogE(ebuf); throw VideoException(VideoException::EFile); } /* Get stream information */ if(avformat_find_stream_info(pFormatCtx, NULL) < 0){ FlogE("couldn't get stream info"); throw VideoException(VideoException::EStreamInfo); } /* Print video format information */ av_dump_format(pFormatCtx, 0, stream->GetPath().c_str(), 0); // If the loader logged something about wmv being DRM protected, give up if(drm){ throw VideoException(VideoException::EStream); } // find the best audio and video streams audioStream = videoStream = AVERROR_STREAM_NOT_FOUND; pCodec = 0; videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0); if(videoStream == AVERROR_STREAM_NOT_FOUND){ FlogE("couldn't find stream"); throw VideoException(VideoException::EStream); } if(videoStream == AVERROR_DECODER_NOT_FOUND || !pCodec){ FlogE("unsupported codec"); throw VideoException(VideoException::EVideoCodec); } audioStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0); if(hasAudioStream()){ audioHandler = AudioHandler::Create(pFormatCtx->streams[audioStream]->codec, audioDevice, timeHandler); }else{ audioHandler = AudioHandlerNoSound::Create(audioDevice, timeHandler); FlogD("no audio stream or unsupported audio codec"); } /* Get a pointer to the codec context for the video stream */ pCodecCtx = pFormatCtx->streams[videoStream]->codec; // Open codec if(avcodec_open2(pCodecCtx, pCodec, NULL) < 0){ FlogE("unsupported codec"); throw VideoException(VideoException::EVideoCodec); } w = pCodecCtx->width; h = pCodecCtx->height; // limit framequeue memory size int frameMemSize = avpicture_get_size((AVPixelFormat)pCodecCtx->pix_fmt, w, h); int maxVideoQueueMem = 512 * 1024 * 1024; // 512 MB maxFrameQueueSize = maxVideoQueueMem / frameMemSize; // cap to 256 maxFrameQueueSize = std::min(maxFrameQueueSize, 256); // tick the video so that firstPts and firstDts are set tick(true); }