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