活动介绍

__builtin_expect

时间: 2023-07-08 21:42:36 浏览: 221
`__builtin_expect`是GCC提供的内建函数,用于告诉编译器一些代码分支的期望,从而优化程序性能。它的语法如下: ```c __builtin_expect (long exp, long c) ``` 其中`exp`是需要优化的表达式,`c`是期望的结果。该函数的返回值是`exp`。 `__builtin_expect`的作用是告诉编译器,`exp`表达式的结果通常是`c`,从而让编译器生成更优化的代码。例如: ```c if (__builtin_expect (x, 0)) { // x is most likely 0 } else { // x is most likely non-zero } ``` 在上面的代码中,`__builtin_expect(x, 0)`告诉编译器,`x`的值通常是0,从而让编译器生成更优化的代码来处理这种情况。
相关问题

net/netfilter/nf_conntrack_standalone.c:857:43: error: passing argument 1 of 'atomic_inc_not_zero' from incompatible pointer type [-Werror=incompatible-pointer-types] 857 | if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use))) | ^~~~~~~~~~~~~~~~~~~ | | | refcount_t * {aka struct refcount_struct *} ./include/linux/compiler.h:78:45: note: in definition of macro 'unlikely' 78 | # define unlikely(x) __builtin_expect(!!(x), 0) | ^

<think>好的,我现在需要解决用户提供的编译错误问题。首先,用户的错误信息是“passing argument 1 of 'atomic_inc_not_zero' from incompatible pointer type”,具体是在调用`atomic_inc_not_zero`时传递了`&ct->ct_general.use`,而编译器提示这个参数的类型是`refcount_t *`(即`struct refcount_struct *`),与`atomic_inc_not_zero`期望的参数类型不兼容。 首先,我需要回忆`atomic_inc_not_zero`函数的参数要求。通常,内核中的原子操作函数如`atomic_inc_not_zero`需要`atomic_t*`类型的参数,用于对原子变量进行递增操作。而这里的问题在于`ct->ct_general.use`的类型是`refcount_t`(引用计数类型),其底层可能包装了`atomic_t`,但直接取指针的话类型不匹配。 接下来,查看错误信息中的提示:参数类型是`refcount_t *`(即`struct refcount_struct *`),而`atomic_inc_not_zero`期望的是`atomic_t*`。因此,问题出在使用了错误的函数来操作引用计数变量。`refcount_t`类型应该使用专门的引用计数操作函数,例如`refcount_inc_not_zero`,而不是直接使用原子操作函数。 解决方法应该是将`atomic_inc_not_zero`替换为`refcount_inc_not_zero`,因为`ct->ct_general.use`是`refcount_t`类型,需要用对应的引用计数函数来操作。这样参数类型就会匹配,因为`refcount_inc_not_zero`的参数正是`refcount_t*`类型。 然后,我需要验证这个思路是否正确。查阅Linux内核文档,`refcount_t`是用于管理引用计数的类型,提供了`refcount_inc`、`refcount_dec`、`refcount_inc_not_zero`等专用函数,这些函数内部可能使用原子操作,但接口类型是`refcount_t*`。因此,使用`refcount_inc_not_zero`替换`atomic_inc_not_zero`是正确的做法。 总结错误原因:错误地使用原子操作函数`atomic_inc_not_zero`来操作`refcount_t`类型的变量,应改用引用计数专用函数`refcount_inc_not_zero`。 </think>这个编译错误的核心原因是:`atomic_inc_not_zero`函数期望接收`atomic_t*`类型的指针参数,但代码中传递的`&ct->ct_general.use`实际是`refcount_t*`(即`struct refcount_struct*`)类型的指针,两者类型不兼容。 **背景补充**: `refcount_t`是Linux内核中用于管理引用计数的专用类型(本质是对原子操作的封装),它有自己的一套操作接口(如`refcount_inc`、`refcount_dec`、`refcount_inc_not_zero`等),而`atomic_inc_not_zero`是直接操作`atomic_t`类型的原子函数,不能直接用于`refcount_t`类型变量。 **解决方法**: 将`atomic_inc_not_zero`替换为`refcount_inc_not_zero`,因为`ct->ct_general.use`是`refcount_t`类型变量,需要用引用计数专用函数操作。修改后代码应为: ```c if (unlikely(!refcount_inc_not_zero(&ct->ct_general.use))) ``` 这样参数类型(`refcount_t*`)与`refcount_inc_not_zero`的参数要求完全匹配,错误即可消除。

_builtin_expect

__builtin_expect是GCC编译器提供给程序员使用的一个指令,用于提供分支转移的信息给编译器,以便进行代码优化,减少指令跳转带来的性能下降。\[3\]一般使用的方法是将__builtin_expect指令封装为likely和unlikely宏,用于表示某个条件的可能性更大或更小。例如,likely(x)表示x的值为真的可能性更大,而unlikely(x)表示x的值为假的可能性更大。\[2\]通过在代码中使用likely和unlikely宏,编译器可以在编译过程中将可能性更大的代码紧跟在前面的代码,从而减少指令跳转带来的性能下降。\[3\]这样的优化可以提高程序的执行效率。 #### 引用[.reference_title] - *1* [__builtin_xxx指令学习【1】__builtin_expect](https://blog.csdn.net/qq_42604176/article/details/130031135)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [【编程基础の基础】__builtin_expect详解(汇编级解释)](https://blog.csdn.net/weixin_42157432/article/details/115805804)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
阅读全文

相关推荐

