stream_generator.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2013 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_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
  11. #define MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
  12. #include <stdint.h>
  13. #include <list>
  14. #include "modules/video_coding/packet.h"
  15. #include "rtc_base/constructor_magic.h"
  16. namespace webrtc {
  17. const unsigned int kDefaultBitrateKbps = 1000;
  18. const unsigned int kDefaultFrameRate = 25;
  19. const unsigned int kMaxPacketSize = 1500;
  20. const unsigned int kFrameSize =
  21. (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
  22. const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
  23. class StreamGenerator {
  24. public:
  25. StreamGenerator(uint16_t start_seq_num, int64_t current_time);
  26. void Init(uint16_t start_seq_num, int64_t current_time);
  27. // |time_ms| denotes the timestamp you want to put on the frame, and the unit
  28. // is millisecond. GenerateFrame will translate |time_ms| into a 90kHz
  29. // timestamp and put it on the frame.
  30. void GenerateFrame(VideoFrameType type,
  31. int num_media_packets,
  32. int num_empty_packets,
  33. int64_t time_ms);
  34. bool PopPacket(VCMPacket* packet, int index);
  35. void DropLastPacket();
  36. bool GetPacket(VCMPacket* packet, int index);
  37. bool NextPacket(VCMPacket* packet);
  38. uint16_t NextSequenceNumber() const;
  39. int PacketsRemaining() const;
  40. private:
  41. VCMPacket GeneratePacket(uint16_t sequence_number,
  42. uint32_t timestamp,
  43. unsigned int size,
  44. bool first_packet,
  45. bool marker_bit,
  46. VideoFrameType type);
  47. std::list<VCMPacket>::iterator GetPacketIterator(int index);
  48. std::list<VCMPacket> packets_;
  49. uint16_t sequence_number_;
  50. int64_t start_time_;
  51. uint8_t packet_buffer_[kMaxPacketSize];
  52. RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
  53. };
  54. } // namespace webrtc
  55. #endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_