OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |
13 | 13 |
| 14 #include <stdio.h> |
| 15 #include <vector> |
| 16 |
14 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
15 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 18 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
16 | 19 |
17 #include <stdio.h> | |
18 | |
19 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/scoped_ptr.h" | 21 #include "webrtc/base/scoped_ptr.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 class CriticalSectionWrapper; | 24 class CriticalSectionWrapper; |
24 | 25 |
25 namespace media_optimization { | 26 namespace media_optimization { |
26 class MediaOptimization; | 27 class MediaOptimization; |
27 } // namespace media_optimization | 28 } // namespace media_optimization |
28 | 29 |
29 struct EncoderParameters { | 30 struct EncoderParameters { |
30 uint32_t target_bitrate; | 31 uint32_t target_bitrate; |
31 uint8_t loss_rate; | 32 uint8_t loss_rate; |
32 int64_t rtt; | 33 int64_t rtt; |
33 uint32_t input_frame_rate; | 34 uint32_t input_frame_rate; |
34 }; | 35 }; |
35 | 36 |
36 /*************************************/ | 37 /*************************************/ |
37 /* VCMEncodeFrameCallback class */ | 38 /* VCMEncodeFrameCallback class */ |
38 /***********************************/ | 39 /***********************************/ |
39 class VCMEncodedFrameCallback : public EncodedImageCallback | 40 class VCMEncodedFrameCallback : public EncodedImageCallback { |
40 { | 41 public: |
41 public: | 42 explicit VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback); |
42 VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback); | 43 virtual ~VCMEncodedFrameCallback(); |
43 virtual ~VCMEncodedFrameCallback(); | |
44 | 44 |
45 /* | 45 /* |
46 * Callback implementation - codec encode complete | 46 * Callback implementation - codec encode complete |
47 */ | 47 */ |
48 int32_t Encoded( | 48 int32_t Encoded(const EncodedImage& encodedImage, |
49 const EncodedImage& encodedImage, | 49 const CodecSpecificInfo* codecSpecificInfo = NULL, |
50 const CodecSpecificInfo* codecSpecificInfo = NULL, | 50 const RTPFragmentationHeader* fragmentationHeader = NULL); |
51 const RTPFragmentationHeader* fragmentationHeader = NULL); | 51 /* |
52 /* | 52 * Callback implementation - generic encoder encode complete |
53 * Callback implementation - generic encoder encode complete | 53 */ |
54 */ | 54 int32_t SetTransportCallback(VCMPacketizationCallback* transport); |
55 int32_t SetTransportCallback(VCMPacketizationCallback* transport); | 55 /** |
56 /** | 56 * Set media Optimization |
57 * Set media Optimization | 57 */ |
58 */ | 58 void SetMediaOpt(media_optimization::MediaOptimization* mediaOpt); |
59 void SetMediaOpt (media_optimization::MediaOptimization* mediaOpt); | |
60 | 59 |
61 void SetPayloadType(uint8_t payloadType) { _payloadType = payloadType; }; | 60 void SetPayloadType(uint8_t payloadType) { _payloadType = payloadType; } |
62 void SetInternalSource(bool internalSource) { _internalSource = internalSour
ce; }; | 61 void SetInternalSource(bool internalSource) { |
| 62 _internalSource = internalSource; |
| 63 } |
63 | 64 |
64 void SetRotation(VideoRotation rotation) { _rotation = rotation; } | 65 void SetRotation(VideoRotation rotation) { _rotation = rotation; } |
65 | 66 |
66 private: | 67 private: |
67 VCMPacketizationCallback* _sendCallback; | 68 VCMPacketizationCallback* _sendCallback; |
68 media_optimization::MediaOptimization* _mediaOpt; | 69 media_optimization::MediaOptimization* _mediaOpt; |
69 uint8_t _payloadType; | 70 uint8_t _payloadType; |
70 bool _internalSource; | 71 bool _internalSource; |
71 VideoRotation _rotation; | 72 VideoRotation _rotation; |
72 | 73 |
73 EncodedImageCallback* post_encode_callback_; | 74 EncodedImageCallback* post_encode_callback_; |
74 | 75 |
75 #ifdef DEBUG_ENCODER_BIT_STREAM | 76 #ifdef DEBUG_ENCODER_BIT_STREAM |
76 FILE* _bitStreamAfterEncoder; | 77 FILE* _bitStreamAfterEncoder; |
77 #endif | 78 #endif |
78 };// end of VCMEncodeFrameCallback class | 79 }; // end of VCMEncodeFrameCallback class |
79 | |
80 | 80 |
81 /******************************/ | 81 /******************************/ |
82 /* VCMGenericEncoder class */ | 82 /* VCMGenericEncoder class */ |
83 /******************************/ | 83 /******************************/ |
84 class VCMGenericEncoder | 84 class VCMGenericEncoder { |
85 { | 85 friend class VCMCodecDataBase; |
86 friend class VCMCodecDataBase; | |
87 public: | |
88 VCMGenericEncoder(VideoEncoder* encoder, | |
89 VideoEncoderRateObserver* rate_observer, | |
90 VCMEncodedFrameCallback* encoded_frame_callback, | |
91 bool internalSource); | |
92 ~VCMGenericEncoder(); | |
93 /** | |
94 * Free encoder memory | |
95 */ | |
96 int32_t Release(); | |
97 /** | |
98 * Initialize the encoder with the information from the VideoCodec | |
99 */ | |
100 int32_t InitEncode(const VideoCodec* settings, | |
101 int32_t numberOfCores, | |
102 size_t maxPayloadSize); | |
103 /** | |
104 * Encode raw image | |
105 * inputFrame : Frame containing raw image | |
106 * codecSpecificInfo : Specific codec data | |
107 * cameraFrameRate : Request or information from the remote side | |
108 * frameType : The requested frame type to encode | |
109 */ | |
110 int32_t Encode(const VideoFrame& inputFrame, | |
111 const CodecSpecificInfo* codecSpecificInfo, | |
112 const std::vector<FrameType>& frameTypes); | |
113 | 86 |
114 void SetEncoderParameters(const EncoderParameters& params); | 87 public: |
115 EncoderParameters GetEncoderParameters() const; | 88 VCMGenericEncoder(VideoEncoder* encoder, |
| 89 VideoEncoderRateObserver* rate_observer, |
| 90 VCMEncodedFrameCallback* encoded_frame_callback, |
| 91 bool internalSource); |
| 92 ~VCMGenericEncoder(); |
| 93 /** |
| 94 * Free encoder memory |
| 95 */ |
| 96 int32_t Release(); |
| 97 /** |
| 98 * Initialize the encoder with the information from the VideoCodec |
| 99 */ |
| 100 int32_t InitEncode(const VideoCodec* settings, |
| 101 int32_t numberOfCores, |
| 102 size_t maxPayloadSize); |
| 103 /** |
| 104 * Encode raw image |
| 105 * inputFrame : Frame containing raw image |
| 106 * codecSpecificInfo : Specific codec data |
| 107 * cameraFrameRate : Request or information from the remote side |
| 108 * frameType : The requested frame type to encode |
| 109 */ |
| 110 int32_t Encode(const VideoFrame& inputFrame, |
| 111 const CodecSpecificInfo* codecSpecificInfo, |
| 112 const std::vector<FrameType>& frameTypes); |
116 | 113 |
117 int32_t SetPeriodicKeyFrames(bool enable); | 114 void SetEncoderParameters(const EncoderParameters& params); |
| 115 EncoderParameters GetEncoderParameters() const; |
118 | 116 |
119 int32_t RequestFrame(const std::vector<FrameType>& frame_types); | 117 int32_t SetPeriodicKeyFrames(bool enable); |
120 | 118 |
121 bool InternalSource() const; | 119 int32_t RequestFrame(const std::vector<FrameType>& frame_types); |
122 | 120 |
123 void OnDroppedFrame(); | 121 bool InternalSource() const; |
124 | 122 |
125 bool SupportsNativeHandle() const; | 123 void OnDroppedFrame(); |
126 | 124 |
127 int GetTargetFramerate(); | 125 bool SupportsNativeHandle() const; |
128 | 126 |
129 private: | 127 int GetTargetFramerate(); |
130 VideoEncoder* const encoder_; | 128 |
131 VideoEncoderRateObserver* const rate_observer_; | 129 private: |
132 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_; | 130 VideoEncoder* const encoder_; |
133 const bool internal_source_; | 131 VideoEncoderRateObserver* const rate_observer_; |
134 mutable rtc::CriticalSection params_lock_; | 132 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_; |
135 EncoderParameters encoder_params_ GUARDED_BY(params_lock_); | 133 const bool internal_source_; |
136 VideoRotation rotation_; | 134 mutable rtc::CriticalSection params_lock_; |
137 bool is_screenshare_; | 135 EncoderParameters encoder_params_ GUARDED_BY(params_lock_); |
138 }; // end of VCMGenericEncoder class | 136 VideoRotation rotation_; |
| 137 bool is_screenshare_; |
| 138 }; // end of VCMGenericEncoder class |
139 | 139 |
140 } // namespace webrtc | 140 } // namespace webrtc |
141 | 141 |
142 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ | 142 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |
OLD | NEW |