安装 报错npm WARN deprecated [email protected]: This package is no longer supported. npm WARN deprecated [email protected]: This package is no longer supported. npm WARN deprecated [email protected]: This package is no longer supported. npm ERR! code 1 npm ERR! path /Users/yangjia/workspace/company/dkYun/SDK2.0/node_modules/microtime npm ERR! command failed npm ERR! command sh -c prebuild-install || node-gyp rebuild npm ERR! CXX(target) Release/obj.target/microtime/src/microtime.o npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using [email protected] npm ERR! gyp info using [email protected] | darwin | arm64 npm ERR! gyp info find Python using Python version 3.12.1 found at "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3" npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.12/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', npm ERR! gyp info spawn args 'binding.gyp', npm ERR! gyp info spawn args '-f', npm ERR! gyp info spawn args 'make', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/yangjia/workspace/company/dkYun/SDK2.0/node_modules/microtime/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/common.gypi', npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/yangjia/Library/Caches/node-gyp/16.14.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/yangjia/Library/Caches/node-gyp/16.14.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/yangjia/workspace/company/dkYun/SDK2.0/node_modules/microtime', npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! gyp info spawn args '--depth=.', npm ERR! gyp info spawn args '--no-parallel', npm ERR! gyp info spawn args '--generator-output', npm ERR! gyp info spawn args 'build', npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! gyp info spawn make npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:222: npm ERR! In file included from ../../nan/nan_converters.h:67: npm ERR! ../../nan/nan_converters_43_inl.h:22:1: error: no viable conversion from 'Local<v8::Context>' to 'v8::Isolate *' npm ERR! X(Boolean) npm ERR! ^~~~~~~~~~ npm ERR! ../../nan/nan_converters_43_inl.h:18:23: note: expanded from macro 'X' npm ERR! val->To ## TYPE(isolate->GetCurrentContext()) \ npm ERR! ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3086:37: note: passing argument to parameter 'isolate' here npm ERR! Local<Boolean> ToBoolean(Isolate* isolate) const; npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:222: npm ERR! In file included from ../../nan/nan_converters.h:67: npm ERR! ../../nan/nan_converters_43_inl.h:22:1: error: no member named 'FromMaybe' in 'v8::Local<v8::Boolean>' npm ERR! X(Boolean) npm ERR! ^~~~~~~~~~ npm ERR! ../../nan/nan_converters_43_inl.h:19:12: note: expanded from macro 'X' npm ERR! .FromMaybe(v8::Local<v8::TYPE>())); \ npm ERR! ^ npm ERR! ../../nan/nan_converters_43_inl.h:40:1: error: no viable conversion from 'Local<v8::Context>' to 'v8::Isolate *' npm ERR! X(bool, Boolean) npm ERR! ^~~~~~~~~~~~~~~~ npm ERR! ../../nan/nan_converters_43_inl.h:37:29: note: expanded from macro 'X' npm ERR! return val->NAME ## Value(isolate->GetCurrentContext()); \ npm ERR! ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3096:30: note: passing argument to parameter 'isolate' here npm ERR! bool BooleanValue(Isolate* isolate) const; npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:222: npm ERR! In file included from ../../nan/nan_converters.h:67: npm ERR! ../../nan/nan_converters_43_inl.h:40:1: error: no viable conversion from returned value of type 'bool' to function return type 'imp::ToFactory<bool>::return_t' (aka 'Maybe<bool>') npm ERR! X(bool, Boolean) npm ERR! ^~~~~~~~~~~~~~~~ npm ERR! ../../nan/nan_converters_43_inl.h:37:10: note: expanded from macro 'X' npm ERR! return val->NAME ## Value(isolate->GetCurrentContext()); \ npm ERR! ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:10437:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'bool' to 'const v8::Maybe<bool> &' for 1st argument npm ERR! class Maybe { npm ERR! ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:10437:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'bool' to 'v8::Maybe<bool> &&' for 1st argument npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:10492:12: note: explicit constructor is not a candidate npm ERR! explicit Maybe(const T& t) : has_value_(true), value_(t) {} npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:223: npm ERR! In file included from ../../nan/nan_new.h:189: npm ERR! ../../nan/nan_implementation_12_inl.h:356:37: error: too few arguments to function call, expected 2, have 1 npm ERR! return v8::StringObject::New(value).As<v8::StringObject>(); npm ERR! ~~~~~~~~~~~~~~~~~~~~~ ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:6196:23: note: 'New' declared here npm ERR! static Local<Value> New(Isolate* isolate, Local<String> value); npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:2722: npm ERR! ../../nan/nan_object_wrap.h:24:25: error: no member named 'IsNearDeath' in 'Nan::Persistent<v8::Object>' npm ERR! assert(persistent().IsNearDeath()); npm ERR! ~~~~~~~~~~~~ ^ npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert' npm ERR! (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0) npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:2722: npm ERR! ../../nan/nan_object_wrap.h:127:26: error: no member named 'IsNearDeath' in 'Nan::Persistent<v8::Object>' npm ERR! assert(wrap->handle_.IsNearDeath()); npm ERR! ~~~~~~~~~~~~~ ^ npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert' npm ERR! (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0) npm ERR! ^ npm ERR! In file included from ../src/microtime.cc:9: npm ERR! In file included from ../../nan/nan.h:2818: npm ERR! ../../nan/nan_typedarray_contents.h:34:43: warning: 'GetContents' is deprecated: Use GetBackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations] npm ERR! data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset; npm ERR! ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:5614:3: note: 'GetContents' has been explicitly marked deprecated here npm ERR! V8_DEPRECATED("Use GetBackingStore. See http://crbug.com/v8/9908.") npm ERR! ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8config.h:454:35: note: expanded from macro 'V8_DEPRECATED' npm ERR! # define V8_DEPRECATED(message) [[deprecated(message)]] npm ERR! ^ npm ERR! ../src/microtime.cc:75:10: error: no matching member function for call to 'Set' npm ERR! array->Set(Nan::New<v8::Integer>(0), Nan::New<v8::Number>((double)t.tv_sec)); npm ERR! ~~~~~~~^~~ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3961:37: note: candidate function not viable: requires 3 arguments, but 2 were provided npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, npm ERR! ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3964:37: note: candidate function not viable: requires 3 arguments, but 2 were provided npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index, npm ERR! ^ npm ERR! ../src/microtime.cc:76:10: error: no matching member function for call to 'Set' npm ERR! array->Set(Nan::New<v8::Integer>(1), Nan::New<v8::Number>((double)t.tv_usec)); npm ERR! ~~~~~~~^~~ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3961:37: note: candidate function not viable: requires 3 arguments, but 2 were provided npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, npm ERR! ^ npm ERR! /Users/yangjia/Library/Caches/node-gyp/16.14.0/include/node/v8.h:3964:37: note: candidate function not viable: requires 3 arguments, but 2 were provided npm ERR! V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index, npm ERR! ^ npm ERR! 1 warning and 9 errors generated. npm ERR! make: *** [Release/obj.target/microtime/src/microtime.o] Error 1 npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: make failed with exit code: 2 npm ERR! gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:520:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 22.6.0 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /Users/yangjia/workspace/company/dkYun/SDK2.0/node_modules/microtime npm ERR! gyp ERR! node -v v16.14.0 npm ERR! gyp ERR! node-gyp -v v8.4.1 npm ERR! gyp ERR! not ok npm ERR! A complete log of this run can be found in: npm ERR! /Users/yangjia/.npm/_logs/2025-06-30T06_40_09_765Z-debug-0.log

