application.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * copyright (c) 2016 Zhang Rui
  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 AVUTIL_APPLICATION_H
  21. #define AVUTIL_APPLICATION_H
  22. #include "libavutil/log.h"
  23. #define AVAPP_EVENT_WILL_HTTP_OPEN 1 //AVAppHttpEvent
  24. #define AVAPP_EVENT_DID_HTTP_OPEN 2 //AVAppHttpEvent
  25. #define AVAPP_EVENT_WILL_HTTP_SEEK 3 //AVAppHttpEvent
  26. #define AVAPP_EVENT_DID_HTTP_SEEK 4 //AVAppHttpEvent
  27. #define AVAPP_EVENT_ASYNC_STATISTIC 0x11000 //AVAppAsyncStatistic
  28. #define AVAPP_EVENT_ASYNC_READ_SPEED 0x11001 //AVAppAsyncReadSpeed
  29. #define AVAPP_EVENT_IO_TRAFFIC 0x12204 //AVAppIOTraffic
  30. #define AVAPP_CTRL_WILL_TCP_OPEN 0x20001 //AVAppTcpIOControl
  31. #define AVAPP_CTRL_DID_TCP_OPEN 0x20002 //AVAppTcpIOControl
  32. #define AVAPP_CTRL_WILL_HTTP_OPEN 0x20003 //AVAppIOControl
  33. #define AVAPP_CTRL_WILL_LIVE_OPEN 0x20005 //AVAppIOControl
  34. #define AVAPP_CTRL_WILL_CONCAT_SEGMENT_OPEN 0x20007 //AVAppIOControl
  35. typedef struct AVAppIOControl {
  36. size_t size;
  37. char url[4096]; /* in, out */
  38. int segment_index; /* in, default = 0 */
  39. int retry_counter; /* in */
  40. int is_handled; /* out, default = false */
  41. int is_url_changed; /* out, default = false */
  42. } AVAppIOControl;
  43. typedef struct AVAppTcpIOControl {
  44. int error;
  45. int family;
  46. char ip[96];
  47. int port;
  48. int fd;
  49. } AVAppTcpIOControl;
  50. typedef struct AVAppAsyncStatistic {
  51. size_t size;
  52. int64_t buf_backwards;
  53. int64_t buf_forwards;
  54. int64_t buf_capacity;
  55. } AVAppAsyncStatistic;
  56. typedef struct AVAppAsyncReadSpeed {
  57. size_t size;
  58. int is_full_speed;
  59. int64_t io_bytes;
  60. int64_t elapsed_milli;
  61. } AVAppAsyncReadSpeed;
  62. typedef struct AVAppHttpEvent
  63. {
  64. void *obj;
  65. char url[4096];
  66. int64_t offset;
  67. int error;
  68. int http_code;
  69. int64_t filesize;
  70. } AVAppHttpEvent;
  71. typedef struct AVAppIOTraffic
  72. {
  73. void *obj;
  74. int bytes;
  75. } AVAppIOTraffic;
  76. typedef struct AVApplicationContext AVApplicationContext;
  77. struct AVApplicationContext {
  78. const AVClass *av_class; /**< information for av_log(). Set by av_application_open(). */
  79. void *opaque; /**< user data. */
  80. int (*func_on_app_event)(AVApplicationContext *h, int event_type ,void *obj, size_t size);
  81. };
  82. int av_application_alloc(AVApplicationContext **ph, void *opaque);
  83. int av_application_open(AVApplicationContext **ph, void *opaque);
  84. void av_application_close(AVApplicationContext *h);
  85. void av_application_closep(AVApplicationContext **ph);
  86. void av_application_on_http_event(AVApplicationContext *h, int event_type, AVAppHttpEvent *event);
  87. void av_application_will_http_open(AVApplicationContext *h, void *obj, const char *url);
  88. void av_application_did_http_open(AVApplicationContext *h, void *obj, const char *url, int error, int http_code, int64_t filesize);
  89. void av_application_will_http_seek(AVApplicationContext *h, void *obj, const char *url, int64_t offset);
  90. void av_application_did_http_seek(AVApplicationContext *h, void *obj, const char *url, int64_t offset, int error, int http_code);
  91. void av_application_did_io_tcp_read(AVApplicationContext *h, void *obj, int bytes);
  92. int av_application_on_io_control(AVApplicationContext *h, int event_type, AVAppIOControl *control);
  93. int av_application_on_tcp_will_open(AVApplicationContext *h);
  94. int av_application_on_tcp_did_open(AVApplicationContext *h, int error, int fd, AVAppTcpIOControl *control);
  95. void av_application_on_async_statistic(AVApplicationContext *h, AVAppAsyncStatistic *statistic);
  96. void av_application_on_async_read_speed(AVApplicationContext *h, AVAppAsyncReadSpeed *speed);
  97. #endif /* AVUTIL_APPLICATION_H */