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.

220 lines
7.9KB

  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVFORMAT_INTERNAL_H
  21. #define AVFORMAT_INTERNAL_H
  22. #include <stdint.h>
  23. #include "avformat.h"
  24. typedef struct AVCodecTag {
  25. enum CodecID id;
  26. unsigned int tag;
  27. } AVCodecTag;
  28. void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
  29. #ifdef __GNUC__
  30. #define dynarray_add(tab, nb_ptr, elem)\
  31. do {\
  32. __typeof__(tab) _tab = (tab);\
  33. __typeof__(elem) _elem = (elem);\
  34. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  35. ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
  36. } while(0)
  37. #else
  38. #define dynarray_add(tab, nb_ptr, elem)\
  39. do {\
  40. ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
  41. } while(0)
  42. #endif
  43. time_t mktimegm(struct tm *tm);
  44. struct tm *brktimegm(time_t secs, struct tm *tm);
  45. const char *small_strptime(const char *p, const char *fmt,
  46. struct tm *dt);
  47. char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
  48. /**
  49. * Parse a string of hexadecimal strings. Any space between the hexadecimal
  50. * digits is ignored.
  51. *
  52. * @param data if non-null, the parsed data is written to this pointer
  53. * @param p the string to parse
  54. * @return the number of bytes written (or to be written, if data is null)
  55. */
  56. int ff_hex_to_data(uint8_t *data, const char *p);
  57. void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx);
  58. /**
  59. * Add packet to AVFormatContext->packet_buffer list, determining its
  60. * interleaved position using compare() function argument.
  61. */
  62. void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
  63. int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
  64. void ff_read_frame_flush(AVFormatContext *s);
  65. #define NTP_OFFSET 2208988800ULL
  66. #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL)
  67. /** Get the current time since NTP epoch in microseconds. */
  68. uint64_t ff_ntp_time(void);
  69. /**
  70. * Probe a bytestream to determine the input format. Each time a probe returns
  71. * with a score that is too low, the probe buffer size is increased and another
  72. * attempt is made. When the maximum probe size is reached, the input format
  73. * with the highest score is returned.
  74. *
  75. * @param pb the bytestream to probe, it may be closed and opened again
  76. * @param fmt the input format is put here
  77. * @param filename the filename of the stream
  78. * @param logctx the log context
  79. * @param offset the offset within the bytestream to probe from
  80. * @param max_probe_size the maximum probe buffer size (zero for default)
  81. * @return 0 in case of success, a negative value corresponding to an
  82. * AVERROR code otherwise
  83. */
  84. int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt,
  85. const char *filename, void *logctx,
  86. unsigned int offset, unsigned int max_probe_size);
  87. #if LIBAVFORMAT_VERSION_MAJOR < 53
  88. /**
  89. * @deprecated use av_url_split() instead
  90. */
  91. void ff_url_split(char *proto, int proto_size,
  92. char *authorization, int authorization_size,
  93. char *hostname, int hostname_size,
  94. int *port_ptr,
  95. char *path, int path_size,
  96. const char *url);
  97. #endif
  98. /**
  99. * Assemble a URL string from components. This is the reverse operation
  100. * of av_url_split.
  101. *
  102. * Note, this requires networking to be initialized, so the caller must
  103. * ensure ff_network_init has been called.
  104. *
  105. * @see av_url_split
  106. *
  107. * @param str the buffer to fill with the url
  108. * @param size the size of the str buffer
  109. * @param proto the protocol identifier, if null, the separator
  110. * after the identifier is left out, too
  111. * @param authorization an optional authorization string, may be null.
  112. * An empty string is treated the same as a null string.
  113. * @param hostname the host name string
  114. * @param port the port number, left out from the string if negative
  115. * @param fmt a generic format string for everything to add after the
  116. * host/port, may be null
  117. * @return the number of characters written to the destination buffer
  118. */
  119. int ff_url_join(char *str, int size, const char *proto,
  120. const char *authorization, const char *hostname,
  121. int port, const char *fmt, ...);
  122. /**
  123. * Append the media-specific SDP fragment for the media stream c
  124. * to the buffer buff.
  125. *
  126. * Note, the buffer needs to be initialized, since it is appended to
  127. * existing content.
  128. *
  129. * @param buff the buffer to append the SDP fragment to
  130. * @param size the size of the buff buffer
  131. * @param c the AVCodecContext of the media to describe
  132. * @param dest_addr the destination address of the media stream, may be NULL
  133. * @param port the destination port of the media stream, 0 if unknown
  134. * @param ttl the time to live of the stream, 0 if not multicast
  135. */
  136. void ff_sdp_write_media(char *buff, int size, AVCodecContext *c,
  137. const char *dest_addr, int port, int ttl);
  138. /**
  139. * Write a packet to another muxer than the one the user originally
  140. * intended. Useful when chaining muxers, where one muxer internally
  141. * writes a received packet to another muxer.
  142. *
  143. * @param dst the muxer to write the packet to
  144. * @param dst_stream the stream index within dst to write the packet to
  145. * @param pkt the packet to be written
  146. * @param src the muxer the packet originally was intended for
  147. * @return the value av_write_frame returned
  148. */
  149. int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
  150. AVFormatContext *src);
  151. /**
  152. * Get the length in bytes which is needed to store val as v.
  153. */
  154. int ff_get_v_length(uint64_t val);
  155. /**
  156. * Put val using a variable number of bytes.
  157. */
  158. void ff_put_v(ByteIOContext *bc, uint64_t val);
  159. /**
  160. * Read a whole line of text from ByteIOContext. Stop reading after reaching
  161. * either a \n, a \0 or EOF. The returned string is always \0 terminated,
  162. * and may be truncated if the buffer is too small.
  163. *
  164. * @param s the read-only ByteIOContext
  165. * @param buf buffer to store the read line
  166. * @param maxlen size of the buffer
  167. * @return the length of the string written in the buffer, not including the
  168. * final \0
  169. */
  170. int ff_get_line(ByteIOContext *s, char *buf, int maxlen);
  171. #define SPACE_CHARS " \t\r\n"
  172. /**
  173. * Callback function type for ff_parse_key_value.
  174. *
  175. * @param key a pointer to the key
  176. * @param key_len the number of bytes that belong to the key, including the '='
  177. * char
  178. * @param dest return the destination pointer for the value in *dest, may
  179. * be null to ignore the value
  180. * @param dest_len the length of the *dest buffer
  181. */
  182. typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
  183. int key_len, char **dest, int *dest_len);
  184. /**
  185. * Parse a string with comma-separated key=value pairs. The value strings
  186. * may be quoted and may contain escaped characters within quoted strings.
  187. *
  188. * @param str the string to parse
  189. * @param callback_get_buf function that returns where to store the
  190. * unescaped value string.
  191. * @param context the opaque context pointer to pass to callback_get_buf
  192. */
  193. void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
  194. void *context);
  195. #endif /* AVFORMAT_INTERNAL_H */