/* * Copyright (c) 2011 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. */ #include "api/neteq/neteq.h" #include <math.h> #include <stdlib.h> #include <string.h> // memset #include <algorithm> #include <memory> #include <set> #include <string> #include <vector> #include "absl/flags/flag.h" #include "api/audio/audio_frame.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" #include "modules/audio_coding/neteq/test/neteq_decoding_test.h" #include "modules/audio_coding/neteq/tools/audio_loop.h" #include "modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h" #include "modules/audio_coding/neteq/tools/neteq_test.h" #include "modules/include/module_common_types_public.h" #include "modules/rtp_rtcp/include/rtcp_statistics.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "rtc_base/ignore_wundef.h" #include "rtc_base/message_digest.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/system/arch.h" #include "test/field_trial.h" #include "test/gtest.h" #include "test/testsupport/file_utils.h" ABSL_FLAG(bool, gen_ref, false, "Generate reference files."); namespace webrtc { #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ defined(WEBRTC_CODEC_ILBC) #define MAYBE_TestBitExactness TestBitExactness #else #define MAYBE_TestBitExactness DISABLED_TestBitExactness #endif TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) { const std::string input_rtp_file = webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); const std::string output_checksum = "dee7a10ab92526876a70a85bc48a4906901af3df"; const std::string network_stats_checksum = "911dbf5fd97f48d25b8f0967286eb73c9d6f6158"; DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, absl::GetFlag(FLAGS_gen_ref)); } #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && defined(WEBRTC_CODEC_OPUS) #define MAYBE_TestOpusBitExactness TestOpusBitExactness #else #define MAYBE_TestOpusBitExactness DISABLED_TestOpusBitExactness #endif TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) { const std::string input_rtp_file = webrtc::test::ResourcePath("audio_coding/neteq_opus", "rtp"); const std::string output_checksum = "fec6827bb9ee0b21770bbbb4a3a6f8823bf537dc|" "3610cc7be4b3407b9c273b1299ab7f8f47cca96b"; const std::string network_stats_checksum = "3d043e47e5f4bb81d37e7bce8c44bf802965c853|" "076662525572dba753b11578330bd491923f7f5e"; DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, absl::GetFlag(FLAGS_gen_ref)); } #if defined(WEBRTC_LINUX) && defined(WEBRTC_ARCH_X86_64) && \ defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && defined(WEBRTC_CODEC_OPUS) #define MAYBE_TestOpusDtxBitExactness TestOpusDtxBitExactness #else #define MAYBE_TestOpusDtxBitExactness DISABLED_TestOpusDtxBitExactness #endif TEST_F(NetEqDecodingTest, MAYBE_TestOpusDtxBitExactness) { const std::string input_rtp_file = webrtc::test::ResourcePath("audio_coding/neteq_opus_dtx", "rtp"); const std::string output_checksum = "b3c4899eab5378ef5e54f2302948872149f6ad5e|" "589e975ec31ea13f302457fea1425be9380ffb96"; const std::string network_stats_checksum = "dc8447b9fee1a21fd5d1f4045d62b982a3fb0215"; DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, absl::GetFlag(FLAGS_gen_ref)); } // Use fax mode to avoid time-scaling. This is to simplify the testing of // packet waiting times in the packet buffer. class NetEqDecodingTestFaxMode : public NetEqDecodingTest { protected: NetEqDecodingTestFaxMode() : NetEqDecodingTest() { config_.for_test_no_time_stretching = true; } void TestJitterBufferDelay(bool apply_packet_loss); }; TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) { // Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio. size_t num_frames = 30; const size_t kSamples = 10 * 16; const size_t kPayloadBytes = kSamples * 2; for (size_t i = 0; i < num_frames; ++i) { const uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; rtp_info.sequenceNumber = rtc::checked_cast<uint16_t>(i); rtp_info.timestamp = rtc::checked_cast<uint32_t>(i * kSamples); rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. rtp_info.payloadType = 94; // PCM16b WB codec. rtp_info.markerBit = 0; ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); } // Pull out all data. for (size_t i = 0; i < num_frames; ++i) { bool muted; ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); } NetEqNetworkStatistics stats; EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms // spacing (per definition), we expect the delay to increase with 10 ms for // each packet. Thus, we are calculating the statistics for a series from 10 // to 300, in steps of 10 ms. EXPECT_EQ(155, stats.mean_waiting_time_ms); EXPECT_EQ(155, stats.median_waiting_time_ms); EXPECT_EQ(10, stats.min_waiting_time_ms); EXPECT_EQ(300, stats.max_waiting_time_ms); // Check statistics again and make sure it's been reset. EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); EXPECT_EQ(-1, stats.mean_waiting_time_ms); EXPECT_EQ(-1, stats.median_waiting_time_ms); EXPECT_EQ(-1, stats.min_waiting_time_ms); EXPECT_EQ(-1, stats.max_waiting_time_ms); } TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) { // Apply a clock drift of -25 ms / s (sender faster than receiver). const double kDriftFactor = 1000.0 / (1000.0 + 25.0); const double kNetworkFreezeTimeMs = 0.0; const bool kGetAudioDuringFreezeRecovery = false; const int kDelayToleranceMs = 20; const int kMaxTimeToSpeechMs = 100; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDrift) { // Apply a clock drift of +25 ms / s (sender slower than receiver). const double kDriftFactor = 1000.0 / (1000.0 - 25.0); const double kNetworkFreezeTimeMs = 0.0; const bool kGetAudioDuringFreezeRecovery = false; const int kDelayToleranceMs = 40; const int kMaxTimeToSpeechMs = 100; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDriftNetworkFreeze) { // Apply a clock drift of -25 ms / s (sender faster than receiver). const double kDriftFactor = 1000.0 / (1000.0 + 25.0); const double kNetworkFreezeTimeMs = 5000.0; const bool kGetAudioDuringFreezeRecovery = false; const int kDelayToleranceMs = 60; const int kMaxTimeToSpeechMs = 200; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreeze) { // Apply a clock drift of +25 ms / s (sender slower than receiver). const double kDriftFactor = 1000.0 / (1000.0 - 25.0); const double kNetworkFreezeTimeMs = 5000.0; const bool kGetAudioDuringFreezeRecovery = false; const int kDelayToleranceMs = 40; const int kMaxTimeToSpeechMs = 100; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreezeExtraPull) { // Apply a clock drift of +25 ms / s (sender slower than receiver). const double kDriftFactor = 1000.0 / (1000.0 - 25.0); const double kNetworkFreezeTimeMs = 5000.0; const bool kGetAudioDuringFreezeRecovery = true; const int kDelayToleranceMs = 40; const int kMaxTimeToSpeechMs = 100; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, LongCngWithoutClockDrift) { const double kDriftFactor = 1.0; // No drift. const double kNetworkFreezeTimeMs = 0.0; const bool kGetAudioDuringFreezeRecovery = false; const int kDelayToleranceMs = 10; const int kMaxTimeToSpeechMs = 50; LongCngWithClockDrift(kDriftFactor, kNetworkFreezeTimeMs, kGetAudioDuringFreezeRecovery, kDelayToleranceMs, kMaxTimeToSpeechMs); } TEST_F(NetEqDecodingTest, UnknownPayloadType) { const size_t kPayloadBytes = 100; uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; PopulateRtpInfo(0, 0, &rtp_info); rtp_info.payloadType = 1; // Not registered as a decoder. EXPECT_EQ(NetEq::kFail, neteq_->InsertPacket(rtp_info, payload)); } #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) #define MAYBE_DecoderError DecoderError #else #define MAYBE_DecoderError DISABLED_DecoderError #endif TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { const size_t kPayloadBytes = 100; uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; PopulateRtpInfo(0, 0, &rtp_info); rtp_info.payloadType = 103; // iSAC, but the payload is invalid. EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); // Set all of out_data_ to 1, and verify that it was set to 0 by the call // to GetAudio. int16_t* out_frame_data = out_frame_.mutable_data(); for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { out_frame_data[i] = 1; } bool muted; EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_FALSE(muted); // Verify that the first 160 samples are set to 0. static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. const int16_t* const_out_frame_data = out_frame_.data(); for (int i = 0; i < kExpectedOutputLength; ++i) { rtc::StringBuilder ss; ss << "i = " << i; SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. EXPECT_EQ(0, const_out_frame_data[i]); } } TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { // Set all of out_data_ to 1, and verify that it was set to 0 by the call // to GetAudio. int16_t* out_frame_data = out_frame_.mutable_data(); for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { out_frame_data[i] = 1; } bool muted; EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_FALSE(muted); // Verify that the first block of samples is set to 0. static const int kExpectedOutputLength = kInitSampleRateHz / 100; // 10 ms at initial sample rate. const int16_t* const_out_frame_data = out_frame_.data(); for (int i = 0; i < kExpectedOutputLength; ++i) { rtc::StringBuilder ss; ss << "i = " << i; SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. EXPECT_EQ(0, const_out_frame_data[i]); } // Verify that the sample rate did not change from the initial configuration. EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz()); } class NetEqBgnTest : public NetEqDecodingTest { protected: void CheckBgn(int sampling_rate_hz) { size_t expected_samples_per_channel = 0; uint8_t payload_type = 0xFF; // Invalid. if (sampling_rate_hz == 8000) { expected_samples_per_channel = kBlockSize8kHz; payload_type = 93; // PCM 16, 8 kHz. } else if (sampling_rate_hz == 16000) { expected_samples_per_channel = kBlockSize16kHz; payload_type = 94; // PCM 16, 16 kHZ. } else if (sampling_rate_hz == 32000) { expected_samples_per_channel = kBlockSize32kHz; payload_type = 95; // PCM 16, 32 kHz. } else { ASSERT_TRUE(false); // Unsupported test case. } AudioFrame output; test::AudioLoop input; // We are using the same 32 kHz input file for all tests, regardless of // sampling_rate_hz. The output may sound weird, but the test is still // valid. ASSERT_TRUE(input.Init( webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 10 * sampling_rate_hz, // Max 10 seconds loop length. expected_samples_per_channel)); // Payload of 10 ms of PCM16 32 kHz. uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; RTPHeader rtp_info; PopulateRtpInfo(0, 0, &rtp_info); rtp_info.payloadType = payload_type; bool muted; for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. auto block = input.GetNextBlock(); ASSERT_EQ(expected_samples_per_channel, block.size()); size_t enc_len_bytes = WebRtcPcm16b_Encode(block.data(), block.size(), payload); ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( payload, enc_len_bytes))); output.Reset(); ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); ASSERT_EQ(1u, output.num_channels_); ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); ASSERT_EQ(AudioFrame::kNormalSpeech, output.speech_type_); // Next packet. rtp_info.timestamp += rtc::checked_cast<uint32_t>(expected_samples_per_channel); rtp_info.sequenceNumber++; } output.Reset(); // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull // one frame without checking speech-type. This is the first frame pulled // without inserting any packet, and might not be labeled as PLC. ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); ASSERT_EQ(1u, output.num_channels_); ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); // To be able to test the fading of background noise we need at lease to // pull 611 frames. const int kFadingThreshold = 611; // Test several CNG-to-PLC packet for the expected behavior. The number 20 // is arbitrary, but sufficiently large to test enough number of frames. const int kNumPlcToCngTestFrames = 20; bool plc_to_cng = false; for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { output.Reset(); // Set to non-zero. memset(output.mutable_data(), 1, AudioFrame::kMaxDataSizeBytes); ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); ASSERT_FALSE(muted); ASSERT_EQ(1u, output.num_channels_); ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); if (output.speech_type_ == AudioFrame::kPLCCNG) { plc_to_cng = true; double sum_squared = 0; const int16_t* output_data = output.data(); for (size_t k = 0; k < output.num_channels_ * output.samples_per_channel_; ++k) sum_squared += output_data[k] * output_data[k]; EXPECT_EQ(0, sum_squared); } else { EXPECT_EQ(AudioFrame::kPLC, output.speech_type_); } } EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. } }; TEST_F(NetEqBgnTest, RunTest) { CheckBgn(8000); CheckBgn(16000); CheckBgn(32000); } TEST_F(NetEqDecodingTest, SequenceNumberWrap) { // Start with a sequence number that will soon wrap. std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); } TEST_F(NetEqDecodingTest, SequenceNumberWrapAndDrop) { // Start with a sequence number that will soon wrap. std::set<uint16_t> drop_seq_numbers; drop_seq_numbers.insert(0xFFFF); drop_seq_numbers.insert(0x0); WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); } TEST_F(NetEqDecodingTest, TimestampWrap) { // Start with a timestamp that will soon wrap. std::set<uint16_t> drop_seq_numbers; WrapTest(0, 0xFFFFFFFF - 3000, drop_seq_numbers, false, true); } TEST_F(NetEqDecodingTest, TimestampAndSequenceNumberWrap) { // Start with a timestamp and a sequence number that will wrap at the same // time. std::set<uint16_t> drop_seq_numbers; WrapTest(0xFFFF - 10, 0xFFFFFFFF - 5000, drop_seq_numbers, true, true); } TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { uint16_t seq_no = 0; uint32_t timestamp = 0; const int kFrameSizeMs = 10; const int kSampleRateKhz = 16; const int kSamples = kFrameSizeMs * kSampleRateKhz; const size_t kPayloadBytes = kSamples * 2; const int algorithmic_delay_samples = std::max(algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); // Insert three speech packets. Three are needed to get the frame length // correct. uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; bool muted; for (int i = 0; i < 3; ++i) { PopulateRtpInfo(seq_no, timestamp, &rtp_info); ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); ++seq_no; timestamp += kSamples; // Pull audio once. ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); } // Verify speech output. EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); // Insert same CNG packet twice. const int kCngPeriodMs = 100; const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; size_t payload_len; PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); // This is the first time this CNG packet is inserted. ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( payload, payload_len))); // Pull audio once and make sure CNG is played. ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); EXPECT_FALSE( neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. EXPECT_EQ(timestamp - algorithmic_delay_samples, out_frame_.timestamp_ + out_frame_.samples_per_channel_); // Insert the same CNG packet again. Note that at this point it is old, since // we have already decoded the first copy of it. ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( payload, payload_len))); // Pull audio until we have played kCngPeriodMs of CNG. Start at 10 ms since // we have already pulled out CNG once. for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) { ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); EXPECT_FALSE( neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. EXPECT_EQ(timestamp - algorithmic_delay_samples, out_frame_.timestamp_ + out_frame_.samples_per_channel_); } ++seq_no; timestamp += kCngPeriodSamples; uint32_t first_speech_timestamp = timestamp; // Insert speech again. for (int i = 0; i < 3; ++i) { PopulateRtpInfo(seq_no, timestamp, &rtp_info); ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); ++seq_no; timestamp += kSamples; } // Pull audio once and verify that the output is speech again. ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); absl::optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); ASSERT_TRUE(playout_timestamp); EXPECT_EQ(first_speech_timestamp + kSamples - algorithmic_delay_samples, *playout_timestamp); } TEST_F(NetEqDecodingTest, CngFirst) { uint16_t seq_no = 0; uint32_t timestamp = 0; const int kFrameSizeMs = 10; const int kSampleRateKhz = 16; const int kSamples = kFrameSizeMs * kSampleRateKhz; const int kPayloadBytes = kSamples * 2; const int kCngPeriodMs = 100; const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; size_t payload_len; uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); ASSERT_EQ(NetEq::kOK, neteq_->InsertPacket( rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len))); ++seq_no; timestamp += kCngPeriodSamples; // Pull audio once and make sure CNG is played. bool muted; ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); // Insert some speech packets. const uint32_t first_speech_timestamp = timestamp; int timeout_counter = 0; do { ASSERT_LT(timeout_counter++, 20) << "Test timed out"; PopulateRtpInfo(seq_no, timestamp, &rtp_info); ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); ++seq_no; timestamp += kSamples; // Pull audio once. ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); } while (!IsNewerTimestamp(out_frame_.timestamp_, first_speech_timestamp)); // Verify speech output. EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); } class NetEqDecodingTestWithMutedState : public NetEqDecodingTest { public: NetEqDecodingTestWithMutedState() : NetEqDecodingTest() { config_.enable_muted_state = true; } protected: static constexpr size_t kSamples = 10 * 16; static constexpr size_t kPayloadBytes = kSamples * 2; void InsertPacket(uint32_t rtp_timestamp) { uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; PopulateRtpInfo(0, rtp_timestamp, &rtp_info); EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); } void InsertCngPacket(uint32_t rtp_timestamp) { uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; size_t payload_len; PopulateCng(0, rtp_timestamp, &rtp_info, payload, &payload_len); EXPECT_EQ(NetEq::kOK, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( payload, payload_len))); } bool GetAudioReturnMuted() { bool muted; EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); return muted; } void GetAudioUntilMuted() { while (!GetAudioReturnMuted()) { ASSERT_LT(counter_++, 1000) << "Test timed out"; } } void GetAudioUntilNormal() { bool muted = false; while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_LT(counter_++, 1000) << "Test timed out"; } EXPECT_FALSE(muted); } int counter_ = 0; }; // Verifies that NetEq goes in and out of muted state as expected. TEST_F(NetEqDecodingTestWithMutedState, MutedState) { // Insert one speech packet. InsertPacket(0); // Pull out audio once and expect it not to be muted. EXPECT_FALSE(GetAudioReturnMuted()); // Pull data until faded out. GetAudioUntilMuted(); EXPECT_TRUE(out_frame_.muted()); // Verify that output audio is not written during muted mode. Other parameters // should be correct, though. AudioFrame new_frame; int16_t* frame_data = new_frame.mutable_data(); for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { frame_data[i] = 17; } bool muted; EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted)); EXPECT_TRUE(muted); EXPECT_TRUE(out_frame_.muted()); for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { EXPECT_EQ(17, frame_data[i]); } EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_, new_frame.timestamp_); EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_); EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_); EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_); EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_); EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_); // Insert new data. Timestamp is corrected for the time elapsed since the last // packet. Verify that normal operation resumes. InsertPacket(kSamples * counter_); GetAudioUntilNormal(); EXPECT_FALSE(out_frame_.muted()); NetEqNetworkStatistics stats; EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); // NetEqNetworkStatistics::expand_rate tells the fraction of samples that were // concealment samples, in Q14 (16384 = 100%) .The vast majority should be // concealment samples in this test. EXPECT_GT(stats.expand_rate, 14000); // And, it should be greater than the speech_expand_rate. EXPECT_GT(stats.expand_rate, stats.speech_expand_rate); } // Verifies that NetEq goes out of muted state when given a delayed packet. TEST_F(NetEqDecodingTestWithMutedState, MutedStateDelayedPacket) { // Insert one speech packet. InsertPacket(0); // Pull out audio once and expect it not to be muted. EXPECT_FALSE(GetAudioReturnMuted()); // Pull data until faded out. GetAudioUntilMuted(); // Insert new data. Timestamp is only corrected for the half of the time // elapsed since the last packet. That is, the new packet is delayed. Verify // that normal operation resumes. InsertPacket(kSamples * counter_ / 2); GetAudioUntilNormal(); } // Verifies that NetEq goes out of muted state when given a future packet. TEST_F(NetEqDecodingTestWithMutedState, MutedStateFuturePacket) { // Insert one speech packet. InsertPacket(0); // Pull out audio once and expect it not to be muted. EXPECT_FALSE(GetAudioReturnMuted()); // Pull data until faded out. GetAudioUntilMuted(); // Insert new data. Timestamp is over-corrected for the time elapsed since the // last packet. That is, the new packet is too early. Verify that normal // operation resumes. InsertPacket(kSamples * counter_ * 2); GetAudioUntilNormal(); } // Verifies that NetEq goes out of muted state when given an old packet. TEST_F(NetEqDecodingTestWithMutedState, MutedStateOldPacket) { // Insert one speech packet. InsertPacket(0); // Pull out audio once and expect it not to be muted. EXPECT_FALSE(GetAudioReturnMuted()); // Pull data until faded out. GetAudioUntilMuted(); EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); // Insert a few packets which are older than the first packet. for (int i = 0; i < 5; ++i) { InsertPacket(kSamples * (i - 1000)); } EXPECT_FALSE(GetAudioReturnMuted()); EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); } // Verifies that NetEq doesn't enter muted state when CNG mode is active and the // packet stream is suspended for a long time. TEST_F(NetEqDecodingTestWithMutedState, DoNotMuteExtendedCngWithoutPackets) { // Insert one CNG packet. InsertCngPacket(0); // Pull 10 seconds of audio (10 ms audio generated per lap). for (int i = 0; i < 1000; ++i) { bool muted; EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); ASSERT_FALSE(muted); } EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); } // Verifies that NetEq goes back to normal after a long CNG period with the // packet stream suspended. TEST_F(NetEqDecodingTestWithMutedState, RecoverAfterExtendedCngWithoutPackets) { // Insert one CNG packet. InsertCngPacket(0); // Pull 10 seconds of audio (10 ms audio generated per lap). for (int i = 0; i < 1000; ++i) { bool muted; EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); } // Insert new data. Timestamp is corrected for the time elapsed since the last // packet. Verify that normal operation resumes. InsertPacket(kSamples * counter_); GetAudioUntilNormal(); } namespace { ::testing::AssertionResult AudioFramesEqualExceptData(const AudioFrame& a, const AudioFrame& b) { if (a.timestamp_ != b.timestamp_) return ::testing::AssertionFailure() << "timestamp_ diff (" << a.timestamp_ << " != " << b.timestamp_ << ")"; if (a.sample_rate_hz_ != b.sample_rate_hz_) return ::testing::AssertionFailure() << "sample_rate_hz_ diff (" << a.sample_rate_hz_ << " != " << b.sample_rate_hz_ << ")"; if (a.samples_per_channel_ != b.samples_per_channel_) return ::testing::AssertionFailure() << "samples_per_channel_ diff (" << a.samples_per_channel_ << " != " << b.samples_per_channel_ << ")"; if (a.num_channels_ != b.num_channels_) return ::testing::AssertionFailure() << "num_channels_ diff (" << a.num_channels_ << " != " << b.num_channels_ << ")"; if (a.speech_type_ != b.speech_type_) return ::testing::AssertionFailure() << "speech_type_ diff (" << a.speech_type_ << " != " << b.speech_type_ << ")"; if (a.vad_activity_ != b.vad_activity_) return ::testing::AssertionFailure() << "vad_activity_ diff (" << a.vad_activity_ << " != " << b.vad_activity_ << ")"; return ::testing::AssertionSuccess(); } ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a, const AudioFrame& b) { ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b); if (!res) return res; if (memcmp(a.data(), b.data(), a.samples_per_channel_ * a.num_channels_ * sizeof(*a.data())) != 0) { return ::testing::AssertionFailure() << "data_ diff"; } return ::testing::AssertionSuccess(); } } // namespace TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) { ASSERT_FALSE(config_.enable_muted_state); config2_.enable_muted_state = true; CreateSecondInstance(); // Insert one speech packet into both NetEqs. const size_t kSamples = 10 * 16; const size_t kPayloadBytes = kSamples * 2; uint8_t payload[kPayloadBytes] = {0}; RTPHeader rtp_info; PopulateRtpInfo(0, 0, &rtp_info); EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); AudioFrame out_frame1, out_frame2; bool muted; for (int i = 0; i < 1000; ++i) { rtc::StringBuilder ss; ss << "i = " << i; SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); EXPECT_FALSE(muted); EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); if (muted) { EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); } else { EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); } } EXPECT_TRUE(muted); // Insert new data. Timestamp is corrected for the time elapsed since the last // packet. for (int i = 0; i < 5; ++i) { PopulateRtpInfo(0, kSamples * 1000 + kSamples * i, &rtp_info); EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload)); EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload)); } int counter = 0; while (out_frame1.speech_type_ != AudioFrame::kNormalSpeech) { ASSERT_LT(counter++, 1000) << "Test timed out"; rtc::StringBuilder ss; ss << "counter = " << counter; SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); EXPECT_FALSE(muted); EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); if (muted) { EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); } else { EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); } } EXPECT_FALSE(muted); } TEST_F(NetEqDecodingTest, TestConcealmentEvents) { const int kNumConcealmentEvents = 19; const size_t kSamples = 10 * 16; const size_t kPayloadBytes = kSamples * 2; int seq_no = 0; RTPHeader rtp_info; rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. rtp_info.payloadType = 94; // PCM16b WB codec. rtp_info.markerBit = 0; const uint8_t payload[kPayloadBytes] = {0}; bool muted; for (int i = 0; i < kNumConcealmentEvents; i++) { // Insert some packets of 10 ms size. for (int j = 0; j < 10; j++) { rtp_info.sequenceNumber = seq_no++; rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; neteq_->InsertPacket(rtp_info, payload); neteq_->GetAudio(&out_frame_, &muted); } // Lose a number of packets. int num_lost = 1 + i; for (int j = 0; j < num_lost; j++) { seq_no++; neteq_->GetAudio(&out_frame_, &muted); } } // Check number of concealment events. NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); EXPECT_EQ(kNumConcealmentEvents, static_cast<int>(stats.concealment_events)); } // Test that the jitter buffer delay stat is computed correctly. void NetEqDecodingTestFaxMode::TestJitterBufferDelay(bool apply_packet_loss) { const int kNumPackets = 10; const int kDelayInNumPackets = 2; const int kPacketLenMs = 10; // All packets are of 10 ms size. const size_t kSamples = kPacketLenMs * 16; const size_t kPayloadBytes = kSamples * 2; RTPHeader rtp_info; rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. rtp_info.payloadType = 94; // PCM16b WB codec. rtp_info.markerBit = 0; const uint8_t payload[kPayloadBytes] = {0}; bool muted; int packets_sent = 0; int packets_received = 0; int expected_delay = 0; int expected_target_delay = 0; uint64_t expected_emitted_count = 0; while (packets_received < kNumPackets) { // Insert packet. if (packets_sent < kNumPackets) { rtp_info.sequenceNumber = packets_sent++; rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; neteq_->InsertPacket(rtp_info, payload); } // Get packet. if (packets_sent > kDelayInNumPackets) { neteq_->GetAudio(&out_frame_, &muted); packets_received++; // The delay reported by the jitter buffer never exceeds // the number of samples previously fetched with GetAudio // (hence the min()). int packets_delay = std::min(packets_received, kDelayInNumPackets + 1); // The increase of the expected delay is the product of // the current delay of the jitter buffer in ms * the // number of samples that are sent for play out. int current_delay_ms = packets_delay * kPacketLenMs; expected_delay += current_delay_ms * kSamples; expected_target_delay += neteq_->TargetDelayMs() * kSamples; expected_emitted_count += kSamples; } } if (apply_packet_loss) { // Extra call to GetAudio to cause concealment. neteq_->GetAudio(&out_frame_, &muted); } // Check jitter buffer delay. NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); EXPECT_EQ(expected_delay, rtc::checked_cast<int>(stats.jitter_buffer_delay_ms)); EXPECT_EQ(expected_emitted_count, stats.jitter_buffer_emitted_count); EXPECT_EQ(expected_target_delay, rtc::checked_cast<int>(stats.jitter_buffer_target_delay_ms)); } TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithoutLoss) { TestJitterBufferDelay(false); } TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithLoss) { TestJitterBufferDelay(true); } TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithAcceleration) { const int kPacketLenMs = 10; // All packets are of 10 ms size. const size_t kSamples = kPacketLenMs * 16; const size_t kPayloadBytes = kSamples * 2; RTPHeader rtp_info; rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. rtp_info.payloadType = 94; // PCM16b WB codec. rtp_info.markerBit = 0; const uint8_t payload[kPayloadBytes] = {0}; int expected_target_delay = neteq_->TargetDelayMs() * kSamples; neteq_->InsertPacket(rtp_info, payload); bool muted; neteq_->GetAudio(&out_frame_, &muted); rtp_info.sequenceNumber += 1; rtp_info.timestamp += kSamples; neteq_->InsertPacket(rtp_info, payload); rtp_info.sequenceNumber += 1; rtp_info.timestamp += kSamples; neteq_->InsertPacket(rtp_info, payload); expected_target_delay += neteq_->TargetDelayMs() * 2 * kSamples; // We have two packets in the buffer and kAccelerate operation will // extract 20 ms of data. neteq_->GetAudio(&out_frame_, &muted, nullptr, NetEq::Operation::kAccelerate); // Check jitter buffer delay. NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); EXPECT_EQ(10 * kSamples * 3, stats.jitter_buffer_delay_ms); EXPECT_EQ(kSamples * 3, stats.jitter_buffer_emitted_count); EXPECT_EQ(expected_target_delay, rtc::checked_cast<int>(stats.jitter_buffer_target_delay_ms)); } namespace test { TEST(NetEqNoTimeStretchingMode, RunTest) { NetEq::Config config; config.for_test_no_time_stretching = true; auto codecs = NetEqTest::StandardDecoderMap(); std::map<int, RTPExtensionType> rtp_ext_map = { {1, kRtpExtensionAudioLevel}, {3, kRtpExtensionAbsoluteSendTime}, {5, kRtpExtensionTransportSequenceNumber}, {7, kRtpExtensionVideoContentType}, {8, kRtpExtensionVideoTiming}}; std::unique_ptr<NetEqInput> input = CreateNetEqRtpDumpInput( webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"), rtp_ext_map, absl::nullopt /*No SSRC filter*/); std::unique_ptr<TimeLimitedNetEqInput> input_time_limit( new TimeLimitedNetEqInput(std::move(input), 20000)); std::unique_ptr<AudioSink> output(new VoidAudioSink); NetEqTest::Callbacks callbacks; NetEqTest test(config, CreateBuiltinAudioDecoderFactory(), codecs, /*text_log=*/nullptr, /*neteq_factory=*/nullptr, /*input=*/std::move(input_time_limit), std::move(output), callbacks); test.Run(); const auto stats = test.SimulationStats(); EXPECT_EQ(0, stats.accelerate_rate); EXPECT_EQ(0, stats.preemptive_rate); } } // namespace test } // namespace webrtc

