blob: c933a33469782b7ce461a6b1e8cae023b32beef5 [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.
changbin.shao@webrtc.org972ccb82015-02-09 09:14:0332 virtual int32_t Encoded(const EncodedImage& encoded_image,
33 const CodecSpecificInfo* codec_specific_info,
34 const RTPFragmentationHeader* fragmentation) = 0;
pbos@webrtc.org1c655452014-09-17 09:02:2535};
36
37class VideoEncoder {
38 public:
39 enum EncoderType {
40 kVp8,
marpan@webrtc.org66373882014-11-01 06:10:4841 kVp9,
pbos@webrtc.org1c655452014-09-17 09:02:2542 };
43
44 static VideoEncoder* Create(EncoderType codec_type);
45
pbos@webrtc.org6b970152014-09-18 12:42:2846 static VideoCodecVP8 GetDefaultVp8Settings();
marpan@webrtc.org66373882014-11-01 06:10:4847 static VideoCodecVP9 GetDefaultVp9Settings();
pbos@webrtc.org6b970152014-09-18 12:42:2848 static VideoCodecH264 GetDefaultH264Settings();
49
pbos@webrtc.org1c655452014-09-17 09:02:2550 virtual ~VideoEncoder() {}
51
marpan@webrtc.org66373882014-11-01 06:10:4852 // Initialize the encoder with the information from the codecSettings
53 //
54 // Input:
55 // - codec_settings : Codec settings
56 // - number_of_cores : Number of cores available for the encoder
57 // - max_payload_size : The maximum size each payload is allowed
58 // to have. Usually MTU - overhead.
59 //
60 // Return value : Set bit rate if OK
61 // <0 - Errors:
62 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
63 // WEBRTC_VIDEO_CODEC_ERR_SIZE
64 // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED
65 // WEBRTC_VIDEO_CODEC_MEMORY
66 // WEBRTC_VIDEO_CODEC_ERROR
pbos@webrtc.org1c655452014-09-17 09:02:2567 virtual int32_t InitEncode(const VideoCodec* codec_settings,
68 int32_t number_of_cores,
pkasting@chromium.org0ab923a2014-11-20 22:28:1469 size_t max_payload_size) = 0;
marpan@webrtc.org66373882014-11-01 06:10:4870
71 // Register an encode complete callback object.
72 //
73 // Input:
74 // - callback : Callback object which handles encoded images.
75 //
76 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:2577 virtual int32_t RegisterEncodeCompleteCallback(
78 EncodedImageCallback* callback) = 0;
marpan@webrtc.org66373882014-11-01 06:10:4879
80 // Free encoder memory.
81 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:2582 virtual int32_t Release() = 0;
83
marpan@webrtc.org66373882014-11-01 06:10:4884 // Encode an I420 image (as a part of a video stream). The encoded image
85 // will be returned to the user through the encode complete callback.
86 //
87 // Input:
88 // - frame : Image to be encoded
89 // - frame_types : Frame type to be generated by the encoder.
90 //
91 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
92 // <0 - Errors:
93 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
94 // WEBRTC_VIDEO_CODEC_MEMORY
95 // WEBRTC_VIDEO_CODEC_ERROR
96 // WEBRTC_VIDEO_CODEC_TIMEOUT
pbos@webrtc.org1c655452014-09-17 09:02:2597 virtual int32_t Encode(const I420VideoFrame& frame,
98 const CodecSpecificInfo* codec_specific_info,
99 const std::vector<VideoFrameType>* frame_types) = 0;
100
marpan@webrtc.org66373882014-11-01 06:10:48101 // Inform the encoder of the new packet loss rate and the round-trip time of
102 // the network.
103 //
104 // Input:
105 // - packet_loss : Fraction lost
106 // (loss rate in percent = 100 * packetLoss / 255)
107 // - rtt : Round-trip time in milliseconds
108 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
109 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
pkasting@chromium.orga3166c42015-01-12 21:51:21110 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0;
marpan@webrtc.org66373882014-11-01 06:10:48111
112 // Inform the encoder about the new target bit rate.
113 //
114 // Input:
115 // - bitrate : New target bit rate
116 // - framerate : The target frame rate
117 //
118 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
pbos@webrtc.org1c655452014-09-17 09:02:25119 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0;
120
121 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
122 virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) {
123 return -1;
124 }
125};
126
127} // namespace webrtc
128#endif // WEBRTC_VIDEO_ENCODER_H_