webrtc_m130/modules/video_coding/encoded_frame.cc

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

173 lines
6.5 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2012 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/encoded_frame.h"
#include <string.h>
#include "absl/types/variant.h"
#include "api/video/video_timing.h"
#include "modules/video_coding/codecs/interface/common_constants.h"
#include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
namespace webrtc {
VCMEncodedFrame::VCMEncodedFrame()
: webrtc::EncodedImage(),
_renderTimeMs(-1),
_payloadType(0),
_missingFrame(false),
_codec(kVideoCodecGeneric),
_rotation_set(false) {
_codecSpecificInfo.codecType = kVideoCodecGeneric;
}
VCMEncodedFrame::~VCMEncodedFrame() {
Reset();
}
void VCMEncodedFrame::Reset() {
SetTimestamp(0);
SetSpatialIndex(absl::nullopt);
_renderTimeMs = -1;
_payloadType = 0;
_frameType = VideoFrameType::kVideoFrameDelta;
_encodedWidth = 0;
_encodedHeight = 0;
_completeFrame = false;
_missingFrame = false;
set_size(0);
_codecSpecificInfo.codecType = kVideoCodecGeneric;
_codec = kVideoCodecGeneric;
rotation_ = kVideoRotation_0;
content_type_ = VideoContentType::UNSPECIFIED;
timing_.flags = VideoSendTiming::kInvalid;
_rotation_set = false;
}
void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) {
if (header) {
switch (header->codec) {
case kVideoCodecVP8: {
Reland "Remove RTPVideoHeader::vp8() accessors." This reverts commit 1811c04f22a26da3ed2832373a5c92a9786420c3. Reason for revert: Downstream projects fixed. Original change's description: > Revert "Remove RTPVideoHeader::vp8() accessors." > > This reverts commit af7afc66427b0e9109e7d492f2805d63d239b914. > > Reason for revert: Break downstream projects. > > Original change's description: > > Remove RTPVideoHeader::vp8() accessors. > > > > Bug: none > > Change-Id: Ia7d65148fb36a8f26647bee8a876ce7217ff8a68 > > Reviewed-on: https://webrtc-review.googlesource.com/93321 > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#24626} > > TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com > > Change-Id: I3f7f19c0ea810c0fd988c59e6556bbea9b756b33 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: none > Reviewed-on: https://webrtc-review.googlesource.com/98864 > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#24628} TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com Change-Id: I9246f36e638108ae4fc46c1ae4559c8205d50fc1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: none Reviewed-on: https://webrtc-review.googlesource.com/98841 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24629}
2018-09-07 13:03:55 +00:00
const auto& vp8_header =
absl::get<RTPVideoHeaderVP8>(header->video_type_header);
if (_codecSpecificInfo.codecType != kVideoCodecVP8) {
// This is the first packet for this frame.
_codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0;
_codecSpecificInfo.codecSpecific.VP8.layerSync = false;
_codecSpecificInfo.codecSpecific.VP8.keyIdx = -1;
_codecSpecificInfo.codecType = kVideoCodecVP8;
}
_codecSpecificInfo.codecSpecific.VP8.nonReference =
Reland "Remove RTPVideoHeader::vp8() accessors." This reverts commit 1811c04f22a26da3ed2832373a5c92a9786420c3. Reason for revert: Downstream projects fixed. Original change's description: > Revert "Remove RTPVideoHeader::vp8() accessors." > > This reverts commit af7afc66427b0e9109e7d492f2805d63d239b914. > > Reason for revert: Break downstream projects. > > Original change's description: > > Remove RTPVideoHeader::vp8() accessors. > > > > Bug: none > > Change-Id: Ia7d65148fb36a8f26647bee8a876ce7217ff8a68 > > Reviewed-on: https://webrtc-review.googlesource.com/93321 > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#24626} > > TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com > > Change-Id: I3f7f19c0ea810c0fd988c59e6556bbea9b756b33 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: none > Reviewed-on: https://webrtc-review.googlesource.com/98864 > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#24628} TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com Change-Id: I9246f36e638108ae4fc46c1ae4559c8205d50fc1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: none Reviewed-on: https://webrtc-review.googlesource.com/98841 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24629}
2018-09-07 13:03:55 +00:00
vp8_header.nonReference;
if (vp8_header.temporalIdx != kNoTemporalIdx) {
_codecSpecificInfo.codecSpecific.VP8.temporalIdx =
Reland "Remove RTPVideoHeader::vp8() accessors." This reverts commit 1811c04f22a26da3ed2832373a5c92a9786420c3. Reason for revert: Downstream projects fixed. Original change's description: > Revert "Remove RTPVideoHeader::vp8() accessors." > > This reverts commit af7afc66427b0e9109e7d492f2805d63d239b914. > > Reason for revert: Break downstream projects. > > Original change's description: > > Remove RTPVideoHeader::vp8() accessors. > > > > Bug: none > > Change-Id: Ia7d65148fb36a8f26647bee8a876ce7217ff8a68 > > Reviewed-on: https://webrtc-review.googlesource.com/93321 > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#24626} > > TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com > > Change-Id: I3f7f19c0ea810c0fd988c59e6556bbea9b756b33 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: none > Reviewed-on: https://webrtc-review.googlesource.com/98864 > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#24628} TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com Change-Id: I9246f36e638108ae4fc46c1ae4559c8205d50fc1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: none Reviewed-on: https://webrtc-review.googlesource.com/98841 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24629}
2018-09-07 13:03:55 +00:00
vp8_header.temporalIdx;
_codecSpecificInfo.codecSpecific.VP8.layerSync = vp8_header.layerSync;
}
Reland "Remove RTPVideoHeader::vp8() accessors." This reverts commit 1811c04f22a26da3ed2832373a5c92a9786420c3. Reason for revert: Downstream projects fixed. Original change's description: > Revert "Remove RTPVideoHeader::vp8() accessors." > > This reverts commit af7afc66427b0e9109e7d492f2805d63d239b914. > > Reason for revert: Break downstream projects. > > Original change's description: > > Remove RTPVideoHeader::vp8() accessors. > > > > Bug: none > > Change-Id: Ia7d65148fb36a8f26647bee8a876ce7217ff8a68 > > Reviewed-on: https://webrtc-review.googlesource.com/93321 > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> > > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#24626} > > TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com > > Change-Id: I3f7f19c0ea810c0fd988c59e6556bbea9b756b33 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: none > Reviewed-on: https://webrtc-review.googlesource.com/98864 > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Commit-Queue: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#24628} TBR=danilchap@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,philipel@webrtc.org,holmer@google.com Change-Id: I9246f36e638108ae4fc46c1ae4559c8205d50fc1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: none Reviewed-on: https://webrtc-review.googlesource.com/98841 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24629}
2018-09-07 13:03:55 +00:00
if (vp8_header.keyIdx != kNoKeyIdx) {
_codecSpecificInfo.codecSpecific.VP8.keyIdx = vp8_header.keyIdx;
}
break;
}
case kVideoCodecVP9: {
const auto& vp9_header =
absl::get<RTPVideoHeaderVP9>(header->video_type_header);
if (_codecSpecificInfo.codecType != kVideoCodecVP9) {
// This is the first packet for this frame.
_codecSpecificInfo.codecSpecific.VP9.temporal_idx = 0;
_codecSpecificInfo.codecSpecific.VP9.gof_idx = 0;
_codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = false;
_codecSpecificInfo.codecType = kVideoCodecVP9;
}
_codecSpecificInfo.codecSpecific.VP9.inter_pic_predicted =
vp9_header.inter_pic_predicted;
_codecSpecificInfo.codecSpecific.VP9.flexible_mode =
vp9_header.flexible_mode;
Reland of Work on flexible mode and screen sharing. (patchset #1 id:1 of https://codereview.webrtc.org/1438543002/ ) Reason for revert: Failed test not related to this CL (test fails on master at an earlier date), re-landing original CL.. (This time from my @webrtc account.) Original issue's description: > Revert of Work on flexible mode and screen sharing. (patchset #28 id:520001 of https://codereview.webrtc.org/1328113004/ ) > > Reason for revert: > Seems to break VideoSendStreamTest.ReconfigureBitratesSetsEncoderBitratesCorrectly on Linux Memcheck buildbot. > > Original issue's description: > > Work on flexible mode and screen sharing. > > > > Implement VP8 style screensharing but with spatial layers. > > Implement flexible mode. > > > > Files from other patches: > > generic_encoder.cc > > layer_filtering_transport.cc > > > > BUG=webrtc:4914 > > > > Committed: https://crrev.com/77ccfb4d16c148e61a316746bb5d9705e8b39f4a > > Cr-Commit-Position: refs/heads/master@{#10572} > > TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,philipel@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:4914 > > Committed: https://crrev.com/0be8f1d347bdb171462df89c2a4c69b3f3eb7519 > Cr-Commit-Position: refs/heads/master@{#10578} TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,terelius@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:4914 Review URL: https://codereview.webrtc.org/1431283002 Cr-Commit-Position: refs/heads/master@{#10581}
2015-11-10 07:17:23 -08:00
_codecSpecificInfo.codecSpecific.VP9.num_ref_pics =
vp9_header.num_ref_pics;
for (uint8_t r = 0; r < vp9_header.num_ref_pics; ++r) {
Reland of Work on flexible mode and screen sharing. (patchset #1 id:1 of https://codereview.webrtc.org/1438543002/ ) Reason for revert: Failed test not related to this CL (test fails on master at an earlier date), re-landing original CL.. (This time from my @webrtc account.) Original issue's description: > Revert of Work on flexible mode and screen sharing. (patchset #28 id:520001 of https://codereview.webrtc.org/1328113004/ ) > > Reason for revert: > Seems to break VideoSendStreamTest.ReconfigureBitratesSetsEncoderBitratesCorrectly on Linux Memcheck buildbot. > > Original issue's description: > > Work on flexible mode and screen sharing. > > > > Implement VP8 style screensharing but with spatial layers. > > Implement flexible mode. > > > > Files from other patches: > > generic_encoder.cc > > layer_filtering_transport.cc > > > > BUG=webrtc:4914 > > > > Committed: https://crrev.com/77ccfb4d16c148e61a316746bb5d9705e8b39f4a > > Cr-Commit-Position: refs/heads/master@{#10572} > > TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,philipel@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:4914 > > Committed: https://crrev.com/0be8f1d347bdb171462df89c2a4c69b3f3eb7519 > Cr-Commit-Position: refs/heads/master@{#10578} TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,terelius@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:4914 Review URL: https://codereview.webrtc.org/1431283002 Cr-Commit-Position: refs/heads/master@{#10581}
2015-11-10 07:17:23 -08:00
_codecSpecificInfo.codecSpecific.VP9.p_diff[r] =
vp9_header.pid_diff[r];
Reland of Work on flexible mode and screen sharing. (patchset #1 id:1 of https://codereview.webrtc.org/1438543002/ ) Reason for revert: Failed test not related to this CL (test fails on master at an earlier date), re-landing original CL.. (This time from my @webrtc account.) Original issue's description: > Revert of Work on flexible mode and screen sharing. (patchset #28 id:520001 of https://codereview.webrtc.org/1328113004/ ) > > Reason for revert: > Seems to break VideoSendStreamTest.ReconfigureBitratesSetsEncoderBitratesCorrectly on Linux Memcheck buildbot. > > Original issue's description: > > Work on flexible mode and screen sharing. > > > > Implement VP8 style screensharing but with spatial layers. > > Implement flexible mode. > > > > Files from other patches: > > generic_encoder.cc > > layer_filtering_transport.cc > > > > BUG=webrtc:4914 > > > > Committed: https://crrev.com/77ccfb4d16c148e61a316746bb5d9705e8b39f4a > > Cr-Commit-Position: refs/heads/master@{#10572} > > TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,philipel@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:4914 > > Committed: https://crrev.com/0be8f1d347bdb171462df89c2a4c69b3f3eb7519 > Cr-Commit-Position: refs/heads/master@{#10578} TBR=sprang@webrtc.org,stefan@webrtc.org,philipel@google.com,asapersson@webrtc.org,mflodman@webrtc.org,terelius@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:4914 Review URL: https://codereview.webrtc.org/1431283002 Cr-Commit-Position: refs/heads/master@{#10581}
2015-11-10 07:17:23 -08:00
}
_codecSpecificInfo.codecSpecific.VP9.ss_data_available =
vp9_header.ss_data_available;
if (vp9_header.temporal_idx != kNoTemporalIdx) {
_codecSpecificInfo.codecSpecific.VP9.temporal_idx =
vp9_header.temporal_idx;
_codecSpecificInfo.codecSpecific.VP9.temporal_up_switch =
vp9_header.temporal_up_switch;
}
if (vp9_header.spatial_idx != kNoSpatialIdx) {
_codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted =
vp9_header.inter_layer_predicted;
SetSpatialIndex(vp9_header.spatial_idx);
}
if (vp9_header.gof_idx != kNoGofIdx) {
_codecSpecificInfo.codecSpecific.VP9.gof_idx = vp9_header.gof_idx;
}
if (vp9_header.ss_data_available) {
_codecSpecificInfo.codecSpecific.VP9.num_spatial_layers =
vp9_header.num_spatial_layers;
_codecSpecificInfo.codecSpecific.VP9
.spatial_layer_resolution_present =
vp9_header.spatial_layer_resolution_present;
if (vp9_header.spatial_layer_resolution_present) {
for (size_t i = 0; i < vp9_header.num_spatial_layers; ++i) {
_codecSpecificInfo.codecSpecific.VP9.width[i] =
vp9_header.width[i];
_codecSpecificInfo.codecSpecific.VP9.height[i] =
vp9_header.height[i];
}
}
_codecSpecificInfo.codecSpecific.VP9.gof.CopyGofInfoVP9(
vp9_header.gof);
}
break;
}
case kVideoCodecH264: {
_codecSpecificInfo.codecType = kVideoCodecH264;
// The following H264 codec specific data are not used elsewhere.
// Instead they are read directly from the frame marking extension.
// These codec specific data structures should be removed
// when frame marking is used.
_codecSpecificInfo.codecSpecific.H264.temporal_idx = kNoTemporalIdx;
if (header->frame_marking.temporal_id != kNoTemporalIdx) {
_codecSpecificInfo.codecSpecific.H264.temporal_idx =
header->frame_marking.temporal_id;
_codecSpecificInfo.codecSpecific.H264.base_layer_sync =
header->frame_marking.base_layer_sync;
_codecSpecificInfo.codecSpecific.H264.idr_frame =
header->frame_marking.independent_frame;
}
break;
}
default: {
_codecSpecificInfo.codecType = kVideoCodecGeneric;
break;
}
}
}
}
void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) {
size_t old_capacity = capacity();
if (minimumSize > old_capacity) {
// TODO(nisse): EncodedImage::Allocate is implemented as
// std::vector::resize, which means that old contents is kept. Find out if
// any code depends on that behavior.
Allocate(minimumSize);
}
}
} // namespace webrtc