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
131 lines
4.8 KiB
C++
131 lines
4.8 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef WEBRTC_VIDEO_ENCODER_H_
|
|
#define WEBRTC_VIDEO_ENCODER_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "webrtc/common_types.h"
|
|
#include "webrtc/typedefs.h"
|
|
#include "webrtc/video_frame.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class RTPFragmentationHeader;
|
|
// TODO(pbos): Expose these through a public (root) header or change these APIs.
|
|
struct CodecSpecificInfo;
|
|
struct VideoCodec;
|
|
|
|
class EncodedImageCallback {
|
|
public:
|
|
virtual ~EncodedImageCallback() {}
|
|
|
|
// Callback function which is called when an image has been encoded.
|
|
// TODO(pbos): Make encoded_image const or pointer. Remove default arguments.
|
|
virtual int32_t Encoded(
|
|
EncodedImage& encoded_image,
|
|
const CodecSpecificInfo* codec_specific_info = NULL,
|
|
const RTPFragmentationHeader* fragmentation = NULL) = 0;
|
|
};
|
|
|
|
class VideoEncoder {
|
|
public:
|
|
enum EncoderType {
|
|
kVp8,
|
|
kVp9,
|
|
};
|
|
|
|
static VideoEncoder* Create(EncoderType codec_type);
|
|
|
|
static VideoCodecVP8 GetDefaultVp8Settings();
|
|
static VideoCodecVP9 GetDefaultVp9Settings();
|
|
static VideoCodecH264 GetDefaultH264Settings();
|
|
|
|
virtual ~VideoEncoder() {}
|
|
|
|
// Initialize the encoder with the information from the codecSettings
|
|
//
|
|
// Input:
|
|
// - codec_settings : Codec settings
|
|
// - number_of_cores : Number of cores available for the encoder
|
|
// - max_payload_size : The maximum size each payload is allowed
|
|
// to have. Usually MTU - overhead.
|
|
//
|
|
// Return value : Set bit rate if OK
|
|
// <0 - Errors:
|
|
// WEBRTC_VIDEO_CODEC_ERR_PARAMETER
|
|
// WEBRTC_VIDEO_CODEC_ERR_SIZE
|
|
// WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED
|
|
// WEBRTC_VIDEO_CODEC_MEMORY
|
|
// WEBRTC_VIDEO_CODEC_ERROR
|
|
virtual int32_t InitEncode(const VideoCodec* codec_settings,
|
|
int32_t number_of_cores,
|
|
size_t max_payload_size) = 0;
|
|
|
|
// Register an encode complete callback object.
|
|
//
|
|
// Input:
|
|
// - callback : Callback object which handles encoded images.
|
|
//
|
|
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
|
virtual int32_t RegisterEncodeCompleteCallback(
|
|
EncodedImageCallback* callback) = 0;
|
|
|
|
// Free encoder memory.
|
|
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
|
virtual int32_t Release() = 0;
|
|
|
|
// Encode an I420 image (as a part of a video stream). The encoded image
|
|
// will be returned to the user through the encode complete callback.
|
|
//
|
|
// Input:
|
|
// - frame : Image to be encoded
|
|
// - frame_types : Frame type to be generated by the encoder.
|
|
//
|
|
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
|
// <0 - Errors:
|
|
// WEBRTC_VIDEO_CODEC_ERR_PARAMETER
|
|
// WEBRTC_VIDEO_CODEC_MEMORY
|
|
// WEBRTC_VIDEO_CODEC_ERROR
|
|
// WEBRTC_VIDEO_CODEC_TIMEOUT
|
|
virtual int32_t Encode(const I420VideoFrame& frame,
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
const std::vector<VideoFrameType>* frame_types) = 0;
|
|
|
|
// Inform the encoder of the new packet loss rate and the round-trip time of
|
|
// the network.
|
|
//
|
|
// Input:
|
|
// - packet_loss : Fraction lost
|
|
// (loss rate in percent = 100 * packetLoss / 255)
|
|
// - rtt : Round-trip time in milliseconds
|
|
// Return value : WEBRTC_VIDEO_CODEC_OK if OK
|
|
// <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
|
|
virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) = 0;
|
|
|
|
// Inform the encoder about the new target bit rate.
|
|
//
|
|
// Input:
|
|
// - bitrate : New target bit rate
|
|
// - framerate : The target frame rate
|
|
//
|
|
// Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
|
|
virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0;
|
|
|
|
virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
|
|
virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) {
|
|
return -1;
|
|
}
|
|
};
|
|
|
|
} // namespace webrtc
|
|
#endif // WEBRTC_VIDEO_ENCODER_H_
|