callbacks.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <html>
  2. <head>
  3. <title>Tremor - 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>Tremor documentation</p></td>
  10. <td align=right><p class=tiny>Tremor version 1.0 - 20020403</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 Tremor 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. libvorbisidec 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 libvorbisidec, moving
  43. the access cursor to the requested position.<p>
  44. libvorbisidec expects the following behavior:
  45. <ul>
  46. <li>The seek function must always return -1 (failure) if the given
  47. data abstraction is not seekable. It may choose to always return -1
  48. if the application desires libvorbisidec to treat the Vorbis data
  49. strictly as a stream (which makes for a less expensive open
  50. operation).<p>
  51. <li>If the seek function initially indicates seekability, it must
  52. always succeed upon being given a valid seek request.<p>
  53. <li>The seek function must implement all of SEEK_SET, SEEK_CUR and
  54. SEEK_END. The implementation of SEEK_END should set the access cursor
  55. one past the last byte of accessible data, as would stdio
  56. <tt>fseek()</tt><p>
  57. </ul>
  58. <h2>Close function</h2>
  59. The close function should deallocate any access state used by the
  60. passed in instance of the data access abstraction and invalidate the
  61. instance handle. The close function is assumed to succeed.<p>
  62. One common use of callbacks and the close function is to change the
  63. behavior of libvorbisidec with respect to file closure for applications
  64. that <em>must</em> <tt>fclose</tt> data files themselves. By passing
  65. the normal stdio calls as callback functions, but passing a
  66. <tt>close_func</tt> that does nothing, an application may call <a
  67. href="ov_clear.html">ov_clear()</a> and then <tt>fclose()</tt> the
  68. file originally passed to libvorbisidec.
  69. <h2>Tell function</h2>
  70. The tell function is intended to mimic the
  71. behavior of <tt>ftell()</tt> and must return the byte position of the
  72. next data byte that would be read. If the data access cursor is at
  73. the end of the 'file' (pointing to one past the last byte of data, as
  74. it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell
  75. function must return the data position (and thus the total file size),
  76. not an error.<p>
  77. The tell function need not be provided if the data IO abstraction is
  78. not seekable.<p.
  79. <br><br>
  80. <hr noshade>
  81. <table border=0 width=100%>
  82. <tr valign=top>
  83. <td><p class=tiny>copyright &copy; 2002 Xiph.org</p></td>
  84. <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
  85. </tr><tr>
  86. <td><p class=tiny>Tremor documentation</p></td>
  87. <td align=right><p class=tiny>Tremor version 1.0 - 20020403</p></td>
  88. </tr>
  89. </table>
  90. </body>
  91. </html>