OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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 #include "webrtc/media/engine/scopedvideoencoder.h" |
| 12 |
| 13 #include <vector> |
| 14 |
| 15 #include "webrtc/api/video_codecs/video_encoder.h" |
| 16 |
| 17 namespace cricket { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class ScopedVideoEncoder : public webrtc::VideoEncoder { |
| 22 public: |
| 23 ScopedVideoEncoder(WebRtcVideoEncoderFactory* factory, |
| 24 webrtc::VideoEncoder* encoder); |
| 25 |
| 26 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
| 27 int32_t number_of_cores, |
| 28 size_t max_payload_size) override; |
| 29 int32_t RegisterEncodeCompleteCallback( |
| 30 webrtc::EncodedImageCallback* callback) override; |
| 31 int32_t Release() override; |
| 32 int32_t Encode(const webrtc::VideoFrame& frame, |
| 33 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 34 const std::vector<webrtc::FrameType>* frame_types) override; |
| 35 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
| 36 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; |
| 37 int32_t SetRateAllocation(const webrtc::BitrateAllocation& allocation, |
| 38 uint32_t framerate) override; |
| 39 ScalingSettings GetScalingSettings() const override; |
| 40 int32_t SetPeriodicKeyFrames(bool enable) override; |
| 41 bool SupportsNativeHandle() const override; |
| 42 const char* ImplementationName() const override; |
| 43 |
| 44 ~ScopedVideoEncoder() override; |
| 45 |
| 46 private: |
| 47 WebRtcVideoEncoderFactory* factory_; |
| 48 webrtc::VideoEncoder* encoder_; |
| 49 }; |
| 50 |
| 51 ScopedVideoEncoder::ScopedVideoEncoder(WebRtcVideoEncoderFactory* factory, |
| 52 webrtc::VideoEncoder* encoder) |
| 53 : factory_(factory), encoder_(encoder) {} |
| 54 |
| 55 int32_t ScopedVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, |
| 56 int32_t number_of_cores, |
| 57 size_t max_payload_size) { |
| 58 return encoder_->InitEncode(codec_settings, number_of_cores, |
| 59 max_payload_size); |
| 60 } |
| 61 |
| 62 int32_t ScopedVideoEncoder::RegisterEncodeCompleteCallback( |
| 63 webrtc::EncodedImageCallback* callback) { |
| 64 return encoder_->RegisterEncodeCompleteCallback(callback); |
| 65 } |
| 66 |
| 67 int32_t ScopedVideoEncoder::Release() { |
| 68 return encoder_->Release(); |
| 69 } |
| 70 |
| 71 int32_t ScopedVideoEncoder::Encode( |
| 72 const webrtc::VideoFrame& frame, |
| 73 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 74 const std::vector<webrtc::FrameType>* frame_types) { |
| 75 return encoder_->Encode(frame, codec_specific_info, frame_types); |
| 76 } |
| 77 |
| 78 int32_t ScopedVideoEncoder::SetChannelParameters(uint32_t packet_loss, |
| 79 int64_t rtt) { |
| 80 return encoder_->SetChannelParameters(packet_loss, rtt); |
| 81 } |
| 82 |
| 83 int32_t ScopedVideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) { |
| 84 return encoder_->SetRates(bitrate, framerate); |
| 85 } |
| 86 |
| 87 int32_t ScopedVideoEncoder::SetRateAllocation( |
| 88 const webrtc::BitrateAllocation& allocation, |
| 89 uint32_t framerate) { |
| 90 return encoder_->SetRateAllocation(allocation, framerate); |
| 91 } |
| 92 |
| 93 webrtc::VideoEncoder::ScalingSettings ScopedVideoEncoder::GetScalingSettings() |
| 94 const { |
| 95 return encoder_->GetScalingSettings(); |
| 96 } |
| 97 |
| 98 int32_t ScopedVideoEncoder::SetPeriodicKeyFrames(bool enable) { |
| 99 return encoder_->SetPeriodicKeyFrames(enable); |
| 100 } |
| 101 |
| 102 bool ScopedVideoEncoder::SupportsNativeHandle() const { |
| 103 return encoder_->SupportsNativeHandle(); |
| 104 } |
| 105 |
| 106 const char* ScopedVideoEncoder::ImplementationName() const { |
| 107 return encoder_->ImplementationName(); |
| 108 } |
| 109 |
| 110 ScopedVideoEncoder::~ScopedVideoEncoder() { |
| 111 factory_->DestroyVideoEncoder(encoder_); |
| 112 } |
| 113 |
| 114 } // namespace |
| 115 |
| 116 std::unique_ptr<webrtc::VideoEncoder> CreateScopedVideoEncoder( |
| 117 WebRtcVideoEncoderFactory* factory, |
| 118 const VideoCodec& codec) { |
| 119 webrtc::VideoEncoder* encoder = factory->CreateVideoEncoder(codec); |
| 120 if (!encoder) |
| 121 return nullptr; |
| 122 return std::unique_ptr<webrtc::VideoEncoder>( |
| 123 new ScopedVideoEncoder(factory, encoder)); |
| 124 } |
| 125 |
| 126 } // namespace cricket |
OLD | NEW |