2015-06-29 14:34:58 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-16 07:06:59 -07:00
|
|
|
#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOX_ENCODER_H_
|
|
|
|
|
#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOX_ENCODER_H_
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2017-01-10 07:44:26 -08:00
|
|
|
#include "webrtc/api/video/video_rotation.h"
|
2016-05-24 12:21:58 +02:00
|
|
|
#include "webrtc/base/criticalsection.h"
|
2016-10-26 02:48:16 -07:00
|
|
|
#include "webrtc/common_video/h264/h264_bitstream_parser.h"
|
2016-04-26 12:55:07 -07:00
|
|
|
#include "webrtc/common_video/include/bitrate_adjuster.h"
|
2016-11-15 09:56:55 -08:00
|
|
|
#include "webrtc/media/base/codec.h"
|
2015-06-29 14:34:58 -07:00
|
|
|
#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
|
2016-05-24 12:21:58 +02:00
|
|
|
#include "webrtc/modules/video_coding/utility/quality_scaler.h"
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
#include <VideoToolbox/VideoToolbox.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
// This file provides a H264 encoder implementation using the VideoToolbox
|
|
|
|
|
// APIs. Since documentation is almost non-existent, this is largely based on
|
|
|
|
|
// the information in the VideoToolbox header files, a talk from WWDC 2014 and
|
|
|
|
|
// experimentation.
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class H264VideoToolboxEncoder : public H264Encoder {
|
|
|
|
|
public:
|
2016-11-15 09:56:55 -08:00
|
|
|
explicit H264VideoToolboxEncoder(const cricket::VideoCodec& codec);
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
~H264VideoToolboxEncoder() override;
|
|
|
|
|
|
|
|
|
|
int InitEncode(const VideoCodec* codec_settings,
|
|
|
|
|
int number_of_cores,
|
|
|
|
|
size_t max_payload_size) override;
|
|
|
|
|
|
|
|
|
|
int Encode(const VideoFrame& input_image,
|
|
|
|
|
const CodecSpecificInfo* codec_specific_info,
|
2015-10-19 02:39:06 -07:00
|
|
|
const std::vector<FrameType>* frame_types) override;
|
2015-06-29 14:34:58 -07:00
|
|
|
|
|
|
|
|
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
|
|
|
|
|
|
|
|
|
|
int SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
|
|
|
|
|
|
|
|
|
|
int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) override;
|
|
|
|
|
|
|
|
|
|
int Release() override;
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
2016-07-12 01:26:42 -07:00
|
|
|
bool SupportsNativeHandle() const override;
|
|
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
void OnEncodedFrame(OSStatus status,
|
|
|
|
|
VTEncodeInfoFlags info_flags,
|
|
|
|
|
CMSampleBufferRef sample_buffer,
|
|
|
|
|
CodecSpecificInfo codec_specific_info,
|
|
|
|
|
int32_t width,
|
|
|
|
|
int32_t height,
|
|
|
|
|
int64_t render_time_ms,
|
2016-04-19 15:01:23 +02:00
|
|
|
uint32_t timestamp,
|
|
|
|
|
VideoRotation rotation);
|
2016-02-23 22:49:42 -08:00
|
|
|
|
2016-11-29 01:44:11 -08:00
|
|
|
ScalingSettings GetScalingSettings() const override;
|
|
|
|
|
|
2015-06-29 14:34:58 -07:00
|
|
|
private:
|
|
|
|
|
int ResetCompressionSession();
|
|
|
|
|
void ConfigureCompressionSession();
|
|
|
|
|
void DestroyCompressionSession();
|
2016-06-13 13:06:01 +02:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> GetScaledBufferOnEncode(
|
|
|
|
|
const rtc::scoped_refptr<VideoFrameBuffer>& frame);
|
2016-02-23 22:49:42 -08:00
|
|
|
void SetBitrateBps(uint32_t bitrate_bps);
|
|
|
|
|
void SetEncoderBitrateBps(uint32_t bitrate_bps);
|
2015-06-29 14:34:58 -07:00
|
|
|
|
2016-02-23 22:49:42 -08:00
|
|
|
EncodedImageCallback* callback_;
|
2015-06-29 14:34:58 -07:00
|
|
|
VTCompressionSessionRef compression_session_;
|
2016-02-23 22:49:42 -08:00
|
|
|
BitrateAdjuster bitrate_adjuster_;
|
2016-12-16 02:10:20 -08:00
|
|
|
H264PacketizationMode packetization_mode_;
|
2016-02-23 22:49:42 -08:00
|
|
|
uint32_t target_bitrate_bps_;
|
|
|
|
|
uint32_t encoder_bitrate_bps_;
|
2015-06-29 14:34:58 -07:00
|
|
|
int32_t width_;
|
|
|
|
|
int32_t height_;
|
2017-04-11 10:34:31 -07:00
|
|
|
VideoCodecMode mode_;
|
2016-11-15 09:56:55 -08:00
|
|
|
const CFStringRef profile_;
|
2016-05-24 12:21:58 +02:00
|
|
|
|
|
|
|
|
H264BitstreamParser h264_bitstream_parser_;
|
2016-10-20 03:34:29 -07:00
|
|
|
std::vector<uint8_t> nv12_scale_buffer_;
|
2015-06-29 14:34:58 -07:00
|
|
|
}; // H264VideoToolboxEncoder
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-05-16 07:06:59 -07:00
|
|
|
#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOX_ENCODER_H_
|