Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: webrtc/media/engine/videoencodersoftwarefallbackwrapper.h

Issue 2484863009: Move VideoEncoderSoftwareFallbackWrapper from webrtc/video_encoder.h to webrtc/media/engine/ (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/BUILD.gn ('k') | webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_VIDEO_ENCODER_H_ 11 #ifndef WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_
12 #define WEBRTC_VIDEO_ENCODER_H_ 12 #define WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/common_types.h" 18 #include "webrtc/video_encoder.h"
19 #include "webrtc/typedefs.h"
20 #include "webrtc/video_frame.h"
21 19
22 namespace webrtc { 20 namespace webrtc {
23 21
24 class RTPFragmentationHeader;
25 // TODO(pbos): Expose these through a public (root) header or change these APIs.
26 struct CodecSpecificInfo;
27 class VideoCodec;
28
29 class EncodedImageCallback {
30 public:
31 virtual ~EncodedImageCallback() {}
32
33 struct Result {
34 enum Error {
35 OK,
36
37 // Failed to send the packet.
38 ERROR_SEND_FAILED,
39 };
40
41 Result(Error error) : error(error) {}
42 Result(Error error, uint32_t frame_id) : error(error), frame_id(frame_id) {}
43
44 Error error;
45
46 // Frame ID assigned to the frame. The frame ID should be the same as the ID
47 // seen by the receiver for this frame. RTP timestamp of the frame is used
48 // as frame ID when RTP is used to send video. Must be used only when
49 // error=OK.
50 uint32_t frame_id = 0;
51
52 // Tells the encoder that the next frame is should be dropped.
53 bool drop_next_frame = false;
54 };
55
56 // Callback function which is called when an image has been encoded.
57 virtual Result OnEncodedImage(
58 const EncodedImage& encoded_image,
59 const CodecSpecificInfo* codec_specific_info,
60 const RTPFragmentationHeader* fragmentation) = 0;
61 };
62
63 class VideoEncoder {
64 public:
65 enum EncoderType {
66 kH264,
67 kVp8,
68 kVp9,
69 kUnsupportedCodec,
70 };
71
72 static VideoEncoder* Create(EncoderType codec_type);
73 // Returns true if this type of encoder can be created using
74 // VideoEncoder::Create.
75 static bool IsSupportedSoftware(EncoderType codec_type);
76 static EncoderType CodecToEncoderType(VideoCodecType codec_type);
77
78 static VideoCodecVP8 GetDefaultVp8Settings();
79 static VideoCodecVP9 GetDefaultVp9Settings();
80 static VideoCodecH264 GetDefaultH264Settings();
81
82 virtual ~VideoEncoder() {}
83
84 // Initialize the encoder with the information from the codecSettings
85 //
86 // Input:
87 // - codec_settings : Codec settings
88 // - number_of_cores : Number of cores available for the encoder
89 // - max_payload_size : The maximum size each payload is allowed
90 // to have. Usually MTU - overhead.
91 //
92 // Return value : Set bit rate if OK
93 // <0 - Errors:
94 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
95 // WEBRTC_VIDEO_CODEC_ERR_SIZE
96 // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED
97 // WEBRTC_VIDEO_CODEC_MEMORY
98 // WEBRTC_VIDEO_CODEC_ERROR
99 virtual int32_t InitEncode(const VideoCodec* codec_settings,
100 int32_t number_of_cores,
101 size_t max_payload_size) = 0;
102
103 // Register an encode complete callback object.
104 //
105 // Input:
106 // - callback : Callback object which handles encoded images.
107 //
108 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
109 virtual int32_t RegisterEncodeCompleteCallback(
110 EncodedImageCallback* callback) = 0;
111
112 // Free encoder memory.
113 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
114 virtual int32_t Release() = 0;
115
116 // Encode an I420 image (as a part of a video stream). The encoded image
117 // will be returned to the user through the encode complete callback.
118 //
119 // Input:
120 // - frame : Image to be encoded
121 // - frame_types : Frame type to be generated by the encoder.
122 //
123 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
124 // <0 - Errors:
125 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER
126 // WEBRTC_VIDEO_CODEC_MEMORY
127 // WEBRTC_VIDEO_CODEC_ERROR
128 // WEBRTC_VIDEO_CODEC_TIMEOUT
129 virtual int32_t Encode(const VideoFrame& frame,
130 const CodecSpecificInfo* codec_specific_info,
131 const std::vector<FrameType>* frame_types) = 0;
132
133 // Inform the encoder of the new packet loss rate and the round-trip time of
134 // the network.
135 //
136 // Input:
137 // - packet_loss : Fraction lost
138 // (loss rate in percent = 100 * packetLoss / 255)
139 // - rtt : Round-trip time in milliseconds
140 // Return value : WEBRTC_VIDEO_CODEC_OK if OK
141 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
142 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0;
143
144 // Inform the encoder about the new target bit rate.
145 //
146 // Input:
147 // - bitrate : New target bit rate
148 // - framerate : The target frame rate
149 //
150 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
151 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0;
152
153 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
154 virtual void OnDroppedFrame() {}
155 virtual bool SupportsNativeHandle() const { return false; }
156 virtual const char* ImplementationName() const { return "unknown"; }
157 };
158
159 // Class used to wrap external VideoEncoders to provide a fallback option on 22 // Class used to wrap external VideoEncoders to provide a fallback option on
160 // software encoding when a hardware encoder fails to encode a stream due to 23 // software encoding when a hardware encoder fails to encode a stream due to
161 // hardware restrictions, such as max resolution. 24 // hardware restrictions, such as max resolution.
162 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { 25 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder {
163 public: 26 public:
164 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type, 27 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type,
165 webrtc::VideoEncoder* encoder); 28 webrtc::VideoEncoder* encoder);
166 29
167 int32_t InitEncode(const VideoCodec* codec_settings, 30 int32_t InitEncode(const VideoCodec* codec_settings,
168 int32_t number_of_cores, 31 int32_t number_of_cores,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 uint32_t packet_loss_; 63 uint32_t packet_loss_;
201 int64_t rtt_; 64 int64_t rtt_;
202 65
203 const EncoderType encoder_type_; 66 const EncoderType encoder_type_;
204 webrtc::VideoEncoder* const encoder_; 67 webrtc::VideoEncoder* const encoder_;
205 68
206 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; 69 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_;
207 std::string fallback_implementation_name_; 70 std::string fallback_implementation_name_;
208 EncodedImageCallback* callback_; 71 EncodedImageCallback* callback_;
209 }; 72 };
73
210 } // namespace webrtc 74 } // namespace webrtc
211 #endif // WEBRTC_VIDEO_ENCODER_H_ 75
76 #endif // WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_
OLDNEW
« no previous file with comments | « webrtc/media/BUILD.gn ('k') | webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698