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/modules/video_coding/codecs/h264/include/h264.h" | 15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| 16 #include "webrtc/modules/video_coding/include/bitrate_adjuster.h" |
16 | 17 |
17 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 18 #if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
18 | 19 |
19 #include <VideoToolbox/VideoToolbox.h> | 20 #include <VideoToolbox/VideoToolbox.h> |
20 #include <vector> | 21 #include <vector> |
21 | 22 |
22 // This file provides a H264 encoder implementation using the VideoToolbox | 23 // This file provides a H264 encoder implementation using the VideoToolbox |
23 // APIs. Since documentation is almost non-existent, this is largely based on | 24 // APIs. Since documentation is almost non-existent, this is largely based on |
24 // the information in the VideoToolbox header files, a talk from WWDC 2014 and | 25 // the information in the VideoToolbox header files, a talk from WWDC 2014 and |
25 // experimentation. | 26 // experimentation. |
26 | 27 |
27 namespace webrtc { | 28 namespace webrtc { |
28 | 29 |
29 class H264VideoToolboxEncoder : public H264Encoder { | 30 class H264VideoToolboxEncoder : public H264Encoder, |
| 31 public BitrateAdjusterObserver { |
30 public: | 32 public: |
31 H264VideoToolboxEncoder(); | 33 H264VideoToolboxEncoder(); |
32 | 34 |
33 ~H264VideoToolboxEncoder() override; | 35 ~H264VideoToolboxEncoder() override; |
34 | 36 |
35 int InitEncode(const VideoCodec* codec_settings, | 37 int InitEncode(const VideoCodec* codec_settings, |
36 int number_of_cores, | 38 int number_of_cores, |
37 size_t max_payload_size) override; | 39 size_t max_payload_size) override; |
38 | 40 |
39 int Encode(const VideoFrame& input_image, | 41 int Encode(const VideoFrame& input_image, |
40 const CodecSpecificInfo* codec_specific_info, | 42 const CodecSpecificInfo* codec_specific_info, |
41 const std::vector<FrameType>* frame_types) override; | 43 const std::vector<FrameType>* frame_types) override; |
42 | 44 |
43 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; | 45 int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; |
44 | 46 |
45 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | 47 int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
46 | 48 |
47 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override; | 49 int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override; |
48 | 50 |
49 int Release() override; | 51 int Release() override; |
50 | 52 |
51 const char* ImplementationName() const override; | 53 const char* ImplementationName() const override; |
52 | 54 |
| 55 void OnBitrateAdjusted(uint32_t adjusted_bitrate) override; |
| 56 void OnEncodedFrame(OSStatus status, |
| 57 VTEncodeInfoFlags info_flags, |
| 58 CMSampleBufferRef sample_buffer, |
| 59 CodecSpecificInfo codec_specific_info, |
| 60 int32_t width, |
| 61 int32_t height, |
| 62 int64_t render_time_ms, |
| 63 uint32_t timestamp); |
| 64 |
53 private: | 65 private: |
54 int ResetCompressionSession(); | 66 int ResetCompressionSession(); |
55 void ConfigureCompressionSession(); | 67 void ConfigureCompressionSession(); |
56 void DestroyCompressionSession(); | 68 void DestroyCompressionSession(); |
| 69 void SetBitrate(uint32_t bitrate_kbit); |
57 | 70 |
58 webrtc::EncodedImageCallback* callback_; | 71 EncodedImageCallback* callback_; |
59 VTCompressionSessionRef compression_session_; | 72 VTCompressionSessionRef compression_session_; |
60 int32_t bitrate_; // Bitrate in bits per second. | 73 BitrateAdjuster bitrate_adjuster_; |
| 74 uint32_t bitrate_kbit_; |
61 int32_t width_; | 75 int32_t width_; |
62 int32_t height_; | 76 int32_t height_; |
63 }; // H264VideoToolboxEncoder | 77 }; // H264VideoToolboxEncoder |
64 | 78 |
65 } // namespace webrtc | 79 } // namespace webrtc |
66 | 80 |
67 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 81 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
68 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ | 82 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_ |
OLD | NEW |