video_coding: Refatoring I420 wrapper. No functional updates.
BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/673009 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2504 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
0bb817dab0
commit
b95e9ca865
@ -14,41 +14,40 @@
|
||||
#include "video_codec_interface.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
namespace webrtc
|
||||
{
|
||||
namespace webrtc {
|
||||
|
||||
class I420Encoder : public VideoEncoder
|
||||
{
|
||||
class I420Encoder : public VideoEncoder {
|
||||
public:
|
||||
|
||||
I420Encoder();
|
||||
|
||||
virtual ~I420Encoder();
|
||||
|
||||
// Initialize the encoder with the information from the VideoCodec
|
||||
// Initialize the encoder with the information from the VideoCodec.
|
||||
//
|
||||
// Input:
|
||||
// - codecSettings : Codec settings
|
||||
// - numberOfCores : Number of cores available for the encoder
|
||||
// - codecSettings : Codec settings.
|
||||
// - numberOfCores : Number of cores available for the encoder.
|
||||
// - maxPayloadSize : The maximum size each payload is allowed
|
||||
// to have. Usually MTU - overhead.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK.
|
||||
// <0 - Error
|
||||
virtual WebRtc_Word32 InitEncode(const VideoCodec* codecSettings, WebRtc_Word32 /*numberOfCores*/, WebRtc_UWord32 /*maxPayloadSize*/);
|
||||
virtual int InitEncode(const VideoCodec* codecSettings,
|
||||
int /*numberOfCores*/,
|
||||
uint32_t /*maxPayloadSize*/);
|
||||
|
||||
// "Encode" an I420 image (as a part of a video stream). The encoded image
|
||||
// will be returned to the user via the encode complete callback.
|
||||
//
|
||||
// Input:
|
||||
// - inputImage : Image to be encoded
|
||||
// - codecSpecificInfo : Pointer to codec specific data
|
||||
// - inputImage : Image to be encoded.
|
||||
// - codecSpecificInfo : Pointer to codec specific data.
|
||||
// - frameType : Frame type to be sent (Key /Delta).
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK.
|
||||
// <0 - Error
|
||||
virtual WebRtc_Word32
|
||||
Encode(const RawImage& inputImage,
|
||||
virtual int Encode(const RawImage& inputImage,
|
||||
const CodecSpecificInfo* /*codecSpecificInfo*/,
|
||||
const VideoFrameType /*frameTypes*/);
|
||||
|
||||
@ -58,23 +57,20 @@ public:
|
||||
// - callback : Callback object which handles encoded images.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
||||
virtual WebRtc_Word32 RegisterEncodeCompleteCallback(EncodedImageCallback* callback);
|
||||
virtual int RegisterEncodeCompleteCallback(EncodedImageCallback* callback);
|
||||
|
||||
// Free encoder memory.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
||||
virtual WebRtc_Word32 Release();
|
||||
virtual int Release();
|
||||
|
||||
virtual WebRtc_Word32 SetRates(WebRtc_UWord32 /*newBitRate*/,
|
||||
WebRtc_UWord32 /*frameRate*/)
|
||||
virtual int SetRates(uint32_t /*newBitRate*/, uint32_t /*frameRate*/)
|
||||
{return WEBRTC_VIDEO_CODEC_OK;}
|
||||
|
||||
virtual WebRtc_Word32 SetChannelParameters(WebRtc_UWord32 /*packetLoss*/,
|
||||
int /*rtt*/)
|
||||
virtual int SetChannelParameters(uint32_t /*packetLoss*/, int /*rtt*/)
|
||||
{return WEBRTC_VIDEO_CODEC_OK;}
|
||||
|
||||
virtual WebRtc_Word32 CodecConfigParameters(WebRtc_UWord8* /*buffer*/,
|
||||
WebRtc_Word32 /*size*/)
|
||||
virtual int CodecConfigParameters(uint8_t* /*buffer*/, int /*size*/)
|
||||
{return WEBRTC_VIDEO_CODEC_OK;}
|
||||
|
||||
private:
|
||||
@ -84,8 +80,7 @@ private:
|
||||
|
||||
}; // end of WebRtcI420DEncoder class
|
||||
|
||||
class I420Decoder : public VideoDecoder
|
||||
{
|
||||
class I420Decoder : public VideoDecoder {
|
||||
public:
|
||||
|
||||
I420Decoder();
|
||||
@ -97,9 +92,11 @@ public:
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK.
|
||||
// <0 - Errors
|
||||
virtual WebRtc_Word32 InitDecode(const VideoCodec* codecSettings, WebRtc_Word32 /*numberOfCores*/);
|
||||
virtual int InitDecode(const VideoCodec* codecSettings,
|
||||
int /*numberOfCores*/);
|
||||
|
||||
virtual WebRtc_Word32 SetCodecConfigParameters(const WebRtc_UWord8* /*buffer*/, WebRtc_Word32 /*size*/){return WEBRTC_VIDEO_CODEC_OK;};
|
||||
virtual int SetCodecConfigParameters(const uint8_t* /*buffer*/, int /*size*/)
|
||||
{return WEBRTC_VIDEO_CODEC_OK;};
|
||||
|
||||
// Decode encoded image (as a part of a video stream). The decoded image
|
||||
// will be returned to the user through the decode complete callback.
|
||||
@ -113,12 +110,11 @@ public:
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
||||
// <0 - Error
|
||||
virtual WebRtc_Word32 Decode(
|
||||
const EncodedImage& inputImage,
|
||||
virtual int Decode(const EncodedImage& inputImage,
|
||||
bool missingFrames,
|
||||
const RTPFragmentationHeader* /*fragmentation*/,
|
||||
const CodecSpecificInfo* /*codecSpecificInfo*/,
|
||||
WebRtc_Word64 /*renderTimeMs*/);
|
||||
int64_t /*renderTimeMs*/);
|
||||
|
||||
// Register a decode complete callback object.
|
||||
//
|
||||
@ -126,30 +122,29 @@ public:
|
||||
// - callback : Callback object which handles decoded images.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
||||
virtual WebRtc_Word32 RegisterDecodeCompleteCallback(DecodedImageCallback* callback);
|
||||
virtual int RegisterDecodeCompleteCallback(DecodedImageCallback* callback);
|
||||
|
||||
// Free decoder memory.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK if OK.
|
||||
// <0 - Error
|
||||
virtual WebRtc_Word32 Release();
|
||||
virtual int Release();
|
||||
|
||||
// Reset decoder state and prepare for a new call.
|
||||
//
|
||||
// Return value : WEBRTC_VIDEO_CODEC_OK.
|
||||
// <0 - Error
|
||||
virtual WebRtc_Word32 Reset();
|
||||
virtual int Reset();
|
||||
|
||||
private:
|
||||
|
||||
RawImage _decodedImage;
|
||||
WebRtc_Word32 _width;
|
||||
WebRtc_Word32 _height;
|
||||
int _width;
|
||||
int _height;
|
||||
bool _inited;
|
||||
DecodedImageCallback* _decodeCompleteCallback;
|
||||
|
||||
|
||||
}; // end of WebRtcI420Decoder class
|
||||
}; // End of WebRtcI420Decoder class.
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
@ -18,26 +18,20 @@ I420Encoder::I420Encoder():
|
||||
_inited(false),
|
||||
_encodedImage(),
|
||||
_encodedCompleteCallback(NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
{}
|
||||
|
||||
I420Encoder::~I420Encoder()
|
||||
{
|
||||
I420Encoder::~I420Encoder() {
|
||||
_inited = false;
|
||||
if (_encodedImage._buffer != NULL)
|
||||
{
|
||||
if (_encodedImage._buffer != NULL) {
|
||||
delete [] _encodedImage._buffer;
|
||||
_encodedImage._buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
I420Encoder::Release()
|
||||
{
|
||||
// should allocate an encoded frame and then release it here, for that we actaully need an init flag
|
||||
if (_encodedImage._buffer != NULL)
|
||||
{
|
||||
int I420Encoder::Release() {
|
||||
// Should allocate an encoded frame and then release it here, for that we
|
||||
// actually need an init flag.
|
||||
if (_encodedImage._buffer != NULL) {
|
||||
delete [] _encodedImage._buffer;
|
||||
_encodedImage._buffer = NULL;
|
||||
}
|
||||
@ -45,77 +39,64 @@ I420Encoder::Release()
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
I420Encoder::InitEncode(const VideoCodec* codecSettings,
|
||||
WebRtc_Word32 /*numberOfCores*/,
|
||||
WebRtc_UWord32 /*maxPayloadSize */)
|
||||
{
|
||||
if (codecSettings == NULL)
|
||||
{
|
||||
int I420Encoder::InitEncode(const VideoCodec* codecSettings,
|
||||
int /*numberOfCores*/,
|
||||
uint32_t /*maxPayloadSize */) {
|
||||
if (codecSettings == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
if (codecSettings->width < 1 || codecSettings->height < 1)
|
||||
{
|
||||
if (codecSettings->width < 1 || codecSettings->height < 1) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
|
||||
// allocating encoded memory
|
||||
|
||||
if (_encodedImage._buffer != NULL)
|
||||
{
|
||||
// Allocating encoded memory.
|
||||
if (_encodedImage._buffer != NULL) {
|
||||
delete [] _encodedImage._buffer;
|
||||
_encodedImage._buffer = NULL;
|
||||
_encodedImage._size = 0;
|
||||
}
|
||||
const WebRtc_UWord32 newSize = (3 * codecSettings->width *
|
||||
const uint32_t newSize = (3 * codecSettings->width *
|
||||
codecSettings->height) >> 1;
|
||||
WebRtc_UWord8* newBuffer = new WebRtc_UWord8[newSize];
|
||||
if (newBuffer == NULL)
|
||||
{
|
||||
uint8_t* newBuffer = new uint8_t[newSize];
|
||||
if (newBuffer == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_MEMORY;
|
||||
}
|
||||
_encodedImage._size = newSize;
|
||||
_encodedImage._buffer = newBuffer;
|
||||
|
||||
// if no memory allocation, no point to init
|
||||
// If no memory allocation, no point to init.
|
||||
_inited = true;
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WebRtc_Word32
|
||||
I420Encoder::Encode(const RawImage& inputImage,
|
||||
int I420Encoder::Encode(const RawImage& inputImage,
|
||||
const CodecSpecificInfo* /*codecSpecificInfo*/,
|
||||
const VideoFrameType /*frameType*/)
|
||||
{
|
||||
if (!_inited)
|
||||
{
|
||||
const VideoFrameType /*frameType*/) {
|
||||
if (!_inited) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
}
|
||||
if (_encodedCompleteCallback == NULL)
|
||||
{
|
||||
if (_encodedCompleteCallback == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
}
|
||||
|
||||
_encodedImage._frameType = kKeyFrame; // no coding
|
||||
_encodedImage._frameType = kKeyFrame; // No coding.
|
||||
_encodedImage._timeStamp = inputImage._timeStamp;
|
||||
_encodedImage._encodedHeight = inputImage._height;
|
||||
_encodedImage._encodedWidth = inputImage._width;
|
||||
if (inputImage._length > _encodedImage._size)
|
||||
{
|
||||
if (inputImage._length > _encodedImage._size) {
|
||||
|
||||
// allocating encoded memory
|
||||
if (_encodedImage._buffer != NULL)
|
||||
{
|
||||
// Allocating encoded memory.
|
||||
if (_encodedImage._buffer != NULL) {
|
||||
delete [] _encodedImage._buffer;
|
||||
_encodedImage._buffer = NULL;
|
||||
_encodedImage._size = 0;
|
||||
}
|
||||
const WebRtc_UWord32 newSize = (3 * _encodedImage._encodedWidth * _encodedImage._encodedHeight) >> 1;
|
||||
WebRtc_UWord8* newBuffer = new WebRtc_UWord8[newSize];
|
||||
if (newBuffer == NULL)
|
||||
{
|
||||
const uint32_t newSize = (3 * _encodedImage._encodedWidth *
|
||||
_encodedImage._encodedHeight) >> 1;
|
||||
uint8_t* newBuffer = new uint8_t[newSize];
|
||||
if (newBuffer == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_MEMORY;
|
||||
}
|
||||
_encodedImage._size = newSize;
|
||||
@ -128,9 +109,8 @@ I420Encoder::Encode(const RawImage& inputImage,
|
||||
}
|
||||
|
||||
|
||||
WebRtc_Word32
|
||||
I420Encoder::RegisterEncodeCompleteCallback(EncodedImageCallback* callback)
|
||||
{
|
||||
int
|
||||
I420Encoder::RegisterEncodeCompleteCallback(EncodedImageCallback* callback) {
|
||||
_encodedCompleteCallback = callback;
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
@ -142,31 +122,24 @@ _width(0),
|
||||
_height(0),
|
||||
_inited(false),
|
||||
_decodeCompleteCallback(NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
{}
|
||||
|
||||
I420Decoder::~I420Decoder()
|
||||
{
|
||||
I420Decoder::~I420Decoder() {
|
||||
Release();
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
I420Decoder::Reset()
|
||||
{
|
||||
int
|
||||
I420Decoder::Reset() {
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
|
||||
WebRtc_Word32
|
||||
I420Decoder::InitDecode(const VideoCodec* codecSettings, WebRtc_Word32 /*numberOfCores */)
|
||||
{
|
||||
if (codecSettings == NULL)
|
||||
{
|
||||
int
|
||||
I420Decoder::InitDecode(const VideoCodec* codecSettings,
|
||||
int /*numberOfCores */) {
|
||||
if (codecSettings == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
else if (codecSettings->width < 1 || codecSettings->height < 1)
|
||||
{
|
||||
} else if (codecSettings->width < 1 || codecSettings->height < 1) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
_width = codecSettings->width;
|
||||
@ -175,74 +148,61 @@ I420Decoder::InitDecode(const VideoCodec* codecSettings, WebRtc_Word32 /*numberO
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
int
|
||||
I420Decoder::Decode(const EncodedImage& inputImage,
|
||||
bool /*missingFrames*/,
|
||||
const RTPFragmentationHeader* /*fragmentation*/,
|
||||
const CodecSpecificInfo* /*codecSpecificInfo*/,
|
||||
WebRtc_Word64 /*renderTimeMs*/)
|
||||
{
|
||||
if (inputImage._buffer == NULL)
|
||||
{
|
||||
int64_t /*renderTimeMs*/) {
|
||||
if (inputImage._buffer == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
if (_decodeCompleteCallback == NULL)
|
||||
{
|
||||
if (_decodeCompleteCallback == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
}
|
||||
if (inputImage._length <= 0)
|
||||
{
|
||||
if (inputImage._length <= 0) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
if (!_inited)
|
||||
{
|
||||
if (!_inited) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
}
|
||||
|
||||
//Allocate memory for decoded image
|
||||
|
||||
if (_decodedImage._buffer != NULL)
|
||||
{
|
||||
// Allocate memory for decoded image.
|
||||
if (_decodedImage._buffer != NULL) {
|
||||
delete [] _decodedImage._buffer;
|
||||
_decodedImage._buffer = NULL;
|
||||
_decodedImage._size = 0;
|
||||
}
|
||||
if (_decodedImage._buffer == NULL)
|
||||
{
|
||||
const WebRtc_UWord32 newSize = (3*_width*_height) >> 1;
|
||||
WebRtc_UWord8* newBuffer = new WebRtc_UWord8[newSize];
|
||||
if (newBuffer == NULL)
|
||||
{
|
||||
if (_decodedImage._buffer == NULL) {
|
||||
const uint32_t newSize = (3*_width*_height) >> 1;
|
||||
uint8_t* newBuffer = new uint8_t[newSize];
|
||||
if (newBuffer == NULL) {
|
||||
return WEBRTC_VIDEO_CODEC_MEMORY;
|
||||
}
|
||||
_decodedImage._size = newSize;
|
||||
_decodedImage._buffer = newBuffer;
|
||||
}
|
||||
|
||||
// Set decoded image parameters
|
||||
// Set decoded image parameters.
|
||||
_decodedImage._height = _height;
|
||||
_decodedImage._width = _width;
|
||||
_decodedImage._timeStamp = inputImage._timeStamp;
|
||||
memcpy(_decodedImage._buffer, inputImage._buffer, inputImage._length);
|
||||
_decodedImage._length = inputImage._length;
|
||||
//_decodedImage._buffer = inputImage._buffer;
|
||||
|
||||
_decodeCompleteCallback->Decoded(_decodedImage);
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
I420Decoder::RegisterDecodeCompleteCallback(DecodedImageCallback* callback)
|
||||
{
|
||||
int
|
||||
I420Decoder::RegisterDecodeCompleteCallback(DecodedImageCallback* callback) {
|
||||
_decodeCompleteCallback = callback;
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebRtc_Word32
|
||||
I420Decoder::Release()
|
||||
{
|
||||
if (_decodedImage._buffer != NULL)
|
||||
{
|
||||
int
|
||||
I420Decoder::Release() {
|
||||
if (_decodedImage._buffer != NULL) {
|
||||
delete [] _decodedImage._buffer;
|
||||
_decodedImage._buffer = NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user