コード例 #1
0
APEG_STREAM* get_theora_size(const char *fileName, int *width, int *height)
{
  APEG_STREAM* oggVid = apeg_open_stream(fileName);
  if (oggVid != NULL)
  {
    apeg_get_video_size(oggVid, width, height);
  }
  else
  {
    *width = 0;
    *height = 0;
  }
  return oggVid;
}
コード例 #2
0
ファイル: mpeg1dec.c プロジェクト: Cheeseness/ags
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;
}