webrtc_m130/modules/video_coding/test/stream_generator.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.9 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/video_coding/test/stream_generator.h"
#include <string.h>
#include <list>
#include "modules/video_coding/packet.h"
#include "system_wrappers/include/clock.h"
#include "test/gtest.h"
namespace webrtc {
StreamGenerator::StreamGenerator(uint16_t start_seq_num, int64_t current_time)
: packets_(), sequence_number_(start_seq_num), start_time_(current_time) {}
void StreamGenerator::Init(uint16_t start_seq_num, int64_t current_time) {
packets_.clear();
sequence_number_ = start_seq_num;
start_time_ = current_time;
memset(packet_buffer_, 0, sizeof(packet_buffer_));
}
void StreamGenerator::GenerateFrame(FrameType type,
int num_media_packets,
int num_empty_packets,
int64_t time_ms) {
uint32_t timestamp = 90 * (time_ms - start_time_);
for (int i = 0; i < num_media_packets; ++i) {
const int packet_size =
(kFrameSize + num_media_packets / 2) / num_media_packets;
bool marker_bit = (i == num_media_packets - 1);
packets_.push_back(GeneratePacket(sequence_number_, timestamp, packet_size,
(i == 0), marker_bit, type));
++sequence_number_;
}
for (int i = 0; i < num_empty_packets; ++i) {
packets_.push_back(GeneratePacket(sequence_number_, timestamp, 0, false,
false, kEmptyFrame));
++sequence_number_;
}
}
VCMPacket StreamGenerator::GeneratePacket(uint16_t sequence_number,
uint32_t timestamp,
unsigned int size,
bool first_packet,
bool marker_bit,
FrameType type) {
EXPECT_LT(size, kMaxPacketSize);
VCMPacket packet;
packet.seqNum = sequence_number;
packet.timestamp = timestamp;
packet.frameType = type;
Reland of Rename RTPVideoHeader.isFirstPacket to .is_first_packet_in_frame. Add RTC_DEPRACATed anonymous unions to not break downstream projects. Orignal issue's description: > commit 0ad21111fcc57a7e978edba3c4263f0062d7f9ff > Author: danilchap <danilchap@webrtc.org> > Date: Mon Dec 19 09:36:33 2016 -0800 > > Revert of Rename RTPVideoHeader.isFirstPacket to > .is_first_packet_in_frame. (patchset #1 id:1 of > https://codereview.webrtc.org/2574943003/ ) > > Reason for revert: > breaks downstream project. > > Can you make this change in a compatible way using anonymous > union: > union { > bool is_first_packet_in_frame; > RTC_DEPRECATED bool isFirstPacket; > }; > (unfortunetly this this treak breaks braced initialization in > rtp_rtcp_impl_unittest.cc, > so that should be rewritting in a more classic way) > > Original issue's description: > > Rename RTPVideoHeader.isFirstPacket to > > .is_first_packet_in_frame. > > > > Name should represent the actual meaning. > > > > BUG=None > > > > Review-Url: https://codereview.webrtc.org/2574943003 > > Cr-Commit-Position: refs/heads/master@{#15684} > > Committed: > > https://chromium.googlesource.com/external/webrtc/+/efde90838055f44ca05863ba020ca02c88b6d14c > > TBR=stefan@webrtc.org,sprang@webrtc.org,johan@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days > ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=None > > Review-Url: https://codereview.webrtc.org/2589783003 > Cr-Commit-Position: refs/heads/master@{#15686} > BUG=None Review-Url: https://codereview.webrtc.org/2614503002 Cr-Commit-Position: refs/heads/master@{#15987}
2017-01-10 04:21:35 -08:00
packet.is_first_packet_in_frame = first_packet;
packet.markerBit = marker_bit;
packet.sizeBytes = size;
packet.dataPtr = packet_buffer_;
Reland of Rename RTPVideoHeader.isFirstPacket to .is_first_packet_in_frame. Add RTC_DEPRACATed anonymous unions to not break downstream projects. Orignal issue's description: > commit 0ad21111fcc57a7e978edba3c4263f0062d7f9ff > Author: danilchap <danilchap@webrtc.org> > Date: Mon Dec 19 09:36:33 2016 -0800 > > Revert of Rename RTPVideoHeader.isFirstPacket to > .is_first_packet_in_frame. (patchset #1 id:1 of > https://codereview.webrtc.org/2574943003/ ) > > Reason for revert: > breaks downstream project. > > Can you make this change in a compatible way using anonymous > union: > union { > bool is_first_packet_in_frame; > RTC_DEPRECATED bool isFirstPacket; > }; > (unfortunetly this this treak breaks braced initialization in > rtp_rtcp_impl_unittest.cc, > so that should be rewritting in a more classic way) > > Original issue's description: > > Rename RTPVideoHeader.isFirstPacket to > > .is_first_packet_in_frame. > > > > Name should represent the actual meaning. > > > > BUG=None > > > > Review-Url: https://codereview.webrtc.org/2574943003 > > Cr-Commit-Position: refs/heads/master@{#15684} > > Committed: > > https://chromium.googlesource.com/external/webrtc/+/efde90838055f44ca05863ba020ca02c88b6d14c > > TBR=stefan@webrtc.org,sprang@webrtc.org,johan@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days > ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=None > > Review-Url: https://codereview.webrtc.org/2589783003 > Cr-Commit-Position: refs/heads/master@{#15686} > BUG=None Review-Url: https://codereview.webrtc.org/2614503002 Cr-Commit-Position: refs/heads/master@{#15987}
2017-01-10 04:21:35 -08:00
if (packet.is_first_packet_in_frame)
packet.completeNALU = kNaluStart;
else if (packet.markerBit)
packet.completeNALU = kNaluEnd;
else
packet.completeNALU = kNaluIncomplete;
return packet;
}
bool StreamGenerator::PopPacket(VCMPacket* packet, int index) {
std::list<VCMPacket>::iterator it = GetPacketIterator(index);
if (it == packets_.end())
return false;
if (packet)
*packet = (*it);
packets_.erase(it);
return true;
}
bool StreamGenerator::GetPacket(VCMPacket* packet, int index) {
std::list<VCMPacket>::iterator it = GetPacketIterator(index);
if (it == packets_.end())
return false;
if (packet)
*packet = (*it);
return true;
}
bool StreamGenerator::NextPacket(VCMPacket* packet) {
if (packets_.empty())
return false;
if (packet != NULL)
*packet = packets_.front();
packets_.pop_front();
return true;
}
void StreamGenerator::DropLastPacket() {
packets_.pop_back();
}
uint16_t StreamGenerator::NextSequenceNumber() const {
if (packets_.empty())
return sequence_number_;
return packets_.front().seqNum;
}
int StreamGenerator::PacketsRemaining() const {
return packets_.size();
}
std::list<VCMPacket>::iterator StreamGenerator::GetPacketIterator(int index) {
std::list<VCMPacket>::iterator it = packets_.begin();
for (int i = 0; i < index; ++i) {
++it;
if (it == packets_.end())
break;
}
return it;
}
} // namespace webrtc