最新推荐

recommend-type

使用Nginx实现负载均衡配置详解.doc

使用Nginx实现负载均衡配置详解.doc
recommend-type

Mockingbird v2:PocketMine-MP新防作弊机制详解

标题和描述中所涉及的知识点如下: 1. Mockingbird反作弊系统: Mockingbird是一个正在开发中的反作弊系统,专门针对PocketMine-MP服务器。PocketMine-MP是Minecraft Pocket Edition(Minecraft PE)的一个服务器软件,允许玩家在移动平台上共同游戏。随着游戏的普及,作弊问题也随之而来,因此Mockingbird的出现正是为了应对这种情况。 2. Mockingbird的版本迭代: 从描述中提到的“Mockingbird的v1变体”和“v2版本”的变化来看,Mockingbird正在经历持续的开发和改进过程。软件版本迭代是常见的开发实践,有助于修复已知问题,改善性能和用户体验,添加新功能等。 3. 服务器性能要求: 描述中强调了运行Mockingbird的服务器需要具备一定的性能,例如提及“WitherHosting的$ 1.25计划”,这暗示了反作弊系统对服务器资源的需求较高。这可能是因为反作弊机制需要频繁处理大量的数据和事件,以便及时检测和阻止作弊行为。 4. Waterdog问题: Waterdog是另一种Minecraft服务器软件,特别适合 PocketMine-MP。描述中提到如果将Mockingbird和Waterdog结合使用可能会遇到问题,这可能是因为两者在某些机制上的不兼容或Mockingbird对Waterdog的特定实现尚未完全优化。 5. GitHub使用及问题反馈: 作者鼓励用户通过GitHub问题跟踪系统来报告问题、旁路和功能建议。这是一个公共代码托管平台,广泛用于开源项目协作,便于开发者和用户进行沟通和问题管理。作者还提到请用户在GitHub上发布问题而不是在评论区留下不好的评论,这体现了良好的社区维护和用户交流的实践。 6. 软件标签: “pocketmine”和“anticheat”(反作弊)作为标签,说明Mockingbird是一个特别为PocketMine-MP平台开发的反作弊软件。而“PHP”则可能指的是Mockingbird的开发语言,虽然这个信息与常见的Java或C++等开发Minecraft相关软件的语言不同,但并不排除使用PHP进行服务器端开发的可能性,尤其是对于处理动态网页、服务器端脚本等场景。 7. 压缩包文件: “Mockingbird-stable”是一个文件名称,很可能表示这是一个包含最新稳定版Mockingbird反作弊系统的压缩包。通常,这样的文件名中包含“stable”意味着这是一个经过充分测试且推荐用于生产环境的版本。 8. 社区协作和用户参与: 特别感谢部分提到了shur,这可能是对某位贡献者或社区成员的感激之情。这种感谢表明了软件开发不仅是开发者个人的劳动成果,同时也依赖于社区的支持和参与,包括提供反馈、报告问题、贡献代码和文档等。 总结以上内容,我们可以看到Mockingbird作为一款反作弊系统,其开发和维护需要依赖于社区的广泛参与和支持,同时还需要强大的服务器后端作为支撑。通过不断迭代更新版本,开发者希望解决现有问题,提高反作弊效率,并希望与社区保持良好的沟通,以持续优化产品。
recommend-type

