[Vorbis-dev] Introducing ov_open_callbacksp and ov_clearp

Armel Asselin armel at mobipocket.com
Tue Sep 7 01:34:58 PDT 2004


Hello,

I've been looking to the libvorbisfile and got into troubles when trying to
use it: I need to compile it on a PalmOS and the libvorbisfile must be
compiled in ARM whereas calling code is in 68K. This implies that the
interface ov_open_callback is not usable because the OggVorbis_File *vf must
point to something in the target architecture (ARM) whereas the caller
cannot do that.

As well as for this I need a ov_info_basic function so that no internal
structure is returned (which seems to me a somewhat bad design because
you'll get stuck with that: each time an internal modification will occur,
outer code may have to be fixed or re-compiled).

I propose to add that to vorbisfile.h:
/* same as ov_clear but frees memory associated to vf too */
IMPORT_C int ov_clearp(OggVorbis_File *vf);
/* same ov_open_callbacks but also allocates the OggVorbis_File object into
*vf, if any error happen, returns same code as ov_open_callbacks and free
any memory allocated */
IMPORT_C int ov_open_callbacksp(void *datasource, OggVorbis_File **vf,
		char *initial, long ibytes, ov_callbacks callbacks);
IMPORT_C int ov_info_basic(OggVorbis_File *vf,int link, int *channels, long
*rate);

And that to vorbisfile.c:

EXPORT_C int ov_open_callbacksp(void *f,OggVorbis_File **vf,char
*initial,long ibytes,
    ov_callbacks callbacks){
  int ret;
  if (vf==NULL) return -1;
  *vf=_ogg_malloc(sizeof(OggVorbis_File));
  if (*vf==NULL) return -1;
  ret=_ov_open1(f,*vf,initial,ibytes,callbacks);
  if(ret!=0 || (ret=_ov_open2(*vf)) != 0)
  {
    ov_clearp(*vf);
    *vf = NULL;
  	return ret;
  }
  return 0;
}

EXPORT_C int ov_clearp(OggVorbis_File *vf){
	ov_clear(vf);
	if (vf)
		_ogg_free(vf);
	return 0;
}

EXPORT_C int ov_info_basic(OggVorbis_File *vf,int link, int *channels, long
*rate)
{
	vorbis_info *vi = ov_info(vf, link);
	if (vi==NULL)
		return -1;
	*channels = vi->channels;
	*rate = vi->rate;
	return 0;
}

Please tell if it interests anybody, if someone want to integrate it and has
problem feel free to ask any question (I do not know how I could had that to
the lib)

Best regards
Armel



More information about the Vorbis-dev mailing list