2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-06 10:11:25 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-07-16 12:32:05 +00:00
|
|
|
#include "webrtc/modules/video_coding/main/source/frame_buffer.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <assert.h>
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-03-17 21:54:50 +00:00
|
|
|
#include "webrtc/base/checks.h"
|
2015-11-16 16:39:06 -08:00
|
|
|
#include "webrtc/base/logging.h"
|
2013-07-29 21:48:11 +00:00
|
|
|
#include "webrtc/modules/video_coding/main/source/packet.h"
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2011-09-08 06:50:28 +00:00
|
|
|
VCMFrameBuffer::VCMFrameBuffer()
|
|
|
|
|
:
|
2013-06-27 15:20:14 +00:00
|
|
|
_state(kStateEmpty),
|
2011-07-07 08:21:25 +00:00
|
|
|
_nackCount(0),
|
2011-09-08 06:50:28 +00:00
|
|
|
_latestPacketTimeMs(-1) {
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-08 06:50:28 +00:00
|
|
|
VCMFrameBuffer::~VCMFrameBuffer() {
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::VCMFrameBuffer(const VCMFrameBuffer& rhs)
|
2011-07-07 08:21:25 +00:00
|
|
|
:
|
|
|
|
|
VCMEncodedFrame(rhs),
|
|
|
|
|
_state(rhs._state),
|
|
|
|
|
_sessionInfo(),
|
|
|
|
|
_nackCount(rhs._nackCount),
|
2013-07-29 21:48:11 +00:00
|
|
|
_latestPacketTimeMs(rhs._latestPacketTimeMs) {
|
2011-07-07 08:21:25 +00:00
|
|
|
_sessionInfo = rhs._sessionInfo;
|
2012-01-10 11:45:05 +00:00
|
|
|
_sessionInfo.UpdateDataPointers(rhs._buffer, _buffer);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
webrtc::FrameType
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::FrameType() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return _sessionInfo.FrameType();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
int32_t
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::GetLowSeqNum() const {
|
2011-12-13 07:54:56 +00:00
|
|
|
return _sessionInfo.LowSequenceNumber();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
int32_t
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::GetHighSeqNum() const {
|
2011-12-13 07:54:56 +00:00
|
|
|
return _sessionInfo.HighSequenceNumber();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-19 15:55:39 +00:00
|
|
|
int VCMFrameBuffer::PictureId() const {
|
|
|
|
|
return _sessionInfo.PictureId();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 19:04:47 +00:00
|
|
|
int VCMFrameBuffer::TemporalId() const {
|
|
|
|
|
return _sessionInfo.TemporalId();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 14:11:06 +00:00
|
|
|
bool VCMFrameBuffer::LayerSync() const {
|
|
|
|
|
return _sessionInfo.LayerSync();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 19:04:47 +00:00
|
|
|
int VCMFrameBuffer::Tl0PicId() const {
|
|
|
|
|
return _sessionInfo.Tl0PicId();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-12 02:29:34 +00:00
|
|
|
bool VCMFrameBuffer::NonReference() const {
|
|
|
|
|
return _sessionInfo.NonReference();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 00:27:14 -07:00
|
|
|
void VCMFrameBuffer::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) {
|
|
|
|
|
_sessionInfo.SetGofInfo(gof_info, idx);
|
|
|
|
|
// TODO(asapersson): Consider adding hdr->VP9.ref_picture_id for testing.
|
|
|
|
|
_codecSpecificInfo.codecSpecific.VP9.temporal_idx =
|
|
|
|
|
gof_info.temporal_idx[idx];
|
|
|
|
|
_codecSpecificInfo.codecSpecific.VP9.temporal_up_switch =
|
|
|
|
|
gof_info.temporal_up_switch[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
bool
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::IsSessionComplete() const {
|
2011-12-13 07:54:56 +00:00
|
|
|
return _sessionInfo.complete();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Insert packet
|
|
|
|
|
VCMFrameBufferEnum
|
2013-08-01 03:15:08 +00:00
|
|
|
VCMFrameBuffer::InsertPacket(const VCMPacket& packet,
|
|
|
|
|
int64_t timeInMs,
|
|
|
|
|
VCMDecodeErrorMode decode_error_mode,
|
2013-07-29 21:48:11 +00:00
|
|
|
const FrameData& frame_data) {
|
2014-04-11 14:08:35 +00:00
|
|
|
assert(!(NULL == packet.dataPtr && packet.sizeBytes > 0));
|
2013-07-29 21:48:11 +00:00
|
|
|
if (packet.dataPtr != NULL) {
|
2011-07-07 08:21:25 +00:00
|
|
|
_payloadType = packet.payloadType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 21:48:11 +00:00
|
|
|
if (kStateEmpty == _state) {
|
2011-07-07 08:21:25 +00:00
|
|
|
// First packet (empty and/or media) inserted into this frame.
|
|
|
|
|
// store some info and set some initial values.
|
|
|
|
|
_timeStamp = packet.timestamp;
|
2014-04-15 17:46:33 +00:00
|
|
|
// We only take the ntp timestamp of the first packet of a frame.
|
|
|
|
|
ntp_time_ms_ = packet.ntp_time_ms_;
|
2011-07-07 08:21:25 +00:00
|
|
|
_codec = packet.codec;
|
2015-10-19 02:39:06 -07:00
|
|
|
if (packet.frameType != kEmptyFrame) {
|
2011-07-07 08:21:25 +00:00
|
|
|
// first media packet
|
|
|
|
|
SetState(kStateIncomplete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
uint32_t requiredSizeBytes = Length() + packet.sizeBytes +
|
2011-07-07 08:21:25 +00:00
|
|
|
(packet.insertStartCode ? kH264StartCodeLengthBytes : 0);
|
2013-07-29 21:48:11 +00:00
|
|
|
if (requiredSizeBytes >= _size) {
|
2013-04-02 15:54:38 +00:00
|
|
|
const uint8_t* prevBuffer = _buffer;
|
|
|
|
|
const uint32_t increments = requiredSizeBytes /
|
2011-07-07 08:21:25 +00:00
|
|
|
kBufferIncStepSizeBytes +
|
|
|
|
|
(requiredSizeBytes %
|
|
|
|
|
kBufferIncStepSizeBytes > 0);
|
2013-04-02 15:54:38 +00:00
|
|
|
const uint32_t newSize = _size +
|
2011-07-07 08:21:25 +00:00
|
|
|
increments * kBufferIncStepSizeBytes;
|
2013-07-29 21:48:11 +00:00
|
|
|
if (newSize > kMaxJBFrameSizeBytes) {
|
2014-04-11 14:08:35 +00:00
|
|
|
LOG(LS_ERROR) << "Failed to insert packet due to frame being too "
|
|
|
|
|
"big.";
|
2011-07-07 08:21:25 +00:00
|
|
|
return kSizeError;
|
|
|
|
|
}
|
2014-04-11 14:08:35 +00:00
|
|
|
VerifyAndAllocate(newSize);
|
2012-01-10 11:45:05 +00:00
|
|
|
_sessionInfo.UpdateDataPointers(prevBuffer, _buffer);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-08-17 09:47:33 +00:00
|
|
|
|
2013-05-21 15:25:53 +00:00
|
|
|
if (packet.width > 0 && packet.height > 0) {
|
|
|
|
|
_encodedWidth = packet.width;
|
|
|
|
|
_encodedHeight = packet.height;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 13:58:27 +00:00
|
|
|
// Don't copy payload specific data for empty packets (e.g padding packets).
|
|
|
|
|
if (packet.sizeBytes > 0)
|
|
|
|
|
CopyCodecSpecific(&packet.codecSpecificHeader);
|
2011-08-17 09:47:33 +00:00
|
|
|
|
2011-12-13 07:54:56 +00:00
|
|
|
int retVal = _sessionInfo.InsertPacket(packet, _buffer,
|
2013-08-01 03:15:08 +00:00
|
|
|
decode_error_mode,
|
2013-07-29 21:48:11 +00:00
|
|
|
frame_data);
|
|
|
|
|
if (retVal == -1) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kSizeError;
|
2013-07-29 21:48:11 +00:00
|
|
|
} else if (retVal == -2) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return kDuplicatePacket;
|
2013-08-26 17:10:11 +00:00
|
|
|
} else if (retVal == -3) {
|
|
|
|
|
return kOutOfBoundsPacket;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
// update length
|
2013-04-02 15:54:38 +00:00
|
|
|
_length = Length() + static_cast<uint32_t>(retVal);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_latestPacketTimeMs = timeInMs;
|
|
|
|
|
|
2015-03-17 21:54:50 +00:00
|
|
|
// http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
|
|
|
|
|
// ts_126114v120700p.pdf Section 7.4.5.
|
|
|
|
|
// The MTSI client shall add the payload bytes as defined in this clause
|
|
|
|
|
// onto the last RTP packet in each group of packets which make up a key
|
|
|
|
|
// frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265
|
|
|
|
|
// (HEVC)).
|
|
|
|
|
if (packet.markerBit) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(!_rotation_set);
|
2015-03-17 21:54:50 +00:00
|
|
|
_rotation = packet.codecSpecificHeader.rotation;
|
|
|
|
|
_rotation_set = true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 07:54:56 +00:00
|
|
|
if (_sessionInfo.complete()) {
|
2013-06-27 15:20:14 +00:00
|
|
|
SetState(kStateComplete);
|
2011-11-22 22:48:20 +00:00
|
|
|
return kCompleteSession;
|
2011-12-13 07:54:56 +00:00
|
|
|
} else if (_sessionInfo.decodable()) {
|
2011-11-22 22:48:20 +00:00
|
|
|
SetState(kStateDecodable);
|
|
|
|
|
return kDecodableSession;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
return kIncomplete;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
int64_t
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::LatestPacketTimeMs() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return _latestPacketTimeMs;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 23:24:37 +00:00
|
|
|
void
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::IncrementNackCount() {
|
2011-07-07 08:21:25 +00:00
|
|
|
_nackCount++;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
int16_t
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::GetNackCount() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return _nackCount;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 09:38:26 +00:00
|
|
|
bool
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::HaveFirstPacket() const {
|
2013-04-16 09:38:26 +00:00
|
|
|
return _sessionInfo.HaveFirstPacket();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 23:24:37 +00:00
|
|
|
bool
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::HaveLastPacket() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return _sessionInfo.HaveLastPacket();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 21:48:11 +00:00
|
|
|
int
|
|
|
|
|
VCMFrameBuffer::NumPackets() const {
|
|
|
|
|
return _sessionInfo.NumPackets();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-19 23:24:37 +00:00
|
|
|
void
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::Reset() {
|
2011-07-07 08:21:25 +00:00
|
|
|
_length = 0;
|
|
|
|
|
_timeStamp = 0;
|
|
|
|
|
_sessionInfo.Reset();
|
|
|
|
|
_payloadType = 0;
|
|
|
|
|
_nackCount = 0;
|
|
|
|
|
_latestPacketTimeMs = -1;
|
2013-06-27 15:20:14 +00:00
|
|
|
_state = kStateEmpty;
|
2011-07-07 08:21:25 +00:00
|
|
|
VCMEncodedFrame::Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set state of frame
|
|
|
|
|
void
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::SetState(VCMFrameBufferStateEnum state) {
|
|
|
|
|
if (_state == state) {
|
2011-07-07 08:21:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-07-29 21:48:11 +00:00
|
|
|
switch (state) {
|
2011-07-07 08:21:25 +00:00
|
|
|
case kStateIncomplete:
|
|
|
|
|
// we can go to this state from state kStateEmpty
|
2013-06-27 15:20:14 +00:00
|
|
|
assert(_state == kStateEmpty);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Do nothing, we received a packet
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kStateComplete:
|
|
|
|
|
assert(_state == kStateEmpty ||
|
|
|
|
|
_state == kStateIncomplete ||
|
|
|
|
|
_state == kStateDecodable);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kStateEmpty:
|
2013-06-27 15:20:14 +00:00
|
|
|
// Should only be set to empty through Reset().
|
|
|
|
|
assert(false);
|
2011-07-07 08:21:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kStateDecodable:
|
|
|
|
|
assert(_state == kStateEmpty ||
|
|
|
|
|
_state == kStateIncomplete);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_state = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current state of frame
|
|
|
|
|
VCMFrameBufferStateEnum
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::GetState() const {
|
2011-07-07 08:21:25 +00:00
|
|
|
return _state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current state of frame
|
|
|
|
|
VCMFrameBufferStateEnum
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::GetState(uint32_t& timeStamp) const {
|
2011-07-07 08:21:25 +00:00
|
|
|
timeStamp = TimeStamp();
|
|
|
|
|
return GetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::IsRetransmitted() const {
|
2011-12-13 07:54:56 +00:00
|
|
|
return _sessionInfo.session_nack();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-07-29 21:48:11 +00:00
|
|
|
VCMFrameBuffer::PrepareForDecode(bool continuous) {
|
2011-09-08 06:50:28 +00:00
|
|
|
#ifdef INDEPENDENT_PARTITIONS
|
2013-07-29 21:48:11 +00:00
|
|
|
if (_codec == kVideoCodecVP8) {
|
2011-09-08 06:50:28 +00:00
|
|
|
_length =
|
|
|
|
|
_sessionInfo.BuildVP8FragmentationHeader(_buffer, _length,
|
|
|
|
|
&_fragmentation);
|
2013-06-27 15:20:14 +00:00
|
|
|
} else {
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t bytes_removed = _sessionInfo.MakeDecodable();
|
2013-06-27 15:20:14 +00:00
|
|
|
_length -= bytes_removed;
|
2011-09-08 06:50:28 +00:00
|
|
|
}
|
2013-06-27 15:20:14 +00:00
|
|
|
#else
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t bytes_removed = _sessionInfo.MakeDecodable();
|
2013-06-27 15:20:14 +00:00
|
|
|
_length -= bytes_removed;
|
2011-09-08 06:50:28 +00:00
|
|
|
#endif
|
2013-06-27 15:20:14 +00:00
|
|
|
// Transfer frame information to EncodedFrame and create any codec
|
|
|
|
|
// specific information.
|
2015-10-19 02:39:06 -07:00
|
|
|
_frameType = _sessionInfo.FrameType();
|
2013-06-27 15:20:14 +00:00
|
|
|
_completeFrame = _sessionInfo.complete();
|
|
|
|
|
_missingFrame = !continuous;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-29 21:48:11 +00:00
|
|
|
} // namespace webrtc
|