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.

152 lines
4.7KB

  1. /* output byte stream handling */
  2. typedef long long offset_t;
  3. /* unbuffered I/O */
  4. struct URLContext {
  5. struct URLProtocol *prot;
  6. int flags;
  7. int is_streamed; /* true if streamed (no seek possible), default = false */
  8. int packet_size;
  9. void *priv_data;
  10. };
  11. typedef struct URLFormat {
  12. char format_name[32];
  13. int sample_rate;
  14. int frame_rate;
  15. int channels;
  16. int height;
  17. int width;
  18. int pix_fmt;
  19. } URLFormat;
  20. typedef struct URLContext URLContext;
  21. typedef struct URLPollEntry {
  22. URLContext *handle;
  23. int events;
  24. int revents;
  25. } URLPollEntry;
  26. #define URL_RDONLY 0
  27. #define URL_WRONLY 1
  28. int url_open(URLContext **h, const char *filename, int flags);
  29. int url_read(URLContext *h, unsigned char *buf, int size);
  30. int url_write(URLContext *h, unsigned char *buf, int size);
  31. offset_t url_seek(URLContext *h, offset_t pos, int whence);
  32. int url_getformat(URLContext *h, URLFormat *f);
  33. int url_close(URLContext *h);
  34. int url_exist(const char *filename);
  35. offset_t url_filesize(URLContext *h);
  36. /* not implemented */
  37. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  38. typedef struct URLProtocol {
  39. const char *name;
  40. int (*url_open)(URLContext *h, const char *filename, int flags);
  41. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  42. int (*url_write)(URLContext *h, unsigned char *buf, int size);
  43. offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
  44. int (*url_close)(URLContext *h);
  45. /* get precise information about the format, if available. return
  46. -ENODATA if not available */
  47. int (*url_getformat)(URLContext *h, URLFormat *f);
  48. struct URLProtocol *next;
  49. } URLProtocol;
  50. extern URLProtocol *first_protocol;
  51. int register_protocol(URLProtocol *protocol);
  52. typedef struct {
  53. unsigned char *buffer;
  54. int buffer_size;
  55. unsigned char *buf_ptr, *buf_end;
  56. void *opaque;
  57. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
  58. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
  59. int (*seek)(void *opaque, offset_t offset, int whence);
  60. offset_t pos; /* position in the file of the current buffer */
  61. int must_flush; /* true if the next seek should flush */
  62. int eof_reached; /* true if eof reached */
  63. int write_flag; /* true if open for writing */
  64. int is_streamed;
  65. int packet_size;
  66. } ByteIOContext;
  67. int init_put_byte(ByteIOContext *s,
  68. unsigned char *buffer,
  69. int buffer_size,
  70. int write_flag,
  71. void *opaque,
  72. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
  73. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
  74. int (*seek)(void *opaque, offset_t offset, int whence));
  75. void put_byte(ByteIOContext *s, int b);
  76. void put_buffer(ByteIOContext *s, unsigned char *buf, int size);
  77. void put_le64(ByteIOContext *s, unsigned long long val);
  78. void put_be64(ByteIOContext *s, unsigned long long val);
  79. void put_le32(ByteIOContext *s, unsigned int val);
  80. void put_be32(ByteIOContext *s, unsigned int val);
  81. void put_le16(ByteIOContext *s, unsigned int val);
  82. void put_be16(ByteIOContext *s, unsigned int val);
  83. void put_tag(ByteIOContext *s, char *tag);
  84. offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
  85. void url_fskip(ByteIOContext *s, offset_t offset);
  86. offset_t url_ftell(ByteIOContext *s);
  87. int url_feof(ByteIOContext *s);
  88. void put_flush_packet(ByteIOContext *s);
  89. int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
  90. int get_byte(ByteIOContext *s);
  91. unsigned int get_le32(ByteIOContext *s);
  92. unsigned long long get_le64(ByteIOContext *s);
  93. unsigned int get_le16(ByteIOContext *s);
  94. unsigned int get_be16(ByteIOContext *s);
  95. unsigned int get_be32(ByteIOContext *s);
  96. unsigned long long get_be64(ByteIOContext *s);
  97. extern inline int url_is_streamed(ByteIOContext *s)
  98. {
  99. return s->is_streamed;
  100. }
  101. /* get the prefered packet size of the device. All I/Os should be done
  102. by multiple of this size */
  103. extern inline int url_get_packet_size(ByteIOContext *s)
  104. {
  105. return s->packet_size;
  106. }
  107. int url_fdopen(ByteIOContext *s, URLContext *h);
  108. int url_setbufsize(ByteIOContext *s, int buf_size);
  109. int url_fopen(ByteIOContext *s, const char *filename, int flags);
  110. int url_fclose(ByteIOContext *s);
  111. URLContext *url_fileno(ByteIOContext *s);
  112. int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
  113. int url_close_buf(ByteIOContext *s);
  114. /* file.c */
  115. extern URLProtocol file_protocol;
  116. extern URLProtocol pipe_protocol;
  117. /* udp.c */
  118. extern URLProtocol udp_protocol;
  119. /* http.c */
  120. extern URLProtocol http_protocol;
  121. /* audio.c */
  122. extern const char *audio_device;
  123. extern URLProtocol audio_protocol;
  124. /* grab.c */
  125. extern const char *v4l_device;
  126. extern URLProtocol video_protocol;