int audioRead() { while (!audioAvailable()) { Serial.print(""); } int sample = samples[samplesOut]; samplesOut++; if (samplesOut == AUDIO_BUFFER_SIZE) { samplesOut = 0; } return sample; }
MFPlayerControl::MFPlayerControl(MFPlayerSession *session) : QMediaPlayerControl(session) , m_state(QMediaPlayer::StoppedState) , m_videoAvailable(false) , m_audioAvailable(false) , m_duration(-1) , m_seekable(false) , m_session(session) { QObject::connect(m_session, SIGNAL(statusChanged()), this, SLOT(handleStatusChanged())); QObject::connect(m_session, SIGNAL(videoAvailable()), this, SLOT(handleVideoAvailable())); QObject::connect(m_session, SIGNAL(audioAvailable()), this, SLOT(handleAudioAvailable())); QObject::connect(m_session, SIGNAL(durationUpdate(qint64)), this, SLOT(handleDurationUpdate(qint64))); QObject::connect(m_session, SIGNAL(seekableUpdate(bool)), this, SLOT(handleSeekableUpdate(bool))); QObject::connect(m_session, SIGNAL(error(QMediaPlayer::Error, QString, bool)), this, SLOT(handleError(QMediaPlayer::Error, QString, bool))); QObject::connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64))); QObject::connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); QObject::connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool))); QObject::connect(m_session, SIGNAL(playbackRateChanged(qreal)), this, SIGNAL(playbackRateChanged(qreal))); QObject::connect(m_session, SIGNAL(bufferStatusChanged(int)), this, SIGNAL(bufferStatusChanged(int))); }
void gravManager::draw() { // don't draw if either of these objects haven't been initialized yet if ( !earth || !input ) return; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); cam->animateValues(); cam->doGLLookat(); // audio test drawing /*if ( audioAvailable() ) { GLUquadric* sphereQuad = gluNewQuadric(); if ( true ) //drawCounter % 2 == 0 ) { float avg = audio->getLevelAvg(); if ( avg > 0.0001f ) overalllevel = avg; } gluSphere( sphereQuad, overalllevel * 30.0f + 0.5f, 50, 50 ); }*/ // set it to update names only every 30 frames bool updateNames = false; if ( drawCounter == 0 ) { updateNames = true; if ( audioAvailable() ) audio->updateNames(); } // polygon offset to fix z-fighting of coplanar polygons (videos) // disabled, since making the depth buffer read-only in some area takes // care of this issue //glEnable( GL_POLYGON_OFFSET_FILL ); //glPolygonOffset( 0.1, 1.0 ); //glPolygonMode( GL_FRONT, GL_FILL ); //float pOffset = 0.1; std::vector<RectangleBase*>::const_iterator si; lockSources(); // periodically automatically rearrange if on automatic - take last object // and put it in center if ( autoCounter == 0 && getMovableObjects().size() > 0 && autoFocusRotate ) { outerObjs = getMovableObjects(); innerObjs = std::vector<RectangleBase*>( outerObjs.begin(), outerObjs.begin()+1 ); outerObjs.erase( outerObjs.begin() ); std::map<std::string, std::vector<RectangleBase*> > data = \ std::map<std::string, std::vector<RectangleBase*> >(); data["inners"] = innerObjs; data["outers"] = outerObjs; layouts->arrange( "aspectFocus", getScreenRect(), RectangleBase(), data ); moveToTop( innerObjs[0] ); outerObjs.clear(); innerObjs.clear(); } // add objects to tree that need to be added - similar to delete, tree is // modified on the main thread (in other WX places) so if ( objectsToAddToTree->size() > 0 && tree != NULL ) { for ( unsigned int i = 0; i < objectsToAddToTree->size(); i++ ) { tree->addObject( (*objectsToAddToTree)[i] ); } objectsToAddToTree->clear(); } // same for remove if ( objectsToRemoveFromTree->size() > 0 && tree != NULL ) { for ( unsigned int i = 0; i < objectsToRemoveFromTree->size(); i++ ) { tree->removeObject( (*objectsToRemoveFromTree)[i] ); } objectsToRemoveFromTree->clear(); } // delete sources that need to be deleted - see deleteSource for the reason doDelayedDelete(); // draw point on geographical position, selected ones on top (and bigger) for ( si = drawnObjects->begin(); si != drawnObjects->end(); si++ ) { RGBAColor col = (*si)->getColor(); glColor4f( col.R, col.G, col.B, col.A ); if ( !(*si)->isGrouped() && !(*si)->isSelected() ) { //drawCurvedEarthLine( (*si)->getLat(), (*si)->getLon(), // (*si)->getX(), (*si)->getY(), (*si)->getZ() ); drawEarthPoint( (*si)->getLat(), (*si)->getLon(), 3.0f ); } } for ( si = selectedObjects->begin(); si != selectedObjects->end(); si++ ) { RGBAColor col = (*si)->getColor(); glColor4f( col.R, col.G, col.B, col.A ); if ( !(*si)->isGrouped() ) { //drawCurvedEarthLine( (*si)->getLat(), (*si)->getLon(), // (*si)->getX(), (*si)->getY(), (*si)->getZ() ); drawEarthPoint( (*si)->getLat(), (*si)->getLon(), 6.0f ); } } earth->draw(); // this makes the depth buffer read-only for this bit - this prevents // z-fighting on the videos which are coplanar glDepthMask( GL_FALSE ); // iterate through all objects to be drawn, and draw for ( si = drawnObjects->begin(); si != drawnObjects->end(); si++ ) { // do things we only want to do every X frames, // like updating the name if ( updateNames ) { // only bother updating it on the tree if it actually // changes - to suppress "" from getting shown if ( (*si)->updateName() && tree ) tree->updateObjectName( (*si) ); } // only draw if not grouped - groups are responsible for // drawing their members if ( !(*si)->isGrouped() ) { // set the audio effect level on the drawcounter, if audio is // enabled, and if it's selectable (excludes runway) // TODO maybe change this if meaning of selectable changes if ( audioAvailable() && drawCounter == 0 && (*si)->isSelectable() ) { // had a really bizarre bug here - if uninitialized, would hit // > 0.01f check and succeed later if object was selected. what? float level = 0.0f; // if source has siteID, send that (and tell audiomanager to // only check siteIDs), if not, use cname if available if ( (*si)->getSiteID().compare("") != 0 ) { level = audio->getLevel( (*si)->getSiteID(), true, false ); } else if ( (*si)->getAltName().compare("") != 0 ) { level = audio->getLevel( (*si)->getAltName(), true, true ); } if ( level > 0.01f ) { innerObjs.push_back( (*si) ); audioFocusTrigger = true; } else { outerObjs.push_back( (*si) ); } } (*si)->draw(); } else { // object is grouped, so group will draw it itself } } // do the audio focus if it triggered if ( audioAvailable() ) { if ( audioFocusTrigger ) { std::map<std::string, std::vector<RectangleBase*> > data = \ std::map<std::string, std::vector<RectangleBase*> >(); data["inners"] = innerObjs; data["outers"] = outerObjs; layouts->arrange( "aspectFocus", getScreenRect(), RectangleBase(), data ); audioFocusTrigger = false; } outerObjs.clear(); innerObjs.clear(); } // check runway members for potential removal if outside if ( intersectCounter == 0 && runway->numObjects() > 0 && runway->getColor().A > 0.01f ) runway->handleOutsideMembers(); if ( input->haveValidMousePos() ) { bool sessionMouseover = input->getMouseX() > sessionManager->getLBound() && input->getMouseX() < sessionManager->getRBound() && input->getMouseY() < sessionManager->getUBound() && input->getMouseY() > sessionManager->getDBound(); if ( sessionMouseover && !sessionManager->isShown() ) { sessionManager->show( true ); moveToTop( sessionManager ); } else if ( !sessionMouseover && sessionManager->isShown() ) { sessionManager->show( false ); } } unlockSources(); // check session manager for moved session entry objects & shift if // necessary - this needs to be outside the lock() since a shift might // trigger a session disable, which may delete a video which needs to lock // on its own (ie, we're not doing reentrant mutexes) if ( intersectCounter == 0 && sessionManager->getColor().A > 0.01f ) sessionManager->checkGUISessionShift(); // draw the click-and-drag selection box if ( holdCounter > 1 && drawSelectionBox ) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // the main box glBegin(GL_QUADS); glColor4f( 0.1f, 0.2f, 1.0f, holdCounter/25.0f * 0.25f ); glVertex3f(input->getDragStartX(), input->getDragStartY(), 0.0f); glVertex3f(input->getDragEndX(), input->getDragStartY(), 0.0f); glVertex3f(input->getDragEndX(), input->getDragEndY(), 0.0f); glVertex3f(input->getDragStartX(), input->getDragEndY(), 0.0f); glEnd(); // the outline glBegin(GL_LINE_LOOP); glColor4f( 0.5f, 0.6f, 1.0f, holdCounter/25.0f * 0.25f ); glVertex3f(input->getDragStartX(), input->getDragStartY(), 0.0f); glVertex3f(input->getDragEndX(), input->getDragStartY(), 0.0f); glVertex3f(input->getDragEndX(), input->getDragEndY(), 0.0f); glVertex3f(input->getDragStartX(), input->getDragEndY(), 0.0f); glEnd(); glDisable(GL_BLEND); } // header text drawing if ( useHeader ) { glPushMatrix(); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f( 0.953f, 0.431f, 0.129f, 0.5f ); float textXPos = screenRectFull.getLBound() + textOffset; float textYPos = screenRectFull.getUBound() - ( ( headerTextBox.Upper().Yf() - headerTextBox.Lower().Yf() ) * textScale ) - textOffset; glTranslatef( textXPos, textYPos, 0.0f ); glScalef( textScale, textScale, textScale ); const char* text = headerString.c_str(); GLUtil::getInstance()->getMainFont()->Render( text ); glDisable( GL_BLEND ); glPopMatrix(); } // graphics debug drawing if ( graphicsDebugView ) { glPushMatrix(); GLCanvas* canvas = GLUtil::getInstance()->getCanvas(); long drawTime = canvas->getDrawTime(); float color = (33.0f - (float)drawTime) / 17.0f; glColor4f( 1.0f, color, color, 0.8f ); glTranslatef( 0.0f, screenRectFull.getUBound() * 0.9f, 0.0f ); float debugScale = textScale / 2.5f; glScalef( debugScale, debugScale, debugScale ); char text[100]; sprintf( text, "Draw time: %3ld Non-draw time: %3ld Pixel count: %8ld " "FPS: %2.2f", canvas->getDrawTime(), canvas->getNonDrawTime(), videoListener->getPixelCount(), canvas->getFPS() ); GLUtil::getInstance()->getMainFont()->Render( text ); glPopMatrix(); } // back to writeable z-buffer for proper earth/line rendering glDepthMask( GL_TRUE ); glFlush(); // hold counter is a bit different than the others since alpha values // directly depend on it, as above if ( !input->isLeftButtonHeld() && holdCounter > 0 ) holdCounter-=2; else if ( holdCounter < 24 ) holdCounter++; drawCounter = ( drawCounter + 1 ) % 30; intersectCounter = ( intersectCounter + 1 ) % 20; autoCounter = ( autoCounter + 1 ) % 900; }