2014-11-01 06:10:48 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-12-21 03:04:49 -08:00
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_VP9_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_VP9_IMPL_H_
|
|
|
|
|
|
2016-02-29 05:51:59 -08:00
|
|
|
#include <memory>
|
2015-12-21 03:04:49 -08:00
|
|
|
#include <vector>
|
2014-11-01 06:10:48 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
|
2015-05-06 10:42:15 +02:00
|
|
|
#include "webrtc/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h"
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-07-31 06:10:09 -07:00
|
|
|
#include "vpx/svc_context.h"
|
2014-12-17 13:43:55 +00:00
|
|
|
#include "vpx/vpx_decoder.h"
|
|
|
|
|
#include "vpx/vpx_encoder.h"
|
2014-11-01 06:10:48 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
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
|
|
|
class ScreenshareLayersVP9;
|
|
|
|
|
|
2014-11-01 06:10:48 +00:00
|
|
|
class VP9EncoderImpl : public VP9Encoder {
|
|
|
|
|
public:
|
|
|
|
|
VP9EncoderImpl();
|
|
|
|
|
|
|
|
|
|
virtual ~VP9EncoderImpl();
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int Release() override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
int number_of_cores,
|
|
|
|
|
size_t max_payload_size) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
int Encode(const VideoFrame& input_image,
|
2015-03-04 12:58:35 +00:00
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
2015-10-19 02:39:06 -07:00
|
|
|
const std::vector<FrameType>* frame_types) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-04-21 15:30:11 -07:00
|
|
|
void OnDroppedFrame() override {}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
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
|
|
|
struct LayerFrameRefSettings {
|
|
|
|
|
int8_t upd_buf = -1; // -1 - no update, 0..7 - update buffer 0..7
|
|
|
|
|
int8_t ref_buf1 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
|
|
|
|
|
int8_t ref_buf2 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
|
|
|
|
|
int8_t ref_buf3 = -1; // -1 - no reference, 0..7 - reference buffer 0..7
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SuperFrameRefSettings {
|
|
|
|
|
LayerFrameRefSettings layer[kMaxVp9NumberOfSpatialLayers];
|
|
|
|
|
uint8_t start_layer = 0; // The first spatial layer to be encoded.
|
|
|
|
|
uint8_t stop_layer = 0; // The last spatial layer to be encoded.
|
|
|
|
|
bool is_keyframe = false;
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-01 06:10:48 +00:00
|
|
|
private:
|
2015-01-26 15:21:36 +00:00
|
|
|
// Determine number of encoder threads to use.
|
|
|
|
|
int NumberOfThreads(int width, int height, int number_of_cores);
|
|
|
|
|
|
2014-11-01 06:10:48 +00:00
|
|
|
// Call encoder initialize function and set control settings.
|
|
|
|
|
int InitAndSetControlSettings(const VideoCodec* inst);
|
|
|
|
|
|
|
|
|
|
void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
|
|
|
|
|
const vpx_codec_cx_pkt& pkt,
|
|
|
|
|
uint32_t timestamp);
|
|
|
|
|
|
2015-11-02 07:23:20 -08:00
|
|
|
bool ExplicitlyConfiguredSpatialLayers() const;
|
2015-07-31 06:10:09 -07:00
|
|
|
bool SetSvcRates();
|
|
|
|
|
|
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
|
|
|
// Used for flexible mode to set the flags and buffer references used
|
|
|
|
|
// by the encoder. Also calculates the references used by the RTP
|
|
|
|
|
// packetizer.
|
|
|
|
|
//
|
|
|
|
|
// Has to be called for every frame (keyframes included) to update the
|
|
|
|
|
// state used to calculate references.
|
|
|
|
|
vpx_svc_ref_frame_config GenerateRefsAndFlags(
|
|
|
|
|
const SuperFrameRefSettings& settings);
|
|
|
|
|
|
2015-07-31 06:10:09 -07:00
|
|
|
virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt);
|
|
|
|
|
|
|
|
|
|
// Callback function for outputting packets per spatial layer.
|
|
|
|
|
static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt,
|
|
|
|
|
void* user_data);
|
2014-11-01 06:10:48 +00:00
|
|
|
|
|
|
|
|
// Determine maximum target for Intra frames
|
|
|
|
|
//
|
|
|
|
|
// Input:
|
|
|
|
|
// - optimal_buffer_size : Optimal buffer size
|
|
|
|
|
// Return Value : Max target size for Intra frames represented as
|
|
|
|
|
// percentage of the per frame bandwidth
|
|
|
|
|
uint32_t MaxIntraTarget(uint32_t optimal_buffer_size);
|
|
|
|
|
|
|
|
|
|
EncodedImage encoded_image_;
|
|
|
|
|
EncodedImageCallback* encoded_complete_callback_;
|
|
|
|
|
VideoCodec codec_;
|
|
|
|
|
bool inited_;
|
|
|
|
|
int64_t timestamp_;
|
|
|
|
|
uint16_t picture_id_;
|
|
|
|
|
int cpu_speed_;
|
|
|
|
|
uint32_t rc_max_intra_target_;
|
|
|
|
|
vpx_codec_ctx_t* encoder_;
|
|
|
|
|
vpx_codec_enc_cfg_t* config_;
|
|
|
|
|
vpx_image_t* raw_;
|
2015-07-31 06:10:09 -07:00
|
|
|
SvcInternal_t svc_internal_;
|
|
|
|
|
const VideoFrame* input_image_;
|
|
|
|
|
GofInfoVP9 gof_; // Contains each frame's temporal information for
|
|
|
|
|
// non-flexible mode.
|
|
|
|
|
uint8_t tl0_pic_idx_; // Only used in non-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
|
|
|
size_t frames_since_kf_;
|
2015-07-31 06:10:09 -07:00
|
|
|
uint8_t num_temporal_layers_;
|
|
|
|
|
uint8_t num_spatial_layers_;
|
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
|
|
|
|
|
|
|
|
// Used for flexible mode.
|
|
|
|
|
bool is_flexible_mode_;
|
|
|
|
|
int64_t buffer_updated_at_frame_[kNumVp9Buffers];
|
|
|
|
|
int64_t frames_encoded_;
|
|
|
|
|
uint8_t num_ref_pics_[kMaxVp9NumberOfSpatialLayers];
|
|
|
|
|
uint8_t p_diff_[kMaxVp9NumberOfSpatialLayers][kMaxVp9RefPics];
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<ScreenshareLayersVP9> spatial_layer_;
|
2014-11-01 06:10:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VP9DecoderImpl : public VP9Decoder {
|
|
|
|
|
public:
|
|
|
|
|
VP9DecoderImpl();
|
|
|
|
|
|
|
|
|
|
virtual ~VP9DecoderImpl();
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int InitDecode(const VideoCodec* inst, int number_of_cores) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int Decode(const EncodedImage& input_image,
|
|
|
|
|
bool missing_frames,
|
|
|
|
|
const RTPFragmentationHeader* fragmentation,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
int64_t /*render_time_ms*/) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int Release() override;
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
2014-11-01 06:10:48 +00:00
|
|
|
private:
|
2016-04-18 00:41:05 -07:00
|
|
|
int ReturnFrame(const vpx_image_t* img, uint32_t timeStamp);
|
2014-11-01 06:10:48 +00:00
|
|
|
|
2015-05-06 10:42:15 +02:00
|
|
|
// Memory pool used to share buffers between libvpx and webrtc.
|
|
|
|
|
Vp9FrameBufferPool frame_buffer_pool_;
|
2014-11-01 06:10:48 +00:00
|
|
|
DecodedImageCallback* decode_complete_callback_;
|
|
|
|
|
bool inited_;
|
2014-12-17 13:43:55 +00:00
|
|
|
vpx_codec_ctx_t* decoder_;
|
2014-11-01 06:10:48 +00:00
|
|
|
VideoCodec codec_;
|
|
|
|
|
bool key_frame_required_;
|
|
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2015-12-21 03:04:49 -08:00
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_VP9_IMPL_H_
|