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_VIDEO_TOOLBOX_ENCODER_H_ | 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ |
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ | 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ |
14 | 14 |
| 15 #include "webrtc/base/criticalsection.h" |
15 #include "webrtc/common_video/include/bitrate_adjuster.h" | 16 #include "webrtc/common_video/include/bitrate_adjuster.h" |
16 #include "webrtc/common_video/rotation.h" | 17 #include "webrtc/common_video/rotation.h" |
17 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 18 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| 19 #include "webrtc/modules/video_coding/utility/h264_bitstream_parser.h" |
| 20 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
18 | 21 |
19 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 22 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
20 | 23 |
21 #include <VideoToolbox/VideoToolbox.h> | 24 #include <VideoToolbox/VideoToolbox.h> |
22 #include <vector> | 25 #include <vector> |
23 | 26 |
24 // This file provides a H264 encoder implementation using the VideoToolbox | 27 // This file provides a H264 encoder implementation using the VideoToolbox |
25 // APIs. Since documentation is almost non-existent, this is largely based on | 28 // APIs. Since documentation is almost non-existent, this is largely based on |
26 // the information in the VideoToolbox header files, a talk from WWDC 2014 and | 29 // the information in the VideoToolbox header files, a talk from WWDC 2014 and |
27 // experimentation. | 30 // experimentation. |
28 | 31 |
29 namespace webrtc { | 32 namespace webrtc { |
30 | 33 |
31 class H264VideoToolboxEncoder : public H264Encoder { | 34 class H264VideoToolboxEncoder : public H264Encoder { |
32 public: | 35 public: |
33 H264VideoToolboxEncoder(); | 36 H264VideoToolboxEncoder(); |
34 | 37 |
35 ~H264VideoToolboxEncoder() override; | 38 ~H264VideoToolboxEncoder() override; |
36 | 39 |
37 int InitEncode(const VideoCodec* codec_settings, | 40 int InitEncode(const VideoCodec* codec_settings, |
38 int number_of_cores, | 41 int number_of_cores, |
39 size_t max_payload_size) override; | 42 size_t max_payload_size) override; |
40 | 43 |
41 int Encode(const VideoFrame& input_image, | 44 int Encode(const VideoFrame& input_image, |
42 const CodecSpecificInfo* codec_specific_info, | 45 const CodecSpecificInfo* codec_specific_info, |
43 const std::vector<FrameType>* frame_types) override; | 46 const std::vector<FrameType>* frame_types) override; |
44 | 47 |
45 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; | 48 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; |
46 | 49 |
| 50 void OnDroppedFrame() override; |
47 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | 51 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
48 | 52 |
49 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override; | 53 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override; |
50 | 54 |
51 int Release() override; | 55 int Release() override; |
52 | 56 |
53 const char* ImplementationName() const override; | 57 const char* ImplementationName() const override; |
54 | 58 |
55 void OnEncodedFrame(OSStatus status, | 59 void OnEncodedFrame(OSStatus status, |
56 VTEncodeInfoFlags info_flags, | 60 VTEncodeInfoFlags info_flags, |
57 CMSampleBufferRef sample_buffer, | 61 CMSampleBufferRef sample_buffer, |
58 CodecSpecificInfo codec_specific_info, | 62 CodecSpecificInfo codec_specific_info, |
59 int32_t width, | 63 int32_t width, |
60 int32_t height, | 64 int32_t height, |
61 int64_t render_time_ms, | 65 int64_t render_time_ms, |
62 uint32_t timestamp, | 66 uint32_t timestamp, |
63 VideoRotation rotation); | 67 VideoRotation rotation); |
64 | 68 |
65 private: | 69 private: |
66 int ResetCompressionSession(); | 70 int ResetCompressionSession(); |
67 void ConfigureCompressionSession(); | 71 void ConfigureCompressionSession(); |
68 void DestroyCompressionSession(); | 72 void DestroyCompressionSession(); |
| 73 const VideoFrame& GetScaledFrameOnEncode(const VideoFrame& frame); |
69 void SetBitrateBps(uint32_t bitrate_bps); | 74 void SetBitrateBps(uint32_t bitrate_bps); |
70 void SetEncoderBitrateBps(uint32_t bitrate_bps); | 75 void SetEncoderBitrateBps(uint32_t bitrate_bps); |
71 | 76 |
72 EncodedImageCallback* callback_; | 77 EncodedImageCallback* callback_; |
73 VTCompressionSessionRef compression_session_; | 78 VTCompressionSessionRef compression_session_; |
74 BitrateAdjuster bitrate_adjuster_; | 79 BitrateAdjuster bitrate_adjuster_; |
75 uint32_t target_bitrate_bps_; | 80 uint32_t target_bitrate_bps_; |
76 uint32_t encoder_bitrate_bps_; | 81 uint32_t encoder_bitrate_bps_; |
77 int32_t width_; | 82 int32_t width_; |
78 int32_t height_; | 83 int32_t height_; |
| 84 |
| 85 rtc::CriticalSection quality_scaler_crit_; |
| 86 QualityScaler quality_scaler_ GUARDED_BY(quality_scaler_crit_); |
| 87 H264BitstreamParser h264_bitstream_parser_; |
79 }; // H264VideoToolboxEncoder | 88 }; // H264VideoToolboxEncoder |
80 | 89 |
81 } // namespace webrtc | 90 } // namespace webrtc |
82 | 91 |
83 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 92 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
84 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ | 93 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ |
OLD | NEW |