You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
7.4 KiB

  1. /*
  2. cdrfifo.c , Copyright 2006 - 2016 Thomas Schmitt <scdbackup@gmx.net>
  3. A fd-to-fd or fd-to-memory fifo to be used within cdrskin or independently.
  4. By chaining of fifo objects, several fifos can be run simultaneously
  5. in fd-to-fd mode. Modes are controlled by parameter flag of
  6. Cdrfifo_try_to_work().
  7. Provided under GPL license within cdrskin and under BSD license elsewise.
  8. */
  9. #ifndef Cdrfifo_headerfile_includeD
  10. #define Cdrfifo_headerfile_includeD
  11. /** The fifo buffer which will smoothen the data stream from data provider
  12. to data consumer. Although this is not a mandatory lifesaver for modern
  13. burners any more, a fifo can speed up burning of data which is delivered
  14. with varying bandwidths (e.g. compressed archives created on the fly
  15. or mkisofs running at its speed limit.).
  16. This structure is opaque to applications and may only be used via
  17. the Cdrfifo*() methods described in cdrfifo.h .
  18. */
  19. struct CdrfifO;
  20. /** Create a fifo object.
  21. @param ff Returns the address of the new object.
  22. @param source_fd Filedescriptor opened to a readable data stream.
  23. @param dest_fd Filedescriptor opened to a writable data stream.
  24. To work with libburn, it needs to be attached to a
  25. struct burn_source object.
  26. @param chunk_size Size of buffer block for a single transaction (0=default)
  27. @param buffer_size Size of fifo buffer
  28. @param flag bit0= Debugging verbosity
  29. @return 1 on success, <=0 on failure
  30. */
  31. int Cdrfifo_new(struct CdrfifO **ff, int source_fd, int dest_fd,
  32. int chunk_size, int buffer_size, int flag);
  33. /** Release from memory a fifo object previously created by Cdrfifo_new().
  34. @param ff The victim (gets returned as NULL, call can stand *ff==NULL)
  35. @param flag Bitfield for control purposes:
  36. bit0= do not close destination fd
  37. */
  38. int Cdrfifo_destroy(struct CdrfifO **ff, int flag);
  39. /** Close any output fds */
  40. int Cdrfifo_close(struct CdrfifO *o, int flag);
  41. /** Close any output fds of o and its chain peers */
  42. int Cdrfifo_close_all(struct CdrfifO *o, int flag);
  43. int Cdrfifo_get_sizes(struct CdrfifO *o, int *chunk_size, int *buffer_size,
  44. int flag);
  45. /** Set a speed limit for buffer output.
  46. @param o The fifo object
  47. @param bytes_per_second >0 catch up slowdowns over the whole run time
  48. <0 catch up slowdowns only over one interval
  49. =0 disable speed limit
  50. */
  51. int Cdrfifo_set_speed_limit(struct CdrfifO *o, double bytes_per_second,
  52. int flag);
  53. /** Set a fixed size for input in order to cut off any unwanted tail
  54. @param o The fifo object
  55. @param idx index for fds attached via Cdrfifo_attach_follow_up_fds(),
  56. first attached is 0, <0 directs limit to active fd limit
  57. (i.e. first track is -1, second track is 0, third is 1, ...)
  58. */
  59. int Cdrfifo_set_fd_in_limit(struct CdrfifO *o, double fd_in_limit, int idx,
  60. int flag);
  61. int Cdrfifo_set_fds(struct CdrfifO *o, int source_fd, int dest_fd, int flag);
  62. int Cdrfifo_get_fds(struct CdrfifO *o, int *source_fd, int *dest_fd, int flag);
  63. /** Attach a further pair of input and output fd which will use the same
  64. fifo buffer when its predecessors are exhausted. Reading will start as
  65. soon as reading of the predecessor encounters EOF. Writing will start
  66. as soon as all pending predecessor data are written.
  67. @return index number of new item + 1, <=0 indicates error
  68. */
  69. int Cdrfifo_attach_follow_up_fds(struct CdrfifO *o, int source_fd, int dest_fd,
  70. int flag);
  71. /** Attach a further fifo which shall be processed simultaneously with this
  72. one by Cdrfifo_try_to_work() in fd-to-fd mode.
  73. */
  74. int Cdrfifo_attach_peer(struct CdrfifO *o, struct CdrfifO *next, int flag);
  75. /** Obtain buffer state.
  76. @param o The buffer object
  77. @param fill Returns the number of pending payload bytes in the buffer
  78. @param space Returns the number of unused buffer bytes
  79. @param flag unused yet
  80. @return -1=error , 0=inactive , 1=reading and writing ,
  81. 2=reading ended (but still writing)
  82. */
  83. int Cdrfifo_get_buffer_state(struct CdrfifO *o,int *fill,int *space,int flag);
  84. int Cdrfifo_get_counters(struct CdrfifO *o,
  85. double *in_counter, double *out_counter, int flag);
  86. /** reads min_fill and begins measurement interval for next min_fill */
  87. int Cdrfifo_next_interval(struct CdrfifO *o, int *min_fill, int flag);
  88. int Cdrfifo_get_min_fill(struct CdrfifO *o, int *total_min_fill,
  89. int *interval_min_fill, int flag);
  90. int Cdrfifo_get_cdr_counters(struct CdrfifO *o,
  91. double *put_counter, double *get_counter,
  92. double *empty_counter, double *full_counter,
  93. int flag);
  94. /** Inquire the eventually detected size of an eventual ISO-9660 file system
  95. @return 0=no ISO size detected, 1=size_in_bytes is valid
  96. */
  97. int Cdrfifo_get_iso_fs_size(struct CdrfifO *o, double *size_in_bytes,int flag);
  98. /** Take over the eventually memorized blocks 16 to 31 of input (2 kB each).
  99. The fifo forgets the blocks by this call. I.e. a second one will return 0.
  100. After this call it is the responsibility of the caller to dispose the
  101. retrieved memory via call free().
  102. @param pt Will be filled either with NULL or a pointer to 32 kB of data
  103. @return 0=nothing is buffered, 1=pt points to valid freeable data
  104. */
  105. int Cdrfifo_adopt_iso_fs_descr(struct CdrfifO *o, char **pt, int flag);
  106. /** Check for pending data at the fifo's source file descriptor and wether the
  107. fifo is ready to take them. Simultaneously check the buffer for existing
  108. data and the destination fd for readiness to accept some. If so, a small
  109. chunk of data is transferred to and/or from the fifo.
  110. This is done for the given fifo object and all members of its next-chain.
  111. The check and transactions are repeated until a given timespan has elapsed.
  112. libburn applications call this function in the burn loop instead of sleep().
  113. It may also be used instead of read(). Then it returns as soon as an output
  114. transaction would be performed. See flag:bit2.
  115. @param o The fifo object
  116. @param wait_usec The time in microseconds after which the function shall
  117. return.
  118. @param reply_buffer with bit2: Returns write-ready buffer chunk and must
  119. be able to take at least chunk_size bytes
  120. @param reply_count with bit2: Returns number of writeable bytes in reply_pt
  121. @param flag Bitfield for control purposes:
  122. bit0= Enable debug pacifier (same with Cdrfifo_debuG)
  123. bit1= Do not write, just fill buffer
  124. bit2= fd-to-memory mode (else fd-to-fd mode):
  125. Rather than writing a chunk return it and its size.
  126. No simultaneous processing of chained fifos.
  127. bit3= With bit2: do not check destination fd for readiness
  128. @return <0 = error , 0 = idle , 1 = did some work , 2 = all work is done
  129. */
  130. int Cdrfifo_try_to_work(struct CdrfifO *o, int wait_usec,
  131. char *reply_buffer, int *reply_count, int flag);
  132. /** Fill the fifo as far as possible without writing to destination fd.
  133. @param size if >=0 : end filling after the given number of bytes
  134. @return 1 on success, <=0 on failure
  135. */
  136. int Cdrfifo_fill(struct CdrfifO *o, int size, int flag);
  137. #endif /* Cdrfifo_headerfile_includeD */