Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

93 lignes
2.1KB

  1. #pragma once
  2. #if defined(_HAVE_FFMPEG_)
  3. extern "C" {
  4. #include "libavcodec/avcodec.h"
  5. #include "libavformat/avformat.h"
  6. #include "libavdevice/avdevice.h"
  7. #include "libavutil/avutil.h"
  8. #include "libavutil/audio_fifo.h"
  9. #include "libswresample/swresample.h"
  10. }
  11. #include "media-source.h"
  12. #include <string>
  13. #include <stdint.h>
  14. class FFLiveSource : public IMediaSource
  15. {
  16. public:
  17. FFLiveSource(const char *source);
  18. virtual ~FFLiveSource();
  19. public:
  20. virtual int Play();
  21. virtual int Pause();
  22. virtual int Seek(int64_t pos);
  23. virtual int SetSpeed(double speed);
  24. virtual int GetDuration(int64_t& duration) const;
  25. virtual int GetSDPMedia(std::string& sdp) const;
  26. virtual int GetRTPInfo(const char* uri, char *rtpinfo, size_t bytes) const;
  27. virtual int SetTransport(const char* track, std::shared_ptr<IRTPTransport> transport);
  28. private:
  29. int Open(const char* file);
  30. struct media_t;
  31. static void OnRTCPEvent(void* param, const struct rtcp_msg_t* msg);
  32. void OnRTCPEvent(const struct rtcp_msg_t* msg);
  33. static int SendRTCP(struct media_t* m, uint64_t clock);
  34. int SendBye();
  35. static void* RTPAlloc(void* param, int bytes);
  36. static void RTPFree(void* param, void *packet);
  37. static int RTPPacket(void* param, const void *packet, int bytes, uint32_t timestamp, int flags);
  38. void OnVideo(AVStream* stream);
  39. void OnAudio(AVStream* stream);
  40. int ReadFrame(AVPacket* avpkt);
  41. private:
  42. int64_t m_dts;
  43. uint64_t m_clock;
  44. std::string m_sdp;
  45. int m_status;
  46. int64_t m_pos;
  47. double m_speed;
  48. AVFormatContext* m_ic;
  49. AVPacket m_pkt;
  50. struct media_t
  51. {
  52. AVCodecContext* decoder;
  53. AVCodecContext* encoder;
  54. SwrContext* audio_swr; // audio only
  55. std::shared_ptr<AVAudioFifo> audio_fifo; // audio only
  56. void* rtp;
  57. int64_t dts_first; // first frame dts
  58. int64_t dts_last; // last frame dts
  59. uint64_t timestamp; // rtp timestamp
  60. uint64_t rtcp_clock;
  61. uint32_t ssrc;
  62. int bandwidth;
  63. int frequency;
  64. char name[64];
  65. int payload;
  66. void* packer; // rtp encoder
  67. uint8_t packet[2048];
  68. std::shared_ptr<IRTPTransport> transport;
  69. int track; // mp4 track
  70. };
  71. struct media_t m_media[2]; // 0-video, 1-audio
  72. int m_count;
  73. };
  74. #endif