ff-packet-queue.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2015 John R. Bradley <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "ff-clock.h"
  18. #include <libavformat/avformat.h>
  19. #include <pthread.h>
  20. #include <stdbool.h>
  21. #define FF_PACKET_FAIL -1
  22. #define FF_PACKET_EMPTY 0
  23. #define FF_PACKET_SUCCESS 1
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. struct ff_packet {
  28. AVPacket base;
  29. ff_clock_t *clock;
  30. };
  31. struct ff_packet_list {
  32. struct ff_packet packet;
  33. struct ff_packet_list *next;
  34. };
  35. struct ff_packet_queue {
  36. struct ff_packet_list *first_packet;
  37. struct ff_packet_list *last_packet;
  38. pthread_mutex_t mutex;
  39. pthread_cond_t cond;
  40. struct ff_packet flush_packet;
  41. int count;
  42. unsigned int total_size;
  43. bool abort;
  44. };
  45. typedef struct ff_packet_queue ff_packet_queue_t;
  46. bool packet_queue_init(struct ff_packet_queue *q);
  47. void packet_queue_abort(struct ff_packet_queue *q);
  48. void packet_queue_free(struct ff_packet_queue *q);
  49. int packet_queue_put(struct ff_packet_queue *q, struct ff_packet *packet);
  50. int packet_queue_put_flush_packet(struct ff_packet_queue *q);
  51. int packet_queue_get(struct ff_packet_queue *q, struct ff_packet *packet,
  52. bool block);
  53. void packet_queue_flush(struct ff_packet_queue *q);
  54. #ifdef __cplusplus
  55. }
  56. #endif