Skip to content

Commit

Permalink
ビルドを通す
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed May 28, 2024
1 parent d03f394 commit 9865b02
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
8 changes: 3 additions & 5 deletions src/dummy_audio_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ DummyAudioMixer::DummyAudioMixer(webrtc::TaskQueueFactory* task_queue_factory)
* sora::SoraClientContextConfig::use_audio_device を false にした際に設定される、
* webrtc::AudioDeviceDummy はループを回さないため、ここでループを作ることとした。
*/
task_queue_ =
std::make_unique<rtc::TaskQueue>(task_queue_factory_->CreateTaskQueue(
"TestAudioDeviceModuleImpl",
webrtc::TaskQueueFactory::Priority::NORMAL));
task_queue_ = task_queue_factory_->CreateTaskQueue(
"TestAudioDeviceModuleImpl", webrtc::TaskQueueFactory::Priority::NORMAL);

webrtc::RepeatingTaskHandle::Start(task_queue_->Get(), [this]() {
webrtc::RepeatingTaskHandle::Start(task_queue_.get(), [this]() {
ProcessAudio();
// オーディオフレームは 10 ms ごとに処理するため 10000 us を指定する
return webrtc::TimeDelta::Micros(10000);
Expand Down
5 changes: 3 additions & 2 deletions src/dummy_audio_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <api/audio/audio_frame.h>
#include <api/audio/audio_mixer.h>
#include <api/scoped_refptr.h>
#include <api/task_queue/task_queue_base.h>
#include <api/task_queue/task_queue_factory.h>
#include <rtc_base/synchronization/mutex.h>
#include <rtc_base/task_queue.h>
#include <rtc_base/task_utils/repeating_task.h>
#include <rtc_base/thread_annotations.h>

Expand Down Expand Up @@ -44,7 +45,7 @@ class DummyAudioMixer : public webrtc::AudioMixer {
private:
void ProcessAudio();
const webrtc::TaskQueueFactory* task_queue_factory_;
std::unique_ptr<rtc::TaskQueue> task_queue_;
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter> task_queue_;

mutable webrtc::Mutex mutex_;
std::vector<std::unique_ptr<SourceStatus>> audio_source_list_
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic_h264_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// WebRTC
#include <api/video/i420_buffer.h>
#include <modules/video_coding/include/video_error_codes.h>
#include <rtc_base/logging.h>
#include <third_party/libyuv/include/libyuv.h>

Expand Down Expand Up @@ -33,8 +34,7 @@ bool DynamicH264Decoder::Configure(const Settings& settings) {
Release();
return false;
}
destroy_decoder_ =
(DestroyDecoderFunc)::dlsym(handle, "WelsDestroyDecoder");
destroy_decoder_ = (DestroyDecoderFunc)::dlsym(handle, "WelsDestroyDecoder");
if (destroy_decoder_ == nullptr) {
RTC_LOG(LS_ERROR) << "Failed to dlsym(WelsDestroyDecoder)";
Release();
Expand Down
42 changes: 25 additions & 17 deletions src/dynamic_h264_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@

#include "dynamic_h264_encoder.h"

#include <dlfcn.h>

#include <algorithm>
#include <limits>
#include <string>

// Linux
#include <dlfcn.h>

// WebRTC
#include <absl/strings/match.h>
#include <absl/types/optional.h>
#include <api/video/video_codec_constants.h>
#include <api/video_codecs/scalability_mode.h>
#include <common_video/libyuv/include/webrtc_libyuv.h>
#include <modules/video_coding/include/video_codec_interface.h>
#include <modules/video_coding/include/video_error_codes.h>
#include <modules/video_coding/svc/create_scalability_structure.h>
#include <modules/video_coding/utility/simulcast_rate_allocator.h>
#include <modules/video_coding/utility/simulcast_utility.h>
Expand Down Expand Up @@ -53,7 +56,7 @@ static const int kLowH264QpThreshold = 24;
static const int kHighH264QpThreshold = 37;

// Used by histograms. Values of entries should not be changed.
enum DynamicH264EncoderEvent {
enum H264EncoderImplEvent {
kH264EncoderEventInit = 0,
kH264EncoderEventError = 1,
kH264EncoderEventMax = 16,
Expand Down Expand Up @@ -173,22 +176,17 @@ static void RtpFragmentize(EncodedImage* encoded_image, SFrameBSInfo* info) {
}
}

DynamicH264Encoder::DynamicH264Encoder(const cricket::VideoCodec& codec,
DynamicH264Encoder::DynamicH264Encoder(const Environment& env,
H264EncoderSettings settings,
std::string openh264)
: packetization_mode_(H264PacketizationMode::SingleNalUnit),
: env_(env),
packetization_mode_(settings.packetization_mode),
max_payload_size_(0),
number_of_cores_(0),
encoded_image_callback_(nullptr),
has_reported_init_(false),
has_reported_error_(false),
openh264_(std::move(openh264)) {
RTC_CHECK(absl::EqualsIgnoreCase(codec.name, cricket::kH264CodecName));
std::string packetization_mode_string;
if (codec.GetParam(cricket::kH264FmtpPacketizationMode,
&packetization_mode_string) &&
packetization_mode_string == "1") {
packetization_mode_ = H264PacketizationMode::NonInterleaved;
}
downscaled_buffers_.reserve(kMaxSimulcastStreams - 1);
encoded_images_.reserve(kMaxSimulcastStreams);
encoders_.reserve(kMaxSimulcastStreams);
Expand Down Expand Up @@ -260,7 +258,7 @@ int32_t DynamicH264Encoder::InitEncode(const VideoCodec* inst,
++i, --idx) {
ISVCEncoder* openh264_encoder;
// Create encoder.
if (create_encoder_(&openh264_encoder) != 0) {
if (WelsCreateSVCEncoder(&openh264_encoder) != 0) {
// Failed to create encoder.
RTC_LOG(LS_ERROR) << "Failed to create OpenH264 encoder";
RTC_DCHECK(!openh264_encoder);
Expand Down Expand Up @@ -353,7 +351,7 @@ int32_t DynamicH264Encoder::Release() {
ISVCEncoder* openh264_encoder = encoders_.back();
if (openh264_encoder) {
RTC_CHECK_EQ(0, openh264_encoder->Uninitialize());
destroy_encoder_(openh264_encoder);
WelsDestroySVCEncoder(openh264_encoder);
}
encoders_.pop_back();
}
Expand Down Expand Up @@ -544,7 +542,7 @@ int32_t DynamicH264Encoder::Encode(

encoded_images_[i]._encodedWidth = configurations_[i].width;
encoded_images_[i]._encodedHeight = configurations_[i].height;
encoded_images_[i].SetRtpTimestamp(input_frame.timestamp());
encoded_images_[i].SetRtpTimestamp(input_frame.rtp_timestamp());
encoded_images_[i].SetColorSpace(input_frame.color_space());
encoded_images_[i]._frameType = ConvertToVideoFrameType(info.eFrameType);
encoded_images_[i].SetSimulcastIndex(configurations_[i].simulcast_idx);
Expand Down Expand Up @@ -576,10 +574,20 @@ int32_t DynamicH264Encoder::Encode(
codec_specific.codecSpecific.H264.base_layer_sync =
tid > 0 && tid < tl0sync_limit_[i];
if (svc_controllers_[i]) {
if (encoded_images_[i]._frameType == VideoFrameType::kVideoFrameKey) {
// Reset the ScalableVideoController on key frame
// to reset the expected dependency structure.
layer_frames =
svc_controllers_[i]->NextFrameConfig(/* restart= */ true);
RTC_CHECK_EQ(layer_frames.size(), 1);
RTC_DCHECK_EQ(layer_frames[0].TemporalId(), 0);
RTC_DCHECK_EQ(layer_frames[0].IsKeyframe(), true);
}

if (layer_frames[0].TemporalId() != tid) {
RTC_LOG(LS_WARNING)
<< "Encoder produced a frame for layer S" << (i + 1) << "T"
<< tid + 1 << " that wasn't requested.";
<< "Encoder produced a frame with temporal id " << tid
<< ", expected " << layer_frames[0].TemporalId() << ".";
continue;
}
encoded_images_[i].SetTemporalIndex(tid);
Expand Down
17 changes: 10 additions & 7 deletions src/dynamic_h264_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class ISVCEncoder;

namespace webrtc {

class DynamicH264Encoder : public H264Encoder {
class DynamicH264Encoder : public VideoEncoder {
public:
static std::unique_ptr<VideoEncoder> Create(const cricket::VideoCodec& codec,
static std::unique_ptr<VideoEncoder> Create(const Environment& env,
H264EncoderSettings settings,
std::string openh264) {
return std::unique_ptr<VideoEncoder>(
new DynamicH264Encoder(codec, std::move(openh264)));
new DynamicH264Encoder(env, settings, std::move(openh264)));
}

public:
Expand All @@ -66,9 +67,10 @@ class DynamicH264Encoder : public H264Encoder {
void SetStreamState(bool send_stream);
};

public:
explicit DynamicH264Encoder(const cricket::VideoCodec& codec,
const std::string openh264);
DynamicH264Encoder(const Environment& env,
H264EncoderSettings settings,
std::string openh264);

~DynamicH264Encoder() override;

// `settings.max_payload_size` is ignored.
Expand Down Expand Up @@ -115,6 +117,7 @@ class DynamicH264Encoder : public H264Encoder {
absl::InlinedVector<absl::optional<ScalabilityMode>, kMaxSimulcastStreams>
scalability_modes_;

const Environment env_;
VideoCodec codec_;
H264PacketizationMode packetization_mode_;
size_t max_payload_size_;
Expand All @@ -141,4 +144,4 @@ class DynamicH264Encoder : public H264Encoder {

} // namespace webrtc

#endif // MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_
#endif // MODULES_VIDEO_CODING_CODECS_H264_H264_ENCODER_IMPL_H_
4 changes: 3 additions & 1 deletion src/sora_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// WebRTC
#include <api/create_peerconnection_factory.h>
#include <api/environment/environment_factory.h>
#include <api/rtc_event_log/rtc_event_log_factory.h>
#include <api/task_queue/default_task_queue_factory.h>
#include <media/engine/webrtc_media_engine.h>
Expand Down Expand Up @@ -54,7 +55,8 @@ SoraFactory::SoraFactory(std::optional<bool> use_hardware_encoder,
[openh264 = openh264](
auto format) -> std::unique_ptr<webrtc::VideoEncoder> {
return webrtc::DynamicH264Encoder::Create(
cricket::CreateVideoCodec(format), *openh264);
webrtc::CreateEnvironment(),
webrtc::H264EncoderSettings(), *openh264);
}));
dependencies.video_encoder_factory =
absl::make_unique<sora::SoraVideoEncoderFactory>(
Expand Down

0 comments on commit 9865b02

Please sign in to comment.