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.

82 line
2.0KB

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