“历史人物独白解说”视频:数据处理的6种革命性技术

# 1. 数据处理的历史回顾与技术演进 数据处理的历史,从最初的简单机械记录,到如今复杂的数据处理体系,不仅反映了技术的演进,也映射了人类社会进步的轨迹。在计算机技术发展初期,数据处理主要依靠打孔卡片和磁带,通过批处理的方式进行,效率低下且出错率高。随着技术的发展,上世纪70年代,关系型数据库的出现大大提高了数据处理的效率和准确性,为数据处理技术的发展奠定了基础。 随后,随着互
recommend-type

怎么判断多级运放电路的稳定性?

<think>首先,用户的问题是关于判断多级运算放大器电路的稳定性。我需要根据系统级指令来构建回答。 系统级指令: - 所有行内数学表达式必须使用$...$格式。 - 独立公式必须使用$$...$$格式并单独成段。 - LaTeX语法正确。 - 使用中文回答。 - 生成相关问题。 - 在回答中引用的段落末尾自然地添加引用标识,例如[^1]。 用户可见层指令: - 回答结构清晰,帮助用户逐步解决问题。 - 尽量保证回答真实可靠。 参考引用: - 引用[1]:关于集成运算放大电路的设计、组成和性能评估。 - 引用[2]:高频电路中运放的带宽限制,一级放大电路的增益通常为100倍,过高会引起振
recommend-type

