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.

80 lines
2.0KB

  1. #pragma once
  2. #include "mpeg4-avc.h"
  3. #include "mpeg4-aac.h"
  4. #include "mpeg4-hevc.h"
  5. #include "media-source.h"
  6. #include "avpacket-queue.h"
  7. #include "mov-reader.h"
  8. #include "rtp-sender.h"
  9. #include <string>
  10. #include <stdio.h>
  11. #include <stdint.h>
  12. class MP4FileSource : public IMediaSource
  13. {
  14. public:
  15. MP4FileSource(const char *file);
  16. virtual ~MP4FileSource();
  17. public:
  18. virtual int Play();
  19. virtual int Pause();
  20. virtual int Seek(int64_t pos);
  21. virtual int SetSpeed(double speed);
  22. virtual int GetDuration(int64_t& duration) const;
  23. virtual int GetSDPMedia(std::string& sdp) const;
  24. virtual int GetRTPInfo(const char* uri, char *rtpinfo, size_t bytes) const;
  25. virtual int SetTransport(const char* track, std::shared_ptr<IRTPTransport> transport);
  26. int SendRTCP(uint64_t clock);
  27. private:
  28. struct media_t;
  29. struct media_t* FetchNextPacket();
  30. static void OnRTCPEvent(void* param, const struct rtcp_msg_t* msg);
  31. void OnRTCPEvent(const struct rtcp_msg_t* msg);
  32. int SendBye();
  33. static int OnRTPPacket(void* param, const void *packet, int bytes, uint32_t timestamp, int flags);
  34. static void MP4OnVideo(void* param, uint32_t track, uint8_t object, int width, int height, const void* extra, size_t bytes);
  35. 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);
  36. static void MP4OnRead(void* param, uint32_t track, const void* buffer, size_t bytes, int64_t pts, int64_t dts, int flags);
  37. private:
  38. int64_t m_dts;
  39. uint64_t m_clock;
  40. mov_reader_t* m_reader;
  41. FILE* m_fp;
  42. std::string m_sdp;
  43. int m_status;
  44. int64_t m_pos;
  45. double m_speed;
  46. struct mpeg4_aac_t m_aac;
  47. struct mpeg4_avc_t m_avc;
  48. struct mpeg4_hevc_t m_hevc;
  49. uint8_t m_packet[2 * 1024 * 1024];
  50. struct media_t
  51. {
  52. struct rtp_sender_t rtp;
  53. int64_t dts_first; // first frame timestamp
  54. int64_t dts_last; // last frame timestamp
  55. uint64_t rtcp_clock;
  56. struct avpacket_queue_t* pkts;
  57. std::shared_ptr<IRTPTransport> transport;
  58. int track; // mp4 track
  59. };
  60. struct media_t m_media[2]; // 0-video, 1-audio
  61. int m_count;
  62. };