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; }
void updateBitmapBgr32(uint8_t* pixels, int w, int h) { if(currentFrame == 0){ FlogE("Video::updateBitmapBgr32() called but currentFrame is unset"); throw VideoException(VideoException::EScaling); } AVPixelFormat fmt = PIX_FMT_RGB32; AVPicture pict; int avret = avpicture_fill(&pict, pixels, fmt, w, h); if(avret < 0){ FlogE("avpicture_fill returned " << avret); throw VideoException(VideoException::EScaling); } currentFrame->CopyScaled(&pict, w, h, fmt); }
void SetArgument(const std::string& pluginName, const std::string& key, const std::string& value){ bool found = false; for(auto& plugin : plugins){ if(plugin.name == pluginName){ plugin.args.push_back(std::tuple<std::string, std::string>{key, value}); found = true; } } if(!found) FlogE("no such plugin enabled: " << pluginName); }
void updateOverlay(uint8_t** pixels, const uint16_t* pitches, int w, int h) { if(currentFrame == 0){ FlogE("Video::updateOverlay() called but currentFrame is unset"); throw VideoException(VideoException::EScaling); } AVPicture pict; int avret = avpicture_fill(&pict, NULL, AV_PIX_FMT_YUYV422, w, h); if(avret < 0){ FlogE("avpicture_fill returned " << avret); throw VideoException(VideoException::EScaling); } for(int i = 0; i < 3; i++){ pict.data[i] = pixels[i]; pict.linesize[i] = pitches[i]; } currentFrame->CopyScaled(&pict, w, h, AV_PIX_FMT_YUYV422); }
bool decodeFrame(StreamFrameMap& streamFrames) { bool done = false; while(!done) { // demux PacketPtr packet = demuxPacket(); if(packet == 0){ FlogE("demuxing failed"); return 0; } // decode decodePacket(packet, streamFrames); // check if any frames finished for(auto pair : streamFrames){ FramePtr frame = pair.second; if(frame->finished != 0){ // set timestamp and break out of loop int64_t pts = av_frame_get_best_effort_timestamp(frame->GetAvFrame()); if(pair.first == videoStream){ if(firstDts == AV_NOPTS_VALUE){ firstDts = frame->GetAvFrame()->pkt_dts; FlogD("setting firstDts to: " << firstDts); } if(firstPts == AV_NOPTS_VALUE){ firstPts = pts; FlogD("setting firstPts to: " << firstPts); } } frame->SetPts(pts); done = true; } } } // successfully decoded frame, reset retry counter ResetRetries(); return true; }
void StartSession(const std::string& shmName, PlatformPtr platform, IpcMessageQueuePtr hostQueue){ for(auto& plugin : plugins){ try { std::string messageQueueName = UuidGenerator::Create()->GenerateUuid(RandChar::Create()); FlogExpD(messageQueueName); plugin.messageQueue = IpcMessageQueue::Create(messageQueueName, 2, 1024 * 1024 * 32, 4, 1024 * 16); plugin.process = platform->StartProcess(plugin.executable, {messageQueueName, shmName}, plugin.directory); plugin.started = true; SendArguments(plugin); } catch (PlatformEx e) { FlogE("could not start plugin: " << plugin.executable << " because: " << e.GetMsg()); plugin.started = false; hostQueue->WriteMessage(Str("error -1 " << plugin.name), "could not start process"); } } }
void HandleResponse(const Command& cmd) { switch(cmd.type){ case CTGetBitmap: if(cmd.args[0].i == 1){ FlogD("got bitmap: " << cmd.args[1].i << "x" << cmd.args[2].i << " " << cmd.args[3].buf.size() << " bytes"); }else{ FlogE("failed to get a bitmap"); } break; case CTGetDimensions: FlogD("got video dimensions: success: " << cmd.args[0].i << ", " << cmd.args[1].i << " x " << cmd.args[2].i); break; default: FlogW("unhandled reponse, seq: " << cmd.seqNum << ", type: " << cmd.type); break; } }
void Init(CommandSenderPtr cmdSend, CommandQueuePtr cmdRecv) { this->cmdSend = cmdSend; this->cmdRecv = cmdRecv; recvThread = std::make_shared<std::thread>([&](){ RecvThread(); }); thread = std::make_shared<std::thread>([&](){ std::string line; std::map<std::string, CommandType> cmdStrs = { {"quit", CTQuit}, {"play", CTPlay}, {"pause", CTPause}, {"stop", CTStop}, {"seek", CTSeek}, {"load", CTLoad}, {"unload", CTUnload}, {"update-output-size", CTUpdateOutputSize}, {"force-redraw", CTForceRedraw}, {"set-playback-speed", CTSetPlaybackSpeed}, {"set-volume", CTSetVolume}, {"set-mute", CTSetMute}, {"set-qv-mute", CTSetQvMute}, {"get-bitmap", CTGetBitmap}, {"get-dimensions", CTGetDimensions}, }; while(!done){ std::cout << "> "; getline(std::cin, line); std::cout << line << std::endl; try { StrVec cmds = StringTools::Split(line, ' '); if(cmds.size() == 0) throw std::runtime_error("expected command"); if(cmds[0] == "show-messages"){ if(cmds.size() != 2) throw std::runtime_error("command expects true/false"); showMessages = cmds[1] == "true"; } else if(cmds[0] == "seek-through"){ std::vector<float> positions = {1.0f, 3.0f, 10.0f, 20.0f, 23.0f, 23.5f, 30.0f, 70.0f}; for(auto pos : positions){ cmdSend->SendCommand(NO_SEQ_NUM, 0, CTSeek, pos); SDL_Delay(500); } } else { auto it = cmdStrs.find(cmds[0]); if(it == cmdStrs.end()) throw std::runtime_error(Str("no such command: " << cmds[0])); Command cmd; cmd.type = it->second; cmd.seqNum = NO_SEQ_NUM; unsigned argsSize = CommandSpecs[cmd.type].requestArgTypes.size(); if(cmds.size() - 1 != argsSize) throw std::runtime_error(Str(cmds[0] << " expects " << argsSize << " args (not " << cmds.size() - 1 << ")")); if(cmd.type == CTQuit) done = true; int i = 1; for(ArgumentType aType : CommandSpecs[cmd.type].requestArgTypes){ Argument arg; arg.type = aType; switch(aType){ case ATStr: arg.str = Tools::StrToWstr(cmds[i]); break; case ATInt32: arg.i = atoi(cmds[i].c_str()); break; case ATFloat: arg.f = atof(cmds[i].c_str()); break; case ATDouble: arg.d = atof(cmds[i].c_str()); break; case ATBuffer: FlogE("can't send a buffer from command line"); break; } cmd.args.push_back(arg); i++; } cmdSend->SendCommand(cmd); } } catch (std::runtime_error e) { std::cerr << "error: " << e.what() << std::endl; } } // wait for a bit to receieve any commands the player might still want to send std::this_thread::sleep_for(std::chrono::milliseconds(1000)); }); }
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); }