callbacks.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <html>
  2. <head>
  3. <title>Vorbisfile - Callbacks and non-stdio I/O</title>
  4. <link rel=stylesheet href="style.css" type="text/css">
  5. </head>
  6. <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
  7. <table border=0 width=100%>
  8. <tr>
  9. <td><p class=tiny>Vorbisfile documentation</p></td>
  10. <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td>
  11. </tr>
  12. </table>
  13. <h1>Callbacks and non-stdio I/O</h1>
  14. Although stdio is convenient and nearly universally implemented as per
  15. ANSI C, it is not suited to all or even most potential uses of Vorbis.
  16. For additional flexibility, embedded applications may provide their
  17. own I/O functions for use with Vorbisfile when stdio is unavailable or not
  18. suitable. One common example is decoding a Vorbis stream from a
  19. memory buffer.<p>
  20. Use custom I/O functions by populating an <a
  21. href="ov_callbacks.html">ov_callbacks</a> structure and calling <a
  22. href="ov_open_callbacks.html">ov_open_callbacks()</a> or <a
  23. href="ov_test_callbacks.html">ov_test_callbacks()</a> rather than the
  24. typical <a href="ov_open.html">ov_open()</a> or <a
  25. href="ov_test.html">ov_test()</a>. Past the open call, use of
  26. libvorbisfile is identical to using it with stdio.
  27. <h2>Read function</h2>
  28. The read-like function provided in the <tt>read_func</tt> field is
  29. used to fetch the requested amount of data. It expects the fetch
  30. operation to function similar to file-access, that is, a multiple read
  31. operations will retrieve contiguous sequential pieces of data,
  32. advancing a position cursor after each read.<p>
  33. The following behaviors are also expected:<p>
  34. <ul>
  35. <li>a return of '0' indicates end-of-data (if the by-thread errno is unset)
  36. <li>short reads mean nothing special (short reads are not treated as error conditions)
  37. <li>a return of zero with the by-thread errno set to nonzero indicates a read error
  38. </ul>
  39. <p>
  40. <h2>Seek function</h2>
  41. The seek-like function provided in the <tt>seek_func</tt> field is
  42. used to request non-sequential data access by libvorbisfile, moving
  43. the access cursor to the requested position. The seek function is
  44. optional; if callbacks are only to handle non-seeking (streaming) data
  45. or the application wishes to force streaming behavior,
  46. <tt>seek_func</tt> and <tt>tell_func</tt> should be set to NULL. If
  47. the seek function is non-NULL, libvorbisfile mandates the following
  48. behavior:
  49. <ul>
  50. <li>The seek function must always return -1 (failure) if the given
  51. data abstraction is not seekable. It may choose to always return -1
  52. if the application desires libvorbisfile to treat the Vorbis data
  53. strictly as a stream (which makes for a less expensive open
  54. operation).<p>
  55. <li>If the seek function initially indicates seekability, it must
  56. always succeed upon being given a valid seek request.<p>
  57. <li>The seek function must implement all of SEEK_SET, SEEK_CUR and
  58. SEEK_END. The implementation of SEEK_END should set the access cursor
  59. one past the last byte of accessible data, as would stdio
  60. <tt>fseek()</tt><p>
  61. </ul>
  62. <h2>Close function</h2>
  63. The close function should deallocate any access state used by the
  64. passed in instance of the data access abstraction and invalidate the
  65. instance handle. The close function is assumed to succeed; its return
  66. code is not checked.<p>
  67. The <tt>close_func</tt> may be set to NULL to indicate that libvorbis
  68. should not attempt to close the file/data handle in <a
  69. href="ov_clear.html">ov_clear</a> but allow the application to handle
  70. file/data access cleanup itself. For example, by passing the normal
  71. stdio calls as callback functions, but passing a <tt>close_func</tt>
  72. that is NULL or does nothing (as in the case of OV_CALLBACKS_NOCLOSE), an
  73. application may call <a href="ov_clear.html">ov_clear()</a> and then
  74. later <tt>fclose()</tt> the file originally passed to libvorbisfile.
  75. <h2>Tell function</h2>
  76. The tell function is intended to mimic the
  77. behavior of <tt>ftell()</tt> and must return the byte position of the
  78. next data byte that would be read. If the data access cursor is at
  79. the end of the 'file' (pointing to one past the last byte of data, as
  80. it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell
  81. function must return the data position (and thus the total file size),
  82. not an error.<p>
  83. The tell function need not be provided if the data IO abstraction is
  84. not seekable, or the application wishes to force streaming
  85. behavior. In this case, the <tt>tell_func</tt> and <tt>seek_func</tt>
  86. fields should be set to NULL.<p>
  87. <br><br>
  88. <hr noshade>
  89. <table border=0 width=100%>
  90. <tr valign=top>
  91. <td><p class=tiny>copyright &copy; 2007 Xiph.org</p></td>
  92. <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
  93. </tr><tr>
  94. <td><p class=tiny>Vorbisfile documentation</p></td>
  95. <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td>
  96. </tr>
  97. </table>
  98. </body>
  99. </html>