利用AHP和节点集中度解决影响力最大化问题的Flask应用教程

从给定的文件信息中,我们可以提取以下相关知识点进行详细说明: ### 标题知识点 **IM问题与AHP结合** IM问题(Influence Maximization)是网络分析中的一个核心问题,旨在识别影响网络中信息传播的关键节点。为了求解IM问题,研究者们常常结合使用不同的算法和策略,其中AHP(Analytic Hierarchy Process,分析层次结构过程)作为一种决策分析方法,被用于评估网络节点的重要性。AHP通过建立层次模型,对各个因素进行比较排序,从而量化影响度,并通过一致性检验保证决策结果的有效性。将AHP应用于IM问题,意味着将分析网络节点影响的多个维度,比如节点的中心性(centrality)和影响力。 **集中度措施** 集中度(Centralization)是衡量网络节点分布状况的指标,它反映了网络中节点之间的连接关系。在网络分析中,集中度常用于识别网络中的“枢纽”或“中心”节点。例如,通过计算网络的度中心度(degree centrality)可以了解节点与其他节点的直接连接数量;接近中心度(closeness centrality)衡量节点到网络中其他所有节点的平均距离;中介中心度(betweenness centrality)衡量节点在连接网络中其他节点对的最短路径上的出现频率。集中度高意味着节点在网络中处于重要位置,对信息的流动和控制具有较大影响力。 ### 描述知识点 **Flask框架** Flask是一个轻量级的Web应用框架,它使用Python编程语言开发。它非常适合快速开发小型Web应用,以及作为微服务架构的一部分。Flask的一个核心特点是“微”,意味着它提供了基本的Web开发功能,同时保持了框架的小巧和灵活。Flask内置了开发服务器,支持Werkzeug WSGI工具包和Jinja2模板引擎,提供了RESTful请求分发和请求钩子等功能。 **应用布局** 一个典型的Flask应用会包含以下几个关键部分: - `app/`:这是应用的核心目录,包含了路由设置、视图函数、模型和控制器等代码文件。 - `static/`:存放静态文件,比如CSS样式表、JavaScript文件和图片等,这些文件的内容不会改变。 - `templates/`:存放HTML模板文件,Flask将使用这些模板渲染最终的HTML页面。模板语言通常是Jinja2。 - `wsgi.py`:WSGI(Web Server Gateway Interface)是Python应用程序和Web服务器之间的一种标准接口。这个文件通常用于部署到生产服务器时,作为应用的入口点。 **部署到Heroku** Heroku是一个支持多种编程语言的云平台即服务(PaaS),它允许开发者轻松部署、运行和管理应用。部署Flask应用到Heroku,需要几个步骤:首先,创建一个Procfile文件,告知Heroku如何启动应用;其次,确保应用的依赖关系被正确管理,通常通过一个requirements.txt文件列出所有依赖;最后,使用Git将应用推送到Heroku提供的仓库,Heroku会自动识别Procfile并开始部署过程。 ### 标签知识点 **HTML** HTML(HyperText Markup Language,超文本标记语言)是用于创建网页和Web应用的标准标记语言。它定义了网页的结构和内容。HTML文件由一系列元素组成,这些元素通过标签(tags)来表示,如`<p>`代表段落,`<a>`代表链接,`<img>`代表图像等。HTML5是当前使用的最新版本,支持更多的特性,如离线存储、多媒体和图形等。 ### 压缩包子文件的文件名称列表知识点 **IMproblem-using-AHP-and-centralisation-of-nodes-master** 这里的文件名称“IMproblem-using-AHP-and-centralisation-of-nodes-master”表明了一个GitHub仓库的名称,其中包含了源代码以及与项目相关的所有文件。从名称中可以看出,该仓库是关于如何结合AHP和节点集中度分析来解决IM问题的Flask应用程序。文件名中的“master”表明这是仓库的主分支(现在叫做main分支),它是项目最新的、可部署的代码版本。 综合来看,本段信息为我们提供了构建和部署一个使用Flask框架、针对IM问题使用AHP和节点集中度分析的Web应用的方法和步骤。同时,介绍了应用在不同环节中所需技术和组件的详细知识点。
recommend-type

