ffmpeg_mux.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Muxer internal APIs - should not be included outside of ffmpeg_mux*
  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 FFTOOLS_FFMPEG_MUX_H
  21. #define FFTOOLS_FFMPEG_MUX_H
  22. #include <stdatomic.h>
  23. #include <stdint.h>
  24. #include "thread_queue.h"
  25. #include "libavformat/avformat.h"
  26. #include "libavcodec/packet.h"
  27. #include "libavutil/dict.h"
  28. #include "libavutil/fifo.h"
  29. #include "libavutil/thread.h"
  30. typedef struct MuxStream {
  31. OutputStream ost;
  32. // name used for logging
  33. char log_name[32];
  34. /* the packets are buffered here until the muxer is ready to be initialized */
  35. AVFifo *muxing_queue;
  36. AVBSFContext *bsf_ctx;
  37. AVPacket *bsf_pkt;
  38. AVPacket *pkt;
  39. EncStats stats;
  40. int64_t max_frames;
  41. /*
  42. * The size of the AVPackets' buffers in queue.
  43. * Updated when a packet is either pushed or pulled from the queue.
  44. */
  45. size_t muxing_queue_data_size;
  46. int max_muxing_queue_size;
  47. /* Threshold after which max_muxing_queue_size will be in effect */
  48. size_t muxing_queue_data_threshold;
  49. // timestamp from which the streamcopied streams should start,
  50. // in AV_TIME_BASE_Q;
  51. // everything before it should be discarded
  52. int64_t ts_copy_start;
  53. /* dts of the last packet sent to the muxer, in the stream timebase
  54. * used for making up missing dts values */
  55. int64_t last_mux_dts;
  56. int64_t stream_duration;
  57. AVRational stream_duration_tb;
  58. // state for av_rescale_delta() call for audio in write_packet()
  59. int64_t ts_rescale_delta_last;
  60. // combined size of all the packets sent to the muxer
  61. uint64_t data_size_mux;
  62. int copy_initial_nonkeyframes;
  63. int copy_prior_start;
  64. int streamcopy_started;
  65. } MuxStream;
  66. typedef struct Muxer {
  67. OutputFile of;
  68. // name used for logging
  69. char log_name[32];
  70. AVFormatContext *fc;
  71. pthread_t thread;
  72. ThreadQueue *tq;
  73. AVDictionary *opts;
  74. int thread_queue_size;
  75. /* filesize limit expressed in bytes */
  76. int64_t limit_filesize;
  77. atomic_int_least64_t last_filesize;
  78. int header_written;
  79. SyncQueue *sq_mux;
  80. AVPacket *sq_pkt;
  81. } Muxer;
  82. /* whether we want to print an SDP, set in of_open() */
  83. extern int want_sdp;
  84. int mux_check_init(Muxer *mux);
  85. static MuxStream *ms_from_ost(OutputStream *ost)
  86. {
  87. return (MuxStream*)ost;
  88. }
  89. #endif /* FFTOOLS_FFMPEG_MUX_H */