blob: a66a51a7d9fadc9395ee3cb659e7b0344e34721b [file] [log] [blame]
pbos@webrtc.org1c655452014-09-17 09:02:251/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_VIDEO_ENCODER_H_
12#define WEBRTC_VIDEO_ENCODER_H_
13
14#include <vector>
15
pbos@webrtc.org6b970152014-09-18 12:42:2816#include "webrtc/common_types.h"
pbos@webrtc.org1c655452014-09-17 09:02:2517#include "webrtc/typedefs.h"
18#include "webrtc/video_frame.h"
19
20namespace webrtc {
21
22class RTPFragmentationHeader;
23// TODO(pbos): Expose these through a public (root) header or change these APIs.
24struct CodecSpecificInfo;
25struct VideoCodec;
26
27class EncodedImageCallback {
28 public:
29 virtual ~EncodedImageCallback() {}
30
31 // Callback function which is called when an image has been encoded.
pbos@webrtc.orgee9497c2014-12-01 15:23:2132 // TODO(pbos): Remove default arguments.
pbos@webrtc.org1c655452014-09-17 09:02:2533 virtual int32_t Encoded(
pbos@webrtc.orgee9497c2014-12-01 15:23:2134 const EncodedImage& encoded_image,
pbos@webrtc.org1c655452014-09-17 09:02:2535 const CodecSpecificInfo* codec_specific_info = NULL,
36 const RTPFragmentationHeader* fragmentation = NULL) = 0;
37};
38
39class VideoEncoder {
40 public:
41 enum EncoderType {
42 kVp8,
marpan@webrtc.org66373882014-11-01 06:10:4843 kVp9,
pbos@webrtc.org1c655452014-09-17 09:02:2544 };
45
46 static VideoEncoder* Create(EncoderType codec_type);
47
pbos@webrtc.org6b970152014-09-18 12:42:2848 static VideoCodecVP8 GetDefaultVp8Settings();
marpan@webrtc.org66373882014-11-01 06:10:4849 static VideoCodecVP9 GetDefaultVp9Settings();
pbos@webrtc.org6b970152014-09-18 12:42:2850 static VideoCodecH264 GetDefaultH264Settings();
51
pbos@webrtc.org1c655452014-09-17 09:02:2552 virtual ~VideoEncoder() {}
53
marpan@webrtc.org66373882014-11-01 06:10:4854 // Initialize the encoder with the information from the codecSettings
55 //
56 // Input:
57 // - codec_settings : Codec settings
58 // - number_of_cores : Number of cores available for the encoder
59 // - max_payload_size : The maximum size each payload is allowed
60 // to have. Usually MTU - overhead.
61 //
62 // Return value : Set bit rate if OK
63 // <0 - Errors:
64 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
65 // WEBRTC_VIDEO_CODEC_ERR_SIZE
66 // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED
67 // WEBRTC_VIDEO_CODEC_MEMORY
68 // WEBRTC_VIDEO_CODEC_ERROR
pbos@webrtc.org1c655452014-09-17 09:02:2569 virtual int32_t InitEncode(const VideoCodec* codec_settings,
70 int32_t number_of_cores,
pkasting@chromium.org0ab923a2014-11-20 22:28:1471 size_t max_payload_size) = 0;
marpan@webrtc.org66373882014-11-01 06:10:4872
73 // Register an encode complete callback object.
74 //
75 // Input:
76 // - callback : Callback object which handles encoded images.
77 //
78 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:2579 virtual int32_t RegisterEncodeCompleteCallback(
80 EncodedImageCallback* callback) = 0;
marpan@webrtc.org66373882014-11-01 06:10:4881
82 // Free encoder memory.
83 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:2584 virtual int32_t Release() = 0;
85
marpan@webrtc.org66373882014-11-01 06:10:4886 // Encode an I420 image (as a part of a video stream). The encoded image
87 // will be returned to the user through the encode complete callback.
88 //
89 // Input:
90 // - frame : Image to be encoded
91 // - frame_types : Frame type to be generated by the encoder.
92 //
93 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
94 // <0 - Errors:
95 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
96 // WEBRTC_VIDEO_CODEC_MEMORY
97 // WEBRTC_VIDEO_CODEC_ERROR
98 // WEBRTC_VIDEO_CODEC_TIMEOUT
pbos@webrtc.org1c655452014-09-17 09:02:2599 virtual int32_t Encode(const I420VideoFrame& frame,
100 const CodecSpecificInfo* codec_specific_info,
101 const std::vector<VideoFrameType>* frame_types) = 0;
102
marpan@webrtc.org66373882014-11-01 06:10:48103 // Inform the encoder of the new packet loss rate and the round-trip time of
104 // the network.
105 //
106 // Input:
107 // - packet_loss : Fraction lost
108 // (loss rate in percent = 100 * packetLoss / 255)
109 // - rtt : Round-trip time in milliseconds
110 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
111 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
pbos@webrtc.org1c655452014-09-17 09:02:25112 virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) = 0;
marpan@webrtc.org66373882014-11-01 06:10:48113
114 // Inform the encoder about the new target bit rate.
115 //
116 // Input:
117 // - bitrate : New target bit rate
118 // - framerate : The target frame rate
119 //
120 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:25121 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0;
122
123 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
124 virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) {
125 return -1;
126 }
127};
128
129} // namespace webrtc
130#endif // WEBRTC_VIDEO_ENCODER_H_