RTPFile.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_AUDIO_CODING_TEST_RTPFILE_H_
  11. #define MODULES_AUDIO_CODING_TEST_RTPFILE_H_
  12. #include <stdio.h>
  13. #include <queue>
  14. #include "api/rtp_headers.h"
  15. #include "rtc_base/synchronization/rw_lock_wrapper.h"
  16. namespace webrtc {
  17. class RTPStream {
  18. public:
  19. virtual ~RTPStream() {}
  20. virtual void Write(const uint8_t payloadType,
  21. const uint32_t timeStamp,
  22. const int16_t seqNo,
  23. const uint8_t* payloadData,
  24. const size_t payloadSize,
  25. uint32_t frequency) = 0;
  26. // Returns the packet's payload size. Zero should be treated as an
  27. // end-of-stream (in the case that EndOfFile() is true) or an error.
  28. virtual size_t Read(RTPHeader* rtp_Header,
  29. uint8_t* payloadData,
  30. size_t payloadSize,
  31. uint32_t* offset) = 0;
  32. virtual bool EndOfFile() const = 0;
  33. protected:
  34. void MakeRTPheader(uint8_t* rtpHeader,
  35. uint8_t payloadType,
  36. int16_t seqNo,
  37. uint32_t timeStamp,
  38. uint32_t ssrc);
  39. void ParseRTPHeader(RTPHeader* rtp_header, const uint8_t* rtpHeader);
  40. };
  41. class RTPPacket {
  42. public:
  43. RTPPacket(uint8_t payloadType,
  44. uint32_t timeStamp,
  45. int16_t seqNo,
  46. const uint8_t* payloadData,
  47. size_t payloadSize,
  48. uint32_t frequency);
  49. ~RTPPacket();
  50. uint8_t payloadType;
  51. uint32_t timeStamp;
  52. int16_t seqNo;
  53. uint8_t* payloadData;
  54. size_t payloadSize;
  55. uint32_t frequency;
  56. };
  57. class RTPBuffer : public RTPStream {
  58. public:
  59. RTPBuffer();
  60. ~RTPBuffer();
  61. void Write(const uint8_t payloadType,
  62. const uint32_t timeStamp,
  63. const int16_t seqNo,
  64. const uint8_t* payloadData,
  65. const size_t payloadSize,
  66. uint32_t frequency) override;
  67. size_t Read(RTPHeader* rtp_header,
  68. uint8_t* payloadData,
  69. size_t payloadSize,
  70. uint32_t* offset) override;
  71. bool EndOfFile() const override;
  72. private:
  73. RWLockWrapper* _queueRWLock;
  74. std::queue<RTPPacket*> _rtpQueue;
  75. };
  76. class RTPFile : public RTPStream {
  77. public:
  78. ~RTPFile() {}
  79. RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
  80. void Open(const char* outFilename, const char* mode);
  81. void Close();
  82. void WriteHeader();
  83. void ReadHeader();
  84. void Write(const uint8_t payloadType,
  85. const uint32_t timeStamp,
  86. const int16_t seqNo,
  87. const uint8_t* payloadData,
  88. const size_t payloadSize,
  89. uint32_t frequency) override;
  90. size_t Read(RTPHeader* rtp_header,
  91. uint8_t* payloadData,
  92. size_t payloadSize,
  93. uint32_t* offset) override;
  94. bool EndOfFile() const override { return _rtpEOF; }
  95. private:
  96. FILE* _rtpFile;
  97. bool _rtpEOF;
  98. };
  99. } // namespace webrtc
  100. #endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_