stream_generator.h (2438B)
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_DEPRECATED_STREAM_GENERATOR_H_ 11 #define MODULES_VIDEO_CODING_DEPRECATED_STREAM_GENERATOR_H_ 12 13 #include <stdint.h> 14 15 #include <list> 16 17 #include "api/video/video_frame_type.h" 18 #include "modules/video_coding/deprecated/packet.h" 19 20 namespace webrtc { 21 22 const unsigned int kDefaultBitrateKbps = 1000; 23 const unsigned int kDefaultFrameRate = 25; 24 const unsigned int kMaxPacketSize = 1500; 25 const unsigned int kFrameSize = 26 (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8); 27 const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate; 28 29 class StreamGenerator { 30 public: 31 StreamGenerator(uint16_t start_seq_num, int64_t current_time); 32 33 StreamGenerator(const StreamGenerator&) = delete; 34 StreamGenerator& operator=(const StreamGenerator&) = delete; 35 36 void Init(uint16_t start_seq_num, int64_t current_time); 37 38 // `time_ms` denotes the timestamp you want to put on the frame, and the unit 39 // is millisecond. GenerateFrame will translate `time_ms` into a 90kHz 40 // timestamp and put it on the frame. 41 void GenerateFrame(VideoFrameType type, 42 int num_media_packets, 43 int num_empty_packets, 44 int64_t time_ms); 45 46 bool PopPacket(VCMPacket* packet, int index); 47 void DropLastPacket(); 48 49 bool GetPacket(VCMPacket* packet, int index); 50 51 bool NextPacket(VCMPacket* packet); 52 53 uint16_t NextSequenceNumber() const; 54 55 int PacketsRemaining() const; 56 57 private: 58 VCMPacket GeneratePacket(uint16_t sequence_number, 59 uint32_t timestamp, 60 unsigned int size, 61 bool first_packet, 62 bool marker_bit, 63 VideoFrameType type); 64 65 std::list<VCMPacket>::iterator GetPacketIterator(int index); 66 67 std::list<VCMPacket> packets_; 68 uint16_t sequence_number_; 69 int64_t start_time_; 70 uint8_t packet_buffer_[kMaxPacketSize]; 71 }; 72 73 } // namespace webrtc 74 75 #endif // MODULES_VIDEO_CODING_DEPRECATED_STREAM_GENERATOR_H_