// CreateAudioSupplier
AudioSupplier*
PlaylistPlaybackManager::CreateAudioSupplier()
{
	fAudioSupplier = new PlaylistAudioSupplier(fPlaylist, fLocker,
		this, FramesPerSecond());
	return fAudioSupplier;
}
Example #2
0
status_t
NodeManager::FormatChanged(BRect videoBounds, float videoFrameRate,
	color_space preferredVideoFormat, float audioFrameRate,
	uint32 audioChannels, uint32 enabledNodes, bool useOverlays, bool force)
{
	TRACE("NodeManager::FormatChanged()\n");

	if (!force && videoBounds == VideoBounds()
		&& videoFrameRate == FramesPerSecond()) {
		TRACE("   -> reusing existing nodes\n");
		// TODO: if enabledNodes would indicate that audio or video
		// is no longer needed, or, worse yet, suddenly needed when
		// it wasn't before, then we should not return here!
		PlaybackManager::Init(videoFrameRate, false, LoopMode(),
			IsLoopingEnabled(), Speed(), MODE_PLAYING_PAUSED_FORWARD,
			CurrentFrame());
		return B_OK;
	}

	_StopNodes();
	_TearDownNodes();

	PlaybackManager::Init(videoFrameRate, true, LoopMode(), IsLoopingEnabled(),
		Speed(), MODE_PLAYING_PAUSED_FORWARD, CurrentFrame());

	SetVideoBounds(videoBounds);

	status_t ret = _SetUpNodes(preferredVideoFormat, enabledNodes,
		useOverlays, audioFrameRate, audioChannels);
	if (ret == B_OK)
		_StartNodes();
	else
		fprintf(stderr, "unable to setup nodes: %s\n", strerror(ret));

	return ret;
}
Example #3
0
status_t
NodeManager::_SetUpVideoNodes(color_space preferredVideoFormat,
	bool useOverlays)
{
	// create the video producer node
	fVideoProducer = new VideoProducer(NULL, "MediaPlayer video out", 0,
		this, fVideoSupplier);

	// register the producer node
	fStatus = fMediaRoster->RegisterNode(fVideoProducer);
	if (fStatus != B_OK) {
		print_error("Can't register the video producer", fStatus);
		return fStatus;
	}

	// make sure the Media Roster knows that we're using the node
//	fMediaRoster->GetNodeFor(fVideoProducer->Node().node,
//		&fVideoConnection.producer);
	fVideoConnection.producer = fVideoProducer->Node();

	// create the video consumer node
	fVideoConsumer = new VideoConsumer("MediaPlayer video in", NULL, 0, this,
		fVideoTarget);

	// register the consumer node
	fStatus = fMediaRoster->RegisterNode(fVideoConsumer);
	if (fStatus != B_OK) {
		print_error("Can't register the video consumer", fStatus);
		return fStatus;
	}

	// make sure the Media Roster knows that we're using the node
//	fMediaRoster->GetNodeFor(fVideoConsumer->Node().node,
//		&fVideoConnection.consumer);
	fVideoConnection.consumer = fVideoConsumer->Node();

	// find free producer output
	media_input videoInput;
	media_output videoOutput;
	int32 count = 1;
	fStatus = fMediaRoster->GetFreeOutputsFor(fVideoConnection.producer,
		&videoOutput, 1, &count, B_MEDIA_RAW_VIDEO);
	if (fStatus != B_OK || count < 1) {
		fStatus = B_RESOURCE_UNAVAILABLE;
		print_error("Can't find an available video stream", fStatus);
		return fStatus;
	}

	// find free consumer input
	count = 1;
	fStatus = fMediaRoster->GetFreeInputsFor(fVideoConnection.consumer,
		&videoInput, 1, &count, B_MEDIA_RAW_VIDEO);
	if (fStatus != B_OK || count < 1) {
		fStatus = B_RESOURCE_UNAVAILABLE;
		print_error("Can't find an available connection to the video window",
			fStatus);
		return fStatus;
	}

	// connect the nodes
	media_format format;
	format.type = B_MEDIA_RAW_VIDEO;
	media_raw_video_format videoFormat = {
		FramesPerSecond(), 1, 0,
		(uint32)fVideoBounds.IntegerWidth(),
		B_VIDEO_TOP_LEFT_RIGHT, 1, 1,
		{
			preferredVideoFormat,
			(uint32)(fVideoBounds.IntegerWidth() + 1),
			(uint32)(fVideoBounds.IntegerHeight() + 1),
			0, 0, 0
		}
	};
	format.u.raw_video = videoFormat;

	// connect video producer to consumer (hopefully using overlays)
	fVideoConsumer->SetTryOverlay(useOverlays);
	fStatus = fMediaRoster->Connect(videoOutput.source, videoInput.destination,
		&format, &videoOutput, &videoInput);

	if (fStatus != B_OK) {
		print_error("Can't connect the video source to the video window... "
			"trying without overlays", fStatus);

		uint32 flags = 0;
		bool supported = bitmaps_support_space(
			format.u.raw_video.display.format, &flags);
		if (!supported || (flags & B_VIEWS_SUPPORT_DRAW_BITMAP) == 0) {
			// cannot create bitmaps with such a color space
			// or BViews don't support drawing it, fallback to B_RGB32
			format.u.raw_video.display.format = B_RGB32;
			printf("NodeManager::_SetupVideoNodes() - falling back to "
				"B_RGB32\n");
		}

		fVideoConsumer->SetTryOverlay(false);
		// connect video producer to consumer (not using overlays and using
		// a colorspace that BViews support drawing)
		fStatus = fMediaRoster->Connect(videoOutput.source,
			videoInput.destination, &format, &videoOutput, &videoInput);
	}
	// bail if second attempt failed too
	if (fStatus != B_OK) {
		print_error("Can't connect the video source to the video window",
			fStatus);
		return fStatus;
	}

	// the inputs and outputs might have been reassigned during the
	// nodes' negotiation of the Connect().  That's why we wait until
	// after Connect() finishes to save their contents.
	fVideoConnection.format = format;
	fVideoConnection.source = videoOutput.source;
	fVideoConnection.destination = videoInput.destination;
	fVideoConnection.connected = true;

	// set time sources
	fStatus = fMediaRoster->SetTimeSourceFor(fVideoConnection.producer.node,
		fTimeSource.node);
	if (fStatus != B_OK) {
		print_error("Can't set the timesource for the video source", fStatus);
		return fStatus;
	}

	fStatus = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(),
		fTimeSource.node);
	if (fStatus != B_OK) {
		print_error("Can't set the timesource for the video window", fStatus);
		return fStatus;
	}

	return fStatus;
}
Example #4
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.5;  //  Length of axes
   double Ex = -2*dim*Sin(th)*Cos(ph);
   double Ey = +2*dim        *Sin(ph);
   double Ez = +2*dim*Cos(th)*Cos(ph);

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);

   //  Integrate
   Step();

   //  Set shader
   glUseProgram(shader);
   int id = glGetUniformLocation(shader,"star");
   if (id>=0) glUniform1i(id,0);
   id = glGetUniformLocation(shader,"size");
   if (id>=0) glUniform1f(id,0.1);
   glBlendFunc(GL_ONE,GL_ONE);
   glEnable(GL_BLEND);

   //  Draw stars using vertex arrays
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_COLOR_ARRAY);
   glVertexPointer(3,GL_FLOAT,sizeof(float3),pos[src]);
   glColorPointer(3,GL_FLOAT,sizeof(Color),col);
   //  Draw all stars
   glDrawArrays(GL_POINTS,0,N);
   //  Disable vertex arrays
   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_COLOR_ARRAY);

   //  Unset shader
   glUseProgram(0);
   glDisable(GL_BLEND);

   //  Draw axes
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("FPS=%d Angle=%d,%d Mode=%s",
      FramesPerSecond(),th,ph,text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Example #5
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]   = {0.3,0.3,0.3,1.0};
   float Diffuse[]   = {1.0,1.0,1.0,1.0};
   float Specular[]  = {1.0,1.0,1.0,1.0};
   float Position[]  = {(float)(2*Cos(zh)),Ylight,(float)(2*Sin(zh)),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      float Ex = -2*dim*Sin(th)*Cos(ph);
      float Ey = +2*dim        *Sin(ph);
      float Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere
   //  This uses the fixed pipeline
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();

   //  Fixed pipeline
   if (mode==0)
   {
      //  OpenGL should normalize normal vectors
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);

      //  Enable textures
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D,crate);

      //  Enabe arrays
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Set pointers
      glVertexPointer  (4,GL_FLOAT,12*sizeof(GLfloat),cube_data);
      glNormalPointer  (  GL_FLOAT,12*sizeof(GLfloat),cube_data+4);
      glColorPointer   (3,GL_FLOAT,12*sizeof(GLfloat),cube_data+7);
      glTexCoordPointer(2,GL_FLOAT,12*sizeof(GLfloat),cube_data+10);

      //  Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable arrays
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_NORMAL_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Disable textures
      glDisable(GL_TEXTURE_2D);
   }
   //  OpenGL 4 style shaders
   else
   {
      int loc;
      float ModelViewMatrix[16];
      float ProjectionMatrix[16];
      glGetFloatv(GL_PROJECTION_MATRIX,ProjectionMatrix);
      glGetFloatv(GL_MODELVIEW_MATRIX,ModelViewMatrix);

      // Use our shader
      glUseProgram(shader);

      //  Set Modelview and Projection Matrix
      loc = glGetUniformLocation(shader, "ModelViewMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ModelViewMatrix);
      loc = glGetUniformLocation(shader, "ProjectionMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ProjectionMatrix);

      //  Select cube buffer
      glBindBuffer(GL_ARRAY_BUFFER,cube_buffer);
      //   Attribute 0: vertex coordinate (vec4) at offset 0
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)0);
      //   Attribute 1:  vertex color (vec3) offset 7 floats
      glEnableVertexAttribArray(1);
      glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)(7*sizeof(float)));

      // Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable vertex arrays
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);

      //  Unbind this buffer
      glBindBuffer(GL_ARRAY_BUFFER,0);

      // Back to fixed pipeline
      glUseProgram(0);
   }

   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("FPS=%d Dim=%.1f Projection=%s Mode=%s",
     FramesPerSecond(),dim,proj?"Perpective":"Orthogonal",text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Example #6
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int ndm[] = {31,28,31,30,31,30,31,31,30,31,30,31};
   int doy = zh/360;
   int mo,dy,hr,mn;
   int id;
   //  Sun angle
   float fh = doy*360.0/365.0;
   //  Light direction
   float Position[]  = {Cos(fh),0.0,Sin(fh),0.0};

   //  Time of day
   id = (zh+(int)fh)%360;
   hr = (id/15)%24;
   mn = 4*(id%15);
   //  Compute month and day
   dy = doy+1;
   for (mo=0;dy>ndm[mo];mo++)
      dy -= ndm[mo];
   fh = (dy-1)/(float)ndm[mo];
   mo++;

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Set tranformation
   glLoadIdentity();
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);

   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set position of light 0
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   //  Texture for this month
   glActiveTexture(GL_TEXTURE0);
   glBindTexture(GL_TEXTURE_2D,day[mo-1]);
   //  Texture for next month
   glActiveTexture(GL_TEXTURE1);
   glBindTexture(GL_TEXTURE_2D,day[mo%12]);

   //  Rotate Z up and inclined 23.5 degrees
   glRotated(-90,1,0,0);
   glRotated(-23.5,0,1,0);
   //  Draw planet
   glColor3f(1,1,1);
   glEnable(GL_TEXTURE_2D);
   //  Rotation around spin axis
   glRotated(zh,0,0,1);
   //  Solid
   gluQuadricDrawStyle(ball,GLU_FILL);
   //  Calculate normals
   gluQuadricNormals(ball,GLU_SMOOTH);
   //  Apply Textures
   gluQuadricTexture(ball,1);
   //  Enable shader
   glUseProgram(shader);
   //  Set textures
   id = glGetUniformLocation(shader,"DayTex0");
   if (id>=0) glUniform1i(id,0);
   id = glGetUniformLocation(shader,"DayTex1");
   if (id>=0) glUniform1i(id,1);
   id = glGetUniformLocation(shader,"NightTex");
   if (id>=0) glUniform1i(id,2);
   id = glGetUniformLocation(shader,"CloudGloss");
   if (id>=0) glUniform1i(id,3);
   id = glGetUniformLocation(shader,"mode");
   if (id>=0) glUniform1i(id,mode);
   id = glGetUniformLocation(shader,"frac");
   if (id>=0) glUniform1f(id,fh);
   //  Draw the ball
   gluSphere(ball,2.0,72,72);
   //  Shader off
   glUseProgram(0);

   //  No lighting from here on
   glDisable(GL_LIGHTING);
   //  Axes
   glBegin(GL_LINES);
   glVertex3f(0,0,+2.5);
   glVertex3f(0,0,-2.5);
   glEnd();

   //  Display parameters
   glColor3f(1,1,1);
   glWindowPos2i(5,5);
   Print("FPS=%d Dim=%.1f %d/%.2d %.2d:%.2d UTC %s", 
      FramesPerSecond(),dim,mo,dy,hr,mn,text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Example #7
0
int64_t XWindow::TicksPerFrame()
{ return TicksPerSecond() / FramesPerSecond(); }
Example #8
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Wait for first reshape
   if (H==0) return;
   //  Set initial pattern
   if (N==0)
   {
      //  Clear screen and set color
      glClearColor(0,0,0,0);
      glClear(GL_COLOR_BUFFER_BIT);
      glColor4f(1,0,0,1);
      //  Draw pattern from file
      LoadPattern(file);
   }
   //
   //  Compute next generation
   //
   else
   {
      //  Set shader
      glUseProgram(shader);

      //  Set offsets
      int id = glGetUniformLocation(shader,"dX");
      if (id>=0) glUniform1f(id,dX);
      id = glGetUniformLocation(shader,"dY");
      if (id>=0) glUniform1f(id,dY);
      id = glGetUniformLocation(shader,"img");
      if (id>=0) glUniform1i(id,0);

      //  Copy original scene to texture
      glBindTexture(GL_TEXTURE_2D,img);
      glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,0,0,W,H,0);

      //  Redraw the texture
      glClear(GL_COLOR_BUFFER_BIT);
      glEnable(GL_TEXTURE_2D);
      glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-1,-1);
      glTexCoord2f(0,1); glVertex2f(-1,+1);
      glTexCoord2f(1,1); glVertex2f(+1,+1);
      glTexCoord2f(1,0); glVertex2f(+1,-1);
      glEnd();
      glDisable(GL_TEXTURE_2D);

      //  Shader off
      glUseProgram(0);
   }

   //  Lock alpha since to not interfere with game
   glColorMask(1,1,1,0);
   //  Display parameters
   glColor4f(1,1,0,0);
   glWindowPos2i(5,5);
   if (warn) Print("Pattern too large for screen ");
   if (move) Print("FPS=%d ",FramesPerSecond());
   Print("Generation=%d",N);
   glColorMask(1,1,1,1);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
   //  Increment generations
   N++;
}