blob: 9f73f36e5d6e5e153ff13c5db2a365bfdc28ae07 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.org52fd98d2012-02-13 09:03:53 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_
12#define WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_
13
philipel9d3ab612015-12-21 04:12:39 -080014#include <stdio.h>
15#include <vector>
16
Henrik Kjellander2557b862015-11-18 22:00:21 +010017#include "webrtc/modules/video_coding/include/video_codec_interface.h"
18#include "webrtc/modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
tommi@webrtc.org558dc402015-03-07 20:55:56 +000020#include "webrtc/base/criticalsection.h"
Peter Boström02bafc62016-07-01 12:45:15 +020021#include "webrtc/base/race_checker.h"
sprang@webrtc.org40709352013-11-26 11:41:59 +000022
andresp@webrtc.org1df9dc32014-01-09 08:01:57 +000023namespace webrtc {
sprang@webrtc.org40709352013-11-26 11:41:59 +000024class CriticalSectionWrapper;
25
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000026namespace media_optimization {
henrik.lundin@webrtc.orgbec11ef2013-09-23 19:54:25 +000027class MediaOptimization;
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000028} // namespace media_optimization
niklase@google.com470e71d2011-07-07 08:21:25 +000029
Peter Boström69ccb332015-10-29 16:30:23 +010030struct EncoderParameters {
31 uint32_t target_bitrate;
32 uint8_t loss_rate;
33 int64_t rtt;
34 uint32_t input_frame_rate;
35};
36
philipel9d3ab612015-12-21 04:12:39 -080037class VCMEncodedFrameCallback : public EncodedImageCallback {
38 public:
perkj376b1922016-05-02 11:35:24 -070039 VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback,
40 media_optimization::MediaOptimization* media_opt);
sprang3911c262016-04-15 01:24:14 -070041 virtual ~VCMEncodedFrameCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +000042
sprang3911c262016-04-15 01:24:14 -070043 // Implements EncodedImageCallback.
sergeyu51db4dd2016-08-02 17:33:42 -070044 int32_t Encoded(const EncodedImage& encoded_image,
45 const CodecSpecificInfo* codec_specific,
46 const RTPFragmentationHeader* fragmentation_header) override;
sprang3911c262016-04-15 01:24:14 -070047 void SetInternalSource(bool internal_source) {
48 internal_source_ = internal_source;
49 }
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000050
philipel9d3ab612015-12-21 04:12:39 -080051 private:
sprang3911c262016-04-15 01:24:14 -070052 bool internal_source_;
perkj376b1922016-05-02 11:35:24 -070053 EncodedImageCallback* const post_encode_callback_;
54 media_optimization::MediaOptimization* const media_opt_;
sprang3911c262016-04-15 01:24:14 -070055};
sprang@webrtc.org40709352013-11-26 11:41:59 +000056
philipel9d3ab612015-12-21 04:12:39 -080057class VCMGenericEncoder {
58 friend class VCMCodecDataBase;
Peter Boström69ccb332015-10-29 16:30:23 +010059
philipel9d3ab612015-12-21 04:12:39 -080060 public:
61 VCMGenericEncoder(VideoEncoder* encoder,
philipel9d3ab612015-12-21 04:12:39 -080062 VCMEncodedFrameCallback* encoded_frame_callback,
sprang3911c262016-04-15 01:24:14 -070063 bool internal_source);
philipel9d3ab612015-12-21 04:12:39 -080064 ~VCMGenericEncoder();
philipel9d3ab612015-12-21 04:12:39 -080065 int32_t Release();
philipel9d3ab612015-12-21 04:12:39 -080066 int32_t InitEncode(const VideoCodec* settings,
sprang3911c262016-04-15 01:24:14 -070067 int32_t number_of_cores,
68 size_t max_payload_size);
69 int32_t Encode(const VideoFrame& frame,
70 const CodecSpecificInfo* codec_specific,
71 const std::vector<FrameType>& frame_types);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
perkj376b1922016-05-02 11:35:24 -070073 const char* ImplementationName() const;
74
philipel9d3ab612015-12-21 04:12:39 -080075 void SetEncoderParameters(const EncoderParameters& params);
76 EncoderParameters GetEncoderParameters() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
philipel9d3ab612015-12-21 04:12:39 -080078 int32_t SetPeriodicKeyFrames(bool enable);
philipel9d3ab612015-12-21 04:12:39 -080079 int32_t RequestFrame(const std::vector<FrameType>& frame_types);
philipel9d3ab612015-12-21 04:12:39 -080080 bool InternalSource() const;
philipel9d3ab612015-12-21 04:12:39 -080081 void OnDroppedFrame();
philipel9d3ab612015-12-21 04:12:39 -080082 bool SupportsNativeHandle() const;
philipel9d3ab612015-12-21 04:12:39 -080083
84 private:
Peter Boström02bafc62016-07-01 12:45:15 +020085 rtc::RaceChecker race_checker_;
86
87 VideoEncoder* const encoder_ GUARDED_BY(race_checker_);
philipel9d3ab612015-12-21 04:12:39 -080088 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_;
89 const bool internal_source_;
pbos5ad935c2016-01-25 03:52:44 -080090 rtc::CriticalSection params_lock_;
philipel9d3ab612015-12-21 04:12:39 -080091 EncoderParameters encoder_params_ GUARDED_BY(params_lock_);
philipel9d3ab612015-12-21 04:12:39 -080092 bool is_screenshare_;
sprang3911c262016-04-15 01:24:14 -070093};
niklase@google.com470e71d2011-07-07 08:21:25 +000094
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000095} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000096
philipel9d3ab612015-12-21 04:12:39 -080097#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_