ogg_packer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (c) 2017 Jean-Marc Valin */
  2. /*
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  12. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  13. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  14. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  15. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef OGGPACKER_H
  24. # define OGGPACKER_H
  25. # if defined(__cplusplus)
  26. extern "C" {
  27. # endif
  28. typedef unsigned long long oggp_uint64;
  29. typedef unsigned oggp_uint32;
  30. typedef int oggp_int32;
  31. typedef struct oggpacker oggpacker;
  32. /** Allocates an oggpacker object */
  33. oggpacker *oggp_create(oggp_int32 serialno);
  34. /** Frees memory associated with an oggpacker object */
  35. void oggp_destroy(oggpacker *oggp);
  36. /** Sets the maximum muxing delay in granulepos units. Pages will be auto-flushed
  37. to enforce the delay and to avoid continued pages if possible. */
  38. void oggp_set_muxing_delay(oggpacker *oggp, oggp_uint64 delay);
  39. /** Get a buffer where to write the next packet. The buffer will have
  40. size "bytes", but fewer bytes can be written. The buffer remains valid through
  41. a call to oggp_close_page() or oggp_get_next_page(), but is invalidated by
  42. another call to oggp_get_packet_buffer() or by a call to oggp_commit_packet(). */
  43. unsigned char *oggp_get_packet_buffer(oggpacker *oggp, oggp_int32 bytes);
  44. /** Tells the oggpacker that the packet buffer obtained from
  45. oggp_get_packet_buffer() has been filled and the number of bytes written
  46. has to be no more than what was originally asked for. */
  47. int oggp_commit_packet(oggpacker *oggp, oggp_int32 bytes, oggp_uint64 granulepos, int eos);
  48. /** Create a page from the data written so far (and not yet part of a previous page).
  49. If there is too much data for one page, then all page continuations will be closed too. */
  50. int oggp_flush_page(oggpacker *oggp);
  51. /** Get a pointer to the contents of the next available page. Pointer is
  52. invalidated on the next call to oggp_get_next_page() or oggp_commit_packet(). */
  53. int oggp_get_next_page(oggpacker *oggp, unsigned char **page, oggp_int32 *bytes);
  54. /** Creates a new (chained) stream. This closes all outstanding pages. These
  55. pages remain available with oggp_get_next_page(). */
  56. int oggp_chain(oggpacker *oggp, oggp_int32 serialno);
  57. # if defined(__cplusplus)
  58. }
  59. # endif
  60. #endif