diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 04f8cdf7e..60ef8e207 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2025-11-04, AI: Fix AAC audio sample rate reporting in API. v7.0.101 (#4518) * v7.0, 2025-10-20, Merge [#4537](https://github.com/ossrs/srs/pull/4537): Forward: Reject RTMPS destinations with clear error message. v7.0.100 (#4537) * v7.0, 2025-10-17, Merge [#4534](https://github.com/ossrs/srs/pull/4534): HLS: Fix a iterator bug in hls_ctx cleanup function. v7.0.99 (#4534) * v7.0, 2025-10-16, Merge [#4530](https://github.com/ossrs/srs/pull/4530): fix crash issue caused by reload configuration file. v7.0.98 (#4530) diff --git a/trunk/src/app/srs_app_rtmp_source.cpp b/trunk/src/app/srs_app_rtmp_source.cpp index 232786d18..3deb096cb 100644 --- a/trunk/src/app/srs_app_rtmp_source.cpp +++ b/trunk/src/app/srs_app_rtmp_source.cpp @@ -997,7 +997,14 @@ srs_error_t SrsOriginHub::on_audio(SrsMediaPacket *shared_audio) static int flv_sound_types[] = {1, 2, 0}; // when got audio stream info. - if ((err = stat_->on_audio_info(req_, format->acodec_->id_, c->sound_rate_, c->sound_type_, c->aac_object_)) != srs_success) { + // For AAC, convert aac_sample_rate_ index to SrsAudioSampleRate enum + // For MP3 and other codecs, use sound_rate_ directly (FLV enum) + SrsAudioSampleRate sample_rate = c->sound_rate_; + if (format->acodec_->id_ == SrsAudioCodecIdAAC && c->aac_sample_rate_ < SrsAAcSampleRateNumbers) { + sample_rate = srs_audio_sample_rate_from_number(srs_aac_srates[c->aac_sample_rate_]); + } + + if ((err = stat_->on_audio_info(req_, format->acodec_->id_, sample_rate, c->sound_type_, c->aac_object_)) != srs_success) { return srs_error_wrap(err, "stat audio"); } diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 3ef88dc60..7873a1d61 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -166,7 +166,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject *obj) obj->set("audio", audio); audio->set("codec", SrsJsonAny::str(srs_audio_codec_id2str(acodec_).c_str())); - audio->set("sample_rate", SrsJsonAny::integer(srs_flv_srates[asample_rate_])); + audio->set("sample_rate", SrsJsonAny::integer(srs_audio_sample_rate2number(asample_rate_))); audio->set("channel", SrsJsonAny::integer(asound_type_ + 1)); audio->set("profile", SrsJsonAny::str(srs_aac_object2str(aac_object_).c_str())); } diff --git a/trunk/src/core/srs_core_version7.hpp b/trunk/src/core/srs_core_version7.hpp index 3d199c7ba..1c1366458 100644 --- a/trunk/src/core/srs_core_version7.hpp +++ b/trunk/src/core/srs_core_version7.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 7 #define VERSION_MINOR 0 -#define VERSION_REVISION 100 +#define VERSION_REVISION 101 #endif \ No newline at end of file diff --git a/trunk/src/utest/srs_utest_ai17.cpp b/trunk/src/utest/srs_utest_ai17.cpp index 9ab045082..f0e0e36bd 100644 --- a/trunk/src/utest/srs_utest_ai17.cpp +++ b/trunk/src/utest/srs_utest_ai17.cpp @@ -3012,6 +3012,45 @@ VOID TEST(StatisticTest, StreamMediaInfo) EXPECT_EQ(55, stream->frames_->sugar_); } +// Test SrsStatistic audio sample rate handling for AAC 48000 Hz +// This test verifies the fix for issue #4518 - API should report correct sample rate for AAC streams +VOID TEST(StatisticTest, AudioSampleRateAAC48000Hz) +{ + srs_error_t err = srs_success; + + // Create SrsStatistic instance + SrsUniquePtr stat(new SrsStatistic()); + + // Create mock request for testing + SrsUniquePtr req(new MockSrsRequest("test.vhost", "live", "stream_48k")); + + // Test on_audio_info() with AAC 48000 Hz sample rate + HELPER_EXPECT_SUCCESS(stat->on_audio_info(req.get(), SrsAudioCodecIdAAC, SrsAudioSampleRate48000, SrsAudioChannelsStereo, SrsAacObjectTypeAacLC)); + + // Verify audio info was set correctly + SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); + EXPECT_TRUE(stream != NULL); + EXPECT_TRUE(stream->has_audio_); + EXPECT_EQ(SrsAudioCodecIdAAC, stream->acodec_); + EXPECT_EQ(SrsAudioSampleRate48000, stream->asample_rate_); + EXPECT_EQ(SrsAudioChannelsStereo, stream->asound_type_); + EXPECT_EQ(SrsAacObjectTypeAacLC, stream->aac_object_); + + // Verify JSON dumps reports correct sample rate (48000 Hz, not 44100 Hz) + SrsUniquePtr obj(SrsJsonAny::object()); + HELPER_EXPECT_SUCCESS(stream->dumps(obj.get())); + + // Check that audio object exists and has correct sample_rate + SrsJsonAny *audio_any = obj->get_property("audio"); + EXPECT_TRUE(audio_any != NULL); + EXPECT_TRUE(audio_any->is_object()); + + SrsJsonObject *audio = audio_any->to_object(); + SrsJsonAny *sample_rate_any = audio->get_property("sample_rate"); + EXPECT_TRUE(sample_rate_any != NULL); + EXPECT_EQ(48000, sample_rate_any->to_integer()); +} + // Test SrsStatistic dumps methods: dumps_streams, dumps_clients, and dumps_hints_kv // This test covers the major use scenario for dumping statistics to JSON and hints VOID TEST(StatisticTest, DumpsStreamsClientsAndHints)