Exemple #1
0
/*! \brief Save all markers out to packfile
 *
 * Saves individual \sa s_marker objects to the specified PACKFILE.
 *
 * \param[out] marray - Current array of markers from whence data are pulled
 * \param[out] pf - PACKFILE to where data is written
 * \return     Non-0 on error, 0 on success
 */
size_t save_markers (s_marker_array *marray, PACKFILE *pf)
{
   size_t i;

   assert (marray && "marray == NULL");
   assert (pf && "pf == NULL");

   if (!marray || !pf) {
      printf ("NULL passed into save_markers()\n");
      return 1;
   }

   pack_iputw (marray->size, pf);
   if (pack_feof (pf)) {
      assert (0 && "pack_iputw() for marray->size received EOF signal.");
      printf ("Encountered EOF when writing marker array size.\n");
      return 2;
   }

   for (i = 0; i < marray->size; ++i) {
      pack_fwrite (marray->array[i].name, sizeof (marray->array[i].name), pf);
      pack_iputw (marray->array[i].x, pf);
      pack_iputw (marray->array[i].y, pf);

      if (pack_feof (pf)) {
         assert (0 && "pack_iputw() for marker->[xy] received EOF signal.");
         printf ("Encountered EOF when writing marker %dsize.\n", i);
         return 3;
      }
   }

   return 0;
}
/* egg_eof:
 *  Have we reached the end of the file?
 */
static int egg_eof()
{
   if (egg_file)
      return pack_feof(egg_file);
   else
      return (egg_data_length > 0);
}
Exemple #3
0
/*! \brief Load all markers in from packfile
 *
 * Loads individual \sa s_marker objects from the specified PACKFILE.
 *
 * \param[in,out] marray - Current array of markers to be reallocated
 * \param[in]     pf - PACKFILE from whence data are pulled
 * \return        Non-0 on error, 0 on success
 */
