OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 | 11 |
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ | 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ |
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ | 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/common_video/h264/h264_bitstream_parser.h" | 18 #include "webrtc/common_video/h264/h264_bitstream_parser.h" |
19 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 19 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
20 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 20 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
21 | 21 |
22 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" | 22 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" |
23 | 23 |
24 class ISVCEncoder; | 24 class ISVCEncoder; |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 | 27 |
28 class H264EncoderImpl : public H264Encoder { | 28 class H264EncoderImpl : public H264Encoder { |
29 public: | 29 public: |
30 H264EncoderImpl(); | 30 explicit H264EncoderImpl(const cricket::VideoCodec& codec); |
31 ~H264EncoderImpl() override; | 31 ~H264EncoderImpl() override; |
32 | 32 |
33 // |max_payload_size| is ignored. | 33 // |max_payload_size| is ignored. |
34 // The following members of |codec_settings| are used. The rest are ignored. | 34 // The following members of |codec_settings| are used. The rest are ignored. |
35 // - codecType (must be kVideoCodecH264) | 35 // - codecType (must be kVideoCodecH264) |
36 // - targetBitrate | 36 // - targetBitrate |
37 // - maxFramerate | 37 // - maxFramerate |
38 // - width | 38 // - width |
39 // - height | 39 // - height |
40 int32_t InitEncode(const VideoCodec* codec_settings, | 40 int32_t InitEncode(const VideoCodec* codec_settings, |
41 int32_t number_of_cores, | 41 int32_t number_of_cores, |
42 size_t /*max_payload_size*/) override; | 42 size_t max_payload_size) override; |
43 int32_t Release() override; | 43 int32_t Release() override; |
44 | 44 |
45 int32_t RegisterEncodeCompleteCallback( | 45 int32_t RegisterEncodeCompleteCallback( |
46 EncodedImageCallback* callback) override; | 46 EncodedImageCallback* callback) override; |
47 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, | 47 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, |
48 uint32_t framerate) override; | 48 uint32_t framerate) override; |
49 | 49 |
50 // The result of encoding - an EncodedImage and RTPFragmentationHeader - are | 50 // The result of encoding - an EncodedImage and RTPFragmentationHeader - are |
51 // passed to the encode complete callback. | 51 // passed to the encode complete callback. |
52 int32_t Encode(const VideoFrame& frame, | 52 int32_t Encode(const VideoFrame& frame, |
53 const CodecSpecificInfo* codec_specific_info, | 53 const CodecSpecificInfo* codec_specific_info, |
54 const std::vector<FrameType>* frame_types) override; | 54 const std::vector<FrameType>* frame_types) override; |
55 | 55 |
56 const char* ImplementationName() const override; | 56 const char* ImplementationName() const override; |
57 | 57 |
58 // Unsupported / Do nothing. | 58 // Unsupported / Do nothing. |
59 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | 59 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
60 int32_t SetPeriodicKeyFrames(bool enable) override; | 60 int32_t SetPeriodicKeyFrames(bool enable) override; |
61 void OnDroppedFrame() override; | 61 void OnDroppedFrame() override; |
62 | 62 |
| 63 // Exposed for testing. |
| 64 H264PacketizationMode PacketizationModeForTesting() const { |
| 65 return packetization_mode_; |
| 66 } |
| 67 |
63 private: | 68 private: |
64 bool IsInitialized() const; | 69 bool IsInitialized() const; |
65 SEncParamExt CreateEncoderParams() const; | 70 SEncParamExt CreateEncoderParams() const; |
66 | 71 |
67 webrtc::H264BitstreamParser h264_bitstream_parser_; | 72 webrtc::H264BitstreamParser h264_bitstream_parser_; |
68 QualityScaler quality_scaler_; | 73 QualityScaler quality_scaler_; |
69 // Reports statistics with histograms. | 74 // Reports statistics with histograms. |
70 void ReportInit(); | 75 void ReportInit(); |
71 void ReportError(); | 76 void ReportError(); |
72 | 77 |
73 ISVCEncoder* openh264_encoder_; | 78 ISVCEncoder* openh264_encoder_; |
74 // Settings that are used by this encoder. | 79 // Settings that are used by this encoder. |
75 int width_; | 80 int width_; |
76 int height_; | 81 int height_; |
77 float max_frame_rate_; | 82 float max_frame_rate_; |
78 uint32_t target_bps_; | 83 uint32_t target_bps_; |
79 uint32_t max_bps_; | 84 uint32_t max_bps_; |
80 VideoCodecMode mode_; | 85 VideoCodecMode mode_; |
81 // H.264 specifc parameters | 86 // H.264 specifc parameters |
82 bool frame_dropping_on_; | 87 bool frame_dropping_on_; |
83 int key_frame_interval_; | 88 int key_frame_interval_; |
| 89 H264PacketizationMode packetization_mode_; |
84 | 90 |
| 91 size_t max_payload_size_; |
85 int32_t number_of_cores_; | 92 int32_t number_of_cores_; |
86 | 93 |
87 EncodedImage encoded_image_; | 94 EncodedImage encoded_image_; |
88 std::unique_ptr<uint8_t[]> encoded_image_buffer_; | 95 std::unique_ptr<uint8_t[]> encoded_image_buffer_; |
89 EncodedImageCallback* encoded_image_callback_; | 96 EncodedImageCallback* encoded_image_callback_; |
90 | 97 |
91 bool has_reported_init_; | 98 bool has_reported_init_; |
92 bool has_reported_error_; | 99 bool has_reported_error_; |
93 }; | 100 }; |
94 | 101 |
95 } // namespace webrtc | 102 } // namespace webrtc |
96 | 103 |
97 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ | 104 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_ |
OLD | NEW |