1 /* 2 * Copyright (c) 2012 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_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ 13 14 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" 15 16 #include <stdio.h> 17 18 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 19 20 namespace webrtc { 21 class CriticalSectionWrapper; 22 23 namespace media_optimization { 24 class MediaOptimization; 25 } // namespace media_optimization 26 27 /*************************************/ 28 /* VCMEncodeFrameCallback class */ 29 /***********************************/ 30 class VCMEncodedFrameCallback : public EncodedImageCallback 31 { 32 public: 33 VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback); 34 virtual ~VCMEncodedFrameCallback(); 35 36 /* 37 * Callback implementation - codec encode complete 38 */ 39 int32_t Encoded( 40 EncodedImage& encodedImage, 41 const CodecSpecificInfo* codecSpecificInfo = NULL, 42 const RTPFragmentationHeader* fragmentationHeader = NULL); 43 /* 44 * Callback implementation - generic encoder encode complete 45 */ 46 int32_t SetTransportCallback(VCMPacketizationCallback* transport); 47 /** 48 * Set media Optimization 49 */ 50 void SetMediaOpt (media_optimization::MediaOptimization* mediaOpt); 51 52 void SetPayloadType(uint8_t payloadType) { _payloadType = payloadType; }; 53 void SetInternalSource(bool internalSource) { _internalSource = internalSource; }; 54 55 private: 56 VCMPacketizationCallback* _sendCallback; 57 media_optimization::MediaOptimization* _mediaOpt; 58 uint8_t _payloadType; 59 bool _internalSource; 60 61 EncodedImageCallback* post_encode_callback_; 62 63 #ifdef DEBUG_ENCODER_BIT_STREAM 64 FILE* _bitStreamAfterEncoder; 65 #endif 66 };// end of VCMEncodeFrameCallback class 67 68 69 /******************************/ 70 /* VCMGenericEncoder class */ 71 /******************************/ 72 class VCMGenericEncoder 73 { 74 friend class VCMCodecDataBase; 75 public: 76 VCMGenericEncoder(VideoEncoder& encoder, bool internalSource = false); 77 ~VCMGenericEncoder(); 78 /** 79 * Free encoder memory 80 */ 81 int32_t Release(); 82 /** 83 * Initialize the encoder with the information from the VideoCodec 84 */ 85 int32_t InitEncode(const VideoCodec* settings, 86 int32_t numberOfCores, 87 uint32_t maxPayloadSize); 88 /** 89 * Encode raw image 90 * inputFrame : Frame containing raw image 91 * codecSpecificInfo : Specific codec data 92 * cameraFrameRate : Request or information from the remote side 93 * frameType : The requested frame type to encode 94 */ 95 int32_t Encode(const I420VideoFrame& inputFrame, 96 const CodecSpecificInfo* codecSpecificInfo, 97 const std::vector<FrameType>& frameTypes); 98 /** 99 * Set new target bitrate (bits/s) and framerate. 100 * Return Value: new bit rate if OK, otherwise <0s. 101 */ 102 int32_t SetRates(uint32_t target_bitrate, uint32_t frameRate); 103 /** 104 * Set a new packet loss rate and a new round-trip time in milliseconds. 105 */ 106 int32_t SetChannelParameters(int32_t packetLoss, int rtt); 107 int32_t CodecConfigParameters(uint8_t* buffer, int32_t size); 108 /** 109 * Register a transport callback which will be called to deliver the encoded 110 * buffers 111 */ 112 int32_t RegisterEncodeCallback( 113 VCMEncodedFrameCallback* VCMencodedFrameCallback); 114 /** 115 * Get encoder bit rate 116 */ 117 uint32_t BitRate() const; 118 /** 119 * Get encoder frame rate 120 */ 121 uint32_t FrameRate() const; 122 123 int32_t SetPeriodicKeyFrames(bool enable); 124 125 int32_t RequestFrame(const std::vector<FrameType>& frame_types); 126 127 bool InternalSource() const; 128 129 private: 130 VideoEncoder& _encoder; 131 VideoCodecType _codecType; 132 VCMEncodedFrameCallback* _VCMencodedFrameCallback; 133 uint32_t _bitRate; 134 uint32_t _frameRate; 135 bool _internalSource; 136 }; // end of VCMGenericEncoder class 137 138 } // namespace webrtc 139 140 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ 141