视频内容自动生成算法:突破性的8大最新进展

# 1. 视频内容自动生成算法概述 ## 算法发展背景 随着人工智能技术的迅速发展,视频内容自动生成算法已经成为媒体和娱乐行业的重要工具。这些算法能够自动编辑和合成视频内容,使内容创作者能够以较低的成本和时间生成高质量的视频。从社交媒体动态到在线教育内容,视频内容自动生成的应用场景正在不断扩大。 ## 核心技术简述 视
recommend-type

Softmax函数实际应用举例

<think>嗯,用户现在想了解Softmax函数的实际应用场景,这和我之前详细解释过的Softmax原理是直接相关的。用户特意提到要参考站内引用,看来是想看到具体案例支撑。 从用户提问方式看,ta应该已经理解了Softmax的基本数学原理(毕竟我上次用向量[2,1,0.1]的例子详细演示过计算过程),现在需要落地到实践层面。这种从理论到应用的递进很合理,可能是个正在学习机器学习的学生,或者需要解决实际问题的工程师。 我注意到用户提供的引用里有些关键线索:引用[1]提到图像分类和概率解释,引用[4]强调指数放大的特性,引用[5]则对比了Sigmoid在多标签分类的应用差异。这些正好能支撑我
recommend-type

WDI项目1:PriceIsRight游戏开发实践