size_t load_markers (s_marker_array *marray, PACKFILE *pf)
{
   s_marker *mmarker = NULL;
   size_t i;

   assert (marray && "marray == NULL");
   assert (pf && "pf == NULL");

   if (!marray || !pf) {
      printf ("NULL passed into load_markers()\n");
      return 1;
   }

   marray->size = pack_igetw (pf);
   if (pack_feof (pf)) {
      assert (0 && "pack_igetw() for marray->size received EOF signal.");
      printf ("Expected value for number of markers. Instead, received EOF.\n");
      return 2;
   } else if (marray->size == 0) {
      marray->array = NULL;
      return 0; // Success: okay to have 0 markers in a map
   }

   marray->array = (s_marker *) realloc
      (marray->array, marray->size * sizeof (s_marker));
   for (i = 0; i < marray->size; ++i) {
      mmarker = &marray->array[i];

      pack_fread (mmarker->name, sizeof (mmarker->name), pf);
      mmarker->x = pack_igetw (pf);
      mmarker->y = pack_igetw (pf);

      if (pack_feof (pf)) {
         assert (0 && "pack_igetw() for marker->[xy] received EOF signal.");
         printf ("Encountered EOF during marker read.\n");
         return 3;
      }
   }

   return 0; // Success
}
Exemple #4
0
/* Fills more data into the Ogg stream parser */
static INLINE int buffer_data(APEG_LAYER *layer, ALOGG_INFO *info)
{
	if(!pack_feof(layer->pf))
	{
		int i = 98304;
		unsigned char *buf = ogg_sync_buffer(&info->osync, i);

		i = pack_fread(buf, i, layer->pf);
		if(i < 0)
			i = 0;
		ogg_sync_wrote(&info->osync, i);
		return i;
	}
	return 0;
}
PACKFILE *file_handle(char code_letter)
{
   static PACKFILE *file = NULL;
   static char current_code_letter = 0;
   char file_name[30];
   
   if (code_letter == 0)
   {
      current_code_letter = 0;
      if (file != NULL)
         pack_fclose(file);
      file = NULL;
   }
   else if (code_letter != current_code_letter)
   {
      if (file != NULL)
      {
         pack_fclose(file);
         file = NULL;
      }
   
      sprintf(file_name, "%s#%ccodes", code_defs_file_name, tolower(code_letter));
      packfile_password(PASSWORD);
      file = pack_fopen(file_name, F_READ_PACKED);
      packfile_password(NULL);
      current_code_letter = code_letter;
   }
   
   if (file == NULL)     
      return NULL;
      
   if (pack_feof(file) == TRUE) 
      return NULL;
      
   return file;
}
Exemple #6
0
static int decode_stream(APEG_LAYER *layer, BITMAP *target)
{
	int ret;
	int dw, dh;

	if((ret = setjmp(jmp_buffer)) != 0)
		return ret;

	apeg_get_video_size(&layer->stream, &dw, &dh);

	layer->stream.frame = 0;
	if((layer->stream.flags & APEG_HAS_VIDEO))
	{
		layer->stream.timer = -1;
		while(layer->stream.timer == -1)
			;
	}

	// loop through the pictures in the sequence
	do {
		layer->stream.frame_updated = -1;
		layer->stream.audio.flushed = FALSE;
		ret = APEG_OK;

		if((layer->stream.flags & APEG_HAS_AUDIO) && layer->multiple > 0.0)
		{
			ret = _apeg_audio_poll(layer);
			if((layer->stream.flags & APEG_HAS_VIDEO))
			{
				int t = _apeg_audio_get_position(layer);
				if(t >= 0)
					layer->stream.timer = (double)t*layer->stream.frame_rate/
					                      (double)layer->stream.audio.freq -
					                      layer->stream.frame;
			}
		}

		if((layer->stream.flags & APEG_HAS_VIDEO))
		{
			if(!layer->picture)
			{
				if((layer->stream.flags&APEG_MPG_VIDEO))
				{
					// Get the next MPEG header
					if(apeg_get_header(layer) == 1)
					{
						// Decode the next picture
						if(layer->picture_type != B_TYPE ||
						   !framedrop || layer->stream.timer <= 1)
							layer->picture = apeg_get_frame(layer);
					}
					// If end of stream, display the last frame
					else if((!framedrop || layer->stream.timer <= 1) &&
					        !layer->got_last)
					{
						layer->got_last = TRUE;
						layer->picture = layer->backward_frame;
					}
				}
				else
					layer->picture = altheora_get_frame(layer);

				if(pack_feof(layer->pf) &&
				   (!(layer->stream.flags&APEG_HAS_AUDIO)||
				    layer->multiple==0.0 || ret!=APEG_OK))
					ret = APEG_EOF;
			}

			if(layer->stream.timer > 0)
			{
				// Update frame and timer count
				++(layer->stream.frame);
				--(layer->stream.timer);

				// If we're not behind, update the display frame
				layer->stream.frame_updated = 0;
				if(layer->picture && (!framedrop || layer->stream.timer == 0))
				{
					apeg_display_frame(layer, layer->picture);
				}
				layer->picture = NULL;
			}
			if(layer->stream.frame_updated == 1 || layer->picture)
				ret = APEG_OK;
		}

		if(ret == APEG_OK)
		{
			if((!(layer->stream.flags & APEG_HAS_VIDEO) ||
			    layer->stream.frame_updated >= 0) && (ret = callback_proc(layer->stream.bitmap)))
				break;

			if(layer->stream.frame_updated < 0 && !layer->stream.audio.flushed)
				rest(1);
		}
	} while(ret == APEG_OK);

	return ret;
}
Exemple #7
0
int apeg_advance_stream(APEG_STREAM *stream, int loop)
{
	APEG_LAYER *layer = (APEG_LAYER*)stream;
	int ret;

	// Set the jump buffer
	if((ret = setjmp(jmp_buffer)) != 0)
		return ret;

	layer->stream.frame_updated = -1;
	layer->stream.audio.flushed = FALSE;
	ret = APEG_OK;

	if((layer->stream.flags&APEG_HAS_AUDIO) && layer->multiple > 0.0)
	{
		ret = _apeg_audio_poll(layer);
		if((layer->stream.flags&APEG_HAS_VIDEO))
		{
			int t = _apeg_audio_get_position(layer);
			if(t >= 0)
				layer->stream.timer = (double)t*stream->frame_rate/
				                      (double)stream->audio.freq -
				                      stream->frame;
		}
	}

	if((layer->stream.flags&APEG_HAS_VIDEO))
	{
		if(!layer->picture)
		{
			if((layer->stream.flags&APEG_MPG_VIDEO))
			{
				// Get the next MPEG header
				if(apeg_get_header(layer) == 1)
				{
					// Decode the next picture
					if(layer->picture_type != B_TYPE ||
					   !framedrop || layer->stream.timer <= 1)
						layer->picture = apeg_get_frame(layer);
				}
				// If end of stream, display the last frame
				else if((!framedrop || layer->stream.timer <= 1) &&
				        !layer->got_last)
				{
					layer->got_last = TRUE;
					layer->picture = layer->backward_frame;
				}
			}
			else
				layer->picture = altheora_get_frame(layer);

			if(pack_feof(layer->pf) && (!(layer->stream.flags&APEG_HAS_AUDIO)||
			                            layer->multiple==0.0 ||
			                            ret!=APEG_OK))
				ret = APEG_EOF;
		}

		if(layer->stream.timer > 0)
		{
			// Update frame and timer count
			++(layer->stream.frame);
			--(layer->stream.timer);

			// If we're not behind, update the display frame
			layer->stream.frame_updated = 0;
			if(layer->picture && (!framedrop || layer->stream.timer == 0))
				apeg_display_frame(layer, layer->picture);
			layer->picture = NULL;
		}
		if(layer->stream.frame_updated == 1 || layer->picture)
			ret = APEG_OK;
	}

	if(ret == APEG_EOF && loop)
		ret = apeg_reset_stream((APEG_STREAM*)layer);

	return ret;
}