Cleanup encode call.

Review URL: https://webrtc-codereview.appspot.com/491003

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2011 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pwestin@webrtc.org 2012-04-12 06:59:14 +00:00
parent f1e020ec99
commit ce33035dee
23 changed files with 80 additions and 117 deletions

View File

@ -50,7 +50,7 @@ public:
virtual WebRtc_Word32 virtual WebRtc_Word32
Encode(const RawImage& inputImage, Encode(const RawImage& inputImage,
const CodecSpecificInfo* /*codecSpecificInfo*/, const CodecSpecificInfo* /*codecSpecificInfo*/,
const VideoFrameType* /*frameTypes*/); const VideoFrameType /*frameTypes*/);
// Register an encode complete callback object. // Register an encode complete callback object.
// //

View File

@ -87,7 +87,7 @@ I420Encoder::InitEncode(const VideoCodec* codecSettings,
WebRtc_Word32 WebRtc_Word32
I420Encoder::Encode(const RawImage& inputImage, I420Encoder::Encode(const RawImage& inputImage,
const CodecSpecificInfo* /*codecSpecificInfo*/, const CodecSpecificInfo* /*codecSpecificInfo*/,
const VideoFrameType* /*frameTypes*/) const VideoFrameType /*frameType*/)
{ {
if (!_inited) if (!_inited)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
@ -39,7 +39,7 @@ class MockVideoEncoder : public VideoEncoder {
MOCK_METHOD3(Encode, MOCK_METHOD3(Encode,
WebRtc_Word32(const RawImage& inputImage, WebRtc_Word32(const RawImage& inputImage,
const CodecSpecificInfo* codecSpecificInfo, const CodecSpecificInfo* codecSpecificInfo,
const VideoFrameType* frameType)); const VideoFrameType frameType));
MOCK_METHOD1(RegisterEncodeCompleteCallback, MOCK_METHOD1(RegisterEncodeCompleteCallback,
WebRtc_Word32(EncodedImageCallback* callback)); WebRtc_Word32(EncodedImageCallback* callback));
MOCK_METHOD0(Release, WebRtc_Word32()); MOCK_METHOD0(Release, WebRtc_Word32());

View File

@ -97,10 +97,9 @@ public:
// - frameType : The frame type to encode // - frameType : The frame type to encode
// //
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
virtual WebRtc_Word32 virtual WebRtc_Word32 Encode(const RawImage& inputImage,
Encode(const RawImage& inputImage, const CodecSpecificInfo* codecSpecificInfo,
const CodecSpecificInfo* codecSpecificInfo, const VideoFrameType frameType) = 0;
const VideoFrameType* frameTypes) = 0;
// Register an encode complete callback object. // Register an encode complete callback object.
// //

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
@ -146,7 +146,7 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
frame_type = kKeyFrame; frame_type = kKeyFrame;
} }
WebRtc_Word32 encode_result = encoder_->Encode(source_frame_, NULL, WebRtc_Word32 encode_result = encoder_->Encode(source_frame_, NULL,
&frame_type); frame_type);
if (encode_result != WEBRTC_VIDEO_CODEC_OK) { if (encode_result != WEBRTC_VIDEO_CODEC_OK) {
fprintf(stderr, "Failed to encode frame %d, return code: %d\n", fprintf(stderr, "Failed to encode frame %d, return code: %d\n",
frame_number, encode_result); frame_number, encode_result);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
@ -458,7 +458,7 @@ NormalAsyncTest::Encode()
} }
webrtc::CodecSpecificInfo* codecSpecificInfo = CreateEncoderSpecificInfo(); webrtc::CodecSpecificInfo* codecSpecificInfo = CreateEncoderSpecificInfo();
int ret = _encoder->Encode(rawImage, codecSpecificInfo, &frameType); int ret = _encoder->Encode(rawImage, codecSpecificInfo, frameType);
EXPECT_EQ(ret, WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(ret, WEBRTC_VIDEO_CODEC_OK);
if (codecSpecificInfo != NULL) if (codecSpecificInfo != NULL)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
@ -273,7 +273,7 @@ bool PerformanceTest::Encode()
frameType = kKeyFrame; frameType = kKeyFrame;
} }
webrtc::CodecSpecificInfo* codecSpecificInfo = CreateEncoderSpecificInfo(); webrtc::CodecSpecificInfo* codecSpecificInfo = CreateEncoderSpecificInfo();
int ret = _encoder->Encode(rawImage, codecSpecificInfo, &frameType); int ret = _encoder->Encode(rawImage, codecSpecificInfo, frameType);
EXPECT_EQ(ret, WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(ret, WEBRTC_VIDEO_CODEC_OK);
if (codecSpecificInfo != NULL) if (codecSpecificInfo != NULL)
{ {

View File

@ -239,7 +239,7 @@ UnitTest::Setup()
// Ensures our initial parameters are valid. // Ensures our initial parameters are valid.
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
_encoder->Encode(image, NULL, &videoFrameType); _encoder->Encode(image, NULL, videoFrameType);
_refEncFrameLength = WaitForEncodedFrame(); _refEncFrameLength = WaitForEncodedFrame();
ASSERT_TRUE(_refEncFrameLength > 0); ASSERT_TRUE(_refEncFrameLength > 0);
_refEncFrame = new unsigned char[_refEncFrameLength]; _refEncFrame = new unsigned char[_refEncFrameLength];
@ -268,7 +268,7 @@ UnitTest::Setup()
_inputVideoBuffer.SetWidth(_source->GetWidth()); _inputVideoBuffer.SetWidth(_source->GetWidth());
_inputVideoBuffer.SetHeight(_source->GetHeight()); _inputVideoBuffer.SetHeight(_source->GetHeight());
VideoBufferToRawImage(_inputVideoBuffer, image); VideoBufferToRawImage(_inputVideoBuffer, image);
_encoder->Encode(image, NULL, &videoFrameType); _encoder->Encode(image, NULL, videoFrameType);
ASSERT_TRUE(WaitForEncodedFrame() > 0); ASSERT_TRUE(WaitForEncodedFrame() > 0);
} }
EncodedImage encodedImage; EncodedImage encodedImage;
@ -371,7 +371,7 @@ UnitTest::Perform()
// We want to revert the initialization done in Setup(). // We want to revert the initialization done in Setup().
EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType ) EXPECT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType)
== WEBRTC_VIDEO_CODEC_UNINITIALIZED); == WEBRTC_VIDEO_CODEC_UNINITIALIZED);
//-- InitEncode() errors -- //-- InitEncode() errors --
@ -437,7 +437,7 @@ UnitTest::Perform()
// inputVideoBuffer unallocated. // inputVideoBuffer unallocated.
_inputVideoBuffer.Free(); _inputVideoBuffer.Free();
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
_inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame);
@ -449,7 +449,7 @@ UnitTest::Perform()
for (int i = 1; i <= 60; i++) for (int i = 1; i <= 60; i++)
{ {
VideoFrameType frameType = !(i % 2) ? kKeyFrame : kDeltaFrame; VideoFrameType frameType = !(i % 2) ? kKeyFrame : kDeltaFrame;
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &frameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, frameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(WaitForEncodedFrame() > 0); EXPECT_TRUE(WaitForEncodedFrame() > 0);
} }
@ -457,12 +457,12 @@ UnitTest::Perform()
// Init then encode. // Init then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(WaitForEncodedFrame() > 0); EXPECT_TRUE(WaitForEncodedFrame() > 0);
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0); EXPECT_TRUE(frameLength > 0);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
@ -471,11 +471,11 @@ UnitTest::Perform()
// Reset then encode. // Reset then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
WaitForEncodedFrame(); WaitForEncodedFrame();
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0); EXPECT_TRUE(frameLength > 0);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
@ -484,12 +484,12 @@ UnitTest::Perform()
// Release then encode. // Release then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
WaitForEncodedFrame(); WaitForEncodedFrame();
EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0); EXPECT_TRUE(frameLength > 0);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
@ -612,7 +612,7 @@ UnitTest::Perform()
RawImage tempInput(inputImage._buffer, inputImage._length/4, RawImage tempInput(inputImage._buffer, inputImage._length/4,
inputImage._size/4); inputImage._size/4);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
_encoder->Encode(tempInput, NULL, &videoFrameType); _encoder->Encode(tempInput, NULL, videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0); EXPECT_TRUE(frameLength > 0);
@ -630,7 +630,7 @@ UnitTest::Perform()
EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0); EXPECT_TRUE(frameLength > 0);
@ -697,9 +697,7 @@ UnitTest::Perform()
_inputVideoBuffer.SetTimeStamp(frames); _inputVideoBuffer.SetTimeStamp(frames);
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
ASSERT_TRUE(_encoder->Encode(inputImage, ASSERT_TRUE(_encoder->Encode(inputImage, NULL, videoFrameType) ==
NULL,
&videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
//ASSERT_TRUE(frameLength); //ASSERT_TRUE(frameLength);
@ -779,7 +777,7 @@ UnitTest::RateControlTests()
static_cast<float>(_inst.maxFramerate))); static_cast<float>(_inst.maxFramerate)));
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
ASSERT_EQ(_encoder->Encode(inputImage, NULL, &videoFrameType), ASSERT_EQ(_encoder->Encode(inputImage, NULL, videoFrameType),
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
ASSERT_GE(frameLength, 0u); ASSERT_GE(frameLength, 0u);

View File

@ -74,7 +74,7 @@ class VP8Encoder : public VideoEncoder {
virtual int Encode(const RawImage& input_image, virtual int Encode(const RawImage& input_image,
const CodecSpecificInfo* codec_specific_info, const CodecSpecificInfo* codec_specific_info,
const VideoFrameType* frame_types); const VideoFrameType frame_type);
// Register an encode complete callback object. // Register an encode complete callback object.
// //

View File

@ -316,7 +316,7 @@ uint32_t VP8Encoder::MaxIntraTarget(uint32_t optimalBuffersize) {
int VP8Encoder::Encode(const RawImage& input_image, int VP8Encoder::Encode(const RawImage& input_image,
const CodecSpecificInfo* codec_specific_info, const CodecSpecificInfo* codec_specific_info,
const VideoFrameType* frame_types) { const VideoFrameType frame_type) {
if (!inited_) { if (!inited_) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED; return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
} }
@ -347,7 +347,7 @@ int VP8Encoder::Encode(const RawImage& input_image,
flags |= temporal_layers_->EncodeFlags(); flags |= temporal_layers_->EncodeFlags();
} }
#endif #endif
bool send_keyframe = frame_types && (*frame_types == kKeyFrame); bool send_keyframe = (frame_type == kKeyFrame);
if (send_keyframe) { if (send_keyframe) {
// Key frame request from caller. // Key frame request from caller.
// Will update both golden and alt-ref. // Will update both golden and alt-ref.

View File

@ -162,7 +162,7 @@ bool VP8RpsTest::EncodeRps(RpsDecodeCompleteCallback* decodeCallback) {
sli_ = false; sli_ = false;
} }
printf("Encoding: %u\n", _framecnt); printf("Encoding: %u\n", _framecnt);
int ret = _encoder->Encode(rawImage, codecSpecificInfo, &frameType); int ret = _encoder->Encode(rawImage, codecSpecificInfo, frameType);
if (ret < 0) if (ret < 0)
printf("Failed to encode: %u\n", _framecnt); printf("Failed to encode: %u\n", _framecnt);

View File

@ -256,16 +256,11 @@ public:
const VideoContentMetrics* contentMetrics = NULL, const VideoContentMetrics* contentMetrics = NULL,
const CodecSpecificInfo* codecSpecificInfo = NULL) = 0; const CodecSpecificInfo* codecSpecificInfo = NULL) = 0;
// Next frame encoded should be of the type frameType. // Next frame encoded should be an intra frame (keyframe).
//
// Input:
// - frameType : The frame type to encode next time a VideoFrame
// is added to the module.
// //
// Return value : VCM_OK, on success. // Return value : VCM_OK, on success.
// < 0, on error. // < 0, on error.
virtual WebRtc_Word32 FrameTypeRequest(FrameType frameType, virtual WebRtc_Word32 IntraFrameRequest() = 0;
WebRtc_UWord8 simulcastIdx) = 0;
// Frame Dropper enable. Can be used to disable the frame dropping when the encoder // Frame Dropper enable. Can be used to disable the frame dropping when the encoder
// over-uses its bit rate. This API is designed to be used when the encoded frames // over-uses its bit rate. This API is designed to be used when the encoded frames

View File

@ -59,7 +59,7 @@ VCMGenericEncoder::InitEncode(const VideoCodec* settings,
WebRtc_Word32 WebRtc_Word32
VCMGenericEncoder::Encode(const VideoFrame& inputFrame, VCMGenericEncoder::Encode(const VideoFrame& inputFrame,
const CodecSpecificInfo* codecSpecificInfo, const CodecSpecificInfo* codecSpecificInfo,
FrameType* frameType) const FrameType frameType)
{ {
RawImage rawImage(inputFrame.Buffer(), RawImage rawImage(inputFrame.Buffer(),
inputFrame.Length(), inputFrame.Length(),
@ -68,12 +68,9 @@ VCMGenericEncoder::Encode(const VideoFrame& inputFrame,
rawImage._height = inputFrame.Height(); rawImage._height = inputFrame.Height();
rawImage._timeStamp = inputFrame.TimeStamp(); rawImage._timeStamp = inputFrame.TimeStamp();
VideoFrameType videoFrameTypes[kMaxSimulcastStreams]; VideoFrameType videoFrameType =
for (int i = 0; i < kMaxSimulcastStreams; i++) VCMEncodedFrame::ConvertFrameType(frameType);
{ return _encoder.Encode(rawImage, codecSpecificInfo, videoFrameType);
videoFrameTypes[i] = VCMEncodedFrame::ConvertFrameType(frameType[i]);
}
return _encoder.Encode(rawImage, codecSpecificInfo, videoFrameTypes);
} }
WebRtc_Word32 WebRtc_Word32
@ -122,16 +119,10 @@ VCMGenericEncoder::SetPeriodicKeyFrames(bool enable)
return _encoder.SetPeriodicKeyFrames(enable); return _encoder.SetPeriodicKeyFrames(enable);
} }
WebRtc_Word32 WebRtc_Word32 VCMGenericEncoder::RequestFrame(const FrameType frameType) {
VCMGenericEncoder::RequestFrame(FrameType* frameTypes) RawImage image;
{ VideoFrameType videoFrameType = VCMEncodedFrame::ConvertFrameType(frameType);
RawImage image; return _encoder.Encode(image, NULL, videoFrameType);
VideoFrameType videoFrameTypes[kMaxSimulcastStreams];
for (int i = 0; i < kMaxSimulcastStreams; i++)
{
videoFrameTypes[i] = VCMEncodedFrame::ConvertFrameType(frameTypes[i]);
}
return _encoder.Encode(image, NULL, videoFrameTypes);
} }
WebRtc_Word32 WebRtc_Word32

View File

@ -99,7 +99,7 @@ public:
*/ */
WebRtc_Word32 Encode(const VideoFrame& inputFrame, WebRtc_Word32 Encode(const VideoFrame& inputFrame,
const CodecSpecificInfo* codecSpecificInfo, const CodecSpecificInfo* codecSpecificInfo,
FrameType* frameType); const FrameType frameType);
/** /**
* Set new target bit rate and frame rate * Set new target bit rate and frame rate
* Return Value: new bit rate if OK, otherwise <0s * Return Value: new bit rate if OK, otherwise <0s
@ -125,7 +125,7 @@ public:
WebRtc_Word32 SetPeriodicKeyFrames(bool enable); WebRtc_Word32 SetPeriodicKeyFrames(bool enable);
WebRtc_Word32 RequestFrame(FrameType* frameTypes); WebRtc_Word32 RequestFrame(const FrameType frameType);
bool InternalSource() const; bool InternalSource() const;

View File

@ -72,6 +72,7 @@ _scheduleKeyRequest(false),
_sendCritSect(CriticalSectionWrapper::CreateCriticalSection()), _sendCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_encoder(), _encoder(),
_encodedFrameCallback(), _encodedFrameCallback(),
_nextFrameType(kVideoFrameDelta),
_mediaOpt(id, clock_), _mediaOpt(id, clock_),
_sendCodecType(kVideoCodecUnknown), _sendCodecType(kVideoCodecUnknown),
_sendStatsCallback(NULL), _sendStatsCallback(NULL),
@ -84,10 +85,6 @@ _retransmissionTimer(10, clock_),
_keyRequestTimer(500, clock_) _keyRequestTimer(500, clock_)
{ {
assert(clock_); assert(clock_);
for (int i = 0; i < kMaxSimulcastStreams; i++)
{
_nextFrameType[i] = kVideoFrameDelta;
}
#ifdef DEBUG_DECODER_BIT_STREAM #ifdef DEBUG_DECODER_BIT_STREAM
_bitStreamBeforeDecoder = fopen("decoderBitStream.bit", "wb"); _bitStreamBeforeDecoder = fopen("decoderBitStream.bit", "wb");
#endif #endif
@ -666,7 +663,7 @@ VideoCodingModuleImpl::AddVideoFrame(const VideoFrame& videoFrame,
{ {
return VCM_UNINITIALIZED; return VCM_UNINITIALIZED;
} }
if (_nextFrameType[0] == kFrameEmpty) if (_nextFrameType == kFrameEmpty)
{ {
return VCM_OK; return VCM_OK;
} }
@ -700,35 +697,22 @@ VideoCodingModuleImpl::AddVideoFrame(const VideoFrame& videoFrame,
"Encode error: %d", ret); "Encode error: %d", ret);
return ret; return ret;
} }
for (int i = 0; i < kMaxSimulcastStreams; i++) _nextFrameType = kVideoFrameDelta; // default frame type
{
_nextFrameType[i] = kVideoFrameDelta; // default frame type
}
} }
return VCM_OK; return VCM_OK;
} }
// Next frame encoded should be of the type frameType WebRtc_Word32 VideoCodingModuleImpl::IntraFrameRequest() {
// Good for only one frame CriticalSectionScoped cs(_sendCritSect);
WebRtc_Word32 _nextFrameType = kVideoFrameKey;
VideoCodingModuleImpl::FrameTypeRequest(FrameType frameType, if (_encoder != NULL && _encoder->InternalSource()) {
WebRtc_UWord8 simulcastIdx) // Try to request the frame if we have an external encoder with
{ // internal source since AddVideoFrame never will be called.
assert(simulcastIdx < kMaxSimulcastStreams); if (_encoder->RequestFrame(_nextFrameType) == WEBRTC_VIDEO_CODEC_OK) {
_nextFrameType = kVideoFrameDelta;
CriticalSectionScoped cs(_sendCritSect);
_nextFrameType[simulcastIdx] = frameType;
if (_encoder != NULL && _encoder->InternalSource())
{
// Try to request the frame if we have an external encoder with
// internal source since AddVideoFrame never will be called.
if (_encoder->RequestFrame(_nextFrameType) == WEBRTC_VIDEO_CODEC_OK)
{
_nextFrameType[simulcastIdx] = kVideoFrameDelta;
}
} }
return VCM_OK; }
return VCM_OK;
} }
WebRtc_Word32 WebRtc_Word32

View File

@ -147,9 +147,7 @@ public:
const VideoContentMetrics* _contentMetrics = NULL, const VideoContentMetrics* _contentMetrics = NULL,
const CodecSpecificInfo* codecSpecificInfo = NULL); const CodecSpecificInfo* codecSpecificInfo = NULL);
// Next frame encoded should be of the type frameType. virtual WebRtc_Word32 IntraFrameRequest();
virtual WebRtc_Word32 FrameTypeRequest(FrameType frameType,
WebRtc_UWord8 simulcastIdx);
//Enable frame dropper //Enable frame dropper
virtual WebRtc_Word32 EnableFrameDropper(bool enable); virtual WebRtc_Word32 EnableFrameDropper(bool enable);
@ -295,7 +293,7 @@ private:
CriticalSectionWrapper* _sendCritSect; // Critical section for send side CriticalSectionWrapper* _sendCritSect; // Critical section for send side
VCMGenericEncoder* _encoder; VCMGenericEncoder* _encoder;
VCMEncodedFrameCallback _encodedFrameCallback; VCMEncodedFrameCallback _encodedFrameCallback;
FrameType _nextFrameType[kMaxSimulcastStreams]; FrameType _nextFrameType;
VCMMediaOptimization _mediaOpt; VCMMediaOptimization _mediaOpt;
VideoCodecType _sendCodecType; VideoCodecType _sendCodecType;
VCMSendStatisticsCallback* _sendStatsCallback; VCMSendStatisticsCallback* _sendStatsCallback;

View File

@ -238,7 +238,7 @@ CodecDataBaseTest::Perform(CmdArgs& args)
// Try to decode a delta frame. Should get a warning since we have enabled the "require key frame" setting // Try to decode a delta frame. Should get a warning since we have enabled the "require key frame" setting
// and because no frame type request callback has been registered. // and because no frame type request callback has been registered.
TEST(_vcm->Decode() == VCM_MISSING_CALLBACK); TEST(_vcm->Decode() == VCM_MISSING_CALLBACK);
TEST(_vcm->FrameTypeRequest(kVideoFrameKey, 0) == VCM_OK); TEST(_vcm->IntraFrameRequest() == VCM_OK);
_timeStamp += (WebRtc_UWord32)(9e4 / _frameRate); _timeStamp += (WebRtc_UWord32)(9e4 / _frameRate);
sourceFrame.SetTimeStamp(_timeStamp); sourceFrame.SetTimeStamp(_timeStamp);
TEST(_vcm->AddVideoFrame(sourceFrame) == VCM_OK); TEST(_vcm->AddVideoFrame(sourceFrame) == VCM_OK);
@ -250,7 +250,7 @@ CodecDataBaseTest::Perform(CmdArgs& args)
sendCodec.width = _width; sendCodec.width = _width;
sendCodec.height = _height; sendCodec.height = _height;
TEST(_vcm->RegisterReceiveCodec(&sendCodec, 1) == VCM_OK); TEST(_vcm->RegisterReceiveCodec(&sendCodec, 1) == VCM_OK);
TEST(_vcm->FrameTypeRequest(kVideoFrameKey, 0) == VCM_OK); TEST(_vcm->IntraFrameRequest() == VCM_OK);
waitEvent->Wait(33); waitEvent->Wait(33);
_timeStamp += (WebRtc_UWord32)(9e4 / _frameRate); _timeStamp += (WebRtc_UWord32)(9e4 / _frameRate);
sourceFrame.SetTimeStamp(_timeStamp); sourceFrame.SetTimeStamp(_timeStamp);
@ -260,7 +260,7 @@ CodecDataBaseTest::Perform(CmdArgs& args)
waitEvent->Wait(33); waitEvent->Wait(33);
_timeStamp += (WebRtc_UWord32)(9e4 / _frameRate); _timeStamp += (WebRtc_UWord32)(9e4 / _frameRate);
sourceFrame.SetTimeStamp(_timeStamp); sourceFrame.SetTimeStamp(_timeStamp);
TEST(_vcm->FrameTypeRequest(kVideoFrameKey, 0) == VCM_OK); TEST(_vcm->IntraFrameRequest() == VCM_OK);
TEST(_vcm->AddVideoFrame(sourceFrame) == VCM_OK); TEST(_vcm->AddVideoFrame(sourceFrame) == VCM_OK);
TEST(_vcm->Decode() == VCM_OK); TEST(_vcm->Decode() == VCM_OK);
TEST(_vcm->ResetDecoder() == VCM_OK); TEST(_vcm->ResetDecoder() == VCM_OK);

View File

@ -36,7 +36,7 @@ public:
virtual WebRtc_Word32 Encode( virtual WebRtc_Word32 Encode(
const webrtc::RawImage& inputImage, const webrtc::RawImage& inputImage,
const webrtc::CodecSpecificInfo* codecSpecificInfo, const webrtc::CodecSpecificInfo* codecSpecificInfo,
const webrtc::VideoFrameType* frameType); const webrtc::VideoFrameType frameType);
virtual WebRtc_Word32 RegisterEncodeCompleteCallback( virtual WebRtc_Word32 RegisterEncodeCompleteCallback(
webrtc::EncodedImageCallback* callback); webrtc::EncodedImageCallback* callback);

View File

@ -118,7 +118,7 @@ WebRtc_Word32 TbI420Encoder::InitEncode(const webrtc::VideoCodec* inst,
WebRtc_Word32 TbI420Encoder::Encode( WebRtc_Word32 TbI420Encoder::Encode(
const webrtc::RawImage& inputImage, const webrtc::RawImage& inputImage,
const webrtc::CodecSpecificInfo* /*codecSpecificInfo*/, const webrtc::CodecSpecificInfo* /*codecSpecificInfo*/,
const webrtc::VideoFrameType* /*frameType*/) const webrtc::VideoFrameType /*frameType*/)
{ {
_functionCalls.Encode++; _functionCalls.Encode++;
if (!_inited) if (!_inited)

View File

@ -745,15 +745,15 @@ WebRtc_Word32 ViECapturer::InitEncode(const VideoCodec* codec_settings,
WebRtc_Word32 ViECapturer::Encode(const RawImage& input_image, WebRtc_Word32 ViECapturer::Encode(const RawImage& input_image,
const CodecSpecificInfo* codec_specific_info, const CodecSpecificInfo* codec_specific_info,
const VideoFrameType* frame_types) { const VideoFrameType frame_type) {
CriticalSectionScoped cs(encoding_cs_.get()); CriticalSectionScoped cs(encoding_cs_.get());
if (!capture_encoder_) { if (!capture_encoder_) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED; return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
} }
if (*frame_types == kKeyFrame) { if (frame_type == kKeyFrame) {
return capture_encoder_->EncodeFrameType(kVideoFrameKey); return capture_encoder_->EncodeFrameType(kVideoFrameKey);
} }
if (*frame_types == kSkipFrame) { if (frame_type == kSkipFrame) {
return capture_encoder_->EncodeFrameType(kFrameEmpty); return capture_encoder_->EncodeFrameType(kFrameEmpty);
} }
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;

View File

@ -141,7 +141,7 @@ class ViECapturer
WebRtc_UWord32 max_payload_size); WebRtc_UWord32 max_payload_size);
virtual WebRtc_Word32 Encode(const RawImage& input_image, virtual WebRtc_Word32 Encode(const RawImage& input_image,
const CodecSpecificInfo* codec_specific_info, const CodecSpecificInfo* codec_specific_info,
const VideoFrameType* frame_types); const VideoFrameType frame_type);
virtual WebRtc_Word32 RegisterEncodeCompleteCallback( virtual WebRtc_Word32 RegisterEncodeCompleteCallback(
EncodedImageCallback* callback); EncodedImageCallback* callback);
virtual WebRtc_Word32 Release(); virtual WebRtc_Word32 Release();

View File

@ -84,9 +84,9 @@ ViEEncoder::ViEEncoder(WebRtc_Word32 engine_id, WebRtc_Word32 channel_id,
ViEId(engine_id, channel_id), ViEId(engine_id, channel_id),
"%s(engine_id: %d) 0x%p - Constructor", __FUNCTION__, engine_id, "%s(engine_id: %d) 0x%p - Constructor", __FUNCTION__, engine_id,
this); this);
for (int i = 0; i < kMaxSimulcastStreams; i++) {
time_last_intra_request_ms_[i] = 0; time_last_intra_request_ms_ = 0;
}
} }
bool ViEEncoder::Init() { bool ViEEncoder::Init() {
@ -597,10 +597,10 @@ int ViEEncoder::GetPreferedFrameSettings(int& width,
return 0; return 0;
} }
WebRtc_Word32 ViEEncoder::SendKeyFrame() { int ViEEncoder::SendKeyFrame() {
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); ViEId(engine_id_, channel_id_), "%s", __FUNCTION__);
return vcm_.FrameTypeRequest(kVideoFrameKey, 0); // Simulcast idx = 0. return vcm_.IntraFrameRequest();
} }
WebRtc_Word32 ViEEncoder::SendCodecStatistics( WebRtc_Word32 ViEEncoder::SendCodecStatistics(
@ -807,25 +807,23 @@ void ViEEncoder::OnRPSIReceived(const WebRtc_Word32 id,
has_received_rpsi_ = true; has_received_rpsi_ = true;
} }
void ViEEncoder::OnReceivedIntraFrameRequest(const WebRtc_Word32 id, void ViEEncoder::OnReceivedIntraFrameRequest(const WebRtc_Word32 /*id*/,
const FrameType type, const FrameType /*type*/,
const WebRtc_UWord8 stream_idx) { const WebRtc_UWord8 /*idx*/) {
assert(stream_idx < kMaxSimulcastStreams);
// Key frame request from remote side, signal to VCM. // Key frame request from remote side, signal to VCM.
WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), "%s", __FUNCTION__); ViEId(engine_id_, channel_id_), "%s", __FUNCTION__);
WebRtc_Word64 now = TickTime::MillisecondTimestamp(); WebRtc_Word64 now = TickTime::MillisecondTimestamp();
if (time_last_intra_request_ms_[stream_idx] + kViEMinKeyRequestIntervalMs > if (time_last_intra_request_ms_ + kViEMinKeyRequestIntervalMs >
now) { now) {
WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo, WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceVideo,
ViEId(engine_id_, channel_id_), ViEId(engine_id_, channel_id_),
"%s: Not not encoding new intra due to timing", __FUNCTION__); "%s: Not not encoding new intra due to timing", __FUNCTION__);
return; return;
} }
vcm_.FrameTypeRequest(type, stream_idx); vcm_.IntraFrameRequest();
time_last_intra_request_ms_[stream_idx] = now; time_last_intra_request_ms_ = now;
} }
void ViEEncoder::OnNetworkChanged(const WebRtc_Word32 id, void ViEEncoder::OnNetworkChanged(const WebRtc_Word32 id,

View File

@ -157,7 +157,7 @@ class ViEEncoder
VideoCodec send_codec_; VideoCodec send_codec_;
bool paused_; bool paused_;
WebRtc_Word64 time_last_intra_request_ms_[kMaxSimulcastStreams]; WebRtc_Word64 time_last_intra_request_ms_;
WebRtc_Word32 channels_dropping_delta_frames_; WebRtc_Word32 channels_dropping_delta_frames_;
bool drop_next_frame_; bool drop_next_frame_;