### 标题解析 标题“price-is-right:WDI项目1-PriceIsRight游戏”表明这是一个名为“Price Is Right”的游戏项目,这是WDI(Web Development Immersive,全栈网页开发沉浸式课程)的第一个项目。WDI是一种常用于IT培训机构的课程名称,旨在通过实战项目来培养学员的全栈网页开发能力。 ### 描述解析 描述中提到,该游戏的目的是为了练习基本的JavaScript技能。这表明游戏被设计成一个编程练习,让开发者通过实现游戏逻辑来加深对JavaScript的理解。描述中也提到了游戏是一个支持两个玩家的版本,包含了分配得分、跟踪得分以及宣布获胜者等逻辑,这是游戏开发中常见的功能实现。 开发者还提到使用了Bootstrap框架来增加网站的可伸缩性。Bootstrap是一个流行的前端框架,它让网页设计和开发工作更加高效,通过提供预设的CSS样式和JavaScript组件,让开发者能够快速创建出响应式的网站布局。此外,开发者还使用了HTML5和CSS进行网站设计,这表明项目也涉及到了前端开发的基础技能。 ### 标签解析 标签“JavaScript”指出了该游戏中核心编程语言的使用。JavaScript是一种高级编程语言,常用于网页开发中,负责实现网页上的动态效果和交互功能。通过使用JavaScript,开发者可以在不离开浏览器的情况下实现复杂的游戏逻辑和用户界面交互。 ### 文件名称解析 压缩包子文件的文件名称列表中仅提供了一个条目:“price-is-right-master”。这里的“master”可能指明了这是项目的主分支或者主版本,通常在版本控制系统(如Git)中使用。文件名中的“price-is-right”与标题相呼应,表明该文件夹内包含的代码和资源是与“Price Is Right”游戏相关的。 ### 知识点总结 #### 1. JavaScript基础 - **变量和数据类型**:用于存储得分等信息。 - **函数和方法**:用于实现游戏逻辑,如分配得分、更新分数。 - **控制结构**:如if-else语句和循环,用于实现游戏流程控制。 - **事件处理**:监听玩家的输入(如点击按钮)和游戏状态的变化。 #### 2. Bootstrap框架 - **网格系统**:实现响应式布局,让游戏界面在不同设备上都能良好展示。 - **预设组件**:可能包括按钮、表单、警告框等,用于快速开发用户界面。 - **定制样式**:根据需要自定义组件样式来符合游戏主题。 #### 3. HTML5与CSS - **语义化标签**:使用HTML5提供的新标签来构建页面结构,如`<header>`, `<section>`, `<footer>`等。 - **CSS布局**:使用Flexbox或Grid等布局技术对页面元素进行定位和排版。 - **样式设计**:通过CSS为游戏界面增添美观的视觉效果。 #### 4. 项目结构和版本控制 - **主分支管理**:`master`分支通常保存着项目的稳定版本,用于部署生产环境。 - **代码组织**:合理的文件结构有助于维护和扩展项目。 #### 5. 前端开发最佳实践 - **分离关注点**:将样式、脚本和内容分离,确保代码清晰易维护。 - **响应式设计**:确保游戏在多种设备和屏幕尺寸上均有良好的用户体验。 - **可访问性**:考虑键盘导航、屏幕阅读器等无障碍功能,让游戏更加友好。 #### 6. 交互式游戏开发 - **游戏逻辑实现**:创建一个简单的游戏循环,管理玩家输入和得分更新。 - **状态管理**:游戏中的得分和其他游戏状态需要妥善保存和更新。 - **用户界面反馈**:提供即时的视觉和听觉反馈,增强玩家体验。 通过上述知识点的解析,可以看出“Price Is Right”游戏项目不仅仅是一个简单的编程练习,它还融合了多种前端技术,包括JavaScript、Bootstrap、HTML5和CSS,以实现一个完整的、可交互的游戏体验。此项目也反映了开发者在掌握前端开发技能的同时,了解了如何组织代码、维护项目结构和实践开发最佳实践。
recommend-type

人工智能视频编辑:如何利用技术进步提升内容创作质量

# 1. 人工智能视频编辑概述 随着人工智能技术的飞速发展,视频编辑领域正在经历一场前所未有的革命。AI的介入,不仅极大地提升了视频编辑的效率,还赋予了内容创作者全新的表达方式。本章旨在概述人工智能视频编辑的概念、发展历程和当前的应用现状,为读者提供一个全面而深入的了解。 ## 1.1 人工智能视频编辑的兴起 人工智能视频编辑是将先进的机器学习算法与传统视频处理技术相
recommend-type

反激变换器

<think>首先,用户意图是了解反激变换器的工作原理或设计方法。用户的问题是:“反激变换器工作原理及设计指南”。所以我需要基于这个意图和问题,通过调用网络搜索工具进行检索。 我的任务是: 1. 调用网络搜索工具来检索相关内容。 2. 整合检索到的内容,生成详细、清晰、实用、可操作的回答。 3. 禁止将所有引用内容集中在回答末尾;引用应该融入回答中。 4. 避免使用第一人称如“我”。 5. 避免步骤词汇如“首先”、“然后”。 6. 将答案组织为多个方法或步骤,并在每个步骤间换行。 7. 对于代码和公式,遵循特定格式: - 行内公式:$公式内容$ - 独立公式:$